From 61eff496e0c28a3c45c2dbcaffd34405d0d7e24e Mon Sep 17 00:00:00 2001 From: Peter Mitsis Date: Mon, 1 Jun 2015 11:27:55 -0400 Subject: [PATCH] kbuild: link using ${LD} instead of ${CC} Not all GCC toolchains generate a fully linked image (non-relocatable) when using ${CC} for linking. Change-Id: Id99501b6510cd6eeb87f245a6273fcebd6d36cde Signed-off-by: Peter Mitsis --- Makefile | 25 ++++++++++++------------- scripts/link-tinymountain.sh | 14 +++++++------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index bc0a058069a8..0df67e0499b0 100644 --- a/Makefile +++ b/Makefile @@ -389,10 +389,10 @@ KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := KBUILD_AFLAGS := -c -g -xassembler-with-cpp -LDFLAGS += $(call cc-ldoption,-nostartfiles) -LDFLAGS += $(call cc-ldoption,-nodefaultlibs) -LDFLAGS += $(call cc-ldoption,-nostdlib) -LDFLAGS += $(call cc-ldoption,-static) +LDFLAGS += $(call ld-option,-nostartfiles) +LDFLAGS += $(call ld-option,-nodefaultlibs) +LDFLAGS += $(call ld-option,-nostdlib) +LDFLAGS += $(call ld-option,-static) LDLIBS_TOOLCHAIN ?= -lgcc KERNELVERSION = $(VERSION_GENERATION).$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_REVISION) @@ -720,15 +720,14 @@ KBUILD_CFLAGS += $(KCFLAGS) # Use --build-id when available. -LDFLAGS_tinymountain += $(call cc-ldoption,-nostartfiles) -LDFLAGS_tinymountain += $(call cc-ldoption,-nodefaultlibs) -LDFLAGS_tinymountain += $(call cc-ldoption,-nostdlib) -LDFLAGS_tinymountain += $(call cc-ldoption,-static) -#LDFLAGS_tinymountain += $(call cc-ldoption,-Wl$(comma)--unresolved-symbols=ignore-in-object-files) -LDFLAGS_tinymountain += $(call cc-ldoption,-Wl$(comma)-X) -LDFLAGS_tinymountain += $(call cc-ldoption,-Wl$(comma)-N) -LDFLAGS_tinymountain += $(call cc-ldoption,-Wl$(comma)--gc-sections) -LDFLAGS_tinymountain += $(call cc-ldoption,-Wl$(comma)--build-id=none) +LDFLAGS_tinymountain += $(call ld-option,-nostartfiles) +LDFLAGS_tinymountain += $(call ld-option,-nodefaultlibs) +LDFLAGS_tinymountain += $(call ld-option,-nostdlib) +LDFLAGS_tinymountain += $(call ld-option,-static) +LDFLAGS_tinymountain += $(call ld-option,-X) +LDFLAGS_tinymountain += $(call ld-option,-N) +LDFLAGS_tinymountain += $(call ld-option,--gc-sections) +LDFLAGS_tinymountain += $(call ld-option,--build-id=none) LD_TOOLCHAIN ?= -D__GCC_LINKER_CMD__ diff --git a/scripts/link-tinymountain.sh b/scripts/link-tinymountain.sh index 576d8f963bb0..79b4d62c8643 100755 --- a/scripts/link-tinymountain.sh +++ b/scripts/link-tinymountain.sh @@ -45,13 +45,13 @@ linker_params() LIBS="" for tcl in ${ALL_LIBS}; do LIBS="${LIBS} -l${tcl}"; done echo "${LDFLAGS_tinymountain}" > ${1} - echo "-Wl,-Map,./${2}" >> ${1} + echo "-Map ./${2}" >> ${1} echo "-L ${objtree}/include/generated" >> ${1} echo "-u _OffsetAbsSyms -u _ConfigAbsSyms" >> ${1} - echo "-Wl,-e,__start" >> ${1} - echo "-Wl,--start-group ${KBUILD_TIMO_MAIN}" >> ${1} + echo "-e __start" >> ${1} + echo "--start-group ${KBUILD_TIMO_MAIN}" >> ${1} echo "${objtree}/include/generated/offsets.o" >> ${1} - echo "-Wl,--end-group" >> ${1} + echo "--end-group" >> ${1} echo "${LIB_INCLUDE_DIR} ${LIBS}" >> ${1} } @@ -60,7 +60,7 @@ linker_params() # {2} optional additional link parameters linker_command() { - ${CC} -x assembler-with-cpp -nostdinc -undef -E -P \ + ${CC} -x assembler-with-cpp -nostdinc -undef -E -P \ ${LDFLAG_LINKERCMD} \ ${LD_TOOLCHAIN} ${2} \ -I${srctree}/include -I${objtree}/include/generated \ @@ -74,7 +74,7 @@ linker_command() # ${3} linker command file initial_link() { - ${CC} -o ${1} @${2} -T ${3} + ${LD} -T ${3} @${2} -o ${1} } #Generates IDT and merge them into final binary @@ -96,7 +96,7 @@ gen_idt() # ${4} - output file tinymountain_link() { - ${CC} -o ${4} @${1} ${3} -T ${2} + ${LD} -T ${2} @${1} ${3} -o ${4} ${OBJCOPY} --set-section-flags intList=noload ${4} elf.tmp ${OBJCOPY} -R intList elf.tmp ${4} rm elf.tmp