Reference:
https://lld.llvm.org/#using-lld
$ clang++ -fuse-ld=lld
Reference:
https://youtu.be/7QNtiH5wTAs?si=c8I_prA9k9Hasfdr
Reference:
undefined reference to vtable for X
What is a C++ "Key Function" as described by gold?
class X {
public:
virtual ~X() = 0;
void f();
virtual void g() { }
virtual void h(); // defined inline out side of class.
virtual void i(); // <-- Key fuction.
virtual void j();
};
inline void X::h() { }
#include <iostream>
class Base {
public:
virtual void foo() = 0; // Pure virtual function
};
class Derived : public Base {
public:
void foo() override; // Declaring but not defining foo()
};
int main() {
Derived d; // This will cause a linker error due to missing vtable
return 0;
}
Reference:
https://maskray.me/blog/2021-07-25-comdat-and-section-group
COMDAT gives indication to the linker to deduplicate the inline/weak reference/external linkage symbols.
https://github.com/llvm/llvm-project/blob/2e603c6/clang/lib/AST/ItaniumMangle.cpp#L1458-L1472
inline vs. non-inline name mangling with extra letter 'L'.
e.g.
_ZSt8in_place vs. _ZStL8in_place
References and excerpt from: http://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/ http://eli.thegreenplace.net/2011/11/11/position-independent-code-pic-in-shared-libraries-on-x64/ http://eli.thegreenplace.net/2011/08/25/load-time-relocation-of-shared-libraries/ http://eli.thegreenplace.net/2012/01/03/understanding-the-x64-code-models/ http://eli.thegreenplace.net/2012/08/13/how-statically-linked-programs-run-on-linux/
gcc -flto -o f f1.o f2.o
int (*fp)(int) = [](int x) { return x * x; };
Such closures can be treated like functions.
int atexit(void (*f)()) noexcept; // from <cstdlib>
std::atexit([]{ logMsg("Shutting down..."); });
In C++11, function pointer linkage not specified ⇒ possible linkage problems.Excerpt: The LD_BIND_NOW env var, when defined, tells the dynamic loader to always perform the resolution for all symbols at start-up time, and not lazily. Conversely, the LD_BIND_NOT env var tells the dynamic loader not to update the GOT entry at all. Each call to an external function will then go through the dynamic loader and be resolved anew.