diff options
| author | Rui Ueyama <ruiu@google.com> | 2013-08-27 03:18:11 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2013-08-27 03:18:11 +0000 |
| commit | 4c3184f3c0fb0b5e0ad0295fc6e63bbdfc88569c (patch) | |
| tree | ab5fe834d7ad800fd2a3cfc6b9300b3ab44b5ce7 | |
| parent | a382db02936d930d1c8bcbc12d6713bbd8ca2f66 (diff) | |
| download | bcm5719-llvm-4c3184f3c0fb0b5e0ad0295fc6e63bbdfc88569c.tar.gz bcm5719-llvm-4c3184f3c0fb0b5e0ad0295fc6e63bbdfc88569c.zip | |
Treat entry point symbol as an undefined atom.
With this patch the entry symbol is treated as an undefined symbol, to force
the resolver to resolve the entry symbol.
Differential Revision: http://llvm-reviews.chandlerc.com/D1524
llvm-svn: 189307
| -rw-r--r-- | lld/include/lld/Core/LinkingContext.h | 26 | ||||
| -rw-r--r-- | lld/lib/Driver/WinLinkDriver.cpp | 2 | ||||
| -rw-r--r-- | lld/test/pecoff/Inputs/main.obj.yaml | 12 | ||||
| -rw-r--r-- | lld/test/pecoff/drectve.test | 2 | ||||
| -rw-r--r-- | lld/test/pecoff/imagebase.test | 5 | ||||
| -rw-r--r-- | lld/test/pecoff/importlib.test | 19 | ||||
| -rw-r--r-- | lld/test/pecoff/lib.test | 2 | ||||
| -rw-r--r-- | lld/test/pecoff/multi.test | 4 | ||||
| -rw-r--r-- | lld/test/pecoff/trivial.test | 7 | ||||
| -rw-r--r-- | lld/unittests/DriverTests/WinLinkDriverTest.cpp | 3 |
10 files changed, 47 insertions, 35 deletions
diff --git a/lld/include/lld/Core/LinkingContext.h b/lld/include/lld/Core/LinkingContext.h index 3ae0ec5abbf..6946b98af18 100644 --- a/lld/include/lld/Core/LinkingContext.h +++ b/lld/include/lld/Core/LinkingContext.h @@ -77,6 +77,13 @@ public: return _deadStripRoots; } + /// Add the given symbol name to the dead strip root set. Only used if + /// deadStrip() returns true. + void addDeadStripRoot(StringRef symbolName) { + assert(_deadStrip && "only applicable when deadstripping enabled"); + _deadStripRoots.push_back(symbolName); + } + /// Archive files (aka static libraries) are normally lazily loaded. That is, /// object files within an archive are only loaded and linked in, if the /// object file contains a DefinedAtom which will replace an existing @@ -178,7 +185,16 @@ public: /// \name Methods used by Drivers to configure TargetInfo /// @{ void setOutputPath(StringRef str) { _outputPath = str; } - void setEntrySymbolName(StringRef name) { _entrySymbolName = name; } + + // Set the entry symbol name. You may also need to call addDeadStripRoot() for + // the symbol if your platform supports dead-stripping, so that the symbol + // will not be removed from the output. + void setEntrySymbolName(StringRef name) { + // Entry function have to be resolved as an undefined symbol. + addInitialUndefinedSymbol(name); + _entrySymbolName = name; + } + void setDeadStripping(bool enable) { _deadStrip = enable; } void setGlobalsAreDeadStripRoots(bool v) { _globalsAreDeadStripRoots = v; } void setSearchArchivesToOverrideTentativeDefinitions(bool search) { @@ -214,9 +230,11 @@ public: } virtual InputGraph &inputGraph() const { return *_inputGraph; } - /// This method adds undefined symbols specified by the -u option to the - /// to the list of undefined symbols known to the linker. This option - /// essentially forces an undefined symbol to be create. + /// This method adds undefined symbols specified by the -u option to the to + /// the list of undefined symbols known to the linker. This option essentially + /// forces an undefined symbol to be create. You may also need to call + /// addDeadStripRoot() for the symbol if your platform supports dead + /// stripping, so that the symbol will not be removed from the output. void addInitialUndefinedSymbol(StringRef symbolName) { _initialUndefinedSymbols.push_back(symbolName); } diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp index 3cb76c4ebaa..a312eb2a126 100644 --- a/lld/lib/Driver/WinLinkDriver.cpp +++ b/lld/lib/Driver/WinLinkDriver.cpp @@ -422,7 +422,7 @@ bool WinLinkDriver::parse(int argc, const char *argv[], } // 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 diff --git a/lld/test/pecoff/Inputs/main.obj.yaml b/lld/test/pecoff/Inputs/main.obj.yaml index d99554ac390..e3f9b2126c2 100644 --- a/lld/test/pecoff/Inputs/main.obj.yaml +++ b/lld/test/pecoff/Inputs/main.obj.yaml @@ -22,10 +22,6 @@ sections: 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 @@ symbols: 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 ... diff --git a/lld/test/pecoff/drectve.test b/lld/test/pecoff/drectve.test index 100a71020dd..87ca6d5a93c 100644 --- a/lld/test/pecoff/drectve.test +++ b/lld/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 diff --git a/lld/test/pecoff/imagebase.test b/lld/test/pecoff/imagebase.test index 206a525c725..82230ba4366 100644 --- a/lld/test/pecoff/imagebase.test +++ b/lld/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 diff --git a/lld/test/pecoff/importlib.test b/lld/test/pecoff/importlib.test index 7476c011ad4..11ba4540490 100644 --- a/lld/test/pecoff/importlib.test +++ b/lld/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: diff --git a/lld/test/pecoff/lib.test b/lld/test/pecoff/lib.test index a1eca9ceec8..94a7044b7a0 100644 --- a/lld/test/pecoff/lib.test +++ b/lld/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: diff --git a/lld/test/pecoff/multi.test b/lld/test/pecoff/multi.test index df6e321fcce..787de318722 100644 --- a/lld/test/pecoff/multi.test +++ b/lld/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: diff --git a/lld/test/pecoff/trivial.test b/lld/test/pecoff/trivial.test index e4facd145f7..536aea0943a 100644 --- a/lld/test/pecoff/trivial.test +++ b/lld/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 diff --git a/lld/unittests/DriverTests/WinLinkDriverTest.cpp b/lld/unittests/DriverTests/WinLinkDriverTest.cpp index 9cade4c9f7c..416af38c76b 100644 --- a/lld/unittests/DriverTests/WinLinkDriverTest.cpp +++ b/lld/unittests/DriverTests/WinLinkDriverTest.cpp @@ -54,7 +54,8 @@ TEST_F(WinLinkParserTest, Basic) { EXPECT_TRUE(_context.getBaseRelocationEnabled()); EXPECT_TRUE(_context.isTerminalServerAware()); EXPECT_TRUE(_context.getDynamicBaseEnabled()); - EXPECT_TRUE(_context.initialUndefinedSymbols().empty()); + EXPECT_FALSE(_context.initialUndefinedSymbols().empty()); + EXPECT_EQ("_start", _context.initialUndefinedSymbols()[0]); } TEST_F(WinLinkParserTest, UnixStyleOption) { |

