[libc-commits] [libc] [libc][startup] set --target= for linker when cross compiling (PR #96342)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Fri Jun 21 11:23:04 PDT 2024


https://github.com/nickdesaulniers created https://github.com/llvm/llvm-project/pull/96342

Otherwise the startup objects will fail to link since they were cross compiled,
but the linker is not informed of the intent to cross compile, which results in
linker errors when the host architecture does not match the target
architecture.

>From dbf586d66ef2e992ee8c5df8fbe7f9043102b286 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Fri, 21 Jun 2024 11:19:52 -0700
Subject: [PATCH] [libc][startup] set --target= for linker when cross compiling

Otherwise the startup objects will fail to link since they were cross compiled,
but the linker is not informed of the intent to cross compile, which results in
linker errors when the host architecture does not match the target
architecture.
---
 libc/startup/linux/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/startup/linux/CMakeLists.txt b/libc/startup/linux/CMakeLists.txt
index 68f68ff45aa9e..31c0ada31aebd 100644
--- a/libc/startup/linux/CMakeLists.txt
+++ b/libc/startup/linux/CMakeLists.txt
@@ -26,7 +26,7 @@ function(merge_relocatable_object name)
   )
   # Pass -r to the driver is much cleaner than passing -Wl,-r: the compiler knows it is
   # a relocatable linking and will not pass other irrelevant flags to the linker.
-  target_link_options(${relocatable_target} PRIVATE -r -nostdlib)
+  target_link_options(${relocatable_target} PRIVATE -r -nostdlib --target=${explicit_target_triple})
   set_target_properties(
     ${relocatable_target}
     PROPERTIES



More information about the libc-commits mailing list