[libc-commits] [libc] [libc][startup] check that we're cross compiling and using LLD (PR #96357)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Fri Jun 21 13:48:37 PDT 2024


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

We only need to set `--target=` for LLD when cross compiling. This should fix
the host build using BFD.

Fixes: #96342

>From b22cd93bcbf9ea181f9f290023d9e20604ef05f0 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Fri, 21 Jun 2024 13:40:23 -0700
Subject: [PATCH] [libc][startup] check that we're cross compiling and using
 LLD

We only need to set `--target=` for LLD when cross compiling. This should fix
the host build using BFD.

Fixes: #96342
---
 libc/startup/linux/CMakeLists.txt | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libc/startup/linux/CMakeLists.txt b/libc/startup/linux/CMakeLists.txt
index 31c0ada31aebd..ece88c25a4aa8 100644
--- a/libc/startup/linux/CMakeLists.txt
+++ b/libc/startup/linux/CMakeLists.txt
@@ -26,7 +26,11 @@ 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=${explicit_target_triple})
+  set(link_opts -r -nostdlib)
+  if (explicit_target_triple)
+    list(APPEND link_opts --target=${explicit_target_triple})
+  endif()
+  target_link_options(${relocatable_target} PRIVATE ${link_opts})
   set_target_properties(
     ${relocatable_target}
     PROPERTIES



More information about the libc-commits mailing list