forked from OSchip/llvm-project
Separates /fixed (no .reloc section) and /dynamicbase (enable ASLR)
in order to match link.exe's behaviour. Patch by Ron Ofir. llvm-svn: 189159
This commit is contained in:
parent
00335ea34e
commit
72165ec8c3
|
@ -29,7 +29,8 @@ public:
|
|||
_heapReserve(1024 * 1024), _heapCommit(4096),
|
||||
_subsystem(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN), _minOSVersion(6, 0),
|
||||
_nxCompat(true), _largeAddressAware(false),
|
||||
_baseRelocationEnabled(true), _terminalServerAware(true) {}
|
||||
_baseRelocationEnabled(true), _terminalServerAware(true),
|
||||
_dynamicBaseEnabled(true) {}
|
||||
|
||||
struct OSVersion {
|
||||
OSVersion(int v1, int v2) : majorVersion(v1), minorVersion(v2) {}
|
||||
|
@ -92,6 +93,9 @@ public:
|
|||
void setTerminalServerAware(bool val) { _terminalServerAware = val; }
|
||||
bool isTerminalServerAware() const { return _terminalServerAware; }
|
||||
|
||||
void setDynamicBaseEnabled(bool val) { _dynamicBaseEnabled = val; }
|
||||
bool getDynamicBaseEnabled() const { return _dynamicBaseEnabled; }
|
||||
|
||||
virtual ErrorOr<Reference::Kind> relocKindFromString(StringRef str) const;
|
||||
virtual ErrorOr<std::string> stringFromRelocKind(Reference::Kind kind) const;
|
||||
|
||||
|
@ -123,6 +127,7 @@ private:
|
|||
bool _largeAddressAware;
|
||||
bool _baseRelocationEnabled;
|
||||
bool _terminalServerAware;
|
||||
bool _dynamicBaseEnabled;
|
||||
|
||||
std::vector<StringRef> _inputSearchPaths;
|
||||
mutable std::unique_ptr<Reader> _reader;
|
||||
|
|
|
@ -350,7 +350,20 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
|
|||
|
||||
case OPT_fixed:
|
||||
// handle /fixed
|
||||
|
||||
// make sure /dynamicbase wasn't specified
|
||||
if (parsedArgs->getLastArg(OPT_dynamicbase)) {
|
||||
diagnostics << "/dynamicbase must not be specified with /fixed\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
ctx.setBaseRelocationEnabled(false);
|
||||
ctx.setDynamicBaseEnabled(false);
|
||||
break;
|
||||
|
||||
case OPT_no_dynamicbase:
|
||||
// handle /dynamicbase:no
|
||||
ctx.setDynamicBaseEnabled(false);
|
||||
break;
|
||||
|
||||
case OPT_tsaware:
|
||||
|
|
|
@ -42,6 +42,9 @@ def no_largeaddressaware : F<"largeaddressaware:no">,
|
|||
def fixed : F<"fixed">;
|
||||
def no_fixed : F<"fixed:no">, HelpText<"Enable base relocations">;
|
||||
|
||||
def dynamicbase : F<"dynamicbase">;
|
||||
def no_dynamicbase : F<"dynamicbase:no">, HelpText<"Disable address space layout randomization">;
|
||||
|
||||
def tsaware : F<"tsaware">;
|
||||
def no_tsaware : F<"tsaware:no">,
|
||||
HelpText<"Create non-Terminal Server aware executable">;
|
||||
|
|
|
@ -204,7 +204,7 @@ public:
|
|||
llvm::COFF::IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE;
|
||||
if (context.isNxCompat())
|
||||
dllCharacteristics |= llvm::COFF::IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
|
||||
if (context.getBaseRelocationEnabled())
|
||||
if (context.getDynamicBaseEnabled())
|
||||
dllCharacteristics |= llvm::COFF::IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
|
||||
_peHeader.DLLCharacteristics = dllCharacteristics;
|
||||
|
||||
|
|
|
@ -19,14 +19,12 @@ NOBASEREL-SECTION-NOT: Contents of section .reloc:
|
|||
|
||||
# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
|
||||
# RUN: && llvm-readobj -file-headers %t1 \
|
||||
# RUN: | FileCheck %s --check-prefix=BASEREL1
|
||||
# RUN: | FileCheck %s --check-prefix=BASEREL-HEADER
|
||||
#
|
||||
# RUN: lld -flavor link /out:%t1 /subsystem:console /force /fixed -- %t.obj \
|
||||
# RUN: && llvm-readobj -file-headers %t1 \
|
||||
# RUN: | FileCheck %s --check-prefix=BASEREL2
|
||||
# RUN: | FileCheck %s --check-prefix=NOBASEREL-HEADER
|
||||
|
||||
BASEREL1-NOT: IMAGE_FILE_RELOCS_STRIPPED
|
||||
BASEREL1: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE
|
||||
BASEREL-HEADER-NOT: IMAGE_FILE_RELOCS_STRIPPED
|
||||
|
||||
BASEREL2: IMAGE_FILE_RELOCS_STRIPPED
|
||||
BASEREL2-NOT: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE
|
||||
NOBASEREL-HEADER: IMAGE_FILE_RELOCS_STRIPPED
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj
|
||||
#
|
||||
# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
|
||||
# RUN: && llvm-readobj -file-headers %t1 \
|
||||
# RUN: | FileCheck %s --check-prefix=DYNAMICBASE
|
||||
#
|
||||
# RUN: lld -flavor link /out:%t1 /subsystem:console /force /dynamicbase:no \
|
||||
# RUN: -- %t.obj && llvm-readobj -file-headers %t1 \
|
||||
# RUN: | FileCheck %s --check-prefix=NODYNAMICBASE
|
||||
#
|
||||
# RUN: lld -flavor link /out:%t1 /subsystem:console /force /fixed -- %t.obj \
|
||||
# RUN: && llvm-readobj -file-headers %t1 \
|
||||
# RUN: | FileCheck %s --check-prefix=NODYNAMICBASE
|
||||
#
|
||||
# RUN: not lld -flavor link /out:%t1 /subsystem:console /force /fixed \
|
||||
# RUN: /dynamicbase -- %t.obj 2>&1 | FileCheck %s --check-prefix=DYNAMIC-AND-FIXED
|
||||
|
||||
DYNAMICBASE: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE
|
||||
|
||||
NODYNAMICBASE-NOT: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE
|
||||
|
||||
DYNAMIC-AND-FIXED: /dynamicbase must not be specified with /fixed
|
|
@ -53,6 +53,7 @@ TEST_F(WinLinkParserTest, Basic) {
|
|||
EXPECT_FALSE(_context.getLargeAddressAware());
|
||||
EXPECT_TRUE(_context.getBaseRelocationEnabled());
|
||||
EXPECT_TRUE(_context.isTerminalServerAware());
|
||||
EXPECT_TRUE(_context.getDynamicBaseEnabled());
|
||||
EXPECT_TRUE(_context.initialUndefinedSymbols().empty());
|
||||
}
|
||||
|
||||
|
@ -171,6 +172,7 @@ TEST_F(WinLinkParserTest, NoLargeAddressAware) {
|
|||
TEST_F(WinLinkParserTest, Fixed) {
|
||||
EXPECT_FALSE(parse("link.exe", "/fixed", "a.out", nullptr));
|
||||
EXPECT_FALSE(_context.getBaseRelocationEnabled());
|
||||
EXPECT_FALSE(_context.getDynamicBaseEnabled());
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, NoFixed) {
|
||||
|
@ -188,6 +190,16 @@ TEST_F(WinLinkParserTest, NoTerminalServerAware) {
|
|||
EXPECT_FALSE(_context.isTerminalServerAware());
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, DynamicBase) {
|
||||
EXPECT_FALSE(parse("link.exe", "/dynamicbase", "a.out", nullptr));
|
||||
EXPECT_TRUE(_context.getDynamicBaseEnabled());
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, NoDynamicBase) {
|
||||
EXPECT_FALSE(parse("link.exe", "/dynamicbase:no", "a.out", nullptr));
|
||||
EXPECT_FALSE(_context.getDynamicBaseEnabled());
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, Include) {
|
||||
EXPECT_FALSE(parse("link.exe", "/include:foo", "a.out", nullptr));
|
||||
auto symbols = _context.initialUndefinedSymbols();
|
||||
|
|
Loading…
Reference in New Issue