Bug 20693

Summary: kernel build error on ppc64le
Product: binutils Reporter: Markus Trippelsdorf <markus>
Component: goldAssignee: Cary Coutant <ccoutant>
Status: RESOLVED FIXED    
Severity: normal CC: bb2983148, Grace_Cooper406, ian, npiggin, sourceware
Priority: P2    
Version: 2.28   
Target Milestone: ---   
See Also: https://bugzilla.kernel.org/show_bug.cgi?id=177741
https://bugs.gentoo.org/show_bug.cgi?id=602532
Host: Target:
Build: Last reconfirmed: 2016-11-21 00:00:00

Description Markus Trippelsdorf 2016-10-17 06:03:17 UTC
On ppc64le I get during Linux kernel build:

objdump -h lib/lib.a | sed -ne '/___ksymtab/{s/.*+/EXTERN(/;s/ .*/)/;p}' >lib/.lib-ksyms.o.lds; rm -f lib/.lib_exports.o; ar rcsD lib/.lib_exports.o; ld -EL    -r -o lib/lib-ksyms.o -T lib/.lib-ksyms.o.lds lib/.lib_exports.o; rm lib/.lib_exports.o lib/.lib-ksyms.o.lds
ld: internal error in target, at parameters.h:105


trippels@gcc2-power8 linux % rm foo.o
trippels@gcc2-power8 linux % ar rcsD foo.o
trippels@gcc2-power8 linux % cat foo.o
!<arch>
trippels@gcc2-power8 linux % cat test.lds
EXTERN(bar)
trippels@gcc2-power8 linux % ld.bfd -T test.lds foo.o
trippels@gcc2-power8 linux % ld.gold -T test.lds foo.o
ld.gold: internal error in target, at parameters.h:105
Comment 1 Markus Trippelsdorf 2016-10-17 10:39:11 UTC
It happens on all archs with an empty archive.
Comment 2 Cary Coutant 2016-11-21 20:19:48 UTC
*** Bug 20767 has been marked as a duplicate of this bug. ***
Comment 3 Cary Coutant 2016-11-21 20:26:13 UTC
The best gold can do here is print a (proper) error that there are no input objects. Without at least one object, gold has no idea what target to generate an output file for.

What kind of file does ld.bfd generate?

And why is this useful?
Comment 4 Markus Trippelsdorf 2016-11-21 20:47:08 UTC
Here is an example:
trippels@gcc2-power8 linux % objdump -h lib/lib.a | sed -ne '/___ksymtab/{s/.*+/EXTERN(/;s/ .*/)/;p}' >|lib/.lib-ksyms.o.lds
trippels@gcc2-power8 linux % cat lib/.lib-ksyms.o.lds
EXTERN(argv_free)
EXTERN(argv_split)
... <The actual list goes on>
trippels@gcc2-power8 linux % ar rcsD lib/.lib_exports.o
trippels@gcc2-power8 linux % ld.bfd -r -o lib/lib-ksyms.o -T lib/.lib-ksyms.o.lds lib/.lib_exports.o
trippels@gcc2-power8 linux % eu-readelf -a lib/lib-ksyms.o
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF64
  Data:                              2's complement, little endian
  Ident Version:                     1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           PowerPC 64-bit
  Version:                           1 (current)
  Entry point address:               0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          192 (bytes into file)
  Flags:                             
  Size of this header:               64 (bytes)
  Size of program header entries:    0 (bytes)
  Number of program headers entries: 0
  Size of section header entries:    64 (bytes)
  Number of section headers entries: 4
  Section header string table index: 3

Section Headers:
[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
[ 1] .symtab              SYMTAB       0000000000000000 00000040 00000048 24        2   1  8
[ 2] .strtab              STRTAB       0000000000000000 00000088 00000016  0        0   0  1
[ 3] .shstrtab            STRTAB       0000000000000000 0000009e 0000001b  0        0   0  1


Symbol table [ 1] '.symtab' contains 3 entries:
 1 local symbol  String table: [ 2] '.strtab'
  Num:            Value   Size Type    Bind   Vis          Ndx Name
    0: 0000000000000000      0 NOTYPE  LOCAL  DEFAULT    UNDEF 
    1: 0000000000000000      0 NOTYPE  GLOBAL DEFAULT    UNDEF argv_split
    2: 0000000000000000      0 NOTYPE  GLOBAL DEFAULT    UNDEF argv_free

String section [2] '.strtab' contains 22 bytes at offset 0x88:
  [     0]  
  [     1]  argv_split
  [     c]  argv_free
Comment 5 Sourceware Commits 2016-11-21 22:06:59 UTC
The master branch has been updated by Cary Coutant <ccoutant@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c13b08dbbcf752480a7621aa1f89bc5440c74c25

commit c13b08dbbcf752480a7621aa1f89bc5440c74c25
Author: Cary Coutant <ccoutant@gmail.com>
Date:   Mon Nov 21 14:05:40 2016 -0800

    Fix bug where -u option with empty archive results in internal error.
    
    gold/
    	PR gold/20693
    	* gold.cc (queue_middle_tasks): Force valid target earlier.
Comment 6 Cary Coutant 2016-11-21 22:12:18 UTC
Turns out we do have logic to choose the default target in such a case -- it's just that the code to process -u/EXTERN options came first.

Fixed on trunk.
Comment 7 Linda Walsh 2016-12-17 00:54:36 UTC
Is this also fixed for the x86_64 platform, as it also pops up there on a kernel build.
Comment 8 Cary Coutant 2016-12-17 03:02:20 UTC
(In reply to Linda  Walsh from comment #7)
> Is this also fixed for the x86_64 platform, as it also pops up there on a
> kernel build.

Yes, the problem and the fix are target independent, so it should be fixed on all targets.
Comment 9 Grace_Cooper 2021-10-08 06:55:21 UTC Comment hidden (spam)
Comment 10 Grace_Cooper 2021-10-08 06:57:27 UTC Comment hidden (spam)
Comment 11 Grace_Cooper 2021-10-18 01:15:01 UTC Comment hidden (spam)
Comment 12 bb2983148 2021-11-08 04:44:38 UTC Comment hidden (spam)