[PATCH] ldd::COFF: better behavior when using as a library
Andrew Kelley via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 23 11:40:39 PDT 2017
On Mon, Oct 23, 2017 at 2:30 PM, Rui Ueyama <ruiu at google.com> wrote:
> If you are not particularly interested in doing it yourself, I can do that
> for you based on your patch.
>
Sorry for the delay. I've been trying to get a moment to test and submit
the revision.
If you're willing to do it, that's easiest for me.
>
> On Oct 21, 2017 4:40 PM, "Rui Ueyama" <ruiu at google.com> wrote:
>
>> Thank you for doing this.
>>
>> Can you take a look at ELF/Driver.cpp? elf::link has `CanExitEarly`
>> parameter. We should add the same parameter to coff::link so that two
>> functions have the same interface.
>>
>> On Sat, Oct 21, 2017 at 12:45 PM, Andrew Kelley via llvm-commits <
>> llvm-commits at lists.llvm.org> wrote:
>>
>>> Previously, the COFF driver would call exit(0) when called as
>>> a library. Now there is a global function setLibraryMode()
>>> which causes link() to return on success.
>>>
>>> Furthermore, link() calls freeArena() before returning, to
>>> clean up resources.
>>> ---
>>> lld/COFF/Driver.cpp | 27 +++++++++++++++++++++++----
>>> lld/COFF/Driver.h | 2 ++
>>> 2 files changed, 25 insertions(+), 4 deletions(-)
>>>
>>>
>>> diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
>>> index c039740715c..a769196e8b8 100644
>>> --- a/lld/COFF/Driver.cpp
>>> +++ b/lld/COFF/Driver.cpp
>>> @@ -46,6 +46,12 @@ using llvm::sys::Process;
>>> namespace lld {
>>> namespace coff {
>>>
>>> +
>>> +static bool IsLibraryMode = false;
>>> +void setLibraryMode(void) {
>>> + IsLibraryMode = true;
>>> +}
>>> +
>>> Configuration *Config;
>>> LinkerDriver *Driver;
>>>
>>> @@ -65,6 +71,7 @@ bool link(ArrayRef<const char *> Args, raw_ostream
>>> &Diag) {
>>>
>>> Driver = make<LinkerDriver>();
>>> Driver->link(Args);
>>> + freeArena();
>>> return !ErrorCount;
>>> }
>>>
>>> @@ -1077,7 +1084,11 @@ void LinkerDriver::link(ArrayRef<const char *>
>>> ArgsArr) {
>>> if (!Args.hasArg(OPT_INPUT)) {
>>> fixupExports();
>>> createImportLibrary(/*AsLib=*/true);
>>> - exit(0);
>>> + if (IsLibraryMode) {
>>> + return;
>>> + } else {
>>> + exit(0);
>>> + }
>>> }
>>>
>>> // Handle /delayload
>>> @@ -1169,7 +1180,11 @@ void LinkerDriver::link(ArrayRef<const char *>
>>> ArgsArr) {
>>> // This is useful because MSVC link.exe can generate complete PDBs.
>>> if (Args.hasArg(OPT_msvclto)) {
>>> invokeMSVC(Args);
>>> - exit(0);
>>> + if (IsLibraryMode) {
>>> + return;
>>> + } else {
>>> + exit(0);
>>> + }
>>> }
>>>
>>> // Do LTO by compiling bitcode input files to a set of native COFF
>>> files then
>>> @@ -1267,8 +1282,12 @@ void LinkerDriver::link(ArrayRef<const char *>
>>> ArgsArr) {
>>> if (ErrorCount)
>>> return;
>>>
>>> - // Call exit to avoid calling destructors.
>>> - exit(0);
>>> + if (IsLibraryMode) {
>>> + return
>>> + } else {
>>> + // Call exit to avoid calling destructors.
>>> + exit(0);
>>> + }
>>> }
>>>
>>> } // namespace coff
>>> diff --git a/lld/COFF/Driver.h b/lld/COFF/Driver.h
>>> index df54fc1e45e..c1c0f36b011 100644
>>> --- a/lld/COFF/Driver.h
>>> +++ b/lld/COFF/Driver.h
>>> @@ -35,6 +35,8 @@ using llvm::COFF::MachineTypes;
>>> using llvm::COFF::WindowsSubsystem;
>>> using llvm::Optional;
>>>
>>> +void setLibraryMode(void);
>>> +
>>> // Implemented in MarkLive.cpp.
>>> void markLive(const std::vector<Chunk *> &Chunks);
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>>
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171023/48a553c8/attachment.html>
More information about the llvm-commits
mailing list