Libraries linked to the lld elf library exposes a function named main. When debugging code linked to such libraries and intending to set a breakpoint at main, the debugger also sets breakpoint at the main function at lld elf driver. The possible choice was to rename it to link but that would again clash with lld::*::link. This patch tries to consistently rename them to linkerMain.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I am always trapped on this. In gdb both b main and b ::main set a breakpoint on lld::elf::LinkerDriver::main. For consistency, I would suggest lld::*::LinkerDriver::link which is used by COFF and wasm ports. However, that has the name collision problems with the free functions lld::*::link... (This may be less of a problem because developers don't often set breakpoints on link? :) )
Another choice is to rename the free functions lld::*::link to linkerMain.
I don't feel strongly about the name...
However I was under the impression that it was a non-goal to make the current version of lld usable as a library. I mean it make very heavy use of globals as well as things like early process exiting doesn't it? Have the goals changed recently?
If it's just one instance at a time, the COFF driver currently works as a library. If you're talking about multi-threaded instances, there's an old prototype here: D86353 (and supporting patches D86351 and D86352) - ie. several multi-threaded instances of LLD in the same process, linking different executables, and it is indeed a bit complicated. But we can discuss the incremental steps to get there. One issue is the CommandLineParser and more broadly everything related to cl::opts. This has been discussed in the past but without a clear consensus (see http://lists.llvm.org/pipermail/llvm-dev/2018-October/127039.html). Most of the remaining issues were local statics which can be made part of a larger context (either per-thread or per linker instance).
However I think this current patch is orthogonal to all that and simply aims to solve a gdb breakpoint issue?
However I think this current patch is orthogonal to all that and simply aims to solve a gdb breakpoint issue?
Yes, it got motivated by the gdb breakpoint issue.
link seems to be a more consistent name as pointed out by @MaskRay
Can we ignore its clash with lld::*::link as the general intent with setting a breakpoint at main is to trap the main function and not the lld::elf::LinkerDriver::main which may not be true for link
This is consistent with the other drivers, LGTM.
Do you have commit access? Please ask for it if you're planning more changes in the future. Otherwise I can land it for you.
Many thanks :) it will be very helpful if you can land it though I've just asked Chris for the access.
Many thanks :) it will be very helpful if you can land it though I've just asked Chris for the access.
This appears to get past a comment.
Can we ignore its clash with lld::*::link as the general intent with setting a breakpoint at main is to trap the main function and not the lld::elf::LinkerDriver::main which may not be true for link
I think changing from main to to avoids an issue and adds a new issue. We should fix the issues all together, and this requires consensus from others ports to proceed.
Is the new issue, the clash with lld::*::link and if so, then ideally we should replace link from all the ports to linkerMain?
I would give +1 to linkerMain since it is unique and we already have lldMain in lld/tools/lld/lld.cpp (and we would otherwise end up with a similar issue as what this patch tries to correct)
Rename LinkerDriver::link and LinkerDriver::main (in ELF) to LinkerDriver::linkerMain
LGTM.
+1 to linkerMain since it is unique and we already have lldMain in lld/tools/lld/lld.cpp