As I mentioned in my answer to this question , is it easy to get the line number that causes the link error depends on whether the compiler emitted all the necessary information.
To begin with, these are the cases that I have encountered, which leads to the behavior that you see:
- Compiler emitting erroneous debugging information (Solaris studio 12.3 with debugging / optimization under certain circumstances)
- Executing a destructor for an object that goes out of scope
- Code inserted by compiler:
- stack protection
- disinfectants
- other tools that enter code for debugging or profiling
What I will suggest for tracking can help if you have a link error resembling:
asdf.o: In function `whatever': asdf.o(.text+0x1238): undefined reference to `fdsa'
... because at least you have an address for work.
First try addr2line :
~ addr2line -e asdf.o 0x1238
Otherwise try objdump :
~ objdump --dwarf=decodedline asdf.o asdf.o: file format elf64-x86-64 Decoded dump of debug contents of section .debug_line: CU: asdf.cc: File name Line number Starting address asdf.cc 1 0x1234 asdf.cc 3 0x1254 asdf.cc 5 0x1274
In the fully fabricated example I cited here, there is no entry in the .debug_line corresponding to 0x1238 (the address is in the linker error), so it can be compiler magic (for example, additional code added by something like a stack protector or sanitizer), or, I hope, it is connected with what happens on the 1/3 lines, since the address is between these two lines.
If this does not give you enough opportunities to continue: when I wanted a little more, I did the following:
- Insert a link flag to stop it from being dismantled to get a distorted character.
- Compile the object file, but instead it will generate an assembly
- Build Search for Distorted Character
Assuming the assembly is annotated enough, it shouldn't be terribly difficult to match the missing character + information from objdump + assembly and at least get a fix in the line of code to run the rest of your search (assuming you still have more holes for rabbits, as is often the case with STL).
source share