Replece LDFLAGS-* = $(no-pie-ldflag) with tst-*-no-pie = yes [BZ #22630]

After

commit 9d7a3741c9
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Dec 15 16:59:33 2017 -0800

    Add --enable-static-pie configure option to build static PIE [BZ #19574]

and

commit 00c714df39
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Dec 18 12:24:26 2017 -0800

    Pass -no-pie to GCC only if GCC defaults to PIE [BZ #22614]

$(no-pie-ldflag) is no longer effective since no-pie-ldflag is defined
to -no-pie only if GCC defaults to PIE.  When --enable-static-pie is
used to configure glibc build and GCC doesn't default to PIE. no-pie-ldflag
is undefined and these tests:

elf/Makefile:LDFLAGS-tst-dlopen-aout = $(no-pie-ldflag)
elf/Makefile:LDFLAGS-tst-prelink = $(no-pie-ldflag)
elf/Makefile:LDFLAGS-tst-main1 = $(no-pie-ldflag)
gmon/Makefile:LDFLAGS-tst-gmon := $(no-pie-ldflag)

may fail to link.  This patch replaces "-pie" with

$(if $($(@F)-no-pie),$(no-pie-ldflag),-pie)

and repleces

LDFLAGS-* = $(no-pie-ldflag)

with

tst-*-no-pie = yes

so that tst-dlopen-aout, tst-prelink, tst-main1 and tst-gmon are always
built as non-PIE, with and without --enable-static-pie, regardless if
GCC defaults to PIE or non-PIE.

Tested with build-many-glibcs.py without --enable-static-pie as well as
with --enable-static-pie for x86_64, x32 and i686.

	[BZ #22630]
	* Makeconfig (link-pie-before-libc): Replace -pie with
	$(if $($(@F)-no-pie),$(no-pie-ldflag),-pie).
	* elf/Makefile (LDFLAGS-tst-dlopen-aout): Removed.
	(tst-dlopen-aout-no-pie): New.
	(LDFLAGS-tst-prelink): Removed.
	(tst-prelink-no-pie): New.
	(LDFLAGS-tst-main1): Removed.
	(tst-main1-no-pie): New.
	* gmon/Makefile (LDFLAGS-tst-gmon): Removed.
	(tst-gmon-no-pie): New.
This commit is contained in:
H.J. Lu 2017-12-19 13:53:00 -08:00
parent 126adc89d8
commit ce16eb52c0
4 changed files with 20 additions and 5 deletions

View File

@ -1,3 +1,17 @@
2017-12-19 H.J. Lu <hongjiu.lu@intel.com>
[BZ #22630]
* Makeconfig (link-pie-before-libc): Replace -pie with
$(if $($(@F)-no-pie),$(no-pie-ldflag),-pie).
* elf/Makefile (LDFLAGS-tst-dlopen-aout): Removed.
(tst-dlopen-aout-no-pie): New.
(LDFLAGS-tst-prelink): Removed.
(tst-prelink-no-pie): New.
(LDFLAGS-tst-main1): Removed.
(tst-main1-no-pie): New.
* gmon/Makefile (LDFLAGS-tst-gmon): Removed.
(tst-gmon-no-pie): New.
2017-12-19 H.J. Lu <hongjiu.lu@intel.com> 2017-12-19 H.J. Lu <hongjiu.lu@intel.com>
* manual/install.texi: Document that --enable-static-pie * manual/install.texi: Document that --enable-static-pie

View File

@ -413,7 +413,8 @@ link-extra-libs-tests = $(libsupport)
# Command for linking PIE programs with the C library. # Command for linking PIE programs with the C library.
ifndef +link-pie ifndef +link-pie
+link-pie-before-libc = $(CC) -pie -Wl,-O1 -nostdlib -nostartfiles -o $@ \ +link-pie-before-libc = $(CC) $(if $($(@F)-no-pie),$(no-pie-ldflag),-pie) \
-Wl,-O1 -nostdlib -nostartfiles -o $@ \
$(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \ $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
$(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \ $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
$(firstword $(CRT-$(@F)) $(csu-objpfx)S$(start-installed-name)) \ $(firstword $(CRT-$(@F)) $(csu-objpfx)S$(start-installed-name)) \

View File

@ -195,7 +195,7 @@ tests-internal += loadtest unload unload2 circleload1 \
tst-ptrguard1 tst-stackguard1 tst-ptrguard1 tst-stackguard1
ifeq ($(build-hardcoded-path-in-tests),yes) ifeq ($(build-hardcoded-path-in-tests),yes)
tests += tst-dlopen-aout tests += tst-dlopen-aout
LDFLAGS-tst-dlopen-aout = $(no-pie-ldflag) tst-dlopen-aout-no-pie = yes
endif endif
test-srcs = tst-pathopt test-srcs = tst-pathopt
selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null) selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null)
@ -369,7 +369,7 @@ ifeq ($(have-glob-dat-reloc),yes)
tests += tst-prelink tests += tst-prelink
# Don't compile tst-prelink.c with PIE for GLOB_DAT relocation. # Don't compile tst-prelink.c with PIE for GLOB_DAT relocation.
CFLAGS-tst-prelink.c += -fno-pie CFLAGS-tst-prelink.c += -fno-pie
LDFLAGS-tst-prelink = $(no-pie-ldflag) tst-prelink-no-pie = yes
ifeq ($(run-built-tests),yes) ifeq ($(run-built-tests),yes)
tests-special += $(objpfx)tst-prelink-cmp.out tests-special += $(objpfx)tst-prelink-cmp.out
endif endif
@ -1433,6 +1433,6 @@ $(objpfx)tst-debug1mod1.so: $(objpfx)testobj1.so
$(objpfx)tst-main1: $(objpfx)tst-main1mod.so $(objpfx)tst-main1: $(objpfx)tst-main1mod.so
CRT-tst-main1 := $(csu-objpfx)crt1.o CRT-tst-main1 := $(csu-objpfx)crt1.o
LDFLAGS-tst-main1 = $(no-pie-ldflag) tst-main1-no-pie = yes
LDLIBS-tst-main1 = $(libsupport) LDLIBS-tst-main1 = $(libsupport)
tst-main1mod.so-no-z-defs = yes tst-main1mod.so-no-z-defs = yes

View File

@ -49,7 +49,7 @@ endif
CFLAGS-mcount.c := -fno-omit-frame-pointer CFLAGS-mcount.c := -fno-omit-frame-pointer
CFLAGS-tst-gmon.c := -fno-omit-frame-pointer -pg CFLAGS-tst-gmon.c := -fno-omit-frame-pointer -pg
LDFLAGS-tst-gmon := $(no-pie-ldflag) tst-gmon-no-pie = yes
CRT-tst-gmon := $(csu-objpfx)gcrt1.o CRT-tst-gmon := $(csu-objpfx)gcrt1.o
tst-gmon-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon.data tst-gmon-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon.data
ifeq ($(run-built-tests),yes) ifeq ($(run-built-tests),yes)