Linking to static library containing duplicate filename fails #2142

Closed
AerialX opened this Issue Feb 20, 2014 · 3 comments

Projects

None yet

2 participants

@AerialX
AerialX commented Feb 20, 2014

When emcc links to a static library, it first runs LLVM_AR x f to extract the objects to a temporary directory (in tools/shared.py:link). If the archive contains a duplicate filename, it will be overwritten during the extraction process and linking will fail due to missing symbols in the file(s) that were destroyed.

GNU ar seems have a specific option to get around this, ar xN count archive filename, though it doesn't seem that llvm-ar has the same feature. To work around the issue personally I've replaced LLVM_AR with the following replacement extractor, which simply extracts an archive while ignoring the original filenames:
https://gist.github.com/AerialX/5f6763559769bf9c30e6

I'm not sure of the best approach for emscripten to take, but is it possible for this to be somehow fixed?

@kripken
Owner
kripken commented Feb 21, 2014

I worry about replacing llvm-ar with a from-scratch script, and this seems like a corner case, so the risk is high for little gain. Perhaps the best solution is to fix this upstream in llvm-ar by adding support for that GNU ar option?

@kripken
Owner
kripken commented May 22, 2015

I pushed a commit to add hashing to each object in .a files, as suggested in #2619 (comment) , which should fix this.

This will break people that expect to be able to read the objects themselves. We'll see if this is a problem on incoming. If it is, we might need to put it behind a flag.

@kripken
Owner
kripken commented May 30, 2015

No problems were reported, this has been merged to master.

@kripken kripken closed this May 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment