From patchwork Tue Jun 6 17:58:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 10374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3574460vqr; Tue, 6 Jun 2023 10:59:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4TVdhT5O9mXX2GagMGVaQ2N9bJ/3Q8+R9rjIFppgcugTjpoVhgcdUM/Qwb8tSrX4/mPEL8 X-Received: by 2002:a17:906:fe0d:b0:96f:1f79:c0a6 with SMTP id wy13-20020a170906fe0d00b0096f1f79c0a6mr3305012ejb.70.1686074340194; Tue, 06 Jun 2023 10:59:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686074340; cv=none; d=google.com; s=arc-20160816; b=BQhcQBQ+fqjm0tC8uraIU7mC6tANH6HjpLduHuBMxiHskmjlFooA1MY8BXlLGnfyxy hWn/jMZ4rHSUmEZzjfyv8AiDQw3sBSbDH8aPj5cLu6+QXTPNKgfWwwUKo+1M9Y26A4/m J9SbtCgrM/acQ+x5FNb9kUliG5tRznWVC7mqm8m3/yhXOXG+rIFIK9gea/20mELnZA/f IC5oC9y4wbjZ42KkcfMl0ilxncUIb1ITOGOkmLXi4zhX1YgCI6DAWcLbfqz3dHhPId+a Vx4ej2eCh8M2X/wmuTqn/b45/xxeW13b7ZFb4mPx5DGC77US6gRDLJnBF8LDNzNlsaoY FyXA== 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:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=+0coDovMZMsy76nf2wpjvcwU7z4f/uXJ+FZx9CAXUgE=; b=ZmRr1daYDCRVQAddUnGMKnSwvA57uGgRjqji7zWV71NkqJ1HOhwv+auY98sptJA/jv qBpHa+59zis7oXBeR/ThApXdyhoFCxGnnE4pSWjG9JSa4lu9KogKUdUnH/r1oP4CL39a ecpw6DNvXVmnY1WAObO6bn9OFXqX6k+yA16hCXr8vv5Sv6woJti8xryNHQ4gX1we1SJr 7Q90TFHC22WIClG1D0xip7TE5VGQPy0zPWGWvcUpXWj/YPJ0WH7SCaR/fVdavV6NVUND 3ZaijjTCUrpeW0RGnFhDAd+rBnWMCghdWkrrYVbUpwgUeR3qGvfAIkMZzCB0MgRAdRs1 z6fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=uioTJXfb; 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 xb10-20020a170907070a00b00956fb99cb7dsi8000594ejb.1053.2023.06.06.10.58.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 10:59:00 -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=uioTJXfb; 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 7193A3857C66 for ; Tue, 6 Jun 2023 17:58:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7193A3857C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1686074338; bh=+0coDovMZMsy76nf2wpjvcwU7z4f/uXJ+FZx9CAXUgE=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=uioTJXfbR8KWemT0haw0Pd1mAHh+tre93IZYkJ5BwaILJTaKxnvLQM5LAmyXe57bH MgWf8Y/78vXbo6qlD/ZAQHC3vjvP1Cv3AMyecXdfrlZMdf8Pe+OGRlOVGNXOD/kHV6 M7EUJmAUQ2ofAN/ze/CUtVxL6Uz/RN7LrSpz3y8U= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 49FE23858D38 for ; Tue, 6 Jun 2023 17:58:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49FE23858D38 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-39a3f165ac5so5509612b6e.3 for ; Tue, 06 Jun 2023 10:58:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686074328; x=1688666328; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+0coDovMZMsy76nf2wpjvcwU7z4f/uXJ+FZx9CAXUgE=; b=iIy8qFaqOnJVQoUM9jy/G4gRkheFTzL/ooz3+DTE6dcE65tagPll9Z2Y68sVE95l/J rGYBxY189AURrXdDxnaecgYzZ1ig5rv0FahzgO/CIR2KB0I7LGJorc5iF6O3dgohTQNE XMWKc89yXsnlUtL/5xdUgIsrrYPKT1prEKA63xt27X+nunp+9u4TwmyDAueQ7oRFUa1P 3qimUTLF3Mwl+VPEt6QqPsokRkZMNyVDlDcmAu3P8uu25betrwIdrngmJQDFaOJSSNpO Psk16ys7nRQVN/LiZyOm6E3cGPnx0qJu2f520OUaUdniUASBVvQ/XgF/ox+pByGF5WzU tHhA== X-Gm-Message-State: AC+VfDzMTPSxwEHDSmR8vhSeLOy0/xbkYCes84cATxDHld5WAJppRkwD bW1Tn4Ms7A6emBJ6zo7DhOA= X-Received: by 2002:a05:6808:612:b0:39a:5cc0:ce61 with SMTP id y18-20020a056808061200b0039a5cc0ce61mr2342435oih.29.1686074328497; Tue, 06 Jun 2023 10:58:48 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.59.160.123]) by smtp.gmail.com with ESMTPSA id bc3-20020a170902930300b001a505f04a06sm8849175plb.190.2023.06.06.10.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 10:58:48 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id D7E9C7402B2; Tue, 6 Jun 2023 10:58:46 -0700 (PDT) To: binutils@sourceware.org Cc: Alan Modra , Florian Weimer , Kaylee Blake Subject: [PATCH v4 0/7] ELF: Strip section header in ELF objects Date: Tue, 6 Jun 2023 10:58:39 -0700 Message-Id: <20230606175846.399377-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3019.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: "H.J. Lu via Binutils" From: "H.J. Lu" Reply-To: "H.J. Lu" 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?1767441871824120314?= X-GMAIL-MSGID: =?utf-8?q?1767977087219932714?= Changes in v4: 1. Disallow -r with -z nosectionheader. 2. Add return after fail in no-section-header.exp. 3. Call free without checking null pointer. 4. Remove dead code. 5. Remove excess parentheses. Changes in v3: 1. Fix indentation. 2. Update tests to allow extra symbols. 3. Limit ld-elf/hash-2.d to targets with shared library support. Changes in v2: 1. Rename the objcopy and strip option to --strip-section-headers. 2. Also strip non-alloc sections. 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, a new objcopy and strip option, --strip-section-headers, to remove ELF section header. H.J. Lu (5): ELF: Discard non-alloc sections without section header bfd: Improve nm and objdump without section header binutils: Add a --strip-section-headers test ld: Add tests for -z nosectionheader and --strip-section-headers ld: Add -z nosectionheader test to bootstrap.exp Kaylee Blake (2): ELF: Strip section header in ELF objects ld: Add simple tests for -z nosectionheader bfd/bfd-in2.h | 6 +- bfd/bfd.c | 6 +- bfd/elf-bfd.h | 15 + bfd/elf.c | 742 ++++++++++++++++-- bfd/elfcode.h | 91 ++- bfd/elflink.c | 12 + bfd/elfxx-target.h | 4 +- binutils/NEWS | 5 +- binutils/doc/binutils.texi | 10 + binutils/objcopy.c | 38 +- binutils/testsuite/binutils-all/objcopy.exp | 5 + .../binutils-all/strip-section-headers-1.d | 5 + ld/NEWS | 3 + ld/emultempl/elf.em | 4 + ld/ld.h | 3 + ld/ld.texi | 5 + ld/ldlang.c | 8 + ld/lexsup.c | 13 + ld/testsuite/ld-bootstrap/bootstrap.exp | 10 +- ld/testsuite/ld-elf/hash-2.d | 11 + ld/testsuite/ld-elf/no-section-header.exp | 371 +++++++++ ld/testsuite/ld-elf/nosectionheader-1.d | 14 + ld/testsuite/ld-elf/nosectionheader-2.d | 4 + ld/testsuite/ld-elf/pr25617-1-no-sec-hdr.nd | 3 + ld/testsuite/ld-elf/pr25617-1-no-sec-hdr.rd | 20 + .../ld-elf/pr25617-1-static-no-sec-hdr.rd | 12 + ld/testsuite/ld-elf/pr25617-1a-no-sec-hdr.nd | 3 + ld/testsuite/ld-elf/pr25617-1a-no-sec-hdr.rd | 20 + ld/testsuite/ld-elf/pr25617-1a-sec-hdr.rd | 19 + ld/testsuite/ld-elf/pr25617-1a.c | 11 + ld/testsuite/ld-elf/pr25617-1b.c | 15 + ld/testsuite/ld-elf/start-noheader.rd | 11 + .../ld-elf/start-shared-noheader-gnu.rd | 26 + .../ld-elf/start-shared-noheader-sysv.rd | 26 + ld/testsuite/ld-elf/start-shared-noheader.nd | 11 + 35 files changed, 1475 insertions(+), 87 deletions(-) create mode 100644 binutils/testsuite/binutils-all/strip-section-headers-1.d create mode 100644 ld/testsuite/ld-elf/hash-2.d create mode 100644 ld/testsuite/ld-elf/no-section-header.exp create mode 100644 ld/testsuite/ld-elf/nosectionheader-1.d create mode 100644 ld/testsuite/ld-elf/nosectionheader-2.d create mode 100644 ld/testsuite/ld-elf/pr25617-1-no-sec-hdr.nd create mode 100644 ld/testsuite/ld-elf/pr25617-1-no-sec-hdr.rd create mode 100644 ld/testsuite/ld-elf/pr25617-1-static-no-sec-hdr.rd create mode 100644 ld/testsuite/ld-elf/pr25617-1a-no-sec-hdr.nd create mode 100644 ld/testsuite/ld-elf/pr25617-1a-no-sec-hdr.rd create mode 100644 ld/testsuite/ld-elf/pr25617-1a-sec-hdr.rd create mode 100644 ld/testsuite/ld-elf/pr25617-1a.c create mode 100644 ld/testsuite/ld-elf/pr25617-1b.c 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