Commit Graph

786 Commits

Author SHA1 Message Date
Shankar Easwaran 2a92c18ba3 [lld][ELF] Handle multiple weak symbols
This handles multiple weak symbols which appear back to back. This fix is needed
which otherwise will lead to symbols getting initialized to arbitrary values.

There was a constructor/destructor test that really triggered this to be fixed
on X86_64.

Adds a test.

llvm-svn: 190658
2013-09-13 04:25:44 +00:00
Rui Ueyama 6f32549623 [PECOFF] Handle weak external symbols.
Used the fallback mechanism to implement COFF weak external symbols.

llvm-svn: 190633
2013-09-12 21:42:52 +00:00
Shankar Easwaran 4ff19b3c87 [lld][LinkingContext] Fix doxygen comment
llvm-svn: 190629
2013-09-12 20:00:15 +00:00
Rui Ueyama 55b3cc5054 Do not prepend "_" to external symbols if non-i386.
llvm-svn: 190628
2013-09-12 19:52:59 +00:00
Rui Ueyama 98896ed1b5 [PECOFF] Add a field for machine type to PECOFFLinkingContext.
So that we can determine what the target architecture is. Adding this
field does not mean that we are going to support non-i386 architectures
soon; there are many things to do to support them, and I'm focusing on
i386 now. But this is the first step toward multi architecture support.

llvm-svn: 190627
2013-09-12 19:46:53 +00:00
Rui Ueyama e5416ec2d2 Add a fallback mechanism for undefined atom.
In COFF, an undefined symbol can have up to one alternative name. If a symbol
is resolved by its regular name, then it's linked normally. If a symbol is not
found in any input files, all references to the regular name are resolved using
the alternative name. If the alternative name is not found, it's a link error.
This mechanism is called "weak externals".

To support this mechanism, I added a new member function fallback() to undefined
atom. If an undefined atom has the second name, fallback() returns a new undefined
atom that should be used instead of the original one to resolve undefines. If it
does not have the second name, the function returns nullptr.

Differential Revision: http://llvm-reviews.chandlerc.com/D1550

llvm-svn: 190625
2013-09-12 19:14:05 +00:00
Shankar Easwaran 2206d5ad7d [lld][tests] Fix buildbot failure on darwin
llvm-svn: 190619
2013-09-12 18:10:20 +00:00
Shankar Easwaran d6d1b52937 [lld][LayoutPass] change comments to reflect the sort order
llvm-svn: 190612
2013-09-12 15:59:34 +00:00
Shankar Easwaran 2734d79d94 [lld][ELF] Fix vaddr of the first section
The first section in the output was not aligned to the alignment of the section.

llvm-svn: 190610
2013-09-12 15:43:17 +00:00
Shankar Easwaran df2dd193ee [lld][ELF] Fix the readonly section order.
This associates rodata and sections which just have the SHF_ALLOC flag
to be set to typeConstant.

llvm-svn: 190609
2013-09-12 15:43:13 +00:00
Shankar Easwaran f1b341c80e [lld][LayoutPass] Order the atoms that are in the same chain
We need to order atoms that exist in the same chain. This is to make sure that
the command line order is preserved when we emit the atoms to the output file.

Credits: BigCheese for finding the bug.

Adds a test which otherwise would fail.

llvm-svn: 190608
2013-09-12 15:43:09 +00:00
Rui Ueyama 81d0d29639 Remove hard-coded leading underscore from entry symbol.
llvm-svn: 190586
2013-09-12 05:09:01 +00:00
Rui Ueyama 1e6af15388 Do not hard code the leading underscore.
Mangling scheme varies on platform, and prepending an underscore is valid only
on 32-bit x86. Added a method to mangle name to PECOFFLinkingContext and use
it to avoid hard coding mangled names.

llvm-svn: 190585
2013-09-12 04:42:31 +00:00
Rui Ueyama 2ff9d70ac4 Run clang-format.
llvm-svn: 190554
2013-09-11 22:21:42 +00:00
Nick Kledzik 2e0fb1ef5b Allow darwin driver to use -help when no input files are specified.
Patch by Joe Ranieri

llvm-svn: 190453
2013-09-10 23:57:41 +00:00
Nick Kledzik e773e327d3 Support darwin linker options:
-current_version, -compatibility_version, and -install_name.

Patch by Joe Ranieri

llvm-svn: 190452
2013-09-10 23:55:14 +00:00
Nick Kledzik e850d9dedd Remove PackedVersion from MachOLinkingContext and replace with uint32_t
and a parsePackedVersion() utility.

Patch by Joe Ranieri

llvm-svn: 190451
2013-09-10 23:46:57 +00:00
Rui Ueyama 5c532370d5 Use llvm::sys::Process::GetEnv() instead of ::getenv().
Process::GetEnv() uses GetEnvironmentVariableW, which is a Windows API
to get an environment variable and is preferable over getenv().

llvm-svn: 190431
2013-09-10 20:33:21 +00:00
Rui Ueyama fff7f8a4ed Rename GnuLDInputGraph.h -> GnuLdInputGraph.h for consistency with other files.
llvm-svn: 190332
2013-09-09 19:30:23 +00:00
Rui Ueyama 67de33b075 Use _isWholeArchive to silence -Wunused-private-field warning.
llvm-svn: 190329
2013-09-09 19:21:06 +00:00
Joerg Sonnenberger ecd1d9bc1d Handle _DYNAMIC correctly in the x86_64 backend.
llvm-svn: 190302
2013-09-09 12:19:28 +00:00
Joerg Sonnenberger 23f8d43e5c Recognize -Bstatic as alias for -static, clang uses it.
llvm-svn: 190301
2013-09-09 11:48:43 +00:00
Joerg Sonnenberger bd25241e0e Drop the context forceLoadAllArchives() support. Rename the isForceLoad
attribute in LinkerInput to isWholeArchive and use that for deciding
whether library archives should be expanded. Implement the -all_load
option of the Darwin linker using this flag and drop the support for it
in GNU mode.

llvm-svn: 190275
2013-09-08 13:30:14 +00:00
Joerg Sonnenberger a82566b86e Update documentation.
llvm-svn: 190255
2013-09-07 18:01:39 +00:00
Joerg Sonnenberger 0310e734c3 Run clang-format.
llvm-svn: 190254
2013-09-07 17:56:23 +00:00
Joerg Sonnenberger 5e235de9d3 Change the parseFile argument from MemoryBuffer pointer to LinkerInput
reference. Move readFile logic into FileNode::createLinkerInput.

llvm-svn: 190253
2013-09-07 17:55:28 +00:00
Rui Ueyama 0826dd23c6 [PECOFF] Don't add RVAs to base relocations table.
Patch by Ron Ofir.

llvm-svn: 190210
2013-09-06 22:09:02 +00:00
Rui Ueyama 97086a5a4f [PECOFF] Fix section alignment bug in ReaderCOFF.
Patch by Ron Ofir.

llvm-svn: 190198
2013-09-06 20:08:57 +00:00
Rui Ueyama 02c46bdb75 [PECOFF] Add /machine command line option.
llvm-svn: 190121
2013-09-06 04:17:07 +00:00
Rui Ueyama 030fe96ff3 [PECOFF] Align section contents as specified by the object file's section header.
llvm-svn: 190120
2013-09-06 04:06:58 +00:00
Rui Ueyama 822cb2e44b Remove extraneous parentheses.
llvm-svn: 190119
2013-09-06 03:16:28 +00:00
Rui Ueyama 01951de462 Return early to simplify.
llvm-svn: 190117
2013-09-06 01:48:19 +00:00
Rui Ueyama f48b8fc06d Remove unused identifiers.
llvm-svn: 190095
2013-09-05 20:21:24 +00:00
Shankar Easwaran fc09df0fe9 [lld][cleanup] remove unused ReaderFunc to avoid confusion.
llvm-svn: 190031
2013-09-05 04:27:17 +00:00
Shankar Easwaran 176e7fd05f [lld][ELF] Change the order of the writable note section
Writable note sections if they exist should not appear before text
they belong in the data segment

llvm-svn: 190024
2013-09-05 01:50:21 +00:00
Shankar Easwaran 8c705690ab [lld][ELF] Differentiate between Note sections(RW/RO)
It looks like there is a possibility of seeing RO/RW note sections
and we would need to create an appropriate RO/RW segment associated
with them.

Adds a test too.

llvm-svn: 189907
2013-09-04 02:42:02 +00:00
Rui Ueyama 959aebf873 [PECOFF] Ignore options starting with -?
The compiler is allowed to add a linker option starting with -?<name> to
.drectve section. If the linker can interpret -<name>, it's processed as if
there's no question mark there. If not, such option is silently ignored.

This is a COFF's feature to allow the compiler to emit new linker options
while keeping compatibility with older linkers.

llvm-svn: 189897
2013-09-04 00:51:51 +00:00
Shankar Easwaran b85f1857a1 [lld][ELF] Emit note sections
Emit note sections if the input contains a note section.

Also emit a note segment.

llvm-svn: 189896
2013-09-04 00:51:42 +00:00
Rui Ueyama 8ccf6da056 Rename *Options.td -> <flavor>Options.td.
Before this patch, name of driver implementation is not consistent with its
option table file. Specifically, LDOptions has a different prefix than
GnuLdDriver.

This patch renames option files, so that the option files have the same prefix
as the corresponding driver files.

Differential Revision: http://llvm-reviews.chandlerc.com/D1591

llvm-svn: 189895
2013-09-04 00:24:35 +00:00
Shankar Easwaran 2eaa47a008 [lld][Driver] remove return after llvm_unreachable
llvm-svn: 189891
2013-09-04 00:05:46 +00:00
Joerg Sonnenberger 37f50b7ccc Start a TODO list for the ELF backend.
llvm-svn: 189890
2013-09-04 00:00:48 +00:00
Shankar Easwaran 3df170b84e [lld][Driver] The driver was creating linker inputs twice
Also add a llvm_unreachable call so that the linker will trip on unhandled
inputElement types.

llvm-svn: 189887
2013-09-03 23:52:05 +00:00
Joerg Sonnenberger 33a6d3aaed Recognize -rpath-link option and add arguments to ELFLinkingContext.
llvm-svn: 189883
2013-09-03 23:28:51 +00:00
Rui Ueyama 225f090bdb [PECOFF] Allocate storage for .drective in the reader to avoid multiple calls of allocateString()
llvm-svn: 189881
2013-09-03 23:14:30 +00:00
Rui Ueyama 530488c92a [PECOFF] Verify parameter in validateImpl() not in the driver.
llvm-svn: 189877
2013-09-03 22:57:00 +00:00
Shankar Easwaran d3b3d71a3a [lld] Remove bitfield for boolean members
llvm-svn: 189876
2013-09-03 22:55:45 +00:00
Shankar Easwaran c16b5e76fc [lld][ELF][X86_64] Test alignment for init_array/fini_array sections
llvm-svn: 189875
2013-09-03 22:46:54 +00:00
Shankar Easwaran 84c643fcc3 [lld][ELF][X86_64] Fix alignment of init_array/fini_array sections
llvm-svn: 189874
2013-09-03 22:44:46 +00:00
Shankar Easwaran 2b9d1025d6 [lld][ELF] Change the InitFini atom type from Stub to Data
llvm-svn: 189873
2013-09-03 22:44:44 +00:00
Shankar Easwaran fce7952b79 [lld][ELF][Hexagon] add Init/Fini option for hexagon
This adds init/fini support for Hexagon.

llvm-svn: 189872
2013-09-03 22:44:42 +00:00