NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

toolchain/51030: -pie -static does not work (test failure with MKPIE=yes builds)



>Number:         51030
>Category:       toolchain
>Synopsis:       -pie -static does not work (test failure with MKPIE=yes builds)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 30 19:00:00 +0000 2016
>Originator:     Martin Husemann
>Release:        NetBSD 7.99.26
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD thirdstage.duskware.de 7.99.26 NetBSD 7.99.26 (MODULAR) #466: Tue Mar 29 13:18:26 CEST 2016 martin%thirdstage.duskware.de@localhost:/usr/src/sys/arch/sparc64/compile/MODULAR sparc64
Architecture: sparc64
Machine: sparc64
>Description:

In a build with MKPIE=yes set, the /usr/tests/lib/csu/ tests cause a
new failure (at least on sparc64). This is due to the
/usr/tests/lib/csu/h_initfini2 test being explicitly linked with
-static (this is what is tested) and MKPIE additionaly forcing -pie
LDFLAGS.

It is unclear what kind of binary the combination of "-pie -static"
should create.

On sparc64 currently a dynamic object with reference to the non-existent
dynamic linker /usr/lib/sparcv9/ld.so.1 is created and this binary is
not executable.

Adding -Wl,-dynamic-linker=/usr/libexec/ld.elf_so fixes the issue, but
then this is not a static binary any more.

>How-To-Repeat:

Compile hello word with:

cc -v -Wall -O2 -fPIE -pie -static hello.c

(assuming you have build your whole world with MKPIE=yes, otherwise it
will fail early) and try to run it. Verify file type with file(1)
and/or readelf -l.

>Fix:
Define proper semantics for "-pie -static" and fix whatever needs fixing
to get there. Jörg suggested a DYN object with interpreter pointing to
itself (how exactly?). Other options would be an empty path as interpreter.
None of these fit my definition of "static".

A completely different aproach would be an EXEC binary with load address NULL,
like this:

Elf file type is EXEC (Executable file)
Entry point 0x0
There are 2 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000100000 0x0000000000000000 0x0000000000000000
                 0x0000000000136dd8 0x000000000013b810  RWE    100000
  NOTE           0x00000000002000b0 0x00000000001000b0 0x00000000001000b0
                 0x0000000000000048 0x0000000000000048  R      4

and assorted kernel fixes to treat this as PIE. This, at least, really is
a "static" binary.



Home | Main Index | Thread Index | Old Index