This is an archive of the discontinued LLVM Phabricator instance.

COFF: include archive name in LTO object name
ClosedPublic

Authored by inglorion on Mar 27 2017, 10:43 AM.

Details

Summary

In the ELF linker, we create the buffer identifier for bitcode files by appending the object name to the archive name. This change makes the COFF linker do the same. Without the change, ThinLTO builds can fail with an error message about multiple ThinLTO modules per object file, caused by object files contained in different archives having the same name.

Diff Detail

Repository
rL LLVM

Event Timeline

inglorion created this revision.Mar 27 2017, 10:43 AM

In ELF I believe the offset to the member name is also added. Because an archive can contain two member with the same name.

pcc edited edge metadata.Mar 27 2017, 11:02 AM

In ELF I believe the offset to the member name is also added. Because an archive can contain two member with the same name.

And it is possible to construct such an archive using lib.exe with some effort:

>touch foo.cpp

>cl /c foo.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

foo.cpp

>lib /out:foo.lib foo.obj
Microsoft (R) Library Manager Version 14.00.24215.1
Copyright (C) Microsoft Corporation.  All rights reserved.


>copy foo.lib foo2.lib
        1 file(s) copied.

>lib /out:foo3.lib foo.lib foo2.lib
Microsoft (R) Library Manager Version 14.00.24215.1
Copyright (C) Microsoft Corporation.  All rights reserved.


>\src\llvm-project\ra\bin\llvm-ar t foo3.lib
foo.obj
foo.obj

So we probably want to support such archives eventually. I see it as a lower priority than this bug, though, so up to you whether you want to fix it now.

For this change, please add a test case.

inglorion planned changes to this revision.Mar 27 2017, 11:39 AM

Adding the offset also affects non-LTO archive members, right? If so, I prefer to fix that in a follow up. For this one, I'd like to change ParentName + MB.getBufferIdentifier() to toString(this), which is more consistent with how we form the names in other places. I will also add a test.

pcc added a comment.Mar 27 2017, 11:47 AM

Adding the offset also affects non-LTO archive members, right? If so, I prefer to fix that in a follow up. For this one, I'd like to change ParentName + MB.getBufferIdentifier() to toString(this), which is more consistent with how we form the names in other places. I will also add a test.

That doesn't seem like a good idea to me. toString is mostly meant to be used for error reporting. Here's the implementation: http://llvm-cs.pcc.me.uk/tools/lld/COFF/InputFiles.cpp#395

As you can see it converts names to basenames and normalizes case, so you'd have problems with files with similar names.

ruiu edited edge metadata.Mar 27 2017, 12:43 PM

Yes, toString() is for generating error messages, and message contents can change anytime. It is not designed for other purposes.

inglorion updated this revision to Diff 93293.Mar 28 2017, 1:58 PM

added test

pcc accepted this revision.Mar 28 2017, 2:14 PM

LGTM

This revision is now accepted and ready to land.Mar 28 2017, 2:14 PM
This revision was automatically updated to reflect the committed changes.