: _baseAddress(0x400000), _stackReserve(1024 * 1024), _stackCommit(4096),
_heapReserve(1024 * 1024), _heapCommit(4096),
_subsystem(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN), _minOSVersion(6, 0),
- _nxCompat(true), _largeAddressAware(false) {}
+ _nxCompat(true), _largeAddressAware(false), _baseRelocationEnabled(true) {}
struct OSVersion {
OSVersion(int v1, int v2) : majorVersion(v1), minorVersion(v2) {}
void setNxCompat(bool nxCompat) { _nxCompat = nxCompat; }
bool getNxCompat() const { return _nxCompat; }
- void setLargeAddressAware(bool option) { _largeAddressAware = option; }
+ void setLargeAddressAware(bool val) { _largeAddressAware = val; }
bool getLargeAddressAware() const { return _largeAddressAware; }
+ void setBaseRelocationEnabled(bool val) { _baseRelocationEnabled = val; }
+ bool getBaseRelocationEnabled() const { return _baseRelocationEnabled; }
+
virtual ErrorOr<Reference::Kind> relocKindFromString(StringRef str) const;
virtual ErrorOr<std::string> stringFromRelocKind(Reference::Kind kind) const;
OSVersion _minOSVersion;
bool _nxCompat;
bool _largeAddressAware;
+ bool _baseRelocationEnabled;
std::vector<StringRef> _inputSearchPaths;
mutable std::unique_ptr<Reader> _reader;
if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_entry))
info.setEntrySymbolName(arg->getValue());
- // Hanlde -libpath
+ // Handle -libpath
for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_libpath),
ie = parsedArgs->filtered_end();
it != ie; ++it) {
if (parsedArgs->getLastArg(OPT_force))
info.setAllowRemainingUndefines(true);
- // Hanlde -nxcompat:no
+ // Handle -nxcompat:no
if (parsedArgs->getLastArg(OPT_no_nxcompat))
info.setNxCompat(false);
- // Hanlde -largeaddressaware
+ // Handle -largeaddressaware
if (parsedArgs->getLastArg(OPT_largeaddressaware))
info.setLargeAddressAware(true);
- // Hanlde -out
+ // Handle -fixed
+ if (parsedArgs->getLastArg(OPT_fixed))
+ info.setBaseRelocationEnabled(false);
+
+ // Handle -out
if (llvm::opt::Arg *outpath = parsedArgs->getLastArg(OPT_out))
info.setOutputPath(outpath->getValue());
def no_largeaddressaware : Flag<["-", "/"], "largeaddressaware:no">,
HelpText<"Disable large addresses">;
+def fixed : Flag<["-", "/"], "fixed">,
+ HelpText<"Disable base relocations">;
+def no_fixed : Flag<["-", "/"], "fixed:no">,
+ HelpText<"Enable base relocations">;
+
def help : Flag<["-", "/"], "help">;
def help_q : Flag<["-", "/"], "?">, Alias<help>;
auto *text = new TextSectionChunk(linkedFile);
auto *rdata = new RDataSectionChunk(linkedFile);
auto *data = new DataSectionChunk(linkedFile);
- auto *baseReloc = new BaseRelocChunk(linkedFile);
+ BaseRelocChunk *baseReloc = nullptr;
+ if (_PECOFFTargetInfo.getBaseRelocationEnabled())
+ baseReloc = new BaseRelocChunk(linkedFile);
addChunk(dosStub);
addChunk(peHeader);
// Now that we know the addresses of all defined atoms that needs to be
// relocated. So we can create the ".reloc" section which contains all the
// relocation sites.
- baseReloc->setContents(_chunks);
- if (baseReloc->size()) {
- dataDirectory->setBaseRelocField(baseReloc->getSectionRva(),
- baseReloc->rawSize());
- addSectionChunk(baseReloc, sectionTable);
+ if (baseReloc) {
+ baseReloc->setContents(_chunks);
+ if (baseReloc->size()) {
+ dataDirectory->setBaseRelocField(baseReloc->getSectionRva(),
+ baseReloc->rawSize());
+ addSectionChunk(baseReloc, sectionTable);
+ }
}
setImageSizeOnDisk();
# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj
#
# RUN: lld -flavor link -out %t1 -subsystem console -force -- %t.obj \
-# RUN: && llvm-objdump -s %t1 | FileCheck %s
+# RUN: && llvm-objdump -s %t1 | FileCheck %s --check-prefix=BASEREL
+#
+# RUN: lld -flavor link -out %t1 -subsystem console -force -fixed -- %t.obj \
+# RUN: && llvm-objdump -s %t1 | FileCheck %s --check-prefix=NOBASEREL
# Because llvm-objdump cannot pretty-print the contents of .reloc section, we
# have no choice other than comparing the result with this binary blob.
# TODO: Improve llvm-objdump to pretty print .reloc section as GNU binutil
# objdump does.
-CHECK: Contents of section .reloc:
-CHECK-NEXT: 3000 00100000 0c000000 07300c30 00000000 .........0.0....
+BASEREL: Contents of section .reloc:
+BASEREL-NEXT: 3000 00100000 0c000000 07300c30 00000000 .........0.0....
+
+NOBASEREL-NOT: Contents of section .reloc:
EXPECT_EQ("b.obj", inputFile(1));
EXPECT_EQ("c.obj", inputFile(2));
EXPECT_TRUE(_info.getInputSearchPaths().empty());
+
+ // Unspecified flags will have default values.
EXPECT_EQ(6, _info.getMinOSVersion().majorVersion);
EXPECT_EQ(0, _info.getMinOSVersion().minorVersion);
EXPECT_EQ((uint64_t)0x400000, _info.getBaseAddress());
EXPECT_FALSE(_info.allowRemainingUndefines());
EXPECT_TRUE(_info.getNxCompat());
EXPECT_FALSE(_info.getLargeAddressAware());
+ EXPECT_TRUE(_info.getBaseRelocationEnabled());
}
TEST_F(WinLinkParserTest, WindowsStyleOption) {
EXPECT_FALSE(_info.getLargeAddressAware());
}
+TEST_F(WinLinkParserTest, Fixed) {
+ EXPECT_FALSE(parse("link.exe", "-fixed", "a.out", nullptr));
+ EXPECT_FALSE(_info.getBaseRelocationEnabled());
+}
+
+TEST_F(WinLinkParserTest, NoFixed) {
+ EXPECT_FALSE(parse("link.exe", "-fixed:no", "a.out", nullptr));
+ EXPECT_TRUE(_info.getBaseRelocationEnabled());
+}
TEST_F(WinLinkParserTest, NoInputFiles) {
EXPECT_TRUE(parse("link.exe", nullptr));