This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>
- Cc: Cary Coutant <ccoutant at google dot com>, GCC Development <gcc at gcc dot gnu dot org>, Binutils <binutils at sourceware dot org>
- Date: Tue, 14 Jan 2014 12:01:16 -0800
- Subject: Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Authentication-results: sourceware.org; auth=none
- References: <20140110142001 dot GA6035 at intel dot com> <20140111001259 dot GE5390 at bubble dot grove dot modra dot org> <CAMe9rOo0UtpbdT69cnkK4fZD5pmzQnuX2wMCkBy3GuSLGcmcow at mail dot gmail dot com> <CAHACq4opdALo+T=dvM_PT2M36H+feAqpF6Gsf0sPZy-g=bg8SA at mail dot gmail dot com> <20140114003945 dot GM5390 at bubble dot grove dot modra dot org> <CAHACq4oq4KjUqc8GTgA6onRBQBxyvfxDcQn6OmCC7mrRu04_Aw at mail dot gmail dot com> <CAMe9rOooXfygAUg--xG=XtPpo56kOz0B9sm70zBDhZz+9scm9Q at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1401141928050 dot 8844 at digraph dot polyomino dot org dot uk>
On Tue, Jan 14, 2014 at 11:37 AM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> On Tue, 14 Jan 2014, H.J. Lu wrote:
>
>> When there is -static, -dynamic-linker won't passed to ld. -static,
>> -shared, -pie should be mutually exclusive for GCC driver.
>
> A static PIE shouldn't specify an interpreter; it should handle all
> dynamic relocation processing itself. Thus, it's correct not to specify
> -dynamic-linker when building a static PIE.
If -dynamic-linker isn't specified, linker will use
the default dynamic linker:
[hjl@gnu-6 pr16428]$ cat x.c
int main() { return 0; }
[hjl@gnu-6 pr16428]$ make
gcc -m32 -B./ -pie -static -fPIE -c -o x.o x.c
gcc -m32 -B./ -pie -static -o x x.o
./x
make: ./x: Command not found
make: *** [all] Error 127
[hjl@gnu-6 pr16428]$ readelf -l x
Elf file type is DYN (Shared object file)
Entry point 0x10d0b
There are 8 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000034 0x00000034 0x00000034 0x00100 0x00100 R E 0x4
INTERP 0x000134 0x00000134 0x00000134 0x00013 0x00013 R 0x1
[Requesting program interpreter: /usr/lib/libc.so.1]
LOAD 0x000000 0x00000000 0x00000000 0xb6fda 0xb6fda R E 0x1000
LOAD 0x0b7000 0x000b7000 0x000b7000 0x00e40 0x02534 RW 0x1000
DYNAMIC 0x0b70b0 0x000b70b0 0x000b70b0 0x000d0 0x000d0 RW 0x4
NOTE 0x000148 0x00000148 0x00000148 0x00044 0x00044 R 0x4
TLS 0x0b7000 0x000b7000 0x000b7000 0x00010 0x00028 R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x10
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym
.dynstr .rel.dyn .rel.plt .init .plt .text __libc_thread_freeres_fn
__libc_freeres_fn .fini .rodata .stapsdt.base __libc_thread_subfreeres
__libc_subfreeres __libc_atexit .eh_frame .gcc_except_table
03 .tdata .init_array .fini_array .jcr .data.rel.ro .dynamic
.got .got.plt .data .bss __libc_freeres_ptrs
04 .dynamic
> ld.so itself is a static PIE - it specifies no PT_INTERP or DT_NEEDED, and
> is position-independent. The concept of an arbitrary program meeting
> those conditions, including a copy of the relevant parts of the dynamic
> linker to relocate itself, is perfectly meaningful; it just so happens
> that glibc, and the associated GCC specs, don't support it, but I'm not
> aware of any fundamental problem with supporting it in ld given
> appropriate startup code and static libc built as PIC. (I don't know how
> useful more general static PIE support would be.)
-static -PIE may make sense to ld, but not to GCC driver,
at least, not on Linux/x86 where the dynamic linker isn't
/usr/lib/libc.so.1
> (-shared and -pie do seem mutually exclusive, as the first says what's
> being linked operates as a library and the second says it operates as an
> executable - although of course the same ET_DYN can operate as both.)
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
--
H.J.
- References:
- PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static