ELF: Improve error handling of unknown emulation names.

This patch reverts r253985 and implements the same feature
in a less intrusive way.

llvm-svn: 254004
This commit is contained in:
Rui Ueyama 2015-11-24 18:55:36 +00:00
parent 7b19c34550
commit 9aa5686b9f
1 changed files with 11 additions and 19 deletions

View File

@ -52,12 +52,8 @@ static std::pair<ELFKind, uint16_t> parseEmulation(StringRef S) {
return {ELF64LEKind, EM_X86_64}; return {ELF64LEKind, EM_X86_64};
if (S == "aarch64linux") if (S == "aarch64linux")
return {ELF64LEKind, EM_AARCH64}; return {ELF64LEKind, EM_AARCH64};
if (S == "i386pe") if (S == "i386pe" || S == "i386pep" || S == "thumb2pe")
return {ELFNoneKind, EM_386}; error("Windows targets are not supported on the ELF frontend: " + S);
if (S == "i386pep")
return {ELFNoneKind, EM_X86_64};
if (S == "thumb2pe")
return {ELFNoneKind, EM_ARM};
error("Unknown emulation: " + S); error("Unknown emulation: " + S);
} }
@ -110,21 +106,9 @@ static bool hasZOption(opt::InputArgList &Args, StringRef Key) {
} }
void LinkerDriver::main(ArrayRef<const char *> ArgsArr) { void LinkerDriver::main(ArrayRef<const char *> ArgsArr) {
initSymbols();
opt::InputArgList Args = parseArgs(&Alloc, ArgsArr); opt::InputArgList Args = parseArgs(&Alloc, ArgsArr);
if (auto *Arg = Args.getLastArg(OPT_m)) {
StringRef S = Arg->getValue();
std::pair<ELFKind, uint16_t> P = parseEmulation(S);
Config->EKind = P.first;
Config->EMachine = P.second;
Config->Emulation = S;
}
if((Config->EKind == ELFNoneKind) && (Config->EMachine != EM_NONE))
error("windows coff targets aren't supported on the gnu frontend.");
initSymbols();
createFiles(Args); createFiles(Args);
// Traditional linkers can generate re-linkable object files instead // Traditional linkers can generate re-linkable object files instead
@ -161,6 +145,14 @@ void LinkerDriver::createFiles(opt::InputArgList &Args) {
if (!RPaths.empty()) if (!RPaths.empty())
Config->RPath = llvm::join(RPaths.begin(), RPaths.end(), ":"); Config->RPath = llvm::join(RPaths.begin(), RPaths.end(), ":");
if (auto *Arg = Args.getLastArg(OPT_m)) {
StringRef S = Arg->getValue();
std::pair<ELFKind, uint16_t> P = parseEmulation(S);
Config->EKind = P.first;
Config->EMachine = P.second;
Config->Emulation = S;
}
Config->AllowMultipleDefinition = Args.hasArg(OPT_allow_multiple_definition); Config->AllowMultipleDefinition = Args.hasArg(OPT_allow_multiple_definition);
Config->Bsymbolic = Args.hasArg(OPT_Bsymbolic); Config->Bsymbolic = Args.hasArg(OPT_Bsymbolic);
Config->DiscardAll = Args.hasArg(OPT_discard_all); Config->DiscardAll = Args.hasArg(OPT_discard_all);