@@ -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