Strange error of llvm-ld

I'm using llvm-ld from SVN r41106

When issueing the command

$ /usr/src/llvm/installed/bin/llvm-ld -v -stats -native -O1 -strip-all -o main \
  .obj/conf.o .obj/configwriter.o \
  -L/usr/share/qt3/lib -L/usr/X11R6/lib \
  -lcrypto -lusb -lutil -lqt-mt -lXext -lX11 -lm -lpthread

I get this output:

  Linking bitcode file '.obj/conf.o'
  Linked in file '.obj/conf.o'
  Linking bitcode file '.obj/configwriter.o'
llvm-ld: error: Cannot link file '.obj/configwriter.o'

If I swap the order of configwriter.o and conf.o, then I'll get
the same error, it just says that it cannot link conf.o

The "*.o" files are made by llvm-gcc-4.0 with --emit-llvm. I can
"llvm-dis conf.o -o -" on both files and don't see any apparent
error there.

Should I file a bug and attach those two files?

I think I have experienced this when more than one module contains
definitions for the same values. ie. it should only be a declaration
in one of them.

I think I have experienced this when more than one module
contains definitions for the same values. ie. it should only
be a declaration in one of them.

Hmm, when I compile and link this with plain gcc, it everything
works.

Anyway, llvm-ld should probably not just say "Cannot link
file 'blah'", but why it cannot link it.

I compiled llvm in with --enable-debug. Is there any switch that
I can use to turn on some verbosity, so that I can maybe see
from debug output where the problem is?

Tomas,

Please file a bug for this. Attach the .o files and command line in
question.

Thanks,

Reid.

Holger,

I have just committed a patch to cause the linker to properly propagate
error messages from the LinkModules method up to higher levels of the
linker. With this change it should tell you with more detail what is
going on (why it couldn't link the file in). Please update, rebuild and
try again. If you think the error message is wrong after that, please
file a bug for this.

To get verbose information, use the -v option on llvm-ld. In general,
you can find options from any llvm tool with "tool --help".

Thanks,

Reid.

I have just committed a patch to cause the linker to properly
propagate error messages from the LinkModules method up to
higher levels of the linker.

That helped. The strange error message is:

$ llvm-ld -v -stats -native -O1 -strip-all -o main \
  .obj/conf.o .obj/configwriter.o \
  -L/usr/share/qt3/lib -L/usr/X11R6/lib \
  -lcrypto -lusb -lutil -lqt-mt -lXext -lX11 -lm -lpthread

  Linking bitcode file '.obj/conf.o'
  Linked in file '.obj/conf.o'
  Linking bitcode file '.obj/configwriter.o'
llvm-ld: error: Cannot link file '.obj/configwriter.o': Linking
functions named 'strcmp': symbols have different visibilities!

Now, this happens when I compile the two source files
with "--fvisibility=hidden". If I omit this option, then llvm-ld
happily links those two files.

I made .o files with and without --fvisibility=hidden for both
files. One thing to note is that both versions emit the same
code for the strcmp:

$ grep strcmp *.ll
conf.hidden.o.ll: %tmp13 = tail call i32 @strcmp( i8* %tmp11, i8* %name ) ; <i32> [#uses=1]
conf.hidden.o.ll:declare i32 @strcmp(i8*, i8*)
conf.hidden.o.ll: %tmp421 = tail call i32 @strcmp( i8* %tmp11, i8* getelementptr ([6 x i8]* @.str5, i32 0, i32 0) ) ; <i32> [#uses=1]
conf.normal.o.ll: %tmp13 = tail call i32 @strcmp( i8* %tmp11, i8* %name ) ; <i32> [#uses=1]
conf.normal.o.ll:declare i32 @strcmp(i8*, i8*)
conf.normal.o.ll: %tmp421 = tail call i32 @strcmp( i8* %tmp11, i8* getelementptr ([6 x i8]* @.str5, i32 0, i32 0) ) ; <i32> [#uses=1]
configwriter.hidden.o.ll: %tmp434 = call i32 @strcmp( i8* %tmp411, i8* %tmp394 ) ; <i32> [#uses=1]
configwriter.hidden.o.ll:declare i32 @strcmp(i8*, i8*)
configwriter.normal.o.ll: %tmp434 = call i32 @strcmp( i8* %tmp411, i8* %tmp394 ) ; <i32> [#uses=1]
configwriter.normal.o.ll:declare i32 @strcmp(i8*, i8*)

Tomas,

I'm Holger :slight_smile:

Please file a bug for this. Attach the .o files and command
line in question.

Done, http://llvm.org/bugs/show_bug.cgi?id=1611

> Tomas,

I'm Holger :slight_smile:

Yes, sorry. I realized that about 10 seconds after I pushed the send
button. I was replying to a message from Tomas but my reply was about
things that you had written. Sorry for the confusion.

> Please file a bug for this. Attach the .o files and command
> line in question.

Done, http://llvm.org/bugs/show_bug.cgi?id=1611

Thanks, Holger!

Reid.