-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Closed
Labels
Description
Using LLVM with JIT-compilation requires for some target architectures to call the linker several times, i.e. for AMD GPU kernels to turn an .o
file into an .so
file.
LLVM 15 and also the current code have the following problem:
bool lld::elf::link
returns false
from the second time on its called. I.e. the first call works fine, but subsequent calls fail.
Here's small reproducer:
#include "lld/Common/Driver.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Memory.h"
#include <iostream>
int main()
{
std::cout << "First call ... ";
bool call_a = lld::elf::link( { "ld.lld" , "-shared" , "../kernel.o" , "-o" , "../kernel.so" } , llvm::outs(), llvm::errs(), true, true);
std::cout << call_a << std::endl;
std::cout << "Second call ... ";
bool call_b = lld::elf::link( { "ld.lld" , "-shared" , "../kernel.o" , "-o" , "../kernel.so" } , llvm::outs(), llvm::errs(), true, true);
std::cout << call_b << std::endl;
}
I tested various systems but the output is always:
First call ... 1
Second call ... 0
This behavior is agnostic to the architecture. Initially I ran into this with AMDGPU objects, but could reproduce with X86 objects.
A quick gdb session reveals that during the second call the link procedure is aborted here:
./llvm-project/lld/ELF/Driver.cpp:2624
// Return if there were name resolution errors.
if (errorCount())
return;
Please help.