Created
June 30, 2022 19:13
-
-
Save basedjakfan2/d8681950e2c0cb64ed88f90e153fe920 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 5978020202a4b50eedb64fb9bff1018644ef1a81 Mon Sep 17 00:00:00 2001 | |
From: Taylor Berlioz <nagakamira@gmail.com> | |
Date: Thu, 30 Jun 2022 12:12:14 -0700 | |
Subject: [PATCH 2/2] do not depend on gcc runtime | |
Signed-off-by: Taylor Berlioz <nagakamira@gmail.com> | |
--- | |
Makeconfig | 21 +++++++++++++++------ | |
Makerules | 2 +- | |
config.make.in | 1 + | |
configure | 23 +++++++++++++++++++++++ | |
configure.ac | 8 ++++++++ | |
elf/Makefile | 4 ++-- | |
6 files changed, 50 insertions(+), 9 deletions(-) | |
diff --git a/Makeconfig b/Makeconfig | |
index c0cf1e28..3d8e9f53 100644 | |
--- a/Makeconfig | |
+++ b/Makeconfig | |
@@ -669,22 +669,23 @@ else | |
endif | |
libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed | |
gnulib-arch = | |
-gnulib = -lgcc $(gnulib-arch) | |
-gnulib-tests := -lgcc $(libgcc_eh) | |
+gnulib = `$(CC) $(sysdep-LDFLAGS) --print-libgcc-file-name` $(gnulib-arch) | |
+gnulib-tests := `$(CC) $(sysdep-LDFLAGS) --print-libgcc-file-name` $(libgcc_eh) | |
static-gnulib-arch = | |
# By default, elf/static-stubs.o, instead of -lgcc_eh, is used to | |
# statically link programs. When --disable-shared is used, we use | |
# -lgcc_eh since elf/static-stubs.o isn't sufficient. | |
ifeq (yes,$(build-shared)) | |
-static-gnulib = -lgcc $(static-gnulib-arch) | |
+static-gnulib = `$(CC) $(sysdep-LDFLAGS) --print-libgcc-file-name` $(static-gnulib-arch) | |
else | |
-static-gnulib = -lgcc -lgcc_eh $(static-gnulib-arch) | |
+static-gnulib = `$(CC) $(sysdep-LDFLAGS) --print-libgcc-file-name` $(static-gnulib-arch) | |
endif | |
-static-gnulib-tests := -lgcc -lgcc_eh $(libunwind) | |
-libc.so-gnulib := -lgcc | |
+static-gnulib-tests := `$(CC) $(sysdep-LDFLAGS) --print-libgcc-file-name` $(libunwind) | |
+libc.so-gnulib := `$(CC) $(sysdep-LDFLAGS) --print-libgcc-file-name` | |
endif | |
+preinit = $(addprefix $(csu-objpfx),crti.o) | |
+postinit = $(addprefix $(csu-objpfx),crtn.o) | |
+ifeq (no,$(is-clang)) | |
+prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbegin.o` | |
+postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o` | |
# Variants of the two previous definitions for linking PIE programs. | |
@@ -699,6 +700,14 @@ else | |
+prectorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginT.o` | |
+postctorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o` | |
endif | |
+else | |
++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` | |
++prectorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=clang_rt.crtbegin-$(config-machine).o` | |
++postctorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=clang_rt.crtend-$(config-machine).o` | |
++prectorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=clang_rt.crtbegin-$(config-machine).o` | |
++postctorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=clang_rt.crtend-$(config-machine).o` | |
+endif | |
csu-objpfx = $(common-objpfx)csu/ | |
elf-objpfx = $(common-objpfx)elf/ | |
diff --git a/Makerules b/Makerules | |
index 8c5588bb..e3260bc4 100644 | |
--- a/Makerules | |
+++ b/Makerules | |
@@ -647,7 +647,7 @@ LDFLAGS-c.so += -e __libc_main | |
# between libc.so and ld.so, which can make it impossible to upgrade. | |
$(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a | |
$(LINK.o) -nostdlib -nostartfiles -r -o $@ \ | |
- $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@ | |
+ $(LDFLAGS-c_pic.os) $(whole-archive) $^ -o $@ | |
ifeq (,$(strip $(shlib-lds-flags))) | |
# Generate a list of -R options to excise .gnu.glibc-stub.* sections. | |
diff --git a/config.make.in b/config.make.in | |
index ecde84a7..576cdea8 100644 | |
--- a/config.make.in | |
+++ b/config.make.in | |
@@ -72,6 +72,7 @@ have-cc-with-libunwind = @libc_cv_cc_with_libunwind@ | |
bind-now = @bindnow@ | |
have-hash-style = @libc_cv_hashstyle@ | |
use-default-link = @use_default_link@ | |
+is-clang = @libc_cv_compiler_is_clang@ | |
have-cxx-thread_local = @libc_cv_cxx_thread_local@ | |
have-loop-to-function = @libc_cv_cc_loop_to_function@ | |
have-textrel_ifunc = @libc_cv_textrel_ifunc@ | |
diff --git a/configure b/configure | |
index 31c37700..00dbeb9c 100755 | |
--- a/configure | |
+++ b/configure | |
@@ -641,6 +641,7 @@ PYTHON | |
PYTHON_PROG | |
AUTOCONF | |
NM | |
+libc_cv_compiler_is_clang | |
BISON | |
AWK | |
SED | |
@@ -5226,6 +5227,28 @@ if test $libc_cv_compiler_ok != yes; then : | |
critic_missing="$critic_missing compiler" | |
fi | |
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext | |
+/* end confdefs.h. */ | |
+ | |
+int | |
+main () | |
+{ | |
+ | |
+#ifndef __clang__ | |
+# error not clang | |
+#endif | |
+ ; | |
+ return 0; | |
+} | |
+_ACEOF | |
+if ac_fn_c_try_cpp "$LINENO"; then : | |
+ libc_cv_compiler_is_clang=yes | |
+else | |
+ libc_cv_compiler_is_clang=no | |
+fi | |
+rm -f conftest.err conftest.i conftest.$ac_ext | |
+ | |
+ | |
if test -n "$ac_tool_prefix"; then | |
# Extract the first word of "${ac_tool_prefix}nm", so it can be a program name with args. | |
set dummy ${ac_tool_prefix}nm; ac_word=$2 | |
diff --git a/configure.ac b/configure.ac | |
index 33e98a4f..a5835162 100644 | |
--- a/configure.ac | |
+++ b/configure.ac | |
@@ -1063,6 +1063,14 @@ AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[]], [[ | |
AS_IF([test $libc_cv_compiler_ok != yes], | |
[critic_missing="$critic_missing compiler"]) | |
+AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[]], [[ | |
+#ifndef __clang__ | |
+# error not clang | |
+#endif]])], | |
+ [libc_cv_compiler_is_clang=yes], | |
+ [libc_cv_compiler_is_clang=no]) | |
+AC_SUBST(libc_cv_compiler_is_clang) | |
+ | |
AC_CHECK_TOOL(NM, nm, false) | |
if test "x$maintainer" = "xyes"; then | |
diff --git a/elf/Makefile b/elf/Makefile | |
index 0e240811..f2bb03f0 100644 | |
--- a/elf/Makefile | |
+++ b/elf/Makefile | |
@@ -1207,7 +1207,7 @@ $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a | |
echo ".globl $$symbol"; \ | |
echo "$$symbol:"; \ | |
done | $(CC) -o $@T.o $(ASFLAGS) -c -x assembler - | |
- $(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T | |
+ $(reloc-link) -o $@.o $@T.o "-Wl,-(" $^ `$(reloc-link) --print-libgcc-file-name` "-Wl,-)" -Wl,-Map,$@T | |
rm -f %@T.o $@.o | |
mv -f $@T $@ | |
@@ -1237,7 +1237,7 @@ $(objpfx)rtld-libc.a: $(objpfx)librtld.mk FORCE | |
$(MAKE) -f $< -f rtld-Rules | |
$(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(objpfx)rtld-libc.a | |
- $(LINK.o) -nostdlib -nostartfiles -r -o $@ '-Wl,-(' $^ -lgcc '-Wl,-)' \ | |
+ $(LINK.o) -nostdlib -nostartfiles -r -o $@ "-Wl,-(" $^ `$(reloc-link) --print-libgcc-file-name` "-Wl,-)" \ | |
-Wl,-Map,$@.map | |
generated += librtld.map librtld.mk rtld-libc.a librtld.os.map | |
-- | |
2.34.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment