-
On Linux, if a weak symbol is not defined but used in an On macOS, according to my tests, the Apple linker does not accept undefined weak symbols. Can you confirm that this is the normal behaviour of the current Apple linker? Is there any linker option that could change this behaviour? (I could not find anything related) Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
Default ELF linker semantics are different from default Mach-O linker semantics. ELF allows any undefined symbols, Mach-O does not (note that there are ELF linker options to make it reject missing symbols and, as I am going to write below, options to allow missing symbols on Mach-O). In both cases, weak referenced symbols do operate at runtime in the same way (if the symbol is not present in the dynamically-linked exe, it will be 0). For Mach-O, using current linkers, you have two ways to deal with this;
the second is a large sledgehammer and will not only allow the symbols you want to be undefined, but any others that get accidentally misspelled etc. There are times when the second is useful (mostly in implementing plugins or when too lazy to specify the correct set). additional: dynamic lookup is incompatible with some relocation mechanisms used on Arm64 (according to linker warnings) .. so perhaps it is wise to consider mechanisms to avoid that sledgehammer... |
Beta Was this translation helpful? Give feedback.
Default ELF linker semantics are different from default Mach-O linker semantics. ELF allows any undefined symbols, Mach-O does not (note that there are ELF linker options to make it reject missing symbols and, as I am going to write below, options to allow missing symbols on Mach-O).
In both cases, weak referenced symbols do operate at runtime in the same way (if the symbol is not present in the dynamically-linked exe, it will be 0).
For Mach-O, using current linkers, you have two ways to deal with this;
-U,_symbol
.. or (if there are many) by providing the list in a file [ man ld ].