From patchwork Mon Jun 5 15:32:15 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: 10307 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2768730vqr; Mon, 5 Jun 2023 08:32:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Tvzi7vZwsgRVrR0tZ7a8gUUw/2ocqk8N+6bDJ7pR+NsATivQMrL3FJlffPlLAWfhOmmhK X-Received: by 2002:a17:907:3da3:b0:977:d660:c5aa with SMTP id he35-20020a1709073da300b00977d660c5aamr3492852ejc.31.1685979158459; Mon, 05 Jun 2023 08:32:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685979158; cv=none; d=google.com; s=arc-20160816; b=id1E9MMkSkzkNNBwU+0rX/JieaENFHoE3jAGMuuplQutJuO0o1b+dnVINWXtYcNgtj Pl6oFh+AVx9z5QuyPldLlCThsOtIy7e4ur4YsAJaGx+xwlsmA17fhbWbHJQRUllq2d15 4/qK+uvrUhNvayr5nqCXrlLuwj4C9UoLGtOGXRtsMjqzw9UwzP3sPAPCuMx6CPlKTs94 BIlLqaOub6vx8JmJXztMzocphTScQsg9Myp4LopULY44EoIiFCBdv7MbwBqW/ZXvX2Aj p2f22pvS+1rrL/45pyfN8FYifH/yMFLO/sIXg4JbaDnMHIv7WOQqBGoREurAh7on+QM8 DSow== 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=oNEt0DSr4ZiJj+1kqt85HvXATbFSJMlvQiQZeNrLSck=; b=audKrdoFb1RCzvBjtNd0Y6Efp8+kLC3dtZMnbfMUVOXxoTTa6ig4Q9vvPgRLErvrZt eLVfoLhGXvseFQZqnSyMFna0i0DmTetzDweONqYxYzHlItvWGvpUOPmaydNmg2nxywym qLDVBYTs4fBOsl3W+At8RORFSrvIIWon0uuI2u+V9oyAEY0QRDPUC2N8fAdkIND5yEK/ 9AYxkQdRubpIAVpWEWZNEIKm8oXRpE3fLxZIfpH2IZ3Wb0rBFn4ncXgKVz55TNKsRJqw V9nHJ+1puh8TKFPEphFcXqzuy79zGGa9jzfT20jex/Ar61xiZb0O7rm4tarTho2oLY7h 3fog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=I5FGhfPb; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 ([8.43.85.97]) by mx.google.com with ESMTPS id ds16-20020a170907725000b0096f5c034b2csi5828716ejc.394.2023.06.05.08.32.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 08:32:38 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=I5FGhfPb; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 4DF71388266A for ; Mon, 5 Jun 2023 15:32:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DF71388266A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685979154; bh=oNEt0DSr4ZiJj+1kqt85HvXATbFSJMlvQiQZeNrLSck=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=I5FGhfPb0RaO7HUhpSi0HR36uRKVImUkYOgqbY5Zz/ebpvA6OaMvUZAk0V8utMqJ1 MEhcGKQMZ7l03zPIyWs7OzYq64dmpPK7dklDXX6JLBxSmnXmSeS+D3uZIUVjIQ/+F0 wCY5qOUH57lHs/KgdKZrtP8Fmv8XCf3wmMwM3pHs= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id B855B388217C for ; Mon, 5 Jun 2023 15:32:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B855B388217C Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-652a6bf4e6aso2107064b3a.2 for ; Mon, 05 Jun 2023 08:32:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685979145; x=1688571145; 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=oNEt0DSr4ZiJj+1kqt85HvXATbFSJMlvQiQZeNrLSck=; b=lYjjnbGThUvviwocn6koJY5V11J2rPVbfTJ5egQD7HkFb+B53lvm+c0PDSHUwwN5mM 8LtaZyRhDuoeNo0jcQDovA37OYii4dIfUn2drmdmOPUzAcRoPom6g394XLy7/eKuKjDl 6bS4dJLv67AHUog+51fvYqaibEggl2U77cJuU6UArl7Um6Mo/LbbHRWU0XUEizK/t5TP mEwccQHJCl8fW+vlwmNc11zXO7RHeWCJppNzunSOlUDq5Th6SOu7FtKxcK3wNG5eOhIb +tsc/cXS8dzsNbc/FnwIh2HAaTEjtKzA7v8305nljio9IhUKhuij3OZW3ut5PoOS0bqR oJnA== X-Gm-Message-State: AC+VfDx3H4pX5z0DTKO/duwnN8klDHiMgx1NPREphM02J/UAC42rRSRC dW3F3b6yQLY0Z/N5vBMubq4hGPgFhvo= X-Received: by 2002:a05:6a00:22cd:b0:656:6d18:3d83 with SMTP id f13-20020a056a0022cd00b006566d183d83mr26337pfj.7.1685979144591; Mon, 05 Jun 2023 08:32:24 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.59.160.123]) by smtp.gmail.com with ESMTPSA id u26-20020aa7839a000000b0063b96574b8bsm5318561pfm.220.2023.06.05.08.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 08:32:24 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id C38C774014F; Mon, 5 Jun 2023 08:32:22 -0700 (PDT) To: binutils@sourceware.org Cc: Alan Modra , Kaylee Blake Subject: [PATCH v3 0/7] ELF: Strip section header in ELF objects Date: Mon, 5 Jun 2023 08:32:15 -0700 Message-Id: <20230605153222.1728119-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?1767877281959128962?= 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 a simple test for -z nosectionheader bfd/bfd-in2.h | 6 +- bfd/bfd.c | 6 +- bfd/elf-bfd.h | 15 + bfd/elf.c | 755 ++++++++++++++++-- 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 | 8 + ld/testsuite/ld-bootstrap/bootstrap.exp | 10 +- ld/testsuite/ld-elf/hash-2.d | 11 + ld/testsuite/ld-elf/no-section-header.exp | 370 +++++++++ ld/testsuite/ld-elf/nosectionheader.d | 14 + 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 + 34 files changed, 1478 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.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