clang++ linker issues on Ubuntu AMD64.

Hi All,

I’m attempting to compile the following function

int main() {}

under Ubuntu 10.10 AMD64 with

clang++ -o empty empty.cpp

and it’s yielding

/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
<— snip (there’s about 17 more lines of this…) —>
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 20 has invalid symbol index 20
/usr/lib/gcc/x86_64-linux-gnu/4.5.1/…/…/…/…/lib/crt1.o: In function _start': (.text+0x20): undefined reference to main’
clang: error: linker command failed with exit code 1 (use -v to see invocation)

If I run

clang++ -c -o empty.o empty.cpp
nm empty.o

I see

0000000000000000 T :main

Is that colon the issue? (Object file formats and symbol names are not my area of expertise). In any case renaming “:main” to “main” with objcopy and then running ld manually yields a working executable.

So is this an invalid symbol name? A valid but incorrect one? Is there some flag that clang should be passing to ld to get it to recognise this symbol? I’d file a bug report, but as you can tell I’m slightly hazy on what the bug is.

Cheers,
Lang.

Hi;

Hi,

Specifically I was running with r122866, which was ToT as of earlier today. Updating to r122869, the current ToT, does not fix this issue, and (if I recall correctly) I saw the same issue when I checked clang out on a different AMD64 Ubuntu box a week or so back. Both were Debug+Asserts builds.

Cheers,
Lang.

Hi;

Hi;

Specifically I was running with r122866, which was ToT as of earlier today.
Updating to r122869, the current ToT, does not fix this issue, and (if I
recall correctly) I saw the same issue when I checked clang out on a
different AMD64 Ubuntu box a week or so back. Both were Debug+Asserts
builds.

I am also on x86-64 so this might be a Ubuntu specific problem.

I think this depends on your version of binutils, I get the same on
Debian with gcc on empty file. Ignore the invalid symbol index, the
problem is the missing 'main' function :slight_smile:

$ gcc empty.c
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0
has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1
has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 2
has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 3
has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 4
has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 5
has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 6
has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 7
has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 8
has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 9
has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 10
has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 11
has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 12
has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 13
has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 14
has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 15
has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 16
has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 17
has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 18
has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 19
has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 20
has invalid symbol index 20
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crt1.o: In function
`_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status

Hi;

Hi Török,

I should have been more clear on this detail too: My “empty” file contained an empty main function, rather than being completely empty. So the issue with the “missing” main is due to the main symbol being named “:main” instead of “main”.

  • Lang.

2011/1/5 Török Edwin <edwintorok@gmail.com>

Further details:

The assembly output from “int main() {}”, compiled with “clang -S -o empty empty.c” is

.file “empty.c”
.text
.globl “:main”
.align 16, 0x90
“:main”: # @main
.Leh_func_begin0:

BB#0: # %entry

pushq %rbp
.Ltmp0:
movq %rsp, %rbp
.Ltmp1:
movl $0, %eax
popq %rbp
ret
.Leh_func_end0:

.section .eh_frame,“a”,@progbits
.LEH_frame0:
.Lsection_eh_frame0:
.Leh_frame_common0:
.Lset0 = .Leh_frame_common_end0-.Leh_frame_common_begin0 # Length of Common Information Entry
.long .Lset0
.Leh_frame_common_begin0:
.long 0 # CIE Identifier Tag
.byte 1 # DW_CIE_VERSION
.asciz “zR” # CIE Augmentation
.byte 1 # CIE Code Alignment Factor
.byte 120 # CIE Data Alignment Factor
.byte 16 # CIE Return Address Column
.byte 1 # Augmentation Size
.byte 3 # FDE Encoding = udata4
.byte 12 # DW_CFA_def_cfa
.byte 7 # Register
.byte 8 # Offset
.byte 144 # DW_CFA_offset + Reg (16)
.byte 1 # Offset
.align 8
.Leh_frame_common_end0:
“.L:main.eh”:
.Lset1 = .Leh_frame_end0-.Leh_frame_begin0 # Length of Frame Information Entry
.long .Lset1
.Leh_frame_begin0:
.Lset2 = .Leh_frame_begin0-.Leh_frame_common0 # FDE CIE offset
.long .Lset2
.long .Leh_func_begin0 # FDE initial location
.Lset3 = .Leh_func_end0-.Leh_func_begin0 # FDE address range
.long .Lset3
.byte 0 # Augmentation size
.byte 4 # DW_CFA_advance_loc4
.Lset4 = .Ltmp0-.Leh_func_begin0
.long .Lset4
.byte 14 # DW_CFA_def_cfa_offset
.byte 16 # Offset
.byte 134 # DW_CFA_offset + Reg (6)
.byte 2 # Offset
.byte 4 # DW_CFA_advance_loc4
.Lset5 = .Ltmp1-.Ltmp0

.long .Lset5
.byte 13 # DW_CFA_def_cfa_register
.byte 6 # Register
.align 8
.Leh_frame_end0:

.section .note.GNU-stack,"",@progbits

It’s pretty clear the colon is being prepended in there, I’m just curious as to why?

Ismail - do you see the same output on your Linux AMD64 system?

  • Lang.

2011/1/5 Lang Hames <lhames@gmail.com>

Hi;

2011/1/5 Lang Hames <lhames@gmail.com>

Further details:

The assembly output from “int main() {}”, compiled with “clang -S -o empty empty.c” is

.file “empty.c”
.text
.globl “:main”
.align 16, 0x90

Nope, what I see is

.file “empty.c”
.text
.globl main
.align 16, 0x90
.type main,@function

Regards,
ismail

Ok, I guess this is somehow Ubuntu specific.

-Lang.

And of course a clean rebuild has fixed everything. Thanks to Takumi Nakamura for pointing that out. :slight_smile:

  • Lang.

2011/1/5 Lang Hames <lhames@gmail.com>