https://github.com/jtschuster created 
https://github.com/llvm/llvm-project/pull/186013

913c5b4d1fff removed the `initSections(Opts.NoExecStack, *STI)` call from 
cc1as_main.cpp, assuming it was redundant with the initSections call inside 
Parser->Run(). However, Parser->Run() calls initSections(false, ...), it does 
not forward NoExecStack. This causes -Wa,--noexecstack / -cc1as -mnoexecstack 
to be parsed but silently ignored, producing objects without .note.GNU-stack.

This breaks linking with ld.bfd >= 2.39, which errors on missing 
.note.GNU-stack sections by default.

Restore the explicit initSections call with Opts.NoExecStack. Effectively a 
revert of 913c5b4d1fff.

Add a test to validate the section is present in the output. Existing tests 
only validated the flag was forwarded from clang.

>From 86ec0ed5803ab54b4283915fdb4b43325f67c289 Mon Sep 17 00:00:00 2001
From: Jackson Schuster <[email protected]>
Date: Wed, 11 Mar 2026 17:00:41 -0700
Subject: [PATCH 1/2] Readd initSections call with NoExecStack opt in
 cc1as_main.cpp

913c5b4d1fff removed the `initSections(Opts.NoExecStack, *STI)` call from 
cc1as_main.cpp, assuming it was redundant with the initSections call inside 
Parser->Run(). However, Parser->Run() calls initSections(false, ...), it does 
not forward NoExecStack. This causes -Wa,--noexecstack / -cc1as -mnoexecstack 
to be parsed but silently ignored, producing objects without .note.GNU-stack.

This breaks linking with ld.bfd >= 2.39, which errors on missing 
.note.GNU-stack sections by default.

Restore the explicit initSections call with Opts.NoExecStack.
---
 clang/tools/driver/cc1as_main.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/tools/driver/cc1as_main.cpp 
b/clang/tools/driver/cc1as_main.cpp
index c6cdd46a41f37..944321212a33e 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -602,6 +602,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
     Triple T(Opts.Triple);
     Str.reset(TheTarget->createMCObjectStreamer(
         T, Ctx, std::move(MAB), std::move(OW), std::move(CE), *STI));
+    Str->initSections(Opts.NoExecStack, *STI);
     if (T.isOSBinFormatMachO() && T.isOSDarwin()) {
       Triple *TVT = Opts.DarwinTargetVariantTriple
                         ? &*Opts.DarwinTargetVariantTriple

>From c14a9fd41ce51c02f24024d80f879ca127a7ab6a Mon Sep 17 00:00:00 2001
From: Jackson Schuster <[email protected]>
Date: Wed, 11 Mar 2026 17:18:12 -0700
Subject: [PATCH 2/2] Add test for -cc1as -mnoexecstack emitting
 .note.GNU-stack

Verify that -mnoexecstack actually produces a .note.GNU-stack section in the 
output object file, not just that the flag is forwarded by the driver. This 
would have caught the regression in 913c5b4d1fff.
---
 clang/test/Misc/cc1as-noexecstack.s | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 clang/test/Misc/cc1as-noexecstack.s

diff --git a/clang/test/Misc/cc1as-noexecstack.s 
b/clang/test/Misc/cc1as-noexecstack.s
new file mode 100644
index 0000000000000..91ed33e5a0e04
--- /dev/null
+++ b/clang/test/Misc/cc1as-noexecstack.s
@@ -0,0 +1,10 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -cc1as -triple x86_64-linux-gnu -filetype obj -mnoexecstack -o 
%t.o %s
+// RUN: llvm-readelf -S %t.o | FileCheck %s
+
+// CHECK: .note.GNU-stack
+
+.text
+.globl foo
+foo:
+    retq

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to