From patchwork Thu Nov 3 02:04:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jojo R X-Patchwork-Id: 14588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp263998wru; Wed, 2 Nov 2022 19:04:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4QEFHt660bNEZFmR/wonQV4k7tiq/T8knjlRoAKJ8zpaR34vCdveCVs5ZS26gQhjOIXsTc X-Received: by 2002:a05:6402:4d9:b0:462:e787:3bf8 with SMTP id n25-20020a05640204d900b00462e7873bf8mr27785134edw.195.1667441068229; Wed, 02 Nov 2022 19:04:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667441068; cv=none; d=google.com; s=arc-20160816; b=Ufb42JaJJ/ST60bQvCh/5KNkHFNtCawoDNQTvlNuREV8yd8seIgR2lfICGF03IVgW5 ucEAFDfxnlA7nxQwXgFAhbDg6h2tngIqrpWl+HbiGfvSqbTys6znOr0E1M4XygxXY0eV fHizUJpsNM5yMrT8MBxhu65Wky77KAsW3IXNNRW6WqpaNk5l2xGp9JDjxIOkzaILwt33 X/2FIPgVPzXrog57Iw+JvszZxFmVE6FCty6oy6HbsS2yO3hFF+bPAxZZAzx8cZjCiOue 1aFw6OHHgxbm5tlV4NhNAjbsFIFU/WdYcOdbm/nRZg7+76aOPzvFMtWhijgwW2ensUf6 Soow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=qRU0Io24Xy5fh3lxj8AT/rvYBRm3w6QgdEmedDv6Ugw=; b=EsNqW5Cl969zsg4CDXtQ6XqO8sGISw9r83rkMTWxj4P3/geextHBuI4WSnkWg4wayj a0TXhuHL1skaFXKeR8Q8i8ufT6+Eqb7Sk2AjUSOHEVCSwWuJIv/B9oSL9FLNmfbHfAqP wnEGUm24ZcjI7BXuEVZJKmJ5SZ9rhqK52URVgnE2njHH9HYDyPJOa8v53z5Fx9wH6iwv jigErV+Y8OQ9tKlCMbiZn4fVgrvMN3Eu08FHDIOrqPQh61bq5HyCpecSM2LmN8KeOlGD lx8PZ16VcoFod+UXzIhOzLFjFoMaY8l/5ZfX14/2rAdQQbdmah8um0hYha25vsnIBA/Z TBNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=ktFkhiDO; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b20-20020aa7df94000000b00458cdba7a90si14699872edy.471.2022.11.02.19.04.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 19:04:28 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=ktFkhiDO; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6989D3858C2C for ; Thu, 3 Nov 2022 02:04:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6989D3858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667441065; bh=qRU0Io24Xy5fh3lxj8AT/rvYBRm3w6QgdEmedDv6Ugw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ktFkhiDOJBMaE4y/nBZPZpSOtCfCCVrX7nr1aLKFbFXnAkX4dBYWf6e6rN8CMSq7s pqrWHHvWh3AAJcZ7zPk9tyxm70KZHBFIPEKOQqZu2qp1eMRblUx/H44aCRugs1uSYI HNdJSfWJu6SfxoDyYCMgdSW/m1px5LQ68kyyKqT8= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by sourceware.org (Postfix) with ESMTPS id 9E0A0385840F for ; Thu, 3 Nov 2022 02:04:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9E0A0385840F X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R411e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018046050; MF=rjiejie@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0VTqQwd3_1667441051; Received: from localhost(mailfrom:rjiejie@linux.alibaba.com fp:SMTPD_---0VTqQwd3_1667441051) by smtp.aliyun-inc.com; Thu, 03 Nov 2022 10:04:12 +0800 To: nickc@redhat.com, rjiejie@linux.alibaba.com, binutils@sourceware.org Subject: [PATCH v3] Support multiple .eh_frame sections Date: Thu, 3 Nov 2022 10:04:09 +0800 Message-Id: <20221103020409.37322-1-rjiejie@linux.alibaba.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20221102080112.33378-1-rjiejie@linux.alibaba.com> References: <20221102080112.33378-1-rjiejie@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.1 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jojo R via Binutils From: Jojo R Reply-To: Jojo R Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748370553763802186?= X-GMAIL-MSGID: =?utf-8?q?1748438685625675240?= This patch is based on MULTIPLE_FRAME_SECTIONS and EH_FRAME_LINKONCE, it allows backend to enable this feature and use '--gc-sections' simply. * gas/dw2gencfi.h (TARGET_MULTIPLE_EH_FRAME_SECTIONS): New. (MULTIPLE_FRAME_SECTIONS): Add TARGET_MULTIPLE_EH_FRAME_SECTIONS. * gas/dw2gencfi.c (EH_FRAME_LINKONCE): Add TARGET_MULTIPLE_EH_FRAME_SECTIONS. (is_now_linkonce_segment): Likewise. (get_cfi_seg): Create relocation info between .eh_frame.* and .text.* section. * bfd/elf-bfd.h (elf_backend_can_make_multiple_eh_frame): New. * bfd/elfxx-target.h (elf_backend_can_make_multiple_eh_frame): Likewise. * bfd/elflink.c (_bfd_elf_default_action_discarded): Add checking for elf_backend_can_make_multiple_eh_frame. --- bfd/elf-bfd.h | 3 +++ bfd/elflink.c | 7 +++++++ bfd/elfxx-target.h | 4 ++++ gas/doc/internals.texi | 4 ++++ gas/dw2gencfi.c | 27 +++++++++++++++++++++++++-- gas/dw2gencfi.h | 7 ++++++- 6 files changed, 49 insertions(+), 3 deletions(-) diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index f00f87b2779..fa4b9bcf193 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -1432,6 +1432,9 @@ struct elf_backend_data bool (*elf_backend_can_make_lsda_relative_eh_frame) (bfd *, struct bfd_link_info *, asection *); + /* Tell linker to support multiple eh_frame sections. */ + bool elf_backend_can_make_multiple_eh_frame; + /* This function returns an encoding after computing the encoded value (and storing it in ENCODED) for the given OFFSET into OSEC, to be stored in at LOC_OFFSET into the LOC_SEC input section. diff --git a/bfd/elflink.c b/bfd/elflink.c index 89dcf26108c..019ac302905 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -10924,12 +10924,19 @@ elf_section_ignore_discarded_relocs (asection *sec) unsigned int _bfd_elf_default_action_discarded (asection *sec) { + const struct elf_backend_data *bed; + bed = get_elf_backend_data (sec->owner); + if (sec->flags & SEC_DEBUGGING) return PRETEND; if (strcmp (".eh_frame", sec->name) == 0) return 0; + if (bed->elf_backend_can_make_multiple_eh_frame + && strncmp (sec->name, ".eh_frame.", 10) == 0) + return 0; + if (strcmp (".gcc_except_table", sec->name) == 0) return 0; diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index ca600bb5ddf..f39244e7f52 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -658,6 +658,9 @@ #ifndef elf_backend_can_make_lsda_relative_eh_frame #define elf_backend_can_make_lsda_relative_eh_frame _bfd_elf_can_make_relative #endif +#ifndef elf_backend_can_make_multiple_eh_frame +#define elf_backend_can_make_multiple_eh_frame 0 +#endif #ifndef elf_backend_encode_eh_address #define elf_backend_encode_eh_address _bfd_elf_encode_eh_address #endif @@ -891,6 +894,7 @@ static const struct elf_backend_data elfNN_bed = elf_backend_eh_frame_address_size, elf_backend_can_make_relative_eh_frame, elf_backend_can_make_lsda_relative_eh_frame, + elf_backend_can_make_multiple_eh_frame, elf_backend_encode_eh_address, elf_backend_write_section, elf_backend_elfsym_local_is_section, diff --git a/gas/doc/internals.texi b/gas/doc/internals.texi index a91d2ab9c1e..f0288746d78 100644 --- a/gas/doc/internals.texi +++ b/gas/doc/internals.texi @@ -1581,6 +1581,10 @@ If defined, GAS will check this macro before performing any optimizations on the DWARF call frame debug information that is emitted. Targets which implement link time relaxation may need to define this macro and set it to zero if it is possible to change the size of a function's prologue. + +@item TARGET_MULTIPLE_EH_FRAME_SECTIONS +If defined, GAS will create multiple .eh_frame.* sections according to +the name of owner's function sections. @end table @node Object format backend diff --git a/gas/dw2gencfi.c b/gas/dw2gencfi.c index 6be8cb50495..80b26289289 100644 --- a/gas/dw2gencfi.c +++ b/gas/dw2gencfi.c @@ -75,7 +75,8 @@ # define tc_cfi_endproc(fde) ((void) (fde)) #endif -#define EH_FRAME_LINKONCE (SUPPORT_FRAME_LINKONCE || compact_eh) +#define EH_FRAME_LINKONCE (SUPPORT_FRAME_LINKONCE || compact_eh \ + || TARGET_MULTIPLE_EH_FRAME_SECTIONS) #ifndef DWARF2_FORMAT #define DWARF2_FORMAT(SEC) dwarf2_format_32bit @@ -277,6 +278,9 @@ is_now_linkonce_segment (void) if (compact_eh) return now_seg; + if (TARGET_MULTIPLE_EH_FRAME_SECTIONS) + return now_seg; + if ((bfd_section_flags (now_seg) & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE @@ -1333,14 +1337,33 @@ static segT get_cfi_seg (segT cseg, const char *base, flagword flags, int align) { /* Exclude .debug_frame sections for Compact EH. */ - if (SUPPORT_FRAME_LINKONCE || ((flags & SEC_DEBUGGING) == 0 && compact_eh)) + if (SUPPORT_FRAME_LINKONCE || ((flags & SEC_DEBUGGING) == 0 && compact_eh) + || ((flags & SEC_DEBUGGING) == 0 && TARGET_MULTIPLE_EH_FRAME_SECTIONS)) { + segT iseg = cseg; struct dwcfi_seg_list *l; l = dwcfi_hash_find_or_make (cseg, base, flags); cseg = l->seg; subseg_set (cseg, l->subseg); + + if (TARGET_MULTIPLE_EH_FRAME_SECTIONS + && (flags & DWARF2_EH_FRAME_READ_ONLY)) + { + const frchainS *ifrch = seg_info (iseg)->frchainP; + const frchainS *frch = seg_info (cseg)->frchainP; + expressionS exp; + + exp.X_op = O_symbol; + exp.X_add_symbol = (symbolS *) local_symbol_make (cseg->name, cseg, frch->frch_root, 0); + exp.X_add_number = 0; + subseg_set (iseg, ifrch->frch_subseg); + fix_new_exp (ifrch->frch_root, 0, 0, &exp, 0, BFD_RELOC_NONE); + + /* Restore the original segment info. */ + subseg_set (cseg, l->subseg); + } } else { diff --git a/gas/dw2gencfi.h b/gas/dw2gencfi.h index d570cdb8db3..0f5ae77d800 100644 --- a/gas/dw2gencfi.h +++ b/gas/dw2gencfi.h @@ -66,7 +66,12 @@ extern void cfi_add_CFA_restore_state (void); #define SUPPORT_COMPACT_EH 0 #endif -#define MULTIPLE_FRAME_SECTIONS (SUPPORT_FRAME_LINKONCE || SUPPORT_COMPACT_EH) +#ifndef TARGET_MULTIPLE_EH_FRAME_SECTIONS +#define TARGET_MULTIPLE_EH_FRAME_SECTIONS 0 +#endif + +#define MULTIPLE_FRAME_SECTIONS (SUPPORT_FRAME_LINKONCE || SUPPORT_COMPACT_EH \ + || TARGET_MULTIPLE_EH_FRAME_SECTIONS) struct cfi_insn_data {