diff mbox

Should elf/tst-dlopen-aout.c fail when compiled as PIE?

Message ID CAMe9rOp60JA72qpZjiTAgo+P9v1XX-ohda4526WP1Gq_h8mQ8A@mail.gmail.com
State Dropped
Headers show

Commit Message

H.J. Lu March 6, 2015, 10:26 p.m. UTC
Hi Pail,

You are the author of elf/tst-dlopen-aout.c.  Should it fail
when it is compiled as PIE?  With this patch:


 selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null)

I got

[hjl@gnu-6 build-x86_64-linux]$ ./elf/tst-dlopen-aout
dlopen unexpectedly succeeded
[hjl@gnu-6 build-x86_64-linux]$

Comments

Roland McGrath March 6, 2015, 11 p.m. UTC | #1
It's clear from the content of the test that it cannot test what it's
intended to test unless the file it passes to dlopen it an ET_EXEC.  So if
you want to build the test itself as PIE, then you need to change it to
open some file other than itself.
H.J. Lu March 6, 2015, 11:05 p.m. UTC | #2
On Fri, Mar 6, 2015 at 3:00 PM, Roland McGrath <roland@hack.frob.com> wrote:
> It's clear from the content of the test that it cannot test what it's
> intended to test unless the file it passes to dlopen it an ET_EXEC.  So if
> you want to build the test itself as PIE, then you need to change it to
> open some file other than itself.

Thanks.  I will handle it properly.
Paul Pluzhnikov March 6, 2015, 11:21 p.m. UTC | #3
On Fri, Mar 6, 2015 at 3:05 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Mar 6, 2015 at 3:00 PM, Roland McGrath <roland@hack.frob.com> wrote:
>> It's clear from the content of the test that it cannot test what it's
>> intended to test unless the file it passes to dlopen it an ET_EXEC.  So if
>> you want to build the test itself as PIE, then you need to change it to
>> open some file other than itself.
>
> Thanks.  I will handle it properly.

I think adding

  CFLAGS-tst-dlopen-aout.c += -fno-pie

or some such may be the right fix.

You want to have ET_EXEC, and it's easiest to guarantee ET_EXEC if you
build it yourself, and the test itself will make a good ET_EXEC to
test with -- no reason to build an extra ET_EXEC.
Mike Frysinger March 7, 2015, 12:54 a.m. UTC | #4
On 06 Mar 2015 15:21, Paul Pluzhnikov wrote:
> On Fri, Mar 6, 2015 at 3:05 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> > On Fri, Mar 6, 2015 at 3:00 PM, Roland McGrath <roland@hack.frob.com> wrote:
> >> It's clear from the content of the test that it cannot test what it's
> >> intended to test unless the file it passes to dlopen it an ET_EXEC.  So if
> >> you want to build the test itself as PIE, then you need to change it to
> >> open some file other than itself.
> >
> > Thanks.  I will handle it properly.
> 
> I think adding
> 
>   CFLAGS-tst-dlopen-aout.c += -fno-pie
> 
> or some such may be the right fix.

it should be fine to compile as PIE as long as the final link isn't:
	LDFLAGS-tst-dlopen-aout.c = -no-pie
-mike
diff mbox

Patch

diff --git a/elf/Makefile b/elf/Makefile
index e852b5f..7edfcb7 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -150,6 +150,8 @@  tests += loadtest restest1 preloadtest loadfail
multiload origtest resolvfail \
 #  reldep9
 ifeq ($(build-hardcoded-path-in-tests),yes)
 tests += tst-dlopen-aout
+tests-pie += tst-dlopen-aout
+CFLAGS-tst-dlopen-aout.c += $(pie-ccflag)
 endif
 test-srcs = tst-pathopt