From: Vladimir Serbinenko Date: Mon, 23 Jan 2017 17:17:41 +0000 (+0300) Subject: Discover partial linking arguments dynamically. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0cdef6ef5fb6d83ffdf03203e13fed8f631b698;p=thirdparty%2Fgrub.git Discover partial linking arguments dynamically. clang for android doesn't work with -Wl,-r,-d without -static. --- diff --git a/conf/Makefile.common b/conf/Makefile.common index 11296b550..90e0c4c2f 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common @@ -41,7 +41,7 @@ CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) STRIPFLAGS_KERNEL = -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding -LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d +LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) $(TARGET_INCREMENTAL_LINK) CPPFLAGS_MODULE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) CCASFLAGS_MODULE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) diff --git a/configure.ac b/configure.ac index da40cd97d..d694c6c8b 100644 --- a/configure.ac +++ b/configure.ac @@ -900,6 +900,25 @@ if test x"$target_cpu" = xsparc64 ; then TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_mno_relax" fi +AC_CACHE_CHECK([for incremental link options], grub_cv_target_cc_incremental_link, [ + grub_cv_target_cc_incremental_link=no + for cand in "-Wl,-r,-d" "-static -Wl,-r,-d"; do + #AC_LINK_IFELSE doesn't handle non-executable output correctly + echo > conftest_inclink.c + if $TARGET_CC -o /dev/null $TARGET_CFLAGS $TARGET_CPPFLAGS $TARGET_LDFLAGS -nostdlib -Werror $cand conftest_inclink.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then + grub_cv_target_cc_incremental_link="$cand" + break + fi + done +]) + +if test x"$grub_cv_target_cc_incremental_link" = xno ; then + AC_MSG_ERROR([could not find incremental link options]) +fi + +TARGET_INCREMENTAL_LINK="$grub_cv_target_cc_incremental_link" +AC_SUBST(TARGET_INCREMENTAL_LINK) + # By default, GCC 4.4 generates .eh_frame sections containing unwind # information in some cases where it previously did not. GRUB doesn't need # these and they just use up vital space. Restore the old compiler diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 2dfa22a92..1c8bc9ffc 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -49,20 +49,20 @@ kernel = { nostrip = emu; - emu_ldflags = '-Wl,-r,-d'; - i386_efi_ldflags = '-Wl,-r,-d'; + emu_ldflags = '$(TARGET_INCREMENTAL_LINK)'; + i386_efi_ldflags = '$(TARGET_INCREMENTAL_LINK)'; i386_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; - x86_64_efi_ldflags = '-Wl,-r,-d'; + x86_64_efi_ldflags = '$(TARGET_INCREMENTAL_LINK)'; x86_64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; ia64_efi_cflags = '-fno-builtin -fpic -minline-int-divide-max-throughput'; - ia64_efi_ldflags = '-Wl,-r,-d'; + ia64_efi_ldflags = '$(TARGET_INCREMENTAL_LINK)'; ia64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; - arm_efi_ldflags = '-Wl,-r,-d'; + arm_efi_ldflags = '$(TARGET_INCREMENTAL_LINK)'; arm_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; - arm64_efi_ldflags = '-Wl,-r,-d'; + arm64_efi_ldflags = '$(TARGET_INCREMENTAL_LINK)'; arm64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame'; i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; @@ -90,7 +90,7 @@ kernel = { i386_qemu_cppflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)'; emu_cflags = '$(CFLAGS_GNULIB)'; emu_cppflags = '$(CPPFLAGS_GNULIB)'; - arm_uboot_ldflags = '-Wl,-r,-d'; + arm_uboot_ldflags = '$(TARGET_INCREMENTAL_LINK)'; arm_uboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; i386_pc_startup = kern/i386/pc/startup.S; diff --git a/grub-core/genmod.sh.in b/grub-core/genmod.sh.in index 45d85931e..165bfb016 100644 --- a/grub-core/genmod.sh.in +++ b/grub-core/genmod.sh.in @@ -79,9 +79,9 @@ else for dep in $deps; do echo "char moddep_$dep[] __attribute__ ((section(\"_moddeps, _moddeps\"))) = \"$dep\";" >>$t2; done if test -n "$deps"; then - @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $t2 $tmpfile -Wl,-r,-d + @TARGET_CC@ @TARGET_LDFLAGS@ @TARGET_INCREMENTAL_LINK@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $t2 $tmpfile else - @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $tmpfile -Wl,-r,-d + @TARGET_CC@ @TARGET_LDFLAGS@ @TARGET_INCREMENTAL_LINK@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $tmpfile fi rm -f $t1 $t2 $tmpfile mv $tmpfile2 $tmpfile diff --git a/grub-core/modinfo.sh.in b/grub-core/modinfo.sh.in index f6cd657ce..a3aaa819f 100644 --- a/grub-core/modinfo.sh.in +++ b/grub-core/modinfo.sh.in @@ -19,6 +19,7 @@ grub_target_cflags='@TARGET_CFLAGS@' grub_target_cppflags='@TARGET_CPPFLAGS@' grub_target_ccasflags='@TARGET_CCASFLAGS@' grub_target_ldflags='@TARGET_LDFLAGS@' +grub_target_incremental_ldflags='@TARGET_INCREMENTAL_LINK@' grub_cflags='@CFLAGS@' grub_cppflags='@CPPFLAGS@' grub_ccasflags='@CCASFLAGS@'