[PATCH] ldd::COFF: better behavior when using as a library
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 23 12:44:47 PDT 2017
OK, I created this patch for review: https://reviews.llvm.org/D39202
On Mon, Oct 23, 2017 at 12:00 PM, Andrew Kelley <superjoe30 at gmail.com>
wrote:
>
>
> On Mon, Oct 23, 2017 at 2:48 PM, Rui Ueyama <ruiu at google.com> wrote:
>
>> I just wanted to help you because it seems easy for me to make a change
>> because I know a lot about lld, and you seems to be busy on Zig language
>> itself. I'll update your patch and send it to you for review.
>>
>
> Thanks Rui, I appreciate that very much.
>
>
>>
>> On Mon, Oct 23, 2017 at 11:40 AM, Andrew Kelley <superjoe30 at gmail.com>
>> wrote:
>>
>>>
>>>
>>> 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/a26fe17d/attachment.html>
More information about the llvm-commits
mailing list