[lld] r309091 - [ELF] - Change way how we handle --noinhibit-exec
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 26 02:46:59 PDT 2017
Author: grimar
Date: Wed Jul 26 02:46:59 2017
New Revision: 309091
URL: http://llvm.org/viewvc/llvm-project?rev=309091&view=rev
Log:
[ELF] - Change way how we handle --noinhibit-exec
Previously we handled this option implicitly, only
for infering unresolved symbols handling policy.
ld man says: "--noinhibit-exec Retain the executable
output file whenever it is still usable",
and we may want to handle other cases too.
Differential revision: https://reviews.llvm.org/D35793
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Relocations.cpp
lld/trunk/test/ELF/copy-errors.s
lld/trunk/test/ELF/x86-64-dyn-rel-error.s
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=309091&r1=309090&r2=309091&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Wed Jul 26 02:46:59 2017
@@ -44,7 +44,7 @@ enum class DiscardPolicy { Default, All,
enum class StripPolicy { None, All, Debug };
// For --unresolved-symbols.
-enum class UnresolvedPolicy { ReportError, Warn, WarnAll, Ignore, IgnoreAll };
+enum class UnresolvedPolicy { ReportError, Warn, Ignore, IgnoreAll };
// For --sort-section and linkerscript sorting rules.
enum class SortSectionPolicy { Default, None, Alignment, Name, Priority };
@@ -128,6 +128,7 @@ struct Configuration {
bool ICF;
bool MipsN32Abi = false;
bool NoGnuUnique;
+ bool NoinhibitExec;
bool NoUndefinedVersion;
bool Nostdlib;
bool OFormatBinary;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=309091&r1=309090&r2=309091&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Jul 26 02:46:59 2017
@@ -418,9 +418,6 @@ static std::string getRpath(opt::InputAr
// Determines what we should do if there are remaining unresolved
// symbols after the name resolution.
static UnresolvedPolicy getUnresolvedSymbolPolicy(opt::InputArgList &Args) {
- // -noinhibit-exec or -r imply some default values.
- if (Args.hasArg(OPT_noinhibit_exec))
- return UnresolvedPolicy::WarnAll;
if (Args.hasArg(OPT_relocatable))
return UnresolvedPolicy::IgnoreAll;
@@ -648,6 +645,7 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->MapFile = Args.getLastArgValue(OPT_Map);
Config->NoGnuUnique = Args.hasArg(OPT_no_gnu_unique);
Config->NoUndefinedVersion = Args.hasArg(OPT_no_undefined_version);
+ Config->NoinhibitExec = Args.hasArg(OPT_noinhibit_exec);
Config->Nostdlib = Args.hasArg(OPT_nostdlib);
Config->OFormatBinary = isOutputFormatBinary(Args);
Config->Omagic = Args.hasArg(OPT_omagic);
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=309091&r1=309090&r2=309091&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Wed Jul 26 02:46:59 2017
@@ -535,6 +535,13 @@ template <class ELFT> static void addCop
In<ELFT>::RelaDyn->addReloc({Target->CopyRel, Sec, Off, false, SS, 0});
}
+static void errorOrWarn(const Twine &Msg) {
+ if (!Config->NoinhibitExec)
+ error(Msg);
+ else
+ warn(Msg);
+}
+
template <class ELFT>
static RelExpr adjustExpr(SymbolBody &Body, RelExpr Expr, uint32_t Type,
const uint8_t *Data, InputSectionBase &S,
@@ -609,8 +616,8 @@ static RelExpr adjustExpr(SymbolBody &Bo
return toPlt(Expr);
}
- error("symbol '" + toString(Body) + "' defined in " + toString(Body.File) +
- " has no type");
+ errorOrWarn("symbol '" + toString(Body) + "' defined in " +
+ toString(Body.File) + " has no type");
return Expr;
}
@@ -691,12 +698,10 @@ static void reportUndefined(SymbolBody &
Msg += Src + "\n>>> ";
Msg += S.getObjMsg<ELFT>(Offset);
- if (Config->UnresolvedSymbols == UnresolvedPolicy::WarnAll ||
- (Config->UnresolvedSymbols == UnresolvedPolicy::Warn && CanBeExternal)) {
+ if (Config->UnresolvedSymbols == UnresolvedPolicy::Warn && CanBeExternal)
warn(Msg);
- } else {
- error(Msg);
- }
+ else
+ errorOrWarn(Msg);
}
template <class RelTy>
@@ -905,9 +910,10 @@ static void scanRelocs(InputSectionBase
// We don't know anything about the finaly symbol. Just ask the dynamic
// linker to handle the relocation for us.
if (!Target->isPicRel(Type))
- error("relocation " + toString(Type) +
- " cannot be used against shared object; recompile with -fPIC" +
- getLocation<ELFT>(Sec, Body, Offset));
+ errorOrWarn(
+ "relocation " + toString(Type) +
+ " cannot be used against shared object; recompile with -fPIC" +
+ getLocation<ELFT>(Sec, Body, Offset));
In<ELFT>::RelaDyn->addReloc(
{Target->getDynRel(Type), &Sec, Offset, false, &Body, Addend});
Modified: lld/trunk/test/ELF/copy-errors.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/copy-errors.s?rev=309091&r1=309090&r2=309091&view=diff
==============================================================================
--- lld/trunk/test/ELF/copy-errors.s (original)
+++ lld/trunk/test/ELF/copy-errors.s Wed Jul 26 02:46:59 2017
@@ -9,6 +9,9 @@
// CHECK: >>> referenced by {{.*}}.o:(.text+0x1)
// CHECK: symbol 'zed' defined in {{.*}}.so has no type
+// RUN: not ld.lld --noinhibit-exec %t.o %t2.so -o %t 2>&1 | FileCheck %s --check-prefix=NOINHIBIT
+// NOINHIBIT: warning: symbol 'zed' defined in {{.*}}.so has no type
+
.global _start
_start:
call bar
Modified: lld/trunk/test/ELF/x86-64-dyn-rel-error.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-dyn-rel-error.s?rev=309091&r1=309090&r2=309091&view=diff
==============================================================================
--- lld/trunk/test/ELF/x86-64-dyn-rel-error.s (original)
+++ lld/trunk/test/ELF/x86-64-dyn-rel-error.s Wed Jul 26 02:46:59 2017
@@ -10,3 +10,5 @@ _start:
.long bar
// CHECK: relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC
+
+// RUN: ld.lld --noinhibit-exec %t.o %t2.so -o %t 2>&1 | FileCheck %s
More information about the llvm-commits
mailing list