Bug 12455 - Undefined reference error with ld.dk
Summary: Undefined reference error with ld.dk
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-01 13:50 UTC by Dmitry Gorbachev
Modified: 2011-02-01 17:46 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Testcase (243 bytes, text/plain)
2011-02-01 13:50 UTC, Dmitry Gorbachev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Gorbachev 2011-02-01 13:50:13 UTC
Created attachment 5221 [details]
Testcase
Comment 1 Dave Korn 2011-02-01 17:34:32 UTC
  This is the same failure as the LTO 10 testcase from HJ's patch that he posted the other day(*).  I've analysed the cause: the linker fails to respect the 1-byte alignment of the LTO sections when doing the -r link, so the output sections come out 4-aligned; e.g., from your testcase:

$ objdump -h foo.o

foo.o:     file format pe-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000010  00000000  00000000  000001f4  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  1 .data         00000000  00000000  00000000  00000000  2**2
                  ALLOC, LOAD, DATA
  2 .bss          00000000  00000000  00000000  00000000  2**2
                  ALLOC
  3 .gnu.lto_foo.d4648082 000000aa  00000000  00000000  00000204  2**0
                                                                 ^^^^ correct
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .gnu.lto_.cgraph.d4648082 00000037  00000000  00000000  000002ae  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  5 .gnu.lto_.vars.d4648082 00000012  00000000  00000000  000002e5  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  6 .gnu.lto_.refs.d4648082 00000012  00000000  00000000  000002f7  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  7 .gnu.lto_.statics.d4648082 00000014  00000000  00000000  00000309  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  8 .gnu.lto_.decls.d4648082 00000108  00000000  00000000  0000031d  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  9 .gnu.lto_.symtab.d4648082 00000028  00000000  00000000  00000425  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 10 .gnu.lto_.opts 00000035  00000000  00000000  0000044d  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 11 .eh_frame     00000038  00000000  00000000  00000482  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA

DKAdmin@ubik /gnu/binutils/git.repo/tests/pr12455
$ objdump -h bar.o

bar.o:     file format pe-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         0000000c  00000000  00000000  000000b4  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  00000000  00000000  00000000  2**2
                  ALLOC, LOAD, DATA
  2 .bss          00000000  00000000  00000000  00000000  2**2
                  ALLOC
  3 .eh_frame     00000038  00000000  00000000  000000c0  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA

DKAdmin@ubik /gnu/binutils/git.repo/tests/pr12455
$ objdump -h foobar.o

foobar.o:     file format pe-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         0000001c  00000000  00000000  000001f4  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  1 .data         00000000  00000000  00000000  00000000  2**2
                  ALLOC, LOAD, DATA
  2 .gnu.lto_foo.d4648082 000000ac  00000000  00000000  00000210  2**2
                                                                 ^^^^ wrong!
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .gnu.lto_.cgraph.d4648082 00000038  00000000  00000000  000002bc  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .gnu.lto_.vars.d4648082 00000014  00000000  00000000  000002f4  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  5 .gnu.lto_.refs.d4648082 00000014  00000000  00000000  00000308  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  6 .gnu.lto_.statics.d4648082 00000014  00000000  00000000  0000031c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  7 .gnu.lto_.decls.d4648082 00000108  00000000  00000000  00000330  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  8 .gnu.lto_.symtab.d4648082 00000028  00000000  00000000  00000438  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  9 .gnu.lto_.opts 00000038  00000000  00000000  00000460  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 10 .eh_frame     00000070  00000000  00000000  00000498  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
 11 .bss          00000000  00000000  00000000  00000000  2**2
                  ALLOC

  Increasing the alignment causes the size of the sections also to be rounded up, leaving a few bytes of stray data at the end that confuse the zlib unpacker in the lto input streamer.  This looks like an assumption somewhere in bfd about the minimum valid section alignment; I'll work on it next.

-- 
(*) - http://sourceware.org/ml/binutils/2011-01/msg00383.html
Comment 2 Dave Korn 2011-02-01 17:46:30 UTC
I just took a closer read of the subject line... guess you are getting a different error than me.  Don't know why you're not getting this, like I do:

$ make
gcc-4 -flto -o prog main.o foobar.o
lto1: internal compiler error: compressed stream: data error
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper: gcc-4 returned 1 exit status
/usr/bin/ld: lto-wrapper failed
collect2: ld returned 1 exit status
make: *** [prog] Error 1


... but it could be a matter of luck to do with the size of the lto sections.  Anyway I have to work on this problem next as I'm also getting it for your testcase in PR12430.