Re: pitiful results for GCC 4.8.0

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

 



[ long winding and weaving reply ahead .. sorry ]

> >> It looks like I did not have that set.  I did have :
> >>
> >> LD=/usr/local/bin/gld
> >> LDFLAGS=-L/usr/local/lib
> >> LD_OPTIONS=-R/usr/local/lib:/usr/local/gcc4/lib -L/usr/local/lib:/usr/local/gcc4/lib
> >> LD_RUN_PATH=/usr/local/lib:/usr/local/gcc4/lib
> >> LIBTOOL=/usr/local/bin/libtool
> >>
> >> Those may be the source of my concern as LD_OPTIONS could be trouble.
> >
> > I don't think the GNU linker uses LD_OPTIONS, isn't that a Solaris ld
> > environment variable?

yep.  clearly something I dragged over from one of my Solaris build servers. 
Should be harmless, but useless also. 

> > LD_RUN_PATH would cause your issue though.  Don't do that.

I was wondering if the libs in /usr/local/gcc4/lib are being found and they
belong to GCC 4.7.3 as opposed to 4.8.0 and .. I see yes, you have mentioned
that below. 

> Or if you do, don't have the older GCC libs in those paths, as they
> are being found and that's what causes the test failures.  Once you've
> installed the newer GCC you might find the tests results are better,
> because the older libs don't get found.

Generally I tend to stick with a procedure of "test first" then if that looks okay,
I install. This is a chicken and egg case where I need to install first and then
run tests. Seems reasonable given that changes that have happened in the
GCC 4.8.x world. 

> Is there a reason you're putting /usr/local/lib in the RPATH? Isn't it
> in the default paths searched by ldconfig anyway?

That would be part of my Solaris history showing again. I have this old UNIX 
belief that anything in /usr/lib is definately considered part of the vendor OS
and will always be used by the runtime linker and/or compiler and linker with
no need for me to specify anything. Anything else, however, even things like
software pieces in /usr/lib/vmware/lib or /usr/lib/ure/lib there is no promise.
I have a philosophy, which may be wrong, that messing with crle or making
a modification to the vendor provided default link searchpath should be a 
strict no no. If I were to tweak the system to search /usr/local/lib first, such
that my new libiconv and GNU gettext bits are found first then I could just
as easily place a tweaked libc in there.  Perhaps I could hack in a modified
routine to extract users environment variables and session data and write
that info silently to a file somewhere.  I generally think, perhaps wrongly,
that the stuff in /usr/local/lib should not be searched by default. That the
purpose of RPATH and RUNPATH inside the elf headers exist to ensure that
a given executable uses the libs I want.  This allows me to build a binary
and drop it into someplace like /opt/vendorname/bin with libs inside a path
such as /opt/vendorname/lib with confidence. 

An example would be my binary for gawk : 

dclarke@titan $ elfdump -devl /usr/local/bin/gawk

ELF Header
  ei_magic:   { 0x7f, E, L, F }
  ei_class:   ELFCLASS32          ei_data:      ELFDATA2LSB
  e_machine:  EM_386              e_version:    EV_CURRENT
  e_type:     ET_EXEC
  e_flags:                     0
  e_entry:             0x8055b60  e_ehsize:     52  e_shstrndx:   37
  e_shoff:               0xe5724  e_shentsize:  40  e_shnum:      39
  e_phoff:                  0x34  e_phentsize:  32  e_phnum:       5

Version Needed Section:  .SUNW_version
            file                        version
            libc.so.1                   SUNW_1.18            
                                        SUNWprivate_1.1      
            libsocket.so.1              SUNW_1.4             
            libdl.so.1                  SUNW_0.7             
            libm.so.1                   SUNW_1.1             

Dynamic Section:  .dynamic
     index  tag               value
       [0]  NEEDED           0x1535            libsigsegv.so.2
       [1]  NEEDED           0x14d2            libc.so.1
       [2]  NEEDED           0x1545            libintl.so.8
       [3]  NEEDED           0x1552            libiconv.so.2
       [4]  NEEDED           0x14f6            libsocket.so.1
       [5]  NEEDED           0x1560            libnsl.so.1
       [6]  NEEDED           0x150e            libdl.so.1
       [7]  NEEDED           0x1522            libm.so.1
       [8]  INIT             0x80a9598         
       [9]  FINI             0x80a95a5         
      [10]  RUNPATH          0x156c            /usr/local/lib:/usr/local/gcc4/lib
      [11]  RPATH            0x156c            /usr/local/lib:/usr/local/gcc4/lib
      [12]  HASH             0x80500e8         
      [13]  STRTAB           0x80535b8         
      [14]  STRSZ            0x158f            
      [15]  SYMTAB           0x8051288         
      [16]  SYMENT           0x10              
      [17]  CHECKSUM         0x16bb            
      [18]  VERNEED          0x8054b48         
      [19]  VERNEEDNUM       0x4               
      [20]  PLTRELSZ         0x510             
      [21]  PLTREL           0x11              
      [22]  JMPREL           0x8054c20         
      [23]  REL              0x8054bd8         
      [24]  RELSZ            0x558             
      [25]  RELENT           0x8               
      [26]  DEBUG            0                 
      [27]  FEATURE_1        0x1               [ PARINIT ]
      [28]  FLAGS            0                 0
      [29]  FLAGS_1          0                 0
      [30]  PLTGOT           0x80c5264         

That is on a Solaris box clearly. If I check to see what libs get used when I 
execute gawk I see : 

dclarke@titan $ ldd -fr /usr/local/bin/gawk
        libsigsegv.so.2 =>       /usr/local/lib/libsigsegv.so.2
        libc.so.1 =>     /usr/lib/libc.so.1
        libintl.so.8 =>  /usr/local/lib/libintl.so.8
        libiconv.so.2 =>         /usr/local/lib/libiconv.so.2
        libsocket.so.1 =>        /usr/lib/libsocket.so.1
        libnsl.so.1 =>   /usr/lib/libnsl.so.1
        libdl.so.1 =>    /usr/lib/libdl.so.1
        libm.so.1 =>     /usr/lib/libm.so.1
        libmp.so.2 =>    /usr/lib/libmp.so.2

I can trace everything the runtime linker does with this : 

dclarke@titan $  LD_DEBUG=files /usr/local/bin/gawk --version 
07748: 
07748: configuration file=/var/ld/ld.config: unable to process file
07748: 
07748: 
07748: file=/usr/lib/ld.so.1  [ ELF ]
07748:     dynamic:  0xdfbf20bc  base:  0xdfbc0000
07748:     envp:      0x80479a4  auxv:   0x8047a6c
07748: 
07748: file=/usr/local/bin/gawk  [ ELF ]; generating link map
07748:     dynamic:   0x80c550c  base:   0x8050000  size:      0x82434
07748:     entry:     0x8055b60  lmid:         0x0  lmco:          0xc
07748: 
07748: file=/usr/local/bin/gawk;  analyzing  [ RTLD_LAZY  RTLD_GLOBAL  RTLD_WORLD  RTLD_NODELETE ]
07748: 
07748: file=libsigsegv.so.2;  needed by /usr/local/bin/gawk
07748: file=/usr/local/lib/libsigsegv.so.2  [ ELF ]; generating link map
07748:     dynamic:  0xdfa32b9c  base:  0xdfa20000  size:      0x13000
07748:     entry:    0xdfa20094  lmid:         0x0  lmco:          0xc
07748: 
07748: file=libc.so.1;  needed by /usr/local/bin/gawk
07748: file=/usr/lib/libc.so.1  [ ELF ]; generating link map
07748:     dynamic:  0xdfa08940  base:  0xdf970000  size:      0xa0000
07748:     entry:    0xdf98c1fc  lmid:         0x0  lmco:          0xc
07748: 
07748: file=libintl.so.8;  needed by /usr/local/bin/gawk
07748: file=/usr/local/lib/libintl.so.8  [ ELF ]; generating link map
07748:     dynamic:  0xdf95e53c  base:  0xdf940000  size:      0x1f000
07748:     entry:    0xdf940094  lmid:         0x0  lmco:          0xc
07748: 
07748: file=libiconv.so.2;  needed by /usr/local/bin/gawk
07748: file=/usr/local/lib/libiconv.so.2  [ ELF ]; generating link map
07748:     dynamic:  0xdf92d1c8  base:  0xdf820000  size:     0x10e000
07748:     entry:    0xdf820094  lmid:         0x0  lmco:          0xc
07748: 
07748: file=libsocket.so.1;  needed by /usr/local/bin/gawk
07748: file=/usr/lib/libsocket.so.1  [ ELF ]; generating link map
07748:     dynamic:  0xdf81a294  base:  0xdf800000  size:      0x1b000
07748:     entry:    0xdf800094  lmid:         0x0  lmco:          0xc
07748: 
07748: file=libnsl.so.1;  needed by /usr/local/bin/gawk
07748: file=/usr/lib/libnsl.so.1  [ ELF ]; generating link map
07748:     dynamic:  0xdf7e7f64  base:  0xdf760000  size:      0x94000
07748:     entry:    0xdf760094  lmid:         0x0  lmco:          0xc
07748: 
07748: file=libdl.so.1;  needed by /usr/local/bin/gawk
07748: file=/usr/lib/libdl.so.1  [ ELF ]; generating link map
07748:     dynamic:  0xdf750094  base:  0xdf750000  size:       0x1000
07748:     entry:    0xdf750094  lmid:         0x0  lmco:          0xc
07748: 
07748: file=libm.so.1;  needed by /usr/local/bin/gawk
07748: file=/usr/lib/libm.so.1  [ ELF ]; generating link map
07748:     dynamic:  0xdf742944  base:  0xdf720000  size:      0x24000
07748:     entry:    0xdf720094  lmid:         0x0  lmco:          0xc
07748: 
07748: file=/usr/local/lib/libsigsegv.so.2;  analyzing  [ RTLD_LAZY  RTLD_GLOBAL  RTLD_WORLD  RTLD_NODELETE ]
07748: 
07748: file=libc.so.1;  needed by /usr/local/lib/libsigsegv.so.2
07748: 
07748: file=/usr/lib/libc.so.1;  analyzing  [ RTLD_LAZY  RTLD_GLOBAL  RTLD_WORLD  RTLD_NODELETE ]
07748: 
07748: file=libdl.so.1;  needed by /usr/lib/libc.so.1
07748: 
07748: file=/usr/local/lib/libintl.so.8;  analyzing  [ RTLD_LAZY  RTLD_GLOBAL  RTLD_WORLD  RTLD_NODELETE ]
07748: 
07748: file=libiconv.so.2;  needed by /usr/local/lib/libintl.so.8
07748: 
07748: file=libc.so.1;  needed by /usr/local/lib/libintl.so.8
07748: 
07748: file=/usr/local/lib/libiconv.so.2;  analyzing  [ RTLD_LAZY  RTLD_GLOBAL  RTLD_WORLD  RTLD_NODELETE ]
07748: 
07748: file=libc.so.1;  needed by /usr/local/lib/libiconv.so.2
07748: 
07748: file=/usr/lib/libsocket.so.1;  analyzing  [ RTLD_LAZY  RTLD_GLOBAL  RTLD_WORLD  RTLD_NODELETE ]
07748: 
07748: file=libnsl.so.1;  needed by /usr/lib/libsocket.so.1
07748: 
07748: file=libc.so.1;  needed by /usr/lib/libsocket.so.1
07748: 
07748: file=/usr/lib/libnsl.so.1;  analyzing  [ RTLD_LAZY  RTLD_GLOBAL  RTLD_WORLD  RTLD_NODELETE ]
07748: 
07748: file=libdl.so.1;  needed by /usr/lib/libnsl.so.1
07748: 
07748: file=libc.so.1;  needed by /usr/lib/libnsl.so.1
07748: 
07748: file=libmp.so.2;  needed by /usr/lib/libnsl.so.1
07748: file=/usr/lib/libmp.so.2  [ ELF ]; generating link map
07748:     dynamic:  0xdf703068  base:  0xdf6f0000  size:      0x14000
07748:     entry:    0xdf6f0094  lmid:         0x0  lmco:          0xc
07748: 
07748: file=/usr/lib/libdl.so.1;  analyzing  [ RTLD_LAZY  RTLD_GLOBAL  RTLD_WORLD  RTLD_NODELETE ]
07748: 
07748: file=/usr/lib/libm.so.1;  analyzing  [ RTLD_LAZY  RTLD_GLOBAL  RTLD_WORLD  RTLD_NODELETE ]
07748: 
07748: file=libc.so.1;  needed by /usr/lib/libm.so.1
07748: 
07748: file=/usr/lib/libmp.so.2;  analyzing  [ RTLD_LAZY  RTLD_GLOBAL  RTLD_WORLD  RTLD_NODELETE ]
07748: 
07748: file=libc.so.1;  needed by /usr/lib/libmp.so.2
07748: 
07748: file=/usr/lib/libdl.so.1;  filter for /usr/lib/ld.so.1
07748: 
07748: file=/usr/lib/ld.so.1;  filtered by /usr/lib/libdl.so.1
07748: 
07748: 
07748: 
07748: 
07748: 
07748: 
07748: transferring control: /usr/local/bin/gawk
07748: 
GNU Awk 4.0.2
Copyright (C) 1989, 1991-2012 Free Software Foundation.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
07748: 
07748: 
07748: 
07748: 
07748: 

In this way I can build binaries with confidence and know where the libs
are being pulled from to execute a given function. Am I correct thus far?

Now I switch over to a linux system and I also try to ensure that I have
a RPATH/RUNPATH setup within any binary that goes into a non-standard
place like /usr/local/bin thus : 

dclarke@phobos:/usr/local/build$ /usr/local/bin/greadelf -dh /usr/local/bin/gawk
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:               0x804eb60
  Start of program headers:          52 (bytes into file)
  Start of section headers:          718352 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         8
  Size of section headers:           40 (bytes)
  Number of section headers:         40
  Section header string table index: 37

Dynamic section at offset 0x660d4 contains 25 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libsigsegv.so.2]
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]
 0x00000001 (NEEDED)                     Shared library: [libdl.so.2]
 0x00000001 (NEEDED)                     Shared library: [libm.so.6]
 0x0000000f (RPATH)                      Library rpath: [/usr/local/lib]
 0x0000000c (INIT)                       0x804e0d4
 0x0000000d (FINI)                       0x80a211c
 0x00000004 (HASH)                       0x804818c
 0x6ffffef5 (GNU_HASH)                   0x8049274
 0x00000005 (STRTAB)                     0x804c1ec
 0x00000006 (SYMTAB)                     0x8049efc
 0x0000000a (STRSZ)                      5266 (bytes)
 0x0000000b (SYMENT)                     16 (bytes)
 0x00000015 (DEBUG)                      0x0
 0x00000003 (PLTGOT)                     0x80af1c8
 0x00000002 (PLTRELSZ)                   1312 (bytes)
 0x00000014 (PLTREL)                     REL
 0x00000017 (JMPREL)                     0x804dbb4
 0x00000011 (REL)                        0x804db8c
 0x00000012 (RELSZ)                      40 (bytes)
 0x00000013 (RELENT)                     8 (bytes)
 0x6ffffffe (VERNEED)                    0x804dadc
 0x6fffffff (VERNEEDNUM)                 3
 0x6ffffff0 (VERSYM)                     0x804d67e
 0x00000000 (NULL)                       0x0

I can try to see what libs are being used when I execute gawk like so : 

dclarke@phobos:/usr/local/build$ LD_DEBUG=files /usr/local/bin/gawk --version 
      5199:
      5199:     file=libsigsegv.so.2 [0];  needed by /usr/local/bin/gawk [0]
      5199:     file=libsigsegv.so.2 [0];  generating link map
      5199:       dynamic: 0xb773fe0c  base: 0xb773d000   size: 0x00002f70
      5199:         entry: 0xb773d990  phdr: 0xb773d034  phnum:          5
      5199:
      5199:
      5199:     file=libc.so.6 [0];  needed by /usr/local/bin/gawk [0]
      5199:     file=libc.so.6 [0];  generating link map
      5199:       dynamic: 0xb7727d7c  base: 0xb75e5000   size: 0x00146968
      5199:         entry: 0xb75fbe00  phdr: 0xb75e5034  phnum:         10
      5199:
      5199:
      5199:     file=libdl.so.2 [0];  needed by /usr/local/bin/gawk [0]
      5199:     file=libdl.so.2 [0];  generating link map
      5199:       dynamic: 0xb75e2ed0  base: 0xb75e0000   size: 0x00003078
      5199:         entry: 0xb75e0a40  phdr: 0xb75e0034  phnum:          8
      5199:
      5199:
      5199:     file=libm.so.6 [0];  needed by /usr/local/bin/gawk [0]
      5199:     file=libm.so.6 [0];  generating link map
      5199:       dynamic: 0xb75deef0  base: 0xb75ba000   size: 0x00025080
      5199:         entry: 0xb75bd460  phdr: 0xb75ba034  phnum:          9
      5199:
      5199:
      5199:     calling init: /lib/i686/cmov/libc.so.6
      5199:
      5199:
      5199:     calling init: /lib/i686/cmov/libm.so.6
      5199:
      5199:
      5199:     calling init: /lib/i686/cmov/libdl.so.2
      5199:
      5199:
      5199:     calling init: /usr/local/lib/libsigsegv.so.2
      5199:
      5199:
      5199:     initialize program: /usr/local/bin/gawk
      5199:
      5199:
      5199:     transferring control: /usr/local/bin/gawk
      5199:
GNU Awk 4.0.2
Copyright (C) 1989, 1991-2012 Free Software Foundation.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
      5199:
      5199:     calling fini: /usr/local/bin/gawk [0]
      5199:
      5199:
      5199:     calling fini: /usr/local/lib/libsigsegv.so.2 [0]
      5199:
      5199:
      5199:     calling fini: /lib/i686/cmov/libdl.so.2 [0]
      5199:
      5199:
      5199:     calling fini: /lib/i686/cmov/libm.so.6 [0]
      5199:
      5199:
      5199:     calling fini: /lib/i686/cmov/libc.so.6 [0]
      5199:

There I see libm and libc and libdl all found within /lib.  What if I 
were to be sneaky and slide a modified libc into /usr/local/lib ? 

Consider this spooky looking thing : 

dclarke@phobos:/usr/local/lib$  ldd -r /usr/local/bin/gawk
        linux-gate.so.1 =>  (0xb77cb000)
        libsigsegv.so.2 => /usr/local/lib/libsigsegv.so.2 (0xb77c6000)
        libc.so.6 => /usr/local/lib/libc.so.6 (0xb767f000)
        libdl.so.2 => /usr/local/lib/libdl.so.2 (0xb767a000)
        libm.so.6 => /usr/local/lib/libm.so.6 (0xb7654000)
        /lib/ld-linux.so.2 (0xb77cc000)

There I have placed a libc.so.6 within /usr/local/lib and if I were sneaky
I could make that a hand crafted lib that can do all manner of bad things.

I think the implications are just, well spooky : 

dclarke@phobos:/usr/local/lib$ which gcc
/usr/local/gcc4/bin/gcc
dclarke@phobos:/usr/local/lib$ ldd /usr/local/gcc4/bin/gcc
        linux-gate.so.1 =>  (0xb7745000)
        libiconv.so.2 => /usr/local/lib/libiconv.so.2 (0xb765c000)
        libm.so.6 => /usr/local/lib/libm.so.6 (0xb7636000)
        libc.so.6 => /usr/local/lib/libc.so.6 (0xb74ee000)
        /lib/ld-linux.so.2 (0xb7746000)
dclarke@phobos:/usr/local/lib$ /usr/local/gcc4/bin/gcc --version 
gcc (Blastwave.org Inc. Sun Apr 28 08:01:32 GMT 2013) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

So I try to force binaries to use libs within the destination prefix /usr/local and 
then ensure that there is a RPATH/RUNPATH in the elf headers that points
to that prefix also.  The downside is that I just don't know of a way to really
ensure that libs like libc and libm *always* come from the vendor OS and 
not from some hacked version within /usr/local/lib. 

Sorry if I went way off topic.  Perhaps into the weeds a bit, but I always have 
a somewhat curious opinion of binaries that are not from the OS vendor and 
wonder what else they may be doing, and how, and why.  I just don't know 
how else to say it, and am possibly making a real mess of this. The libs needed
by a given binary should be somehow electric fence protected, possibly even
a sha256 hash in the elf header that clearly identifies it is correct for the binary.

Long long story short, my build of GCC 4.8.x is messy because the testsuite runs
were using libs from /usr/local/lib and /usr/local/gcc4/lib which all are from a 
previous GCC 4.7.3 install.  

So, perhaps some wrong thinking on my part. 

dc




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux