Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -292,6 +292,8 @@ template void LinkerDriver::link(opt::InputArgList &Args) { SymbolTable Symtab; Target.reset(createTarget()); + if (!Target) + return; if (!Config->Shared) { // Add entry symbol. Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -46,28 +46,28 @@ if (isInt(V)) return; StringRef S = getELFRelocationTypeName(Config->EMachine, Type); - fatal("Relocation " + S + " out of range"); + error("Relocation " + S + " out of range"); } template static void checkUInt(uint64_t V, uint32_t Type) { if (isUInt(V)) return; StringRef S = getELFRelocationTypeName(Config->EMachine, Type); - fatal("Relocation " + S + " out of range"); + error("Relocation " + S + " out of range"); } template static void checkIntUInt(uint64_t V, uint32_t Type) { if (isInt(V) || isUInt(V)) return; StringRef S = getELFRelocationTypeName(Config->EMachine, Type); - fatal("Relocation " + S + " out of range"); + error("Relocation " + S + " out of range"); } template static void checkAlignment(uint64_t V, uint32_t Type) { if ((V & (N - 1)) == 0) return; StringRef S = getELFRelocationTypeName(Config->EMachine, Type); - fatal("Improper alignment for relocation " + S); + error("Improper alignment for relocation " + S); } template bool isGnuIFunc(const SymbolBody &S) { @@ -260,7 +260,8 @@ case ELF32BEKind: return new MipsTargetInfo(); default: - fatal("Unsupported MIPS target"); + error("Unsupported MIPS target"); + return nullptr; } case EM_PPC: return new PPCTargetInfo(); @@ -269,7 +270,8 @@ case EM_X86_64: return new X86_64TargetInfo(); } - fatal("Unknown target machine"); + error("Unknown target machine"); + return nullptr; } TargetInfo::~TargetInfo() {} @@ -463,7 +465,7 @@ write32le(Loc, Out::TlsPhdr->p_memsz - SA); break; default: - fatal("unrecognized reloc " + Twine(Type)); + error("unrecognized reloc " + Twine(Type)); } } @@ -697,7 +699,7 @@ // This relocation is defined to have a value of (S + A - P). // The problems start when a non PIC program calls a function in a shared // library. - // In an ideal world, we could just report an fatal saying the relocation + // In an ideal world, we could just report an error saying the relocation // can overflow at runtime. // In the real world with glibc, crt1.o has a R_X86_64_PC32 pointing to // libc.so. @@ -926,7 +928,7 @@ write32le(Loc, SA - P); break; default: - fatal("unrecognized reloc " + Twine(Type)); + error("unrecognized reloc " + Twine(Type)); } } @@ -969,7 +971,7 @@ write16be(Loc, applyPPCLo(SA)); break; default: - fatal("unrecognized reloc " + Twine(Type)); + error("unrecognized reloc " + Twine(Type)); } } @@ -1182,7 +1184,7 @@ write64be(Loc, SA); break; default: - fatal("unrecognized reloc " + Twine(Type)); + error("unrecognized reloc " + Twine(Type)); } } @@ -1201,8 +1203,10 @@ if (Type == R_AARCH64_ABS32 || Type == R_AARCH64_ABS64) return Type; StringRef S = getELFRelocationTypeName(EM_AARCH64, Type); - fatal("Relocation " + S + " cannot be used when making a shared object; " + error("Relocation " + S + " cannot be used when making a shared object; " "recompile with -fPIC."); + // Keep it going with a dummy value so that we can find more reloc errors. + return R_AARCH64_ABS32; } void AArch64TargetInfo::writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const { @@ -1421,7 +1425,7 @@ break; } default: - fatal("unrecognized reloc " + Twine(Type)); + error("unrecognized reloc " + Twine(Type)); } } @@ -1472,8 +1476,10 @@ if (Type == R_MIPS_32 || Type == R_MIPS_64) return R_MIPS_REL32; StringRef S = getELFRelocationTypeName(EM_MIPS, Type); - fatal("Relocation " + S + " cannot be used when making a shared object; " + error("Relocation " + S + " cannot be used when making a shared object; " "recompile with -fPIC."); + // Keep it going with a dummy value so that we can find more reloc errors. + return R_MIPS_32; } template @@ -1600,7 +1606,7 @@ break; } default: - fatal("unrecognized reloc " + Twine(Type)); + error("unrecognized reloc " + Twine(Type)); } } Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -16,8 +16,9 @@ #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/FileOutputBuffer.h" -#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/StringSaver.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace llvm::ELF; @@ -163,7 +164,12 @@ openFile(Config->OutputFile); writeHeader(); writeSections(); - fatal(Buffer->commit()); + error(Buffer->commit()); + + // If there was an error at this stage, the generated file is broken. + // Remove it rather than leave it to not confuse users. + if (HasError) + sys::fs::remove(Config->OutputFile); } namespace {