.weakref

Fangrui Song i@maskray.me
Thu Jun 11 18:12:21 GMT 2020


.weakref has a quite unusual description (
https://sourceware.org/binutils/docs/as/Weakref.html#Weakref )

"This directive creates an alias to the target symbol that enables the
symbol to be referenced with weak-symbol semantics, but without actually
making it weak. If direct references or definitions of the symbol are
present, then the symbol will not be weak, but if all references to it
are through weak references, the symbol will be marked as weak in the
symbol table."

For `.weakref foo, bar` , if bar is neither defined nor referenced, and foo is referenced,
`foo` is emitted as an undefined weak symbol. (llvm-mc emits foo even if
foo is not referenced)

The binutils-gdb commit does not give me useful information. A bit
archaeology takes me to GCC __attribute__((weakref))
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=4372

What features can a dedicated .weakref express while an ordinary .weak
reference can't? (I know nothing will be changed now, but just wanted to
have a better understanding of the design of the directive)


More information about the Binutils mailing list