-
-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.comm in .a not found #256
Comments
Common symbols are resolved in a strange way when they are in archive files. Here is how GNU ld works.
So, the linker does not pull out an object if it results in overwriting a common symbol with a common symbol. This behavior is strange, to say the least. So, mold takes a simpler approach. It does not pull out an archive member for a common symbol. It seems this semantics are working fine in most cases, but as you pointed out, this is indeed different. How did you notice this issue? I wonder if there's a program in the wild that depends on this subtle difference. |
I notices this because my libc makes use of this for the __guard symbol. I could switch that back to a regular symbol if I have to to make it work with mold. I went with the GNU as documentation here: https://ftp.gnu.org/old-gnu/Manuals/gas-2.9.1/html_chapter/as_7.html#SEC76 It does not mention any special behavior for archives. To be honest I'm not sure why we switched from a regular symbol to a .comm in the first place. What would be the downside of pulling in an object for a .comm symbol in mold instead of failing the build? |
@rui314 , I think that I ran into a related issue just yesterday. If statically linking libpthread.a, mold will not be able to find certain common symbols. Toy pthread program:
Under Ubuntu 20.04 with gcc-9:
The undefined symbols here are all common symbols in libpthread.a:
|
I made a change so that unresolved symbols are resolved to common symbols in an archive if exists. It ended up with a small patch, so I don't think it is likely to have an undesirable side effect, but since name resolution is a intricate step, it needs extensive testing. I'll do that by compiling all Gentoo packages before 1.0.2. In the meantime, if you guys notice any issue, please file a bug. |
I'm probably doing something wrong here, this may not be a bug in mold after all.
Here's a minimal repro:
$ cat a.S
.data
.comm foo,4,4
$ cat b.c
extern int foo;
int main() { return foo; }
$ clang -o c a.S b.c
(works)
$ clang -o c a.S b.c -fuse-ld=mold
(still works)
$ clang -c a.S b.c
$ ar cru c.a a.o b.o
$ ranlib c.a
$ clang -o c c.a
(works)
$ clang -o c c.a -fuse-ld=mold
mold: error: undefined symbol: c.a(b.o): foo
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
Huh? Why can't mold find foo if it comes from an archive?
The text was updated successfully, but these errors were encountered: