From ae41acec27bdef2f12c4c2275b24a67828e84207 Mon Sep 17 00:00:00 2001 From: Torsten Hilbrich Date: Tue, 19 Jun 2012 11:05:16 +0200 Subject: [PATCH] Hardening compilation support for 64bit Linux Without this patch the compilation failed with: /usr/bin/ld: main.o: relocation R_X86_64_32S against `vtable for Genode::Dataspace' can not be used when making a shared object; recompile with -fPIC main.o: could not read symbols: Bad value collect2: ld returned 1 exit status make[6]: *** [init] Error 1 For this patch the use of the hardening tool chain must be indicated using the "hardening_tool_chain" SPECS entry within the file /etc/specs.conf Fixes #79 --- base-linux/lib/import/import-lx_hybrid.mk | 7 +++++++ base-linux/mk/spec-linux.mk | 4 ++++ base/lib/import/import-stdcxx.mk | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/base-linux/lib/import/import-lx_hybrid.mk b/base-linux/lib/import/import-lx_hybrid.mk index 71a1af5705..2005f33d4f 100644 --- a/base-linux/lib/import/import-lx_hybrid.mk +++ b/base-linux/lib/import/import-lx_hybrid.mk @@ -77,10 +77,17 @@ endif # # Use the host's startup codes, linker script, and dynamic linker # +ifneq ($(filter hardening_tool_chain, $(SPECS)),) +EXT_OBJECTS += $(shell cc $(CC_MARCH) -print-file-name=Scrt1.o) +EXT_OBJECTS += $(shell cc $(CC_MARCH) -print-file-name=crti.o) +EXT_OBJECTS += $(shell cc $(CC_MARCH) -print-file-name=crtbeginS.o) +EXT_OBJECTS += $(shell cc $(CC_MARCH) -print-file-name=crtendS.o) +else EXT_OBJECTS += $(shell cc $(CC_MARCH) -print-file-name=crt1.o) EXT_OBJECTS += $(shell cc $(CC_MARCH) -print-file-name=crti.o) EXT_OBJECTS += $(shell cc $(CC_MARCH) -print-file-name=crtbegin.o) EXT_OBJECTS += $(shell cc $(CC_MARCH) -print-file-name=crtend.o) +endif EXT_OBJECTS += $(shell cc $(CC_MARCH) -print-file-name=crtn.o) EXT_OBJECTS += -lgcc -lgcc_s -lsupc++ -lc EXT_OBJECTS += -lpthread diff --git a/base-linux/mk/spec-linux.mk b/base-linux/mk/spec-linux.mk index 8c04c855b7..fe6e06151b 100644 --- a/base-linux/mk/spec-linux.mk +++ b/base-linux/mk/spec-linux.mk @@ -15,3 +15,7 @@ LD_SCRIPT_STATIC = $(call select_from_repositories,src/platform/genode.ld) \ else LD_SCRIPT_STATIC = endif + +ifneq ($(filter hardening_tool_chain, $(SPECS)),) +CC_OPT += -fPIC +endif diff --git a/base/lib/import/import-stdcxx.mk b/base/lib/import/import-stdcxx.mk index 0e343f69f6..14c96db2ef 100644 --- a/base/lib/import/import-stdcxx.mk +++ b/base/lib/import/import-stdcxx.mk @@ -18,4 +18,8 @@ INC_DIR += $(shell echo "int main() {return 0;}" |\ # # Link libstdc++ that comes with the tool chain # +ifneq ($(filter hardening_tool_chain, $(SPECS)),) +EXT_OBJECTS += $(shell $(CUSTOM_CXX_LIB) $(CC_MARCH) -print-file-name=libstdc++.so) +else EXT_OBJECTS += $(shell $(CUSTOM_CXX_LIB) $(CC_MARCH) -print-file-name=libstdc++.a) +endif