]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Use crt*.o files from llvm compiler-rt when building with clang
authorStan Shebs <stanshebs@google.com>
Tue, 9 Jun 2020 17:09:34 +0000 (10:09 -0700)
committerFangrui Song <i@maskray.me>
Sat, 28 Aug 2021 00:26:04 +0000 (17:26 -0700)
Makeconfig

index ff744a8f0d07fa570f23e0e334b2921763e6dc98..f5cd92014f19a598f8d0de3a20e2a3715c11e566 100644 (file)
@@ -661,20 +661,40 @@ libc.so-gnulib := -lgcc
 endif
 +preinit = $(addprefix $(csu-objpfx),crti.o)
 +postinit = $(addprefix $(csu-objpfx),crtn.o)
+ifeq ($(with-clang),yes)
+# With clang, use the crt*.o files from llvm's compiler-rt package.
+# The files normally have an architecture name appended, in case of
+# variants (32/64, le/be etc) installed in the same directory.
++prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=clang_rt.crtbegin-$(config-machine).o`
++postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=clang_rt.crtend-$(config-machine).o`
+else
 +prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbegin.o`
 +postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
+endif
 # Variants of the two previous definitions for linking PIE programs.
+ifeq ($(with-clang),yes)
+# compiler-rt crt*.o also works for PIE.
++prectorS = $(+prector)
++postctorS = $(+postctor)
+else
 +prectorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginS.o`
 +postctorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtendS.o`
+endif
 # Variants of the two previous definitions for statically linking programs.
 ifeq (yes,$(enable-static-pie))
 # Static PIE must use PIE variants.
 +prectorT = $(+prectorS)
 +postctorT = $(+postctorS)
 else
+ifeq ($(with-clang),yes)
+# compiler-rt crt*.o also works for static PIE.
++prectorT = $(+prector)
++postctorT = $(+postctor)
+else
 +prectorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginT.o`
 +postctorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
 endif
+endif
 csu-objpfx = $(common-objpfx)csu/
 elf-objpfx = $(common-objpfx)elf/