Browse Source

Peter Mazinger writes:
The attached patch generalizes the use of PIE (all archs are brought in
sync that use/mention it: x86/ppc/frv) and makes use of it building the
target utils.

Tested on x86, ppc should be tested, frv uses -fPIE at one location, but
at another place -fpie, I don't know which is correct (could be both) and
misses the target addition in Config.in.

The test for ppc (requires the earlier sent crt-correction patch to work
correctly):
enable UCLIBC_PIE_SUPPORT, build uClibc and utils, check:
file ./utils/ldd, it should show shared object (instead of executable)

Joakim Tjernlund 19 years ago
parent
commit
13ca772ddc

+ 4 - 2
libc/sysdeps/linux/frv/Makefile

@@ -23,7 +23,9 @@ ASFLAGS=$(CFLAGS)
 
 CRT0_SRC = crt0.S
 CRT0_OBJ = crt0.o crt1.o
+ifeq $(strip $(UCLIBC_PIE_SUPPORT)),y)
 SCRT0_OBJ = $(patsubst %,S%, $(CRT0_OBJ))
+endif
 CRT0_DEPS=gmon-start.S
 
 CTOR_TARGETS = crti.o crtn.o
@@ -54,11 +56,11 @@ crtreloc.o: crtreloc.c
 	$(CC) $(CFLAGS) -c $< -o $@
 
 $(SCRT0_OBJ): $(CRT0_SRC) Scrtreloc.o
-	$(CC) $(CFLAGS) -fPIE -DL_$* -r -nostdlib $< Scrtreloc.o -o $*.o
+	$(CC) $(CFLAGS) $(PIEFLAG) -DL_$* -r -nostdlib $< Scrtreloc.o -o $*.o
 	$(STRIPTOOL) -x -R .note -R .comment $*.o
 
 Scrtreloc.o: crtreloc.c
-	$(CC) $(CFLAGS) -fPIE -c $< -o $@
+	$(CC) $(CFLAGS) $(PIEFLAG) -c $< -o $@
 
 $(CTOR_TARGETS): %.o : %.S
 	$(CC) $(CFLAGS) -c $< -o $@

+ 7 - 3
libc/sysdeps/linux/i386/Makefile

@@ -23,7 +23,7 @@ ASFLAGS=$(CFLAGS)
 CRT0_SRC = crt0.S
 CRT0_OBJ = crt0.o crt1.o
 ifeq ($(strip $(UCLIBC_PIE_SUPPORT)),y)
-CRT0_OBJ += Scrt0.o Scrt1.o
+SCRT0_OBJ = $(patsubst %,S%, $(CRT0_OBJ))
 endif
 CRT0_DEPS=gmon-start.S
 CTOR_TARGETS=$(TOPDIR)lib/crti.o $(TOPDIR)lib/crtn.o
@@ -41,9 +41,9 @@ all: $(OBJS) $(LIBC)
 
 $(LIBC): ar-target 
 
-ar-target: $(OBJS) $(CRT0_OBJ) $(CTOR_TARGETS)
+ar-target: $(OBJS) $(CRT0_OBJ) $(SCRT0_OBJ) $(CTOR_TARGETS)
 	$(AR) $(ARFLAGS) $(LIBC) $(OBJS)
-	cp $(CRT0_OBJ) $(TOPDIR)lib/
+	cp $(CRT0_OBJ) $(SCRT0_OBJ) $(TOPDIR)lib/
 ifeq ($(strip $(UCLIBC_PIE_SUPPORT)),y)
 ifeq ($(strip $(UCLIBC_CTOR_DTOR)),y)
 	$(RM) $(TOPDIR)lib/Scrt0.o
@@ -56,6 +56,10 @@ $(CRT0_OBJ): $(CRT0_SRC)
 	$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
 	$(STRIPTOOL) -x -R .note -R .comment $*.o
 
+$(SCRT0_OBJ): $(CRT0_SRC)
+	$(CC) $(CFLAGS) $(PIEFLAG) -DL_$* $< -c -o $*.o
+	$(STRIPTOOL) -x -R .note -R .comment $*.o
+
 $(SOBJS): %.o : %.S
 	$(CC) $(CFLAGS) -c $< -o $@
 	$(STRIPTOOL) -x -R .note -R .comment $*.o

+ 7 - 3
libc/sysdeps/linux/powerpc/Makefile

@@ -23,7 +23,7 @@ ASFLAGS=$(CFLAGS)
 CRT0_SRC = crt0.S
 CRT0_OBJ = crt0.o crt1.o
 ifeq ($(strip $(UCLIBC_PIE_SUPPORT)),y)
-CRT0_OBJ += Scrt0.o Scrt1.o
+SCRT0_OBJ = $(patsubst %,S%, $(CRT0_OBJ))
 endif
 CRT0_DEPS=gmon-start.S
 CTOR_TARGETS=$(TOPDIR)lib/crti.o $(TOPDIR)lib/crtn.o
@@ -41,9 +41,9 @@ all: $(OBJS) $(LIBC)
 
 $(LIBC): ar-target 
 
-ar-target: $(OBJS) $(CRT0_OBJ) $(CTOR_TARGETS)
+ar-target: $(OBJS) $(CRT0_OBJ) $(SCRT0_OBJ) $(CTOR_TARGETS)
 	$(AR) $(ARFLAGS) $(LIBC) $(OBJS)
-	cp $(CRT0_OBJ) $(TOPDIR)lib/
+	cp $(CRT0_OBJ) $(SCRT0_OBJ) $(TOPDIR)lib/
 ifeq ($(strip $(UCLIBC_PIE_SUPPORT)),y)
 ifeq ($(strip $(UCLIBC_CTOR_DTOR)),y)
 	$(RM) $(TOPDIR)lib/Scrt0.o
@@ -56,6 +56,10 @@ $(CRT0_OBJ): $(CRT0_SRC)
 	$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
 	$(STRIPTOOL) -x -R .note -R .comment $*.o
 
+$(SCRT0_OBJ): $(CRT0_SRC)
+	$(CC) $(CFLAGS) $(PIEFLAG) -DL_$* $< -c -o $*.o
+	$(STRIPTOOL) -x -R .note -R .comment $*.o
+
 $(SOBJS): %.o : %.S
 	$(CC) $(CFLAGS) -c $< -o $@
 	$(STRIPTOOL) -x -R .note -R .comment $*.o

+ 2 - 2
utils/Makefile

@@ -54,7 +54,7 @@ ldconfig:	ldconfig.c readsoname.c
 	$(STRIPTOOL) -x -R .note -R .comment $@
 
 ldd:	ldd.c
-	$(CC) $(CFLAGS) $(XXFLAGS) -Wl,-s \
+	$(CC) $(CFLAGS) $(XXFLAGS) $(PIEFLAG) $(LDPIEFLAG) -Wl,-s \
 		-DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
 		-DUCLIBC_LDSO=$(UCLIBC_LDSO) -I. -I../ldso/include \
 		-nostdlib -o $@ $(BIN_START_FILES) $^ $(LDADD_LIBFLOAT) \
@@ -62,7 +62,7 @@ ldd:	ldd.c
 	$(STRIPTOOL) -x -R .note -R .comment $@
 
 iconv: ../libc/misc/wchar/wchar.c
-	$(CC) $(CFLAGS) $(XXFLAGS) -Wl,-s -DL_iconv_main \
+	$(CC) $(CFLAGS) $(XXFLAGS) $(PIEFLAG) $(LDPIEFLAG) -Wl,-s -DL_iconv_main \
 		-nostdlib -o $@ $(BIN_START_FILES) $^ $(LDADD_LIBFLOAT) \
 		-L../lib -lc $(LIBGCC) $(END_FILES)
 	$(STRIPTOOL) -x -R .note -R .comment $@