forked from OSchip/llvm-project
COFF: Fix image base address for 32-bit.
0x140000000 or 0x180000000 are not correct image base addresses for 32-bit. They are actually much smaller. llvm-svn: 243228
This commit is contained in:
parent
11a9cd956a
commit
5c437cd1e9
|
@ -105,7 +105,7 @@ struct Configuration {
|
|||
// Used for /alternatename.
|
||||
std::map<StringRef, StringRef> AlternateNames;
|
||||
|
||||
uint64_t ImageBase = 0x140000000U;
|
||||
uint64_t ImageBase = -1;
|
||||
uint64_t StackReserve = 1024 * 1024;
|
||||
uint64_t StackCommit = 4096;
|
||||
uint64_t HeapReserve = 1024 * 1024;
|
||||
|
|
|
@ -244,6 +244,12 @@ WindowsSubsystem LinkerDriver::inferSubsystem() {
|
|||
return IMAGE_SUBSYSTEM_UNKNOWN;
|
||||
}
|
||||
|
||||
static uint64_t getDefaultImageBase() {
|
||||
if (Config->is64())
|
||||
return Config->DLL ? 0x180000000 : 0x140000000;
|
||||
return Config->DLL ? 0x10000000 : 0x400000;
|
||||
}
|
||||
|
||||
bool LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
|
||||
// Needed for LTO.
|
||||
llvm::InitializeAllTargetInfos();
|
||||
|
@ -311,7 +317,6 @@ bool LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
|
|||
// Handle /dll
|
||||
if (Args.hasArg(OPT_dll)) {
|
||||
Config->DLL = true;
|
||||
Config->ImageBase = 0x180000000U;
|
||||
Config->ManifestID = 2;
|
||||
}
|
||||
|
||||
|
@ -602,6 +607,10 @@ bool LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
|
|||
}
|
||||
}
|
||||
|
||||
// Set default image base if /base is not given.
|
||||
if (Config->ImageBase == uint64_t(-1))
|
||||
Config->ImageBase = getDefaultImageBase();
|
||||
|
||||
Symtab.addRelative(mangle("__ImageBase"), 0);
|
||||
if (Config->MachineType == IMAGE_FILE_MACHINE_I386) {
|
||||
Config->SEHTable = Symtab.addRelative("___safe_se_handler_table", 0);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# RUN: yaml2obj < %s > %t.obj
|
||||
# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE
|
||||
# RUN: lld -flavor link2 /base:0x400000 /entry:function \
|
||||
# RUN: /subsystem:console /out:%t.exe %t.obj
|
||||
# RUN: lld -flavor link2 /entry:function /subsystem:console /out:%t.exe %t.obj
|
||||
# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER
|
||||
|
||||
# BEFORE: Disassembly of section .text:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# RUN: yaml2obj < %s > %t.obj
|
||||
# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE
|
||||
# RUN: lld -flavor link2 /base:0x400000 /entry:function \
|
||||
# RUN: /subsystem:console /out:%t.exe %t.obj
|
||||
# RUN: lld -flavor link2 /entry:function /subsystem:console /out:%t.exe %t.obj
|
||||
# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER
|
||||
|
||||
# BEFORE: Disassembly of section .text:
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# RUN: yaml2obj < %s > %t.obj
|
||||
# RUN: lld -flavor link /out:%t.exe /base:0x400000 /subsystem:console \
|
||||
# RUN: %t.obj %p/Inputs/library.lib
|
||||
# RUN: lld -flavor link /out:%t.exe /subsystem:console %t.obj %p/Inputs/library.lib
|
||||
# RUN: llvm-readobj -coff-imports %t.exe | FileCheck %s
|
||||
|
||||
# CHECK: Import {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# RUN: yaml2obj < %s > %t.obj
|
||||
# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE
|
||||
# RUN: lld -flavor link /base:0x400000 /out:%t.exe /subsystem:console /entry:get_function %t.obj
|
||||
# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:get_function %t.obj
|
||||
# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER
|
||||
|
||||
# BEFORE: Disassembly of section .text:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# RUN: yaml2obj < %s > %t.obj
|
||||
# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE
|
||||
# RUN: lld -flavor link2 /base:0x400000 /entry:get_buffer /subsystem:console /out:%t.exe %t.obj
|
||||
# RUN: lld -flavor link2 /entry:get_buffer /subsystem:console /out:%t.exe %t.obj
|
||||
# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER
|
||||
|
||||
# BEFORE: Disassembly of section .text:
|
||||
|
|
|
@ -19,11 +19,11 @@ IMPORT-NEXT: BoundDelayImportTable: 0x0
|
|||
IMPORT-NEXT: UnloadDelayImportTable: 0x0
|
||||
IMPORT-NEXT: Import {
|
||||
IMPORT-NEXT: Symbol: ExitProcess (0)
|
||||
IMPORT-NEXT: Address: 0x40002029
|
||||
IMPORT-NEXT: Address: 0x402029
|
||||
IMPORT-NEXT: }
|
||||
IMPORT-NEXT: Import {
|
||||
IMPORT-NEXT: Symbol: MessageBoxA (0)
|
||||
IMPORT-NEXT: Address: 0x1
|
||||
IMPORT-NEXT: Address: 0x0
|
||||
IMPORT-NEXT: }
|
||||
IMPORT-NEXT: }
|
||||
|
||||
|
@ -70,16 +70,16 @@ BASEREL-NEXT: Address: 0x2046
|
|||
BASEREL-NEXT: }
|
||||
BASEREL-NEXT: ]
|
||||
|
||||
DISASM: 202b: 68 20 10 00 40 pushl $1073745952
|
||||
DISASM-NEXT: 2030: 68 00 30 00 40 pushl $1073754112
|
||||
DISASM: 202b: 68 20 10 40 00 pushl $4198432
|
||||
DISASM-NEXT: 2030: 68 00 30 40 00 pushl $4206592
|
||||
DISASM-NEXT: 2035: e8 c6 ff ff ff calll -58 <_main@0>
|
||||
DISASM-NEXT: 203a: 5a popl %edx
|
||||
DISASM-NEXT: 203b: 59 popl %ecx
|
||||
DISASM-NEXT: 203c: ff e0 jmpl *%eax
|
||||
DISASM-NEXT: 203e: 51 pushl %ecx
|
||||
DISASM-NEXT: 203f: 52 pushl %edx
|
||||
DISASM-NEXT: 2040: 68 28 10 00 40 pushl $1073745960
|
||||
DISASM-NEXT: 2045: 68 00 30 00 40 pushl $1073754112
|
||||
DISASM-NEXT: 2040: 68 28 10 40 00 pushl $4198440
|
||||
DISASM-NEXT: 2045: 68 00 30 40 00 pushl $4206592
|
||||
DISASM-NEXT: 204a: e8 b1 ff ff ff calll -79 <_main@0>
|
||||
DISASM-NEXT: 204f: 5a popl %edx
|
||||
DISASM-NEXT: 2050: 59 popl %ecx
|
||||
|
|
|
@ -29,7 +29,7 @@ HEADER-NEXT: SizeOfUninitializedData: 0
|
|||
HEADER-NEXT: AddressOfEntryPoint: 0x2000
|
||||
HEADER-NEXT: BaseOfCode: 0x2000
|
||||
HEADER-NEXT: BaseOfData: 0x0
|
||||
HEADER-NEXT: ImageBase: 0x40000000
|
||||
HEADER-NEXT: ImageBase: 0x400000
|
||||
HEADER-NEXT: SectionAlignment: 4096
|
||||
HEADER-NEXT: FileAlignment: 512
|
||||
HEADER-NEXT: MajorOperatingSystemVersion: 6
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
# CHECK-NEXT: 1000 00200000
|
||||
|
||||
# CHECK: Contents of section .rdata:
|
||||
# CHECK-NEXT: 2000 04100040
|
||||
# CHECK-NEXT: 2000 04104000
|
||||
|
||||
---
|
||||
header:
|
||||
|
|
Loading…
Reference in New Issue