mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-23 01:24:30 +00:00
Linker: Add flag to override linkage rules
Add a flag to lib/Linker (and `llvm-link`) to override linkage rules. When set, the functions in the source module *always* replace those in the destination module. The `llvm-link` option is `-override=abc.ll`. All the "regular" modules are loaded and linked first, followed by the `-override` modules. This is useful for debugging workflows where some subset of the module (e.g., a single function) is extracted into a separate file where it's optimized differently, before being merged back in. Patch by Luqman Aden! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235473 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -38,6 +38,11 @@ static cl::list<std::string>
|
||||
InputFilenames(cl::Positional, cl::OneOrMore,
|
||||
cl::desc("<input bitcode files>"));
|
||||
|
||||
static cl::list<std::string> OverridingInputs(
|
||||
"override", cl::ZeroOrMore, cl::value_desc("filename"),
|
||||
cl::desc(
|
||||
"input bitcode file which can override previously defined symbol(s)"));
|
||||
|
||||
static cl::opt<std::string>
|
||||
OutputFilename("o", cl::desc("Override output filename"), cl::init("-"),
|
||||
cl::value_desc("filename"));
|
||||
@ -108,7 +113,8 @@ static void diagnosticHandler(const DiagnosticInfo &DI) {
|
||||
}
|
||||
|
||||
static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L,
|
||||
const cl::list<std::string> &Files) {
|
||||
const cl::list<std::string> &Files,
|
||||
bool OverrideDuplicateSymbols) {
|
||||
for (const auto &File : Files) {
|
||||
std::unique_ptr<Module> M = loadFile(argv0, File, Context);
|
||||
if (!M.get()) {
|
||||
@ -124,7 +130,7 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L,
|
||||
if (Verbose)
|
||||
errs() << "Linking in '" << File << "'\n";
|
||||
|
||||
if (L.linkInModule(M.get()))
|
||||
if (L.linkInModule(M.get(), OverrideDuplicateSymbols))
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -143,7 +149,12 @@ int main(int argc, char **argv) {
|
||||
auto Composite = make_unique<Module>("llvm-link", Context);
|
||||
Linker L(Composite.get(), diagnosticHandler);
|
||||
|
||||
if (!linkFiles(argv[0], Context, L, InputFilenames))
|
||||
// First add all the regular input files
|
||||
if (!linkFiles(argv[0], Context, L, InputFilenames, false))
|
||||
return 1;
|
||||
|
||||
// Next the -override ones.
|
||||
if (!linkFiles(argv[0], Context, L, OverridingInputs, true))
|
||||
return 1;
|
||||
|
||||
if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;
|
||||
|
Reference in New Issue
Block a user