8

According to ld man pages, the -x link flag suppresses putting non-global symbols into the output file's symbol table. These symbols are useful for debugging but are not used at runtime. But this flag is causing link errors for me on Mavericks. For example, the following source file:

struct Yo
{
    Yo() {}
};

void useYo()
{
    Yo yo;
}

Compiled/linked as follows:

c++ -arch x86_64 -bundle -Wl,-x -o tc.so tc.cpp

Produces the following output:

ld: internal error: atom not found in symbolIndex(__ZN2YoC1Ev) for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The constructor Yo::Yo() is the problem:

c++filt __ZN2YoC1Ev
Yo::Yo()

Removing the -x link flag fixes the problem. Moving the constructor implementation outside the structure declaration also fixes the problem. This code compile/links fine:

struct Yo
{
    Yo();
};

Yo::Yo() {}

void useYo()
{
    Yo yo;
}

Here's my compiler info:

Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix

Is this a bug in clang or the linker, or is there some reason I should not be using the -x link flag?

nobody
  • 19,814
  • 17
  • 56
  • 77
Dave Taflin
  • 474
  • 5
  • 9
  • I've reported this upstream too -- https://llvm.org/bugs/show_bug.cgi?id=23337 – Manav Apr 24 '15 at 11:05
  • @Rizwan Why did you edit this? You changed correct capitalization to wrong capitalization and the correct word to the wrong word. Two errors and zero improvements. – nobody Oct 25 '21 at 00:44

0 Answers0