[PATCH] Entry point function should never be dead-stripped.
Rui Ueyama
ruiu at google.com
Mon Aug 26 16:55:41 PDT 2013
Hi shankarke,
This is a revised patch for http://llvm-reviews.chandlerc.com/D1366
to address Shankar's comments. In this new patch I treat the entry symbol
as an undefined symbol, to force the resolver to resolve the entry symbol.
--
Currently we do not have this logic, so the entry point function can be
dead-stripped, which is wrong.
http://llvm-reviews.chandlerc.com/D1524
Files:
include/lld/Core/LinkingContext.h
lib/Driver/WinLinkDriver.cpp
test/pecoff/Inputs/main.obj.yaml
test/pecoff/drectve.test
test/pecoff/imagebase.test
test/pecoff/importlib.test
test/pecoff/lib.test
test/pecoff/multi.test
test/pecoff/trivial.test
unittests/DriverTests/WinLinkDriverTest.cpp
Index: include/lld/Core/LinkingContext.h
===================================================================
--- include/lld/Core/LinkingContext.h
+++ include/lld/Core/LinkingContext.h
@@ -178,7 +178,14 @@
/// \name Methods used by Drivers to configure TargetInfo
/// @{
void setOutputPath(StringRef str) { _outputPath = str; }
- void setEntrySymbolName(StringRef name) { _entrySymbolName = name; }
+
+ void setEntrySymbolName(StringRef name) {
+ // Entry function will have to be resolved and should never be
+ // dead-stripped.
+ addInitialUndefinedSymbol(name);
+ _entrySymbolName = name;
+ }
+
void setDeadStripping(bool enable) { _deadStrip = enable; }
void setGlobalsAreDeadStripRoots(bool v) { _globalsAreDeadStripRoots = v; }
void setSearchArchivesToOverrideTentativeDefinitions(bool search) {
@@ -219,6 +226,7 @@
/// essentially forces an undefined symbol to be create.
void addInitialUndefinedSymbol(StringRef symbolName) {
_initialUndefinedSymbols.push_back(symbolName);
+ _deadStripRoots.push_back(symbolName);
}
/// Iterators for symbols that appear on the command line
Index: lib/Driver/WinLinkDriver.cpp
===================================================================
--- lib/Driver/WinLinkDriver.cpp
+++ lib/Driver/WinLinkDriver.cpp
@@ -422,7 +422,7 @@
}
// Use the default entry name if /entry option is not given.
- if (!parsedArgs->getLastArg(OPT_entry))
+ if (ctx.entrySymbolName().empty())
setDefaultEntrySymbolName(ctx);
// Arguments after "--" are interpreted as filenames even if they
Index: test/pecoff/Inputs/main.obj.yaml
===================================================================
--- test/pecoff/Inputs/main.obj.yaml
+++ test/pecoff/Inputs/main.obj.yaml
@@ -22,10 +22,6 @@
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
Alignment: 1
SectionData: 04000000F10000006E0000003300011100000000433A5C63796777696E5C686F6D655C727569755C7374617469635C7374617469632D696D706F72742E6F626A0037003C1103020000030000000000000000000A0000001B9D01004D6963726F736F667420285229204D6163726F20417373656D626C657200000000
- - Name: .drectve
- Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
- Alignment: 2147483648
- SectionData: 2F656E7472793A6D61696E20
symbols:
- Name: "@comp.id"
Value: 10394907
@@ -75,12 +71,4 @@
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- - Name: .drectve
- Value: 0
- SectionNumber: 4
- SimpleType: IMAGE_SYM_TYPE_NULL
- ComplexType: IMAGE_SYM_DTYPE_NULL
- StorageClass: IMAGE_SYM_CLASS_STATIC
- NumberOfAuxSymbols: 1
- AuxiliaryData: 0C0000000000000000000000000000000000
...
Index: test/pecoff/drectve.test
===================================================================
--- test/pecoff/drectve.test
+++ test/pecoff/drectve.test
@@ -4,7 +4,7 @@
# RUN: yaml2obj %p/Inputs/drectve.obj.yaml > %t.obj
#
-# RUN: lld -flavor link /out:%t1 /entry:start -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /entry:_start -- %t.obj \
# RUN: && llvm-readobj -file-headers %t1 | FileCheck %s
CHECK: MajorOperatingSystemVersion: 42
Index: test/pecoff/imagebase.test
===================================================================
--- test/pecoff/imagebase.test
+++ test/pecoff/imagebase.test
@@ -1,9 +1,10 @@
# RUN: yaml2obj %p/Inputs/imagebase.obj.yaml > %t.obj
#
-# RUN: lld -flavor link /out:%t1 /subsystem:console -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:__start -- %t.obj \
# RUN: && llvm-objdump -disassemble %t1 | FileCheck -check-prefix=CHECK1 %s
#
-# RUN: lld -flavor link /out:%t1 /subsystem:console /base:65536 -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:__start /base:65536 \
+# RUN: -- %t.obj \
# RUN: && llvm-objdump -disassemble %t1 | FileCheck -check-prefix=CHECK2 %s
CHECK1: a1 00 20 40 00 movl 4202496, %eax
Index: test/pecoff/importlib.test
===================================================================
--- test/pecoff/importlib.test
+++ test/pecoff/importlib.test
@@ -3,20 +3,23 @@
#
# RUN: yaml2obj %p/Inputs/vars-main.obj.yaml > %t.obj
#
-# RUN: lld -flavor link /out:%t1 /subsystem:console -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_main -- %t.obj \
# RUN: %p/Inputs/vars.lib && llvm-objdump -d %t1 | FileCheck %s
#
-# RUN: lld -flavor link /out:%t1 /subsystem:console /libpath:%p/Inputs \
-# RUN: -- %t.obj vars.lib && llvm-objdump -d %t1 | FileCheck %s
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_main \
+# RUN: /libpath:%p/Inputs -- %t.obj vars.lib && llvm-objdump -d %t1 \
+# RUN: | FileCheck %s
#
-# RUN: lld -flavor link /out:%t1 /subsystem:console /libpath:%p/Inputs \
-# RUN: /defaultlib:vars.lib -- %t.obj && llvm-objdump -d %t1 | FileCheck %s
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_main \
+# RUN: /libpath:%p/Inputs /defaultlib:vars.lib -- %t.obj \
+# RUN: && llvm-objdump -d %t1 | FileCheck %s
#
# RUN: env LIB=%p/Inputs lld -flavor link /out:%t1 /subsystem:console \
-# RUN: -- %t.obj vars.lib && llvm-objdump -d %t1 | FileCheck %s
+# RUN: /entry:_main -- %t.obj vars.lib && llvm-objdump -d %t1 | FileCheck %s
#
-# RUN: env LINK="/out:%t1 /subsystem:console -- %t.obj" lld -flavor link \
-# RUN: %p/Inputs/vars.lib && llvm-objdump -d %t1 | FileCheck %s
+# RUN: env LINK="/out:%t1 /subsystem:console /entry:_main -- %t.obj" \
+# RUN: lld -flavor link %p/Inputs/vars.lib && llvm-objdump -d %t1 \
+# RUN: | FileCheck %s
CHECK: Disassembly of section .text:
CHECK-NEXT: .text:
Index: test/pecoff/lib.test
===================================================================
--- test/pecoff/lib.test
+++ test/pecoff/lib.test
@@ -2,7 +2,7 @@
#
# RUN: yaml2obj %p/Inputs/main.obj.yaml > %t.obj
#
-# RUN: lld -flavor link /out:%t1 /subsystem:console -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_main -- %t.obj \
# RUN: %p/Inputs/static.lib && llvm-objdump -d %t1 | FileCheck %s
CHECK: Disassembly of section .text:
Index: test/pecoff/multi.test
===================================================================
--- test/pecoff/multi.test
+++ test/pecoff/multi.test
@@ -4,8 +4,8 @@
# RUN: yaml2obj %p/Inputs/static-data1.obj.yaml > %t2.obj
# RUN: yaml2obj %p/Inputs/static-data2.obj.yaml > %t3.obj
#
-# RUN: lld -flavor link /out:%t1 /subsystem:console -- %t1.obj %t2.obj %t3.obj \
-# RUN: && llvm-objdump -d %t1 | FileCheck %s
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_main \
+# RUN: -- %t1.obj %t2.obj %t3.obj && llvm-objdump -d %t1 | FileCheck %s
CHECK: Disassembly of section .text:
CHECK: .text:
Index: test/pecoff/trivial.test
===================================================================
--- test/pecoff/trivial.test
+++ test/pecoff/trivial.test
@@ -4,10 +4,11 @@
#
# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj
#
-# RUN: lld -flavor link /out:%t1 /subsystem:console,3.11 -- %t.obj \
-# RUN: && llvm-readobj -file-headers %t1 | FileCheck -check-prefix=FILE %s
+# RUN: lld -flavor link /out:%t1 /subsystem:console,3.11 /entry:_start \
+# RUN: -- %t.obj && llvm-readobj -file-headers %t1 \
+# RUN: | FileCheck -check-prefix=FILE %s
#
-# RUN: lld -flavor link /out:%t1 -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /entry:_start -- %t.obj \
# RUN: && llvm-readobj -sections %t1 | FileCheck -check-prefix=SECTIONS %s
FILE: Format: COFF-i386
Index: unittests/DriverTests/WinLinkDriverTest.cpp
===================================================================
--- unittests/DriverTests/WinLinkDriverTest.cpp
+++ unittests/DriverTests/WinLinkDriverTest.cpp
@@ -54,7 +54,8 @@
EXPECT_TRUE(_context.getBaseRelocationEnabled());
EXPECT_TRUE(_context.isTerminalServerAware());
EXPECT_TRUE(_context.getDynamicBaseEnabled());
- EXPECT_TRUE(_context.initialUndefinedSymbols().empty());
+ EXPECT_TRUE(!_context.initialUndefinedSymbols().empty());
+ EXPECT_EQ("_start", _context.initialUndefinedSymbols()[0]);
}
TEST_F(WinLinkParserTest, UnixStyleOption) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1524.1.patch
Type: text/x-patch
Size: 8301 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130826/5425e679/attachment.bin>
More information about the llvm-commits
mailing list