From patchwork Sun Jun 21 17:49:21 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Tolmatcev X-Patchwork-Id: 137509 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B269A4BA23C2 for ; Sun, 21 Jun 2026 17:51:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B269A4BA23C2 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=LHaUPa/m X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id DB0284BA2E0D for ; Sun, 21 Jun 2026 17:51:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB0284BA2E0D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DB0284BA2E0D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782064284; cv=none; b=dzawsVAQFfpl6+84RX/S5gInm29yT0/rhHUHJr5kjqT39YKA0j0GfWUG4Tqezs4oq4KWr8nsrO6pg6tcEx4N+TJ84u2QpcIx3w3OKqw74FHcQvfP43bvGIstt4A+1dx+Yvrs3EEHGkoiB2xMWAdYG54y8SZCOzBB2vW20wFIteE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782064284; c=relaxed/simple; bh=uvuUQLCNuP5UlPGE3F/lwv9540eLwzLhFuR9+itOFmg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vhH6HL53W/dejTFB48a+qeUlQki2JfuUfx8fwy4TJNyDfWpUJQggxdtfJji9++3J0THfmq/gbHlLtFURS4uhdDl5FECQH88+fI7GbZRN3MCKzTzX6LI3Q+MwbmcrsW4IG8KDYmKTkNjQjgU7FNDASylXlHKQGYc2Rz/phmzmdlA= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=LHaUPa/m DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB0284BA2E0D Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-49249072f03so6391115e9.0 for ; Sun, 21 Jun 2026 10:51:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782064283; x=1782669083; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=KK6AtTg0FQEJEv0xd/9uJLzhzTM94B090F/LWM5C53Y=; b=LHaUPa/m/kFNNy7eRKAchdzGKqfUVOveh1YbNUh/V9aZcAJCqq5gnOrysabxAH1m+U K5xAGt4DkYO4J7dgVsnTQuFEpzImLYQlIWf0EIksJlWX2XG7GAsTRr7dOFZM0EkUGoc7 koL8D6yXnGPqsdn3kVLTcM5GV4b/OKU3RQFPl76zgc0YT92eVOHNoivNOnYUlyiEuWjF vMNumcWB4UxH+UM61M0R++eiD7Yt95q87oyq/NpJ0sx59TMc3vNfCQojyMtieEkmFOIV 0UW2pLPWm+AgWt2SQmpqGvQ6+bKPaDaFNsNhUoc317m7EoRNTi5KLo15enpeYOyNOFc6 CKRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782064283; x=1782669083; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=KK6AtTg0FQEJEv0xd/9uJLzhzTM94B090F/LWM5C53Y=; b=bh055q2WcCHQUR0cftmsY6aL3BOUL7jmIFiyTc+Q0hF8eQT+ketA+aBxGy50oGa1If aSeuX1x5q3zqbLilBlsJtmV9e2CLpcBApObr5pJl1juhyBXqpDCvmAKcZkrSgI/NxuWE 3gVZkKCV0DUTmUrm+MKayIp/4AAtcs09SA70qdfwhsOhnUUVcL3UdhVXo4A7jE9Nb1+W t7/fEcoIMVH1Z90iuaW+gaRUO7Z32+QygTEx+reYfr8rmWXk9xIB3sFQb/LlCPPTnA2s oVlULumYK9f7McIIgE8I7uXVOo3yq6LieHg0ANnB9obkeZCMpZMueRTqt5Teqks4Uag3 rb3g== X-Gm-Message-State: AOJu0Yx7v5eG24NXXqSwBfrWQf6wKWH/EuLmWOF9jnBIQvEB2TLO/spq gXJjyYqWqEbYXX60C1luUzZ5VcdE+7H6j3NvJtUVZrgYuX8nm3CYX60qvFzfeA== X-Gm-Gg: AfdE7ckQFRVzejD1SQiFgfzpxNx0NMM93hzfw0wRQhrAon0NOEnAkOqT5aovG91l0Pv j2X+Jgh9HiQLqkSzXDapZ39iGUSIbhApNmob9mkg2s/t5m9REYb2114bfQm580KSquB4LjdseMI jcsw6LWylmqVHC9mFWT9VTpqou+P6V6NLxgWI+MhzW9j5scf7YOseXo9PsqlLpWsKPftLVx795n m8Ph6AaVTfiQIGGo5soHxNZiAKpo+mQ54iBe42VrfSiGtqJJbeeuEjRUslrcZXW3ji9Q9skjhWl Qz8f80i8I+OlLJzeIi/K0s4rSaOtE2EhsXgEY/pzPS/kqrfAvztvuvamAsvI3JLeqE7wcQIZF0c tq39YRToFAkcDzV3IwDJ1hNqVkOhjvvbEmxfnKj5pg0yE2SBYk2idZYQL2qT5Sn6rdE51LtX9E4 Jj2ilTPbifKy72b4msLTCy7NvcRrKz0BdBOSr0xw1Mc+5Wnmb1mnjlZ4NT7ozGv9YANQsQCzzI4 /umpYIc3hE= X-Received: by 2002:a05:600c:468c:b0:492:3c7e:57aa with SMTP id 5b1f17b1804b1-4923eeb494emr191037195e9.0.1782064282496; Sun, 21 Jun 2026 10:51:22 -0700 (PDT) Received: from Mein-PC (p200300ed8f29d70034e7af62491814df.dip0.t-ipconnect.de. [2003:ed:8f29:d700:34e7:af62:4918:14df]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49249455302sm152344495e9.15.2026.06.21.10.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jun 2026 10:51:22 -0700 (PDT) From: Oleg Tolmatcev To: binutils@sourceware.org Cc: Oleg Tolmatcev Subject: [PATCH] PE/COFF: auto-promote to bigobj target when section count overflows Date: Sun, 21 Jun 2026 19:49:21 +0200 Message-ID: <20260621174919.1150-3-oleg.tolmatcev@gmail.com> X-Mailer: git-send-email 2.54.0.windows.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org Regular PE/COFF uses 16-bit section numbers in the symbol table, limiting objects to at most 65535 sections. When this limit is exceeded, the assembler silently truncates section numbers, producing corrupt objects that cause confusing linker errors like: undefined reference to `vtable for ...' Fix this by automatically switching the xvec to the matching bigobj target before any headers or symbols are finalized, so the object is written out using the extended COFF format which supports 32-bit section numbers. bfd/ * coffcode.h (coff_compute_section_file_positions): Auto-promote to bigobj target when section count exceeds 16-bit limit. gas/ * testsuite/gas/pe/big-obj-auto.d: New test. * testsuite/gas/pe/big-obj-auto.s: New test. * testsuite/gas/pe/pe.exp: Run big-obj-auto. Signed-off-by: Oleg Tolmatcev --- bfd/coffcode.h | 14 ++++++++++++++ gas/testsuite/gas/pe/big-obj-auto.d | 9 +++++++++ gas/testsuite/gas/pe/big-obj-auto.s | 16 ++++++++++++++++ gas/testsuite/gas/pe/pe.exp | 1 + 4 files changed, 40 insertions(+) create mode 100644 gas/testsuite/gas/pe/big-obj-auto.d create mode 100644 gas/testsuite/gas/pe/big-obj-auto.s diff --git a/bfd/coffcode.h b/bfd/coffcode.h index 7439fca676..5c9722a15e 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -360,6 +360,10 @@ CODE_FRAGMENT #include "coffswap.h" #endif +#ifdef COFF_WITH_PE_BIGOBJ +extern const bfd_target TARGET_SYM_BIG; +#endif + #define STRING_SIZE_SIZE 4 #define DOT_DEBUG ".debug" @@ -3154,6 +3158,16 @@ coff_compute_section_file_positions (bfd * abfd) if (target_index >= bfd_coff_max_nscns (abfd)) { +#ifdef COFF_WITH_PE_BIGOBJ + if (abfd->xvec != &TARGET_SYM_BIG) + { + /* Regular PE/COFF uses 16-bit section numbers in symbols. + Promote oversized objects to the matching bigobj target + before any headers or symbols are finalized. */ + abfd->xvec = &TARGET_SYM_BIG; + return coff_compute_section_file_positions (abfd); + } +#endif bfd_set_error (bfd_error_file_too_big); _bfd_error_handler /* xgettext:c-format */ diff --git a/gas/testsuite/gas/pe/big-obj-auto.d b/gas/testsuite/gas/pe/big-obj-auto.d new file mode 100644 index 0000000000..9538ed4c67 --- /dev/null +++ b/gas/testsuite/gas/pe/big-obj-auto.d @@ -0,0 +1,9 @@ +#objdump: -h +#name: PE big obj auto-promotion + +.*: *file format pe-bigobj-.* + +Sections: +#... +5000. \.data\$a49999 .* + CONTENTS, ALLOC, LOAD, DATA diff --git a/gas/testsuite/gas/pe/big-obj-auto.s b/gas/testsuite/gas/pe/big-obj-auto.s new file mode 100644 index 0000000000..dbf2585e81 --- /dev/null +++ b/gas/testsuite/gas/pe/big-obj-auto.s @@ -0,0 +1,16 @@ + .file "big-obj-auto.s" + + .irp n,0,1,2,3,4 + .irp m,0,1,2,3,4,5,6,7,8,9 + .irp c,0,1,2,3,4,5,6,7,8,9 + .irp d,0,1,2,3,4,5,6,7,8,9 + .irp u,0,1,2,3,4,5,6,7,8,9 + .globl a\n\m\c\d\u + .section .data$a\n\m\c\d\u,"w" +a\n\m\c\d\u : + .byte 1 + .endr + .endr + .endr + .endr + .endr diff --git a/gas/testsuite/gas/pe/pe.exp b/gas/testsuite/gas/pe/pe.exp index e25de3cfa9..092ab4b335 100644 --- a/gas/testsuite/gas/pe/pe.exp +++ b/gas/testsuite/gas/pe/pe.exp @@ -70,4 +70,5 @@ if {[istarget "aarch64-*-pe*"] || [istarget "aarch64-*-mingw*"]} { if ([istarget "*-*-mingw*"]) then { run_dump_test "big-obj" + run_dump_test "big-obj-auto" }