This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Fix linker plugin support for gnu linker


"H.J. Lu" <hjl.tools@gmail.com> writes:
> On Sat, Jan 8, 2011 at 6:46 AM, Richard Sandiford
> <rdsandiford@googlemail.com> wrote:
>> "H.J. Lu" <hjl.tools@gmail.com> writes:
>>> On Sat, Jan 8, 2011 at 4:10 AM, Richard Sandiford
>>> <rdsandiford@googlemail.com> wrote:
>>>> "H.J. Lu" <hongjiu.lu@intel.com> writes:
>>>>> This patch fixes linker plugin support for gnu linker with 2 stage
>>>>> linking and supports mixed LTO objects:
>>>>>
>>>>> http://www.kernel.org/pub/linux/devel/gcc/lto/mixed-IR/mixed-IR.pdf
>>>>>
>>>>> Any objections?
>>>>
>>>> One problem with the patch as written is that it doesn't cope with
>>>> the kind of embedded setup in which the startup file is specified
>>>> in a linker script. ÂE.g. on mipsisa64-elf, GCC doesn't know what
>>>> system you're targetting, and therefore doesn't what startup files or
>>>> board-specific libraries are needed. ÂYou instead link with something
>>>> like -Tidt64.ld. Âidt64.ld then contains:
>>>>
>>>> STARTUP(crt0.o)
>>>>
>>>> -T options are parsed immediately in-place, and don't show up in the
>>>> cmdline_options. ÂThings like STARTUP don't either. ÂThis means that
>>>> crt0.o is dropped by the second stage link.
>>>>
>>>> The handling of -T also means that the system libraries:
>>>>
>>>> GROUP(-lc -lidt -lgcc)
>>>>
>>>> don't show up in the second link. ÂHowever, that brings up a broader
>>>> question (which might already have been answered, sorry). ÂThe current
>>>> process -- that is, the process before the 2-stage patch -- seems to
>>>> rely on the GCC driver passing the equivalent of:
>>>>
>>>> Â-pass-through=-lgcc -pass-through=-lc -pass-through=-lgcc
>>>>
>>>> to the plugin. ÂBut on targets like mipsisa64-elf, GCC doesn't know
>>>
>>> hjl/lto-mixed branch ignores Â-pass-through=XXX passed from gcc driver.
>>
>> Right, that's what I meant. ÂThe fact that the 2-pass link doesn't
>> need those options means that it would solve the problem for free.
>> But at the moment it doesn't work because it ignores the linker script's
>> GROUP as well.
>
> You can pass -Wl,--verbose to gcc to see exactly what are passed to
> stage 2 linking:
>
> Stage 2 command line:
>   /usr/lib/../lib/crt1.o /usr/lib/../lib/crti.o
> /usr/gcc-4.6/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/32/crtbegin.o
> /tmp/ccmzgIMd.ltrans0.ltrans.o --no-whole-archive
> /usr/gcc-4.6/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/32/libgcc.a
> /usr/gcc-4.6/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../lib/libgcc_s.so
> /usr/lib/../lib/libc.so --no-whole-archive
> /usr/gcc-4.6/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/32/libgcc.a
> /usr/gcc-4.6/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../lib/libgcc_s.so
> /usr/gcc-4.6/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/32/crtend.o
> /usr/lib/../lib/crtn.o

Yeah, that's what I was doing.  crt0.o and the GROUP files are not listed.

The linker command line is:

   /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/libexec/gcc/mipsisa64-elf/4.6.0/liblto_plugin.so -plugin-opt=/export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/libexec/gcc/mipsisa64-elf/4.6.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccyO6BXX.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc -EB -o /tmp/foo /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crti.o /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crtbegin.o -L/export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0 -L/export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/../../../../../H-x86_64-unknown-linux-gnu/mipsisa64-elf/lib /tmp/ccRbTLAW.o -v -M --verbose -lgcc -lgcc /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crtend.o /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crtn.o -T idt64.ld

LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/../../../../../H-x86_64-unknown-linux-gnu/mipsisa64-elf/lib/crt0.o
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crti.o
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crtbegin.o
LOAD /tmp/ccRbTLAW.o
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/libgcc.a
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/libgcc.a
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crtend.o
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crtn.o
START GROUP
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/../../../../../H-x86_64-unknown-linux-gnu/mipsisa64-elf/lib/libc.a
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/../../../../../H-x86_64-unknown-linux-gnu/mipsisa64-elf/lib/libidt.a
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/libgcc.a
END GROUP
[...]
Stage 2 command line:
  /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crti.o /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crtbegin.o /tmp/cctWDG0U.ltrans0.ltrans.o --no-whole-archive /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/libgcc.a --no-whole-archive /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/libgcc.a /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crtend.o /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crtn.o
[...]
OUTPUT(/tmp/foo elf32-bigmips)
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crti.o
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crtbegin.o
LOAD /tmp/cctWDG0U.ltrans0.ltrans.o
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/libgcc.a
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/libgcc.a
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crtend.o
LOAD /export/richards/usr/gcc/H-x86_64-unknown-linux-gnu/lib/gcc/mipsisa64-elf/4.6.0/crtn.o/export/richards/usr/src/H-x86_64-unknown-linux-gnu/bin/mipsisa64-elf-ld: warning: cannot find entry symbol _start; defaulting to 0000000080020000
/tmp/cctWDG0U.ltrans0.ltrans.o: In function `main':
(.text+0x2c): undefined reference to `abort'
/tmp/cctWDG0U.ltrans0.ltrans.o: In function `main':
(.text+0x38): undefined reference to `exit'
collect2: ld returned 1 exit status

Note how crt0.o and the group are missing from the second LOAD list.

> I just need to handle STARTUP properly.

And GROUP. :-)

> If you can provide a native testcase on Linux/x86-64, I will fix it.

Sorry, I don't have time to reproduce this on x86_64.  I'm just trying
to provide feeback to the patch submission.

Richard


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]