Skip to content

Commit 67bcaa2

Browse files
committed
[fix] Optimized free-standing functions are broken
1 parent 4eb4514 commit 67bcaa2

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

lib/Core/Executor.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ llvm::Module *Executor::setModule(
575575
kmodule = std::make_unique<KModule>();
576576

577577
// 1.) Link the modules together && 2.) Apply different instrumentation
578-
kmodule->link(userModules, 0);
578+
kmodule->link(userModules, 1);
579579
kmodule->instrument(opts);
580580

581581
kmodule->link(libsModules, 2);
@@ -603,21 +603,28 @@ llvm::Module *Executor::setModule(
603603
specialFunctionHandler = new SpecialFunctionHandler(*this);
604604
specialFunctionHandler->prepare(preservedFunctions);
605605

606-
preservedFunctions.push_back(opts.EntryPoint.c_str());
607-
608606
// Preserve the free-standing library calls
609607
preservedFunctions.push_back("memset");
610608
preservedFunctions.push_back("memcpy");
611609
preservedFunctions.push_back("memcmp");
612610
preservedFunctions.push_back("memmove");
613611

614612
if (FunctionCallReproduce != "") {
615-
// prevent elimination of the function
616-
auto f = kmodule->module->getFunction(FunctionCallReproduce);
617-
if (f)
613+
preservedFunctions.push_back(FunctionCallReproduce.c_str());
614+
}
615+
616+
// prevent elimination of the preservedFunctions functions
617+
for (auto pf : preservedFunctions) {
618+
auto f = kmodule->module->getFunction(pf);
619+
if (f) {
618620
f->addFnAttr(Attribute::OptimizeNone);
621+
f->addFnAttr(Attribute::NoInline);
622+
}
619623
}
620624

625+
// except the entry point
626+
preservedFunctions.push_back(opts.EntryPoint.c_str());
627+
621628
kmodule->optimiseAndPrepare(opts, preservedFunctions);
622629
kmodule->checkModule();
623630

0 commit comments

Comments
 (0)