Skip to content

Commit d5b49de

Browse files
committed
[PECOFF] Don't set IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE if "-fixed" is provided
Based on Ron Ofir's patch. llvm-svn: 187221
1 parent 9c3ece3 commit d5b49de

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,14 @@ class PEHeaderChunk : public HeaderChunk {
195195
// be set, but regular binaries seem to have these bits, so we follow
196196
// them.
197197
uint16_t dllCharacteristics =
198-
llvm::COFF::IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE |
199198
llvm::COFF::IMAGE_DLL_CHARACTERISTICS_NO_SEH;
200199
if (targetInfo.isTerminalServerAware())
201200
dllCharacteristics |=
202201
llvm::COFF::IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE;
203202
if (targetInfo.isNxCompat())
204203
dllCharacteristics |= llvm::COFF::IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
204+
if (targetInfo.getBaseRelocationEnabled())
205+
dllCharacteristics |= llvm::COFF::IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
205206
_peHeader.DLLCharacteristics = dllCharacteristics;
206207

207208
_peHeader.SizeOfStackReserve = targetInfo.getStackReserve();

lld/test/pecoff/base-reloc.test

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj
22
#
33
# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
4-
# RUN: && llvm-objdump -s %t1 | FileCheck %s --check-prefix=BASEREL
4+
# RUN: && llvm-objdump -s %t1 | FileCheck %s --check-prefix=BASEREL-SECTION
55
#
66
# RUN: lld -flavor link /out:%t1 /subsystem:console /force /fixed -- %t.obj \
7-
# RUN: && llvm-objdump -s %t1 | FileCheck %s --check-prefix=NOBASEREL
7+
# RUN: && llvm-objdump -s %t1 | FileCheck %s --check-prefix=NOBASEREL-SECTION
88

99
# Because llvm-objdump cannot pretty-print the contents of .reloc section, we
1010
# have no choice other than comparing the result with this binary blob.
1111
#
1212
# TODO: Improve llvm-objdump to pretty print .reloc section as GNU binutil
1313
# objdump does.
1414

15-
BASEREL: Contents of section .reloc:
16-
BASEREL-NEXT: 3000 00100000 0c000000 07300c30 00000000 .........0.0....
15+
BASEREL-SECTION: Contents of section .reloc:
16+
BASEREL-SECTION-NEXT: 3000 00100000 0c000000 07300c30 00000000 .........0.0....
1717

18-
NOBASEREL-NOT: Contents of section .reloc:
18+
NOBASEREL-SECTION-NOT: Contents of section .reloc:
19+
20+
# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
21+
# RUN: && llvm-readobj -file-headers %t1 \
22+
# RUN: | FileCheck %s --check-prefix=BASEREL-HEADER
23+
#
24+
# RUN: lld -flavor link /out:%t1 /subsystem:console /force /fixed -- %t.obj \
25+
# RUN: && llvm-readobj -file-headers %t1 \
26+
# RUN: | FileCheck %s --check-prefix=NOBASEREL-HEADER
27+
28+
BASEREL-HEADER: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE
29+
30+
NOBASEREL-HEADER-NOT: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE

0 commit comments

Comments
 (0)