From 51ce75b5b02a7617bfee5272d9236835be48d02d Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sat, 13 Oct 2007 14:50:43 +0000 Subject: - use the compiler-driver instead of the linker - adjust setting flags accordingly to use (hardcoded, see below) -Wl, Potential improvements: *) --warn-unresolved-symbols should perhaps be used for all libs *) eventually rename LDFLAGS to CC_LDFLAGS *) probe for compiler driver's notion of flag to use for passing in linker flags (i.e. don't hardcode "-Wl,") --- Makerules | 18 +++++----- Rules.mak | 54 ++++++++++++++++-------------- TODO | 2 -- ldso/ldso/Makefile.in | 4 +-- ldso/libdl/Makefile.in | 2 +- libc/Makefile.in | 4 +-- libpthread/linuxthreads.old/Makefile.in | 2 +- libpthread/linuxthreads.old_db/Makefile.in | 4 +-- libpthread/linuxthreads/Makefile.in | 2 +- libpthread/linuxthreads_db/Makefile.in | 4 +-- 10 files changed, 49 insertions(+), 47 deletions(-) diff --git a/Makerules b/Makerules index b4df69bb6..aec7238a0 100644 --- a/Makerules +++ b/Makerules @@ -126,9 +126,9 @@ define link.so $(Q)$(INSTALL) -d $(dir $@) $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1) @$(disp_ld) - $(Q)$(LD) $(LDFLAGS-$(notdir $@)) -soname=$(notdir $@).$(2) \ - -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \ - --whole-archive $(firstword $^) --no-whole-archive \ + $(Q)$(CC) $(LDFLAGS-$(notdir $@)) -Wl,-soname=$(notdir $@).$(2) \ + -nostdlib -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \ + -Wl,--whole-archive $(firstword $^) -Wl,--no-whole-archive \ $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@)) $(Q)$(LN) -sf $(1) $@.$(2) $(Q)$(LN) -sf $(1) $@ @@ -150,10 +150,10 @@ define link-flat.so $(Q)$(INSTALL) -d $(dir $@) $(Q)$(RM) $(1) $@ @$(disp_ld) - $(Q)$(LD) $(LDFLAGS-$(notdir $@)) -o $(1) \ - -elf2flt -shared-lib-id $(2) $(top_builddir)lib/Scrt1.o \ - $(top_builddir)/lib/crti.o --whole-archive $(firstword $^) \ - --no-whole-archive $(LIBS-$(notdir $@)) $(LIBGCC) \ + $(Q)$(CC) $(LDFLAGS-$(notdir $@)) -nostdlib -o $(1) \ + -Wl,-elf2flt -Wl,-shared-lib-id $(2) $(top_builddir)lib/Scrt1.o \ + $(top_builddir)/lib/crti.o -Wl,--whole-archive $(firstword $^) \ + -Wl,--no-whole-archive $(LIBS-$(notdir $@)) $(LIBGCC) \ $(top_builddir)/lib/crtn.o endef @@ -161,8 +161,8 @@ define linkm.so $(Q)$(INSTALL) -d $(dir $@) $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1) @$(disp_ld) - $(Q)$(LD) $(LDFLAGS-$(notdir $@)) -soname=$(notdir $@).$(2) \ - -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) $^ \ + $(Q)$(CC) $(LDFLAGS-$(notdir $@)) -Wl,-soname=$(notdir $@).$(2) \ + -nostdlib -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) $^ \ $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@)) $(Q)$(LN) -sf $(1) $@.$(2) $(Q)$(LN) -sf $(1) $@ diff --git a/Rules.mak b/Rules.mak index 97a154197..159f019e8 100644 --- a/Rules.mak +++ b/Rules.mak @@ -117,6 +117,9 @@ interp := ldso := endif +comma:=, +space:= # + ifndef CROSS CROSS=$(subst ",, $(strip $(CROSS_COMPILER_PREFIX))) endif @@ -192,8 +195,8 @@ endif ifeq ($(TARGET_ARCH),arm) OPTIMIZATION+=-fstrict-aliasing - CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-EL - CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-EB + CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-Wl,-EL + CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-Wl,-EB CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-mlittle-endian CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mbig-endian CPU_CFLAGS-$(CONFIG_GENERIC_ARM)+= @@ -216,8 +219,8 @@ ifeq ($(TARGET_ARCH),arm) endif ifeq ($(TARGET_ARCH),mips) - CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-EL - CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-EB + CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-Wl,-EL + CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-Wl,-EB CPU_CFLAGS-$(CONFIG_MIPS_ISA_1)+=-mips1 CPU_CFLAGS-$(CONFIG_MIPS_ISA_2)+=-mips2 -mtune=mips2 CPU_CFLAGS-$(CONFIG_MIPS_ISA_3)+=-mips3 -mtune=mips3 @@ -225,12 +228,12 @@ ifeq ($(TARGET_ARCH),mips) CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS32)+=-mips32 -mtune=mips32 CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS64)+=-mips64 -mtune=mips32 ifeq ($(strip $(ARCH_BIG_ENDIAN)),y) - CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-melf64btsmip - CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-melf32btsmip + CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64btsmip + CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32btsmip endif ifeq ($(strip $(ARCH_LITTLE_ENDIAN)),y) - CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-melf64ltsmip - CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-melf32ltsmip + CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64ltsmip + CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32ltsmip endif CPU_CFLAGS-$(CONFIG_MIPS_N64_ABI)+=-mabi=64 CPU_CFLAGS-$(CONFIG_MIPS_O32_ABI)+=-mabi=32 @@ -238,15 +241,15 @@ ifeq ($(TARGET_ARCH),mips) endif ifeq ($(TARGET_ARCH),nios) - CPU_LDFLAGS-y+=-m32 - CPU_CFLAGS-y+=-m32 + CPU_LDFLAGS-y+=-Wl,-m32 + CPU_CFLAGS-y+=-Wl,-m32 endif ifeq ($(TARGET_ARCH),sh) OPTIMIZATION+=-fstrict-aliasing OPTIMIZATION+= $(call check_gcc,-mprefergot,) - CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-EL - CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-EB + CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-Wl,-EL + CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-Wl,-EB CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-ml CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mb CPU_CFLAGS-$(CONFIG_SH2)+=-m2 @@ -262,23 +265,23 @@ endif ifeq ($(TARGET_ARCH),sh64) OPTIMIZATION+=-fstrict-aliasing - CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN):=-EL - CPU_LDFLAGS-$(ARCH_BIG_ENDIAN):=-EB + CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN):=-Wl,-EL + CPU_LDFLAGS-$(ARCH_BIG_ENDIAN):=-Wl,-EB CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN):=-ml CPU_CFLAGS-$(ARCH_BIG_ENDIAN):=-mb CPU_CFLAGS-$(CONFIG_SH5)+=-m5-32media endif ifeq ($(TARGET_ARCH),h8300) - CPU_LDFLAGS-$(CONFIG_H8300H)+= -ms8300h - CPU_LDFLAGS-$(CONFIG_H8S) += -ms8300s + CPU_LDFLAGS-$(CONFIG_H8300H)+= -Wl,-ms8300h + CPU_LDFLAGS-$(CONFIG_H8S) += -Wl,-ms8300s CPU_CFLAGS-$(CONFIG_H8300H) += -mh -mint32 CPU_CFLAGS-$(CONFIG_H8S) += -ms -mint32 endif ifeq ($(TARGET_ARCH),cris) - CPU_LDFLAGS-$(CONFIG_CRIS)+=-mcrislinux - CPU_LDFLAGS-$(CONFIG_CRISV32)+=-mcrislinux + CPU_LDFLAGS-$(CONFIG_CRIS)+=-Wl,-mcrislinux + CPU_LDFLAGS-$(CONFIG_CRISV32)+=-Wl,-mcrislinux CPU_CFLAGS-$(CONFIG_CRIS)+=-mlinux PICFLAG:=-fpic PIEFLAG_NAME:=-fpie @@ -304,13 +307,13 @@ ifeq ($(TARGET_ARCH),powerpc) endif ifeq ($(TARGET_ARCH),frv) - CPU_LDFLAGS-$(CONFIG_FRV)+=-melf32frvfd + CPU_LDFLAGS-$(CONFIG_FRV)+=-Wl,-melf32frvfd # Using -pie causes the program to have an interpreter, which is # forbidden, so we must make do with -shared. Unfortunately, # -shared by itself would get us global function descriptors # and calls through PLTs, dynamic resolution of symbols, etc, # which would break as well, but -Bsymbolic comes to the rescue. - export LDPIEFLAG:=-shared -Bsymbolic + export LDPIEFLAG:=-Wl,-shared -Wl,-Bsymbolic UCLIBC_LDSO=ld.so.1 endif @@ -396,19 +399,20 @@ endif CFLAGS += $(call check_gcc,-std=gnu99,) -LDFLAGS_NOSTRIP:=$(CPU_LDFLAGS-y) -shared --warn-common --warn-once -z combreloc +LDFLAGS_NOSTRIP:=$(CPU_LDFLAGS-y) -Wl,-shared \ + -Wl,--warn-common -Wl,--warn-once -Wl,-z,combreloc # binutils-2.16.1 warns about ignored sections, 2.16.91.0.3 and newer are ok #LDFLAGS_NOSTRIP+=$(call check_ld,--gc-sections) ifeq ($(UCLIBC_BUILD_RELRO),y) -LDFLAGS_NOSTRIP+=-z relro +LDFLAGS_NOSTRIP+=-Wl,-z,relro endif ifeq ($(UCLIBC_BUILD_NOW),y) -LDFLAGS_NOSTRIP+=-z now +LDFLAGS_NOSTRIP+=-Wl,-z,now endif -LDFLAGS:=$(LDFLAGS_NOSTRIP) -z defs +LDFLAGS:=$(LDFLAGS_NOSTRIP) -Wl,-z,defs ifeq ($(DODEBUG),y) #CFLAGS += -g3 CFLAGS += -O0 -g3 @@ -416,7 +420,7 @@ else CFLAGS += $(OPTIMIZATION) $(XARCH_CFLAGS) endif ifeq ($(DOSTRIP),y) -LDFLAGS += -s +LDFLAGS += -Wl,-s else STRIPTOOL := true -Stripping_disabled endif diff --git a/TODO b/TODO index c87ccea9f..9fb6d02dd 100644 --- a/TODO +++ b/TODO @@ -39,8 +39,6 @@ TODO list for the uClibc 0.9.29 release: *) Should integrate test subdir better ... need to propagate CPU CFLAGS/LDFLAGS to the build/link for target binaries so that when we have a multilib toolchain, the proper ABI is selected. - *) LD/LDFLAGS handling is broken ... stop invoking the linker directly and - have everything go through the compiler driver TODO list for the uClibc 1.0.0 release: diff --git a/ldso/ldso/Makefile.in b/ldso/ldso/Makefile.in index 04c4f2c99..8ae7a1743 100644 --- a/ldso/ldso/Makefile.in +++ b/ldso/ldso/Makefile.in @@ -20,9 +20,9 @@ CFLAGS-ldso.c := -DLDSO_ELFINTERP=\"$(TARGET_ARCH)/elfinterp.c\" ifneq ($(SUPPORT_LD_DEBUG),y) LDFLAGS-$(UCLIBC_LDSO_NAME).so := $(LDFLAGS) else -LDFLAGS-$(UCLIBC_LDSO_NAME).so := $(LDFLAGS_NOSTRIP) -z defs +LDFLAGS-$(UCLIBC_LDSO_NAME).so := $(LDFLAGS_NOSTRIP) -Wl,-z,defs endif -LDFLAGS-$(UCLIBC_LDSO_NAME).so += -e _start -z now -Bsymbolic --export-dynamic --sort-common --discard-locals --discard-all --no-undefined +LDFLAGS-$(UCLIBC_LDSO_NAME).so += -Wl,-e,_start -Wl,-z,now -Wl,-Bsymbolic -Wl,--export-dynamic -Wl,--sort-common -Wl,--discard-locals -Wl,--discard-all -Wl,--no-undefined ldso_FULL_NAME := $(UCLIBC_LDSO_NAME)-$(VERSION).so diff --git a/ldso/libdl/Makefile.in b/ldso/libdl/Makefile.in index f187f063a..baacf7654 100644 --- a/ldso/libdl/Makefile.in +++ b/ldso/libdl/Makefile.in @@ -17,7 +17,7 @@ endif CFLAGS-libdl.c := -DLDSO_ELFINTERP=\"$(TARGET_ARCH)/elfinterp.c\" -LDFLAGS-libdl.so := $(LDFLAGS) -fini dl_cleanup +LDFLAGS-libdl.so := $(LDFLAGS) -Wl,-fini,dl_cleanup LIBS-libdl.so := $(LIBS) $(ldso) diff --git a/libc/Makefile.in b/libc/Makefile.in index a21859166..3ff5ab578 100644 --- a/libc/Makefile.in +++ b/libc/Makefile.in @@ -12,10 +12,10 @@ libc_OUT := $(top_builddir)libc # libc, and if so, include it when linking. VERSION_SCRIPT := $(wildcard $(libc_DIR)/sysdeps/linux/$(TARGET_ARCH)/libc.map) ifneq ($(VERSION_SCRIPT),) -VERSION_SCRIPT := --version-script $(VERSION_SCRIPT) +VERSION_SCRIPT := -Wl,--version-script,$(VERSION_SCRIPT) endif -LDFLAGS-libc.so := $(LDFLAGS) $(VERSION_SCRIPT) -init __uClibc_init +LDFLAGS-libc.so := $(LDFLAGS) $(VERSION_SCRIPT) -Wl,-init,__uClibc_init LIBS-libc.so := $(interp) $(ldso) $(top_builddir)lib/$(NONSHARED_LIBNAME) diff --git a/libpthread/linuxthreads.old/Makefile.in b/libpthread/linuxthreads.old/Makefile.in index de7467684..6b1232c32 100644 --- a/libpthread/linuxthreads.old/Makefile.in +++ b/libpthread/linuxthreads.old/Makefile.in @@ -12,7 +12,7 @@ CFLAGS-linuxthreads.old := $(CFLAGS-dir_linuxthreads.old) $(SSP_ALL_CFLAGS) CFLAGS-libpthread/linuxthreads.old/sysdeps/$(TARGET_ARCH)/ := $(CFLAGS-linuxthreads.old) ifeq ($(PTHREADS_DEBUG_SUPPORT),y) -LDFLAGS-libpthread.so := $(LDFLAGS_NOSTRIP) -z defs +LDFLAGS-libpthread.so := $(LDFLAGS_NOSTRIP) -Wl,-z,defs else LDFLAGS-libpthread.so := $(LDFLAGS) endif diff --git a/libpthread/linuxthreads.old_db/Makefile.in b/libpthread/linuxthreads.old_db/Makefile.in index 0959919fa..f0aa61f13 100644 --- a/libpthread/linuxthreads.old_db/Makefile.in +++ b/libpthread/linuxthreads.old_db/Makefile.in @@ -8,9 +8,9 @@ # Get the thread include dependencies and shared object name CFLAGS-linuxthreads.old_db := -DNOT_IN_libc -DLIBPTHREAD_SO="\"libpthread.so.$(MAJOR_VERSION)\"" -LDFLAGS-libthread_db.so := $(LDFLAGS_NOSTRIP) $(call check_ld,--warn-unresolved-symbols) +LDFLAGS-libthread_db.so := $(LDFLAGS_NOSTRIP) $(if $(call check_ld,--warn-unresolved-symbols),-Wl$(comma)--warn-unresolved-symbols) ifeq ($(DOSTRIP),y) -LDFLAGS-libthread_db.so += -s +LDFLAGS-libthread_db.so += -Wl,-s endif LIBS-libthread_db.so := $(LIBS) diff --git a/libpthread/linuxthreads/Makefile.in b/libpthread/linuxthreads/Makefile.in index a6622958f..37ed96365 100644 --- a/libpthread/linuxthreads/Makefile.in +++ b/libpthread/linuxthreads/Makefile.in @@ -19,7 +19,7 @@ CFLAGS-libpthread/linuxthreads/sysdeps/pthread/ := $(CFLAGS-linuxthreads #CFLAGS:=$(CFLAGS:-O0=-O1) ifeq ($(PTHREADS_DEBUG_SUPPORT),y) -LDFLAGS-libpthread.so := $(LDFLAGS_NOSTRIP) -z defs +LDFLAGS-libpthread.so := $(LDFLAGS_NOSTRIP) -Wl,-z,defs else LDFLAGS-libpthread.so := $(LDFLAGS) endif diff --git a/libpthread/linuxthreads_db/Makefile.in b/libpthread/linuxthreads_db/Makefile.in index 23a9199aa..87f20e208 100644 --- a/libpthread/linuxthreads_db/Makefile.in +++ b/libpthread/linuxthreads_db/Makefile.in @@ -8,9 +8,9 @@ # Get the thread include dependencies and shared object name CFLAGS-linuxthreads_db := -DNOT_IN_libc -DLIBPTHREAD_SO="\"libpthread.so.$(MAJOR_VERSION)\"" -LDFLAGS-libthread_db.so := $(LDFLAGS_NOSTRIP) $(call check_ld,--warn-unresolved-symbols) +LDFLAGS-libthread_db.so := $(LDFLAGS_NOSTRIP) $(if $(call check_ld,--warn-unresolved-symbols),-Wl$(comma)--warn-unresolved-symbols) ifeq ($(DOSTRIP),y) -LDFLAGS-libthread_db.so += -s +LDFLAGS-libthread_db.so += -Wl,-s endif LIBS-libthread_db.so := $(LIBS) -- cgit v1.2.3