From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by sourceware.org (Postfix) with ESMTPS id CDF55393FC25 for ; Thu, 19 Mar 2020 00:48:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CDF55393FC25 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=maskray.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=emacsray@gmail.com Received: by mail-pl1-f195.google.com with SMTP id g6so270792plt.2 for ; Wed, 18 Mar 2020 17:48:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:in-reply-to:user-agent; bh=fdZP8teVNDgtwZ5Mxfz/wD/TKjd2CL40O3Hp8ysI2PQ=; b=syFTQahtnOuFKq98E6ccxaXUEpUQ1FhL35kztyqfJcehpTg94IiDvKgBhAtbAeqDJm FFRlrw2YPHFBQnpeH8GpPIjt3JHpPyugZC3RHC74K2iaca/wBd+xu5/Zh+cH8YDD6uYW zjtMvtoPyjPFqwIGf+WDDUO9/hff8mgx83F+3qKYPx86WA815MHqcCWzWjp0Ws0NtbFU d2JccWbTuEYXeV8xSAcqrWtXpG+ch5dyFGAugQQn0Xdekv8FKpwuamfDL/YXKWCsiMgT Kw6kTYeV1VgawM28CMQogApnVJnX73rEvtRNZ1DKP41yC1PzScsBXWqQ/hKJi8wI7mo9 O1mw== X-Gm-Message-State: ANhLgQ0ZjnjcT9n+HQwakFp8VdhhGMNgOuto6IbWo4gx3rVfStZKwSzV b+M86liiVYXxB9GaaahxvLw= X-Google-Smtp-Source: ADFU+vsP1AJVRvbReS9d31PliAlEqZptWxQbdTY9QuP8sUwUy/NeOKrHIbuVD3gEmJgYGus26LSS6A== X-Received: by 2002:a17:90a:7f95:: with SMTP id m21mr952454pjl.168.1584578899813; Wed, 18 Mar 2020 17:48:19 -0700 (PDT) Received: from localhost ([2601:647:4b01:ae80::51fb]) by smtp.gmail.com with ESMTPSA id e30sm242244pga.6.2020.03.18.17.48.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 17:48:19 -0700 (PDT) Date: Wed, 18 Mar 2020 17:48:18 -0700 From: Fangrui Song To: hjl.tools@gmail.com Cc: binutils@sourceware.org Subject: Re: [PATCH 0/7] ELF: Don't require section header on ELF objects Message-ID: <20200319004818.GA17438@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200308234242.1225816-1-hjl.tools@gmail.com> User-Agent: Mutt/1.12.2 (2019-09-21) X-Spam-Status: No, score=-12.5 required=5.0 tests=FAKE_REPLY_C, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Thu, 19 Mar 2020 00:48:22 -0000 >Section header isn't mandatory on ELF executable nor shared library. >This patch set adds a new linker option, -z nosectionheader, to omit >ELF section header when building an executable or shared library, an >objcopy and strip option, --remove-section-header, to remove ELF >section header from an executable or shared library. > >The PT_DYNAMIC segment contains DT_HASH/DT_GNU_HASH/DT_MIPS_XHASH, >DT_STRTAB, DT_SYMTAB, DT_STRSZ and DT_SYMENT entries, which can be >used to reconstruct dynamic symbol table when section header isn't >available. For DT_HASH, the number of dynamic symbol table entries >equals the number of chains. For DT_GNU_HASH/DT_MIPS_XHASH, only >defined symbols with non-STB_LOCAL indings are in hash table. Since >in dynamic symbol table, all symbols with STB_LOCAL binding are placed >before symbols with other bindings and all undefined symbols are placed >before defined ones, the highest symbol index in DT_GNU_HASH and >DT_MIPS_XHASH is the highest dynamic symbol table index. > > >H.J. Lu (5): > bfd: Reconstruct dynamic symbol table from PT_DYNAMIC segment > readelf: Compute dynamic symbol table size from hash table > binutils: Add --remove-section-header tests > ld: Add tests for -z nosectionheader and --remove-section-header > ld: Add -z nosectionheader test to bootstrap.exp > >Kaylee Blake (2): > ELF: Don't require section header on ELF objects > ld: Add a simple test for -z nosectionheader > > bfd/bfd-in2.h | 8 +- > bfd/bfd.c | 8 +- > bfd/elf-bfd.h | 8 + > bfd/elf.c | 443 ++++++++++++++++++ > bfd/elfcode.h | 174 ++++++- > bfd/elflink.c | 148 ++++-- > bfd/elfxx-target.h | 6 +- > binutils/NEWS | 3 + > binutils/doc/binutils.texi | 12 + > binutils/objcopy.c | 54 ++- > binutils/readelf.c | 226 ++++----- > binutils/testsuite/binutils-all/objcopy.exp | 13 + > .../testsuite/binutils-all/remove-header-1.d | 8 + > ld/NEWS | 3 + > ld/emultempl/elf.em | 4 + > ld/ld.h | 3 + > ld/ld.texi | 6 + > ld/ldlang.c | 4 + > ld/lexsup.c | 12 + > ld/testsuite/ld-bootstrap/bootstrap.exp | 10 +- > ld/testsuite/ld-elf/hash.d | 8 +- > ld/testsuite/ld-elf/no-section-header.exp | 336 +++++++++++++ > ld/testsuite/ld-elf/nosectionheader.d | 12 + > ld/testsuite/ld-elf/pr13195.d | 2 +- > ld/testsuite/ld-elf/pr22393-2a-no-sec-hdr.nd | 3 + > ld/testsuite/ld-elf/pr22393-2a-no-sec-hdr.rd | 20 + > ld/testsuite/ld-elf/pr22393-2a-sec-hdr.rd | 19 + > ld/testsuite/ld-elf/pr22393-2b-no-sec-hdr.nd | 3 + > ld/testsuite/ld-elf/pr22393-2b-no-sec-hdr.rd | 20 + > .../ld-elf/pr22393-2b-static-no-sec-hdr.rd | 12 + > ld/testsuite/ld-elf/start-noheader.rd | 11 + > .../ld-elf/start-shared-noheader-gnu.rd | 22 + > .../ld-elf/start-shared-noheader-sysv.rd | 22 + > ld/testsuite/ld-elf/start-shared-noheader.nd | 5 + > ld/testsuite/ld-elfvsb/hidden2.d | 2 +- > ld/testsuite/ld-mips-elf/hash2.d | 8 +- > 36 files changed, 1458 insertions(+), 200 deletions(-) > create mode 100644 binutils/testsuite/binutils-all/remove-header-1.d > create mode 100644 ld/testsuite/ld-elf/no-section-header.exp > create mode 100644 ld/testsuite/ld-elf/nosectionheader.d > create mode 100644 ld/testsuite/ld-elf/pr22393-2a-no-sec-hdr.nd > create mode 100644 ld/testsuite/ld-elf/pr22393-2a-no-sec-hdr.rd > create mode 100644 ld/testsuite/ld-elf/pr22393-2a-sec-hdr.rd > create mode 100644 ld/testsuite/ld-elf/pr22393-2b-no-sec-hdr.nd > create mode 100644 ld/testsuite/ld-elf/pr22393-2b-no-sec-hdr.rd > create mode 100644 ld/testsuite/ld-elf/pr22393-2b-static-no-sec-hdr.rd > create mode 100644 ld/testsuite/ld-elf/start-noheader.rd > create mode 100644 ld/testsuite/ld-elf/start-shared-noheader-gnu.rd > create mode 100644 ld/testsuite/ld-elf/start-shared-noheader-sysv.rd > create mode 100644 ld/testsuite/ld-elf/start-shared-noheader.nd > >-- >2.24.1 For objcopy --remove-section-header, we can probably implement an enhanced feature --strip-sections first. eu-strip and llvm-objcopy (since https://reviews.llvm.org/D38335) have --strip-sections. --strip-sections strips the section header table and sections not covered by a segment. In llvm-objcopy, a non-SHF_ALLOC section can covered by a segment. For -z nosectionheader, I am questioning about the potential use case. As others have commented on the thread "ELF: Don't require section header on ELF objects", such shared objects should not be used for link. For runtime only use cases, perhaps we can do that with a post-processing tool. For readelf dumping of PT_DYNAMIC and DT_GNU_HASH, I think they are useful features.