Hello Simon,
Please find the review comments below:
On 05/11/2018 04:24 PM, Simon Kuenzer wrote:
Instead of using `ld` directly, `gcc` is used for linking.
`gcc` is going to call `ld` but provides further
optimizations options that could be used for building
images later (e.g., LTO).
* The gcc wiki suggests this:
https://gcc.gnu.org/wiki/LinkTimeOptimizationFAQ#ar.2C_nm_and_ranlib
"If you try to build bigger projects with -flto you have to make
sure that you use a version of
binutils that supports gcc's liblto_plugin. Since version 4.9 gcc
produces slim object files
that only contain the intermediate representation. In order to
handle archives of these objects
you have to use the gcc wrappers: gcc-ar, gcc-nm and gcc-ranlib. (The next version of binutils
will support automatic loading of the liblto_plugin.) "
If we using the changing ld to gcc, we should also use the rest of
the binutils utility as suggested.
* The following gcc documentation list the possible optimization
options.
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
The -flto and -fwhole-program option are incompatible. There are
also other compiler optimization option used in combination with
-flto. Do we consider those option as a part of this patch or do we
support those options.
Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
Makefile | 2 +-
Makefile.uk | 8 ++++----
plat/kvm/Linker.uk | 8 ++++----
plat/linuxu/Linker.uk | 2 +-
plat/xen/Linker.uk | 16 ++++++++--------
5 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile
index b177bff..23ebe21 100644
--- a/Makefile
+++ b/Makefile
@@ -387,7 +387,7 @@ CROSS_COMPILE := $(CROSS_COMPILE:"%"=%)
include $(UK_BASE)/arch/$(UK_ARCH)/Compiler.uk
# Make variables (CC, etc...)
-LD := $(CROSS_COMPILE)ld
+LD := $(CROSS_COMPILE)gcc
CC := $(CROSS_COMPILE)gcc
CPP := $(CC)
CXX := $(CPP)
diff --git a/Makefile.uk b/Makefile.uk
index 5855b40..c540ada 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -20,8 +20,8 @@ CXXINCLUDES += -nostdinc -nostdlib -I$(UK_BASE)/include
# Set the text and data sections to be readable and writable. Also,
# do not page-align the data segment. If the output format supports
# Unix style magic numbers, mark the output as OMAGIC.
-LIBLDFLAGS += --omagic -r
-LDFLAGS += --omagic
+LIBLDFLAGS += -nostdinc -nostdlib -Wl,--omagic -Wl,-r
+LDFLAGS += -nostdinc -nostdlib -Wl,--omagic -Wl,--build-id=none
CFLAGS-$(OPTIMIZE_NONE) += -O0 -fno-optimize-sibling-calls -fno-tree-vectorize
CXXFLAGS-$(OPTIMIZE_NONE) += -O0 -fno-optimize-sibling-calls -fno-tree-vectorize
@@ -32,12 +32,12 @@ CXXFLAGS-$(OPTIMIZE_SIZE) += -Os
CFLAGS-$(OPTIMIZE_DEADELIM) += -fdata-sections -ffunction-sections
CXXFLAGS-$(OPTIMIZE_DEADELIM) += -fdata-sections -ffunction-sections
-LDFLAGS-$(OPTIMIZE_DEADELIM) += --gc-sections
+LDFLAGS-$(OPTIMIZE_DEADELIM) += -Wl,--gc-sections
ifneq ($(DEBUG_SYMBOLS),y)
CFLAGS += -g0
CXXFLAGS += -g0
-LDFLAGS-y += --strip-debug
+LDFLAGS-y += -Wl,--strip-debug
else
CFLAGS-$(DEBUG_SYMBOLS_LVL1) += -g1
CXXFLAGS-$(DEBUG_SYMBOLS_LVL1) += -g1
diff --git a/plat/kvm/Linker.uk b/plat/kvm/Linker.uk
index 7957b7a..a91a786 100644
--- a/plat/kvm/Linker.uk
+++ b/plat/kvm/Linker.uk
@@ -1,6 +1,6 @@
ifeq (x86_64,$(UK_ARCH))
-KVM_LDSCRIPT := $(UK_BASE)/plat/kvm/x86/link64.ld
-KVM_LDFLAGS-y += -m elf_x86_64
+KVM_LDSCRIPT := -Wl,-T,$(UK_BASE)/plat/kvm/x86/link64.ld
+KVM_LDFLAGS-y += -Wl,-m,elf_x86_64
endif
##
@@ -10,12 +10,12 @@ KVM_IMAGE := $(BUILD_DIR)/$(UK_NAME)_kvm-$(UK_ARCH)
$(KVM_IMAGE): $(KVM_LINK) $(KVM_LINK-y) $(UK_LINK) $(UK_LINK-y)
$(call build_cmd,LD,,$@.ld.o,\
- $(LD) $(LIBLDFLAGS) $(LIBLDFLAGS-y) $(KVM_LDFLAGS) $(KVM_LDFLAGS-y) $^ -o $@.ld.o)
+ $(LD) -r $(LIBLDFLAGS) $(LIBLDFLAGS-y) $(KVM_LDFLAGS) $(KVM_LDFLAGS-y) $^ -o $@.ld.o)
$(call build_cmd,OBJCOPY,,$@.o,\
$(OBJCOPY) -w -G kvmos_* -G _libkvmplat_entry $@.ld.o $@.o)
ifeq (x86_64,$(UK_ARCH))
$(call build_cmd,LD,,$@,\
- $(LD) $(LDFLAGS) $(LDFLAGS-y) $(KVM_LDFLAGS) $(KVM_LDFLAGS-y) -T $(KVM_LDSCRIPT) $@.o -o $@)
+ $(LD) $(LDFLAGS) $(LDFLAGS-y) $(KVM_LDFLAGS) $(KVM_LDFLAGS-y) $(KVM_LDSCRIPT) $@.o -o $@)
ifeq ($(OPTIMIZE_DBGFILE),y)
$(call build_cmd,OBJCOPY,,$@.dbg,\
$(OBJCOPY) --only-keep-debug $@ $@.dbg)
diff --git a/plat/linuxu/Linker.uk b/plat/linuxu/Linker.uk
index 16a5b15..d50401f 100644
--- a/plat/linuxu/Linker.uk
+++ b/plat/linuxu/Linker.uk
@@ -1,4 +1,4 @@
-LINUXU_LDFLAGS-y += -e_liblinuxuplat_start
+LINUXU_LDFLAGS-y += -Wl,-e,_liblinuxuplat_start
##
## Link image
diff --git a/plat/xen/Linker.uk b/plat/xen/Linker.uk
index c0851c3..3890196 100644
--- a/plat/xen/Linker.uk
+++ b/plat/xen/Linker.uk
@@ -1,16 +1,16 @@
ifeq (x86_64,$(UK_ARCH))
-XEN_LDSCRIPT := $(UK_BASE)/plat/xen/x86/link64.ld
-XEN_LDFLAGS-y += -m elf_x86_64
+XEN_LDSCRIPT := -Wl,-T,$(UK_BASE)/plat/xen/x86/link64.ld
+XEN_LDFLAGS-y += -Wl,-m,elf_x86_64
endif
ifeq (x86_32,$(UK_ARCH))
-XEN_LDSCRIPT := $(UK_BASE)/plat/xen/x86/link32.ld
-XEN_LDFLAGS-y += -m elf_x86_32
+XEN_LDSCRIPT := -Wl,-T,$(UK_BASE)/plat/xen/x86/link32.ld
+XEN_LDFLAGS-y += -Wl,-m,elf_x86_32
endif
ifeq (arm_64,$(UK_ARCH))
-XEN_LDSCRIPT := $(UK_BASE)/plat/xen/arm/link64.ld
+XEN_LDSCRIPT := -Wl,-T,$(UK_BASE)/plat/xen/arm/link64.ld
endif
ifeq (arm,$(UK_ARCH))
-XEN_LDSCRIPT := $(UK_BASE)/plat/xen/arm/link32.ld
+XEN_LDSCRIPT := -Wl,-T,$(UK_BASE)/plat/xen/arm/link32.ld
endif
##
@@ -25,7 +25,7 @@ $(XEN_IMAGE): $(XEN_LINK) $(XEN_LINK-y) $(UK_LINK) $(UK_LINK-y)
$(OBJCOPY) -w -G xenos_* -G _libxenplat_start $@.ld.o $@.o)
ifeq (arm,$(UK_ARCH))
$(call build_cmd,LD,,$@.elf,\
- $(LD) $(LDFLAGS) $(LDFLAGS-y) $(XEN_LDFLAGS) $(XEN_LDFLAGS-y) -T $(XEN_LDSCRIPT) $@.o -o $@.elf)
+ $(LD) $(LDFLAGS) $(LDFLAGS-y) $(XEN_LDFLAGS) $(XEN_LDFLAGS-y) $(XEN_LDSCRIPT) $@.o -o $@.elf)
ifeq ($(OPTIMIZE_DBGFILE),y)
$(call build_cmd,OBJCOPY,,$@.dbg,\
$(OBJCOPY) --only-keep-debug $@.elf $@.dbg)
@@ -44,7 +44,7 @@ endif
$(GZIP) -f -9 -c $@ >$@.gz)
else
$(call build_cmd,LD,,$@,\
- $(LD) $(LDFLAGS) $(LDFLAGS-y) $(XEN_LDFLAGS) $(XEN_LDFLAGS-y) -T $(XEN_LDSCRIPT) $@.o -o $@)
+ $(LD) $(LDFLAGS) $(LDFLAGS-y) $(XEN_LDFLAGS) $(XEN_LDFLAGS-y) $(XEN_LDSCRIPT) $@.o -o $@)
ifeq ($(OPTIMIZE_DBGFILE),y)
$(call build_cmd,OBJCOPY,,$@.dbg,\
$(OBJCOPY) --only-keep-debug $@ $@.dbg)
The rest of the code looks fine.
Thanks & Regards
Sharan Santhanam
|