llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Brian Cain (androm3da)

<details>
<summary>Changes</summary>

Guard the dynamic-linker, crt1.o, and crti.o additions with OPT_r, consistent 
with Gnu.cpp and the existing -pie suppression in this file. CRT start files 
must not appear in partial links (-r) as they define _start, causing 
duplicate-symbol errors when the output is later linked into an executable.

---
Full diff: https://github.com/llvm/llvm-project/pull/201262.diff


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Hexagon.cpp (+4-3) 
- (modified) clang/test/Driver/hexagon-toolchain-linux.c (+19) 


``````````diff
diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index ce3fd5110953a..45e2ce7d1a432 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -336,14 +336,15 @@ constructHexagonLinkArgs(Compilation &C, const JobAction 
&JA,
   CmdArgs.push_back(Output.getFilename());
 
   if (HTC.getTriple().isMusl()) {
-    if (!Args.hasArg(options::OPT_shared, options::OPT_static))
+    if (!Args.hasArg(options::OPT_shared, options::OPT_static, options::OPT_r))
       CmdArgs.push_back("-dynamic-linker=/lib/ld-musl-hexagon.so.1");
 
     if (!Args.hasArg(options::OPT_shared, options::OPT_nostartfiles,
-                     options::OPT_nostdlib))
+                     options::OPT_nostdlib, options::OPT_r))
       CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/usr/lib/crt1.o"));
     else if (Args.hasArg(options::OPT_shared) &&
-             !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib))
+             !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib,
+                          options::OPT_r))
       CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/usr/lib/crti.o"));
 
     if (!HTC.getSelectedMultilibs().empty() &&
diff --git a/clang/test/Driver/hexagon-toolchain-linux.c 
b/clang/test/Driver/hexagon-toolchain-linux.c
index 05d8b53ec1aad..3f19a37d8a38b 100644
--- a/clang/test/Driver/hexagon-toolchain-linux.c
+++ b/clang/test/Driver/hexagon-toolchain-linux.c
@@ -181,6 +181,25 @@
 // RUN:   | FileCheck -check-prefix=CHECK-PIE-RELOCATABLE %s
 // CHECK-PIE-RELOCATABLE-NOT:  "-pie"
 
+// 
-----------------------------------------------------------------------------
+// Relocatable (-r) links: no CRT start files, no dynamic linker
+// Partial links must not include crt1.o/crti.o — they define _start which
+// would conflict when the relocatable output is later linked into an 
executable.
+// 
-----------------------------------------------------------------------------
+// RUN: %clang -### --target=hexagon-unknown-linux-musl \
+// RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -r %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-RELOC %s
+// CHECK-RELOC-NOT: 
"-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
+// CHECK-RELOC-NOT: "{{.*}}crt1.o"
+// CHECK-RELOC-NOT: "{{.*}}crti.o"
+
+// Verify that a normal (non-relocatable) link still gets the CRT files.
+// RUN: %clang -### --target=hexagon-unknown-linux-musl \
+// RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-RELOC-NORMAL %s
+// CHECK-RELOC-NORMAL: 
"-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
+// CHECK-RELOC-NORMAL: "{{.*}}crt1.o"
+
 // 
-----------------------------------------------------------------------------
 // Sanitizer library paths: -fsanitize=memory
 // 
-----------------------------------------------------------------------------

``````````

</details>


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

Reply via email to