From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-39a3f165ac5so5509612b6e.3 for ; Tue, 06 Jun 2023 10:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686074328; x=1688666328; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+0coDovMZMsy76nf2wpjvcwU7z4f/uXJ+FZx9CAXUgE=; b=s0TQ6mjD6Ypul7gCxLQ7ijSaXlce0nqLTAcc2/+TdajZouTsxnCdtStTYtfwCIxQBA /Xv0lsLwDNvl9RCgex6hnShz14i5O9FBLZKOc5RbfpJKijfAGikYoG4QdcukdhnQD1z5 qwrBHYpbQsGFajIs2c8mKVAzYs3qBVQJ3F4ViSeQIM/8tOFU6xWprR/1zfmWjdxnPdjb qXSdPj4P55ZrVNQFFjeL1MYmTaPWVlyyol2JE+FnxE+hBQK0uMQGgEc1ynDQU5DHcs8Y VOzFn9NAnR9zqTZoQnVDTK2+R65a7wvbVo6QwnCA6P9UW8oQbQJo65kdAaZeoLe2r/mh bh4Q== 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-Google-Smtp-Source: ACHHUZ4f4EDq67r+EoADtZSZDQ86scemP+72YWEBhY31qlZVAePZDz3U3IZ2lSmf9vPVA5QSqcmZSg== 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) From: "H.J. Lu" 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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 -- 2.40.1