Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Sun, 2 Dec 2018 16:16:19 -0500
From: Rich Felker <dalias@...c.org>
To: argante <argante@...me>
Cc: "musl@...ts.openwall.com" <musl@...ts.openwall.com>
Subject: Re: static linking problem

On Sun, Dec 02, 2018 at 07:25:56PM +0000, argante wrote:
> 
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Sunday, 2 December 2018 19:15, Szabolcs Nagy <nsz@...t> wrote:
> 
> > * argante argante@ [2018-12-02 17:20:15 +0000]:
> >
> > > ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> > > On Sunday, 2 December 2018 01:18, Rich Felker dalias@ wrote:
> > >
> > > > On Sat, Dec 01, 2018 at 10:07:53PM +0000, argante wrote:
> > > >
> > > > > /lib/ld-musl-x86_64.so.1 (0x7ff0dca25000)
> > > > > libc.so => /lib/ld-musl-x86_64.so.1 (0x7ff0dca25000)
> > > >
> > > > This is dynamic-linked, yes. But there's nothing wrong with your
> > > > static-linked program. If you really don't want pie, use -no-pie or a
> > > > toolchain that wasn't built to produce pie by default (gcc's
> > > > --enable-default-pie option at configure time).
> >
> > > ./configure \
> > > CFLAGS="-Os -g0" \
> > > CXXFLAGS="${CFLAGS}" \
> > > --enable-languages=c,c++ \
> 
> > > --enable-default-pie \
> >
> >        ^^^^^^^^^^^^^^^^^^^^^
> >
> > > I still can't understand why musl-cross ldd works correctly, and new toolchain shows such a strange result. Did I overlook something? I even tried -Wl,--no-dynamic-linker.
> >
> > what do you mean strange?
> >
> > it seems to work exactly as expected.
> 
> 
> I checked Alpine, where there is also a default pie. Indeed, ldd behaves the same:
> 
> # gcc -v
> Using built-in specs.
> COLLECT_GCC=gcc
> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/lto-wrapper
> Target: x86_64-alpine-linux-musl
> Configured with: /home/buildozer/aports/main/gcc/src/gcc-6.4.0/configure --prefix=/usr
> ....
> --enable-__cxa_atexit --enable-default-pie --enable-cloog-backend --enable-
>                       ^^^^^^^^^^^^^^^^^^^^
> Thread model: posix
> gcc version 6.4.0 (Alpine 6.4.0)
> 
> # gcc -static test.c
> # ldd a.out
> 	ldd (0x7f02ef28d000)
> 
> 
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Sunday, 2 December 2018 01:18, Rich Felker <dalias@> wrote:
> 
> > On Sat, Dec 01, 2018 at 10:07:53PM +0000, argante wrote:
> 
> > > ldd a.out
> > >
> > > ==========
> > >
> > > ldd (0x7fb6c936f000)
> >
> > Is this the musl ldd? I believe it will do this or similar, and that's
> > a known bug or at least limitation. It should report that the program
> > is not dynamic-linked.
> 
> 
> yes, this is musl ldd.
> 
> 
> but Gentoo:
> 
> # gcc -v
> Using built-in specs.
> COLLECT_GCC=/usr/x86_64-gentoo-linux-musl/gcc-bin/7.3.0/gcc
> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-gentoo-linux-musl/7.3.0/lto-wrapper
> Target: x86_64-gentoo-linux-musl
> Configured with: /var/tmp/portage/sys-devel/gcc-7.3.0-r3/work/gcc-7.3.0/configure --host=x86_64-gentoo-linux-musl --build=x86_64-gentoo-linux-musl --prefix=/usr
> 
> ....
> 
> --without-isl --disable-libsanitizer --enable-default-pie --enable-default-ssp
>                                      ^^^^^^^^^^^^^^^^^^^^
> Thread model: posix
> gcc version 7.3.0 (Gentoo Hardened 7.3.0-r3 p1.4)
> 
> 
> # gcc -static test.c
> # ldd a.out
> ldd: a.out: Not a valid dynamic program
> # ls -l /usr/bin/ldd
> lrwxrwxrwx 1 root root 24 Nov 13 21:27 /usr/bin/ldd -> /lib/ld-musl-x86_64.so.1
> 
> or:
> 
> # gcc -c -fPIE test.c
> # gcc -static -pie test.o
> # ldd a.out
> ldd: a.out: Not a valid dynamic program
> # readelf -l a.out
> 
> Elf file type is EXEC (Executable file)
> Entry point 0x40014d
> There are 4 program headers, starting at offset 64
> 
> Program Headers:
>   Type           Offset             VirtAddr           PhysAddr
>                  FileSiz            MemSiz              Flags  Align
>   LOAD           0x0000000000000000 0x0000000000400000 0x0000000000400000
>                  0x000000000000133c 0x000000000000133c  R E    0x200000
>   LOAD           0x0000000000001fd8 0x0000000000601fd8 0x0000000000601fd8
>                  0x0000000000000130 0x0000000000000840  RW     0x200000
>   GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
>                  0x0000000000000000 0x0000000000000000  RW     0x10
>   GNU_RELRO      0x0000000000001fd8 0x0000000000601fd8 0x0000000000601fd8
>                  0x0000000000000028 0x0000000000000028  R      0x1
> 
>  Section to Segment mapping:
>   Segment Sections...
>    00     .init .text .fini .rodata .eh_frame
>    01     .ctors .dtors .data.rel.ro .data .bss
>    02
>    03     .ctors .dtors .data.rel.ro
> 
> 
> 
> that's why it seemed surprising to me.

There is absolutely nothing wrong here. This is what a static pie
looks like. I don't know what you expect but your expectations are
wrong.

Rich

Powered by blists - more mailing lists

Your e-mail address:

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.