Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAA7aPHjAm67x72c_SZUdu5y3PLD0Ang=E5vg6_5cCNuBC9ft2Q@mail.gmail.com>
Date: Wed, 1 Oct 2014 15:11:25 -0400
From: stephen Turner <stephen.n.turner@...il.com>
To: musl@...ts.openwall.com
Subject: Re: converting gcc from glibc to musl

On Wed, Oct 1, 2014 at 2:13 PM, Szabolcs Nagy <nsz@...t70.net> wrote:

> * stephen Turner <stephen.n.turner@...il.com> [2014-10-01 13:54:25 -0400]:
> > On Wed, Oct 1, 2014 at 12:10 PM, Szabolcs Nagy <nsz@...t70.net> wrote:
> > > - can gcc compile a minimal program (empty main)?
> > >
> >
> > I can compile the following program sucessfully to a.out but cannot run
> it.
> >
> > # include <stdio.h>
> > main()
> > {
> > printf("hello world\n");
> > }
> >
> > gcc test.c && chmod +x a.out && ./a.out
> >
> >
> > > - where does gcc/ld fail, how were they invoked (gcc -v)?
> >
> >
> > configure:2078: loading cache /dev/null
> ...
>
> i meant running
>
>  gcc -v test.c
>
> not the configure thing
>
> (so we know if the compiler works at all before
> starting to debug the configure script)
>

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i486-linux-gnu/4.7/lto-wrapper
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5'
--with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs
--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.7 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-gnu-unique-object --enable-plugin --enable-objc-gc
--enable-targets=all --with-arch-32=i586 --with-tune=generic
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5)
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=i586'
 /usr/lib/gcc/i486-linux-gnu/4.7/cc1 -quiet -v -imultiarch i386-linux-gnu
test.c -quiet -dumpbase test.c -mtune=generic -march=i586 -auxbase test
-version -o /tmp/ccc9a5Pc.s
GNU C (Debian 4.7.2-5) version 4.7.2 (i486-linux-gnu)
compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.1.0-p10,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/i386-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i486-linux-gnu/4.7/../../../../i486-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i486-linux-gnu/4.7/include
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.7/include-fixed
 /usr/include/i386-linux-gnu
 /usr/include
End of search list.
GNU C (Debian 4.7.2-5) version 4.7.2 (i486-linux-gnu)
compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.1.0-p10,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 86d53dcb5a2b688dea58f7b6bd2d835d
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=i586'
 as -v --32 -o /tmp/ccHDIj0a.o /tmp/ccc9a5Pc.s
GNU assembler version 2.22 (i486-linux-gnu) using BFD version (GNU Binutils
for Debian) 2.22
COMPILER_PATH=/usr/lib/gcc/i486-linux-gnu/4.7/:/usr/lib/gcc/i486-linux-gnu/4.7/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.7/:/usr/lib/gcc/i486-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/i486-linux-gnu/4.7/:/usr/lib/gcc/i486-linux-gnu/4.7/../../../i386-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.7/../../../../lib/:/lib/i386-linux-gnu/:/lib/../lib/:/usr/lib/i386-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/i486-linux-gnu/4.7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=i586'
 /usr/lib/gcc/i486-linux-gnu/4.7/collect2 --sysroot=/ --build-id
--no-add-needed --eh-frame-hdr -m elf_i386 --hash-style=both
-dynamic-linker /lib/ld-linux.so.2
/usr/lib/gcc/i486-linux-gnu/4.7/../../../i386-linux-gnu/crt1.o
/usr/lib/gcc/i486-linux-gnu/4.7/../../../i386-linux-gnu/crti.o
/usr/lib/gcc/i486-linux-gnu/4.7/crtbegin.o
-L/usr/lib/gcc/i486-linux-gnu/4.7
-L/usr/lib/gcc/i486-linux-gnu/4.7/../../../i386-linux-gnu
-L/usr/lib/gcc/i486-linux-gnu/4.7/../../../../lib -L/lib/i386-linux-gnu
-L/lib/../lib -L/usr/lib/i386-linux-gnu -L/usr/lib/../lib
-L/usr/lib/gcc/i486-linux-gnu/4.7/../../.. /tmp/ccHDIj0a.o -lgcc
--as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s
--no-as-needed /usr/lib/gcc/i486-linux-gnu/4.7/crtend.o
/usr/lib/gcc/i486-linux-gnu/4.7/../../../i386-linux-gnu/crtn.o




>
> > - in the executable is the loader properly set up (readelf)?
> >
>
> check if the machine type/abi is ok:
>
>  readelf -h a.out
>

ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Intel 80386
  Version:                           0x1
  Entry point address:               0x8048240
  Start of program headers:          52 (bytes into file)
  Start of section headers:          1424 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         7
  Size of section headers:           40 (bytes)
  Number of section headers:         24
  Section header string table index: 21



> check if the musl loader is set up as expected:
>
>  readelf -l a.out
>
> (in case of dynamic linking the interpreter should be
> /lib/ld-musl-ARCH.so.1 otherwise there should be no
> interpreter)
>


Elf file type is EXEC (Executable file)
Entry point 0x8048240
There are 7 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  PHDR           0x000034 0x08048034 0x08048034 0x000e0 0x000e0 R E 0x4
  INTERP         0x000114 0x08048114 0x08048114 0x00013 0x00013 R   0x1
      [Requesting program interpreter: /lib/ld-linux.so.2]
  LOAD           0x000000 0x08048000 0x08048000 0x0040c 0x0040c R E 0x1000
  LOAD           0x00040c 0x0804940c 0x0804940c 0x000c4 0x000e4 RW  0x1000
  DYNAMIC        0x000420 0x08049420 0x08049420 0x00098 0x00098 RW  0x4
  GNU_EH_FRAME   0x000390 0x08048390 0x08048390 0x0001c 0x0001c R   0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x10

 Section to Segment mapping:
  Segment Sections...
   00
   01     .interp
   02     .interp .hash .dynsym .dynstr .rel.plt .init .plt .text .fini
.rodata .eh_frame_hdr .eh_frame
   03     .ctors .dtors .jcr .dynamic .got.plt .data .bss
   04     .dynamic
   05     .eh_frame_hdr
   06




>
>
> > - check if the loader/libc at the right path
> >
>
> ls -l /lib/ld-musl-*
>

not exactly, i found /lib/libc.so but no ld-musl* i created a symlink of
ld-musl* to libc.so and gcc is able to work (initially gcc doesnt work as
it cant find the lib it needs) but a.out continues to fail.


>
> > - can you run the executable with the loader explicitly?
>
> run
>
> /lib/ld-musl-ARCH.so.1 ./a.out
>

Yes, this works! albiet i used /lib/libc.so


>
> > > - strace the executable, where does it fail?
>
> strace ./a.out
>

execve("./a.out", ["./a.out"], [/* 13 vars */]) = 0
brk(0)                                  = 0x892b000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or
directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0xb775b000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or
directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=14405, ...}) = 0
mmap2(NULL, 14405, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7757000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or
directory)
open("/lib/i386-linux-gnu/tls/i686/sse2/cmov/libc.so", O_RDONLY) = -1
ENOENT (No such file or directory)
stat64("/lib/i386-linux-gnu/tls/i686/sse2/cmov", 0xbfde3550) = -1 ENOENT
(No such file or directory)
open("/lib/i386-linux-gnu/tls/i686/sse2/libc.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
stat64("/lib/i386-linux-gnu/tls/i686/sse2", 0xbfde3550) = -1 ENOENT (No
such file or directory)
open("/lib/i386-linux-gnu/tls/i686/cmov/libc.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
stat64("/lib/i386-linux-gnu/tls/i686/cmov", 0xbfde3550) = -1 ENOENT (No
such file or directory)
open("/lib/i386-linux-gnu/tls/i686/libc.so", O_RDONLY) = -1 ENOENT (No such
file or directory)
stat64("/lib/i386-linux-gnu/tls/i686", 0xbfde3550) = -1 ENOENT (No such
file or directory)
open("/lib/i386-linux-gnu/tls/sse2/cmov/libc.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
stat64("/lib/i386-linux-gnu/tls/sse2/cmov", 0xbfde3550) = -1 ENOENT (No
such file or directory)
open("/lib/i386-linux-gnu/tls/sse2/libc.so", O_RDONLY) = -1 ENOENT (No such
file or directory)
stat64("/lib/i386-linux-gnu/tls/sse2", 0xbfde3550) = -1 ENOENT (No such
file or directory)
open("/lib/i386-linux-gnu/tls/cmov/libc.so", O_RDONLY) = -1 ENOENT (No such
file or directory)
stat64("/lib/i386-linux-gnu/tls/cmov", 0xbfde3550) = -1 ENOENT (No such
file or directory)
open("/lib/i386-linux-gnu/tls/libc.so", O_RDONLY) = -1 ENOENT (No such file
or directory)
stat64("/lib/i386-linux-gnu/tls", 0xbfde3550) = -1 ENOENT (No such file or
directory)
open("/lib/i386-linux-gnu/i686/sse2/cmov/libc.so", O_RDONLY) = -1 ENOENT
(No such file or directory)
stat64("/lib/i386-linux-gnu/i686/sse2/cmov", 0xbfde3550) = -1 ENOENT (No
such file or directory)
open("/lib/i386-linux-gnu/i686/sse2/libc.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
stat64("/lib/i386-linux-gnu/i686/sse2", 0xbfde3550) = -1 ENOENT (No such
file or directory)
open("/lib/i386-linux-gnu/i686/cmov/libc.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
stat64("/lib/i386-linux-gnu/i686/cmov", {st_mode=S_IFDIR|0755,
st_size=4096, ...}) = 0
open("/lib/i386-linux-gnu/i686/libc.so", O_RDONLY) = -1 ENOENT (No such
file or directory)
stat64("/lib/i386-linux-gnu/i686", {st_mode=S_IFDIR|0755, st_size=4096,
...}) = 0
open("/lib/i386-linux-gnu/sse2/cmov/libc.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
stat64("/lib/i386-linux-gnu/sse2/cmov", 0xbfde3550) = -1 ENOENT (No such
file or directory)
open("/lib/i386-linux-gnu/sse2/libc.so", O_RDONLY) = -1 ENOENT (No such
file or directory)
stat64("/lib/i386-linux-gnu/sse2", 0xbfde3550) = -1 ENOENT (No such file or
directory)
open("/lib/i386-linux-gnu/cmov/libc.so", O_RDONLY) = -1 ENOENT (No such
file or directory)
stat64("/lib/i386-linux-gnu/cmov", 0xbfde3550) = -1 ENOENT (No such file or
directory)
open("/lib/i386-linux-gnu/libc.so", O_RDONLY) = -1 ENOENT (No such file or
directory)
stat64("/lib/i386-linux-gnu", {st_mode=S_IFDIR|0755, st_size=12288, ...}) =
0
open("/usr/lib/i386-linux-gnu/tls/i686/sse2/cmov/libc.so", O_RDONLY) = -1
ENOENT (No such file or directory)
stat64("/usr/lib/i386-linux-gnu/tls/i686/sse2/cmov", 0xbfde3550) = -1
ENOENT (No such file or directory)
open("/usr/lib/i386-linux-gnu/tls/i686/sse2/libc.so", O_RDONLY) = -1 ENOENT
(No such file or directory)
stat64("/usr/lib/i386-linux-gnu/tls/i686/sse2", 0xbfde3550) = -1 ENOENT (No
such file or directory)
open("/usr/lib/i386-linux-gnu/tls/i686/cmov/libc.so", O_RDONLY) = -1 ENOENT
(No such file or directory)
stat64("/usr/lib/i386-linux-gnu/tls/i686/cmov", 0xbfde3550) = -1 ENOENT (No
such file or directory)
open("/usr/lib/i386-linux-gnu/tls/i686/libc.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
stat64("/usr/lib/i386-linux-gnu/tls/i686", 0xbfde3550) = -1 ENOENT (No such
file or directory)
open("/usr/lib/i386-linux-gnu/tls/sse2/cmov/libc.so", O_RDONLY) = -1 ENOENT
(No such file or directory)
stat64("/usr/lib/i386-linux-gnu/tls/sse2/cmov", 0xbfde3550) = -1 ENOENT (No
such file or directory)
open("/usr/lib/i386-linux-gnu/tls/sse2/libc.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
stat64("/usr/lib/i386-linux-gnu/tls/sse2", 0xbfde3550) = -1 ENOENT (No such
file or directory)
open("/usr/lib/i386-linux-gnu/tls/cmov/libc.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
stat64("/usr/lib/i386-linux-gnu/tls/cmov", 0xbfde3550) = -1 ENOENT (No such
file or directory)
open("/usr/lib/i386-linux-gnu/tls/libc.so", O_RDONLY) = -1 ENOENT (No such
file or directory)
stat64("/usr/lib/i386-linux-gnu/tls", 0xbfde3550) = -1 ENOENT (No such file
or directory)
open("/usr/lib/i386-linux-gnu/i686/sse2/cmov/libc.so", O_RDONLY) = -1
ENOENT (No such file or directory)
stat64("/usr/lib/i386-linux-gnu/i686/sse2/cmov", 0xbfde3550) = -1 ENOENT
(No such file or directory)
open("/usr/lib/i386-linux-gnu/i686/sse2/libc.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
stat64("/usr/lib/i386-linux-gnu/i686/sse2", 0xbfde3550) = -1 ENOENT (No
such file or directory)
open("/usr/lib/i386-linux-gnu/i686/cmov/libc.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
stat64("/usr/lib/i386-linux-gnu/i686/cmov", {st_mode=S_IFDIR|0755,
st_size=4096, ...}) = 0
open("/usr/lib/i386-linux-gnu/i686/libc.so", O_RDONLY) = -1 ENOENT (No such
file or directory)
stat64("/usr/lib/i386-linux-gnu/i686", {st_mode=S_IFDIR|0755, st_size=4096,
...}) = 0
open("/usr/lib/i386-linux-gnu/sse2/cmov/libc.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
stat64("/usr/lib/i386-linux-gnu/sse2/cmov", 0xbfde3550) = -1 ENOENT (No
such file or directory)
open("/usr/lib/i386-linux-gnu/sse2/libc.so", O_RDONLY) = -1 ENOENT (No such
file or directory)
stat64("/usr/lib/i386-linux-gnu/sse2", 0xbfde3550) = -1 ENOENT (No such
file or directory)
open("/usr/lib/i386-linux-gnu/cmov/libc.so", O_RDONLY) = -1 ENOENT (No such
file or directory)
stat64("/usr/lib/i386-linux-gnu/cmov", 0xbfde3550) = -1 ENOENT (No such
file or directory)
open("/usr/lib/i386-linux-gnu/libc.so", O_RDONLY) = 3
read(3, "/* GNU ld script\n   Use the shar"..., 512) = 283
close(3)                                = 0
writev(2, [{"./a.out", 7}, {": ", 2}, {"error while loading shared
libra"..., 36}, {": ", 2}, {"/usr/lib/i386-linux-gnu/libc.so", 31}, {": ",
2}, {"invalid ELF header", 18}, {"", 0}, {"", 0}, {"\n", 1}], 10./a.out:
error while loading shared libraries: /usr/lib/i386-linux-gnu/libc.so:
invalid ELF header
) = 99
exit_group(127)                         = ?



>
> >
> > I dont know how to do what your asking here is there a site i can ref on
> > these troubleshooting steps?
>
> if you are not experienced with toolchains i'd try
> alpine or sabotage linux first
> you might be able to customize them to your liking
>

I tried alpine and have only glanced at sabotage. It never fails, when i
use someone elses distro there is something im not happy with. This coupled
with the fact that i want to learn all i can about linux and eventually get
my linux+ or other cert.  Thanks for showing me those tests! looks like i
have reading to understand how to use them effectively :)

I guess i just need to be different and as independent as possible which is
why i have fought with building this system without help for about 3 months
now working my way through issue after issue with only google as my friend
:)

Content of type "text/html" skipped

Powered by blists - more mailing lists

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