20
20
#include " llvm/Bitcode/ReaderWriter.h"
21
21
#include " llvm/CodeGen/Analysis.h"
22
22
#include " llvm/CodeGen/CommandFlags.h"
23
+ #include " llvm/IR/AutoUpgrade.h"
23
24
#include " llvm/IR/Constants.h"
24
25
#include " llvm/IR/DiagnosticInfo.h"
25
26
#include " llvm/IR/DiagnosticPrinter.h"
@@ -273,20 +274,33 @@ static bool shouldSkip(uint32_t Symflags) {
273
274
}
274
275
275
276
static void diagnosticHandler (const DiagnosticInfo &DI, void *Context) {
276
- assert (DI. getSeverity () == DS_Error && " Only expecting errors " );
277
- const auto &BDI = cast<BitcodeDiagnosticInfo>(DI );
278
- std::error_code EC = BDI. getError ();
279
- if (EC == BitcodeError::InvalidBitcodeSignature)
280
- return ;
277
+ if ( const auto *BDI = dyn_cast<BitcodeDiagnosticInfo>(&DI)) {
278
+ std::error_code EC = BDI-> getError ( );
279
+ if ( EC == BitcodeError::InvalidBitcodeSignature)
280
+ return ;
281
+ }
281
282
282
283
std::string ErrStorage;
283
284
{
284
285
raw_string_ostream OS (ErrStorage);
285
286
DiagnosticPrinterRawOStream DP (OS);
286
287
DI.print (DP);
287
288
}
288
- message (LDPL_FATAL, " LLVM gold plugin has failed to create LTO module: %s" ,
289
- ErrStorage.c_str ());
289
+ ld_plugin_level Level;
290
+ switch (DI.getSeverity ()) {
291
+ case DS_Error:
292
+ message (LDPL_FATAL, " LLVM gold plugin has failed to create LTO module: %s" ,
293
+ ErrStorage.c_str ());
294
+ llvm_unreachable (" Fatal doesn't return." );
295
+ case DS_Warning:
296
+ Level = LDPL_WARNING;
297
+ break ;
298
+ case DS_Remark:
299
+ case DS_Note:
300
+ Level = LDPL_INFO;
301
+ break ;
302
+ }
303
+ message (Level, " LLVM gold plugin: %s" , ErrStorage.c_str ());
290
304
}
291
305
292
306
// / Called by gold to see whether this file is one that our plugin can handle.
@@ -561,7 +575,7 @@ static void freeSymName(ld_plugin_symbol &Sym) {
561
575
562
576
static std::unique_ptr<Module>
563
577
getModuleForFile (LLVMContext &Context, claimed_file &F,
564
- off_t Filesize , raw_fd_ostream *ApiFile,
578
+ ld_plugin_input_file &Info , raw_fd_ostream *ApiFile,
565
579
StringSet<> &Internalize, StringSet<> &Maybe) {
566
580
567
581
if (get_symbols (F.handle , F.syms .size (), &F.syms [0 ]) != LDPS_OK)
@@ -571,7 +585,8 @@ getModuleForFile(LLVMContext &Context, claimed_file &F,
571
585
if (get_view (F.handle , &View) != LDPS_OK)
572
586
message (LDPL_FATAL, " Failed to get a view of file" );
573
587
574
- MemoryBufferRef BufferRef (StringRef ((const char *)View, Filesize), " " );
588
+ MemoryBufferRef BufferRef (StringRef ((const char *)View, Info.filesize ),
589
+ Info.name );
575
590
ErrorOr<std::unique_ptr<object::IRObjectFile>> ObjOrErr =
576
591
object::IRObjectFile::create (BufferRef, Context);
577
592
@@ -583,6 +598,8 @@ getModuleForFile(LLVMContext &Context, claimed_file &F,
583
598
584
599
Module &M = Obj.getModule ();
585
600
601
+ UpgradeDebugInfo (M);
602
+
586
603
SmallPtrSet<GlobalValue *, 8 > Used;
587
604
collectUsedGlobalVariables (M, Used, /* CompilerUsed*/ false );
588
605
@@ -792,6 +809,8 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) {
792
809
return LDPS_OK;
793
810
794
811
LLVMContext Context;
812
+ Context.setDiagnosticHandler (diagnosticHandler);
813
+
795
814
std::unique_ptr<Module> Combined (new Module (" ld-temp.o" , Context));
796
815
Linker L (Combined.get ());
797
816
@@ -804,8 +823,7 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) {
804
823
if (get_input_file (F.handle , &File) != LDPS_OK)
805
824
message (LDPL_FATAL, " Failed to get file information" );
806
825
std::unique_ptr<Module> M =
807
- getModuleForFile (Context, F, File.filesize , ApiFile,
808
- Internalize, Maybe);
826
+ getModuleForFile (Context, F, File, ApiFile, Internalize, Maybe);
809
827
if (!options::triple.empty ())
810
828
M->setTargetTriple (options::triple.c_str ());
811
829
else if (M->getTargetTriple ().empty ()) {
0 commit comments