Commit Graph

1741 Commits

Author SHA1 Message Date
Rafael Espindola 5a899e332b Use llvm::sys::findProgramByName. NFC.
llvm-svn: 221257
2014-11-04 12:34:32 +00:00
Shankar Easwaran 1baf2359df [ELF] Update TODO
llvm-svn: 221235
2014-11-04 04:50:58 +00:00
Shankar Easwaran 4e9b8702f5 [ELF] Fix MSVC buildbot.
For some reason, MSVC doesnot like the style.

Checking to make sure this fixes the problem with the build.

llvm-svn: 221234
2014-11-04 04:25:00 +00:00
Shankar Easwaran f56205bb8e [ELF] Fix program headers.
The ELF writer creates a invalid binary for few cases with large filesize and
memory size for segments. This patch addresses the functionality and updates the
test. This patch also cleans up parts of the ELF writer for future enhancements
to support Linker scripts.

llvm-svn: 221233
2014-11-04 03:57:04 +00:00
David Majnemer 4eb0a3fd25 PECOFF: Use the string table for long section names in EXEs/DLLs
Normally, PE files have section names of eight characters or less.
However, this is problematic for DWARF because DWARF section names are
things like .debug_aranges.

Instead of truncating the section name, redirect the section name into
the string table.

Differential Revision: http://reviews.llvm.org/D6104

llvm-svn: 221212
2014-11-04 00:53:57 +00:00
Rafael Espindola b8ceaf15cd Fix leak found by asan.
llvm-svn: 221180
2014-11-03 20:55:23 +00:00
Rafael Espindola 1f9a45fdfb Fix a leak found by asan.
llvm-svn: 221179
2014-11-03 20:49:17 +00:00
Rafael Espindola fd5d365463 Fix warnings about missing override.
llvm-svn: 221165
2014-11-03 17:14:46 +00:00
Rafael Auler d301b9b3e0 [LinkerScript] Change ErrorOr usage to fix MSVC2012 buildbots
Number parsing functions used an ErrorOr<> idiom that is not supported in
MSVC2012. This patch fixes this.

llvm-svn: 221128
2014-11-03 05:26:18 +00:00
Rafael Auler 347fb02093 [lld] Teach LLD how to parse most linker scripts
This patch does *not* implement any semantic actions, but it is a first step to
teach LLD how to read complete linker scripts. The additional linker scripts
statements whose parsing is now supported are:

* SEARCH_DIR directive
* SECTIONS directive
* Symbol definitions inside SECTIONS including PROVIDE and PROVIDE_HIDDEN
* C-like expressions used in many places in linker scripts
* Input to output sections mapping

The goal of this commit was guided towards completely parsing a default GNU ld
linker script and the linker script used to link the FreeBSD kernel. Thus, it
also adds a test case based on the default linker script used in GNU ld for
x86_64 ELF targets. I tested SPEC userland programs linked by GNU ld, using the
linker script dump'ed by this parser, and everything went fine. I then tested
linking the FreeBSD kernel with a dump'ed linker script, installed the new
kernel and booted it, everything went fine.

Directives that still need to be implemented:
* MEMORY
* PHDRS

Reviewers: silvas, shankarke and ruiu

http://reviews.llvm.org/D5852

llvm-svn: 221126
2014-11-03 04:09:51 +00:00
Tim Northover cadb77a43e [mach-o] explicitly cast little_n uses to ints to silence MSVC
Hopefully this'll fix the build failure in the bot.

llvm-svn: 221007
2014-10-31 22:12:20 +00:00
Tim Northover 516e983dd4 [mach-o] use the addend in GOT-based relocations.
These are used to reference typeinfo data in the exception table section, for
example.

llvm-svn: 220916
2014-10-30 18:01:07 +00:00
Nick Kledzik 54ce295849 [mach-o] generate LC_DATA_IN_CODE in final linked images
lld was regenerating LC_DATA_IN_CODE in .o output files, but not into
final linked images.

Update test case to verify data-in-code info makes it into final linked images.

llvm-svn: 220827
2014-10-28 22:21:10 +00:00
Nick Kledzik cb955ae1a5 [mach-o] Turn -single_module error into a warning
To be more compatible with existing darwin linker.

llvm-svn: 220822
2014-10-28 21:11:02 +00:00
Tim Northover 40d3ad3319 TMP: fix readN & writeN to not encourage UB
llvm-svn: 220730
2014-10-27 22:48:35 +00:00
NAKAMURA Takumi 59c74b225a Fix unicode chars into ascii in comment lines.
llvm-svn: 220668
2014-10-27 08:08:18 +00:00
Rui Ueyama fccf7ef924 Remove #ifdef __FreeBSD
r220665 makes configure or CMake to set HAVE_CXXABI_H on FreeBSD 10.0.
We don't need this ugly ifdef condition anymore.

llvm-svn: 220666
2014-10-27 07:44:40 +00:00
Nick Kledzik 4183dbcc03 [mach-o] Support old style objc class names in export lists
Objective-C switched to a new ABI which uses a different mangling for class
names.  But to keep projects building that use export lists that use the old
class name mangling, the linker recognizes the old names and transforms them
to the new mangling.

llvm-svn: 220598
2014-10-24 22:28:54 +00:00
Nick Kledzik 761d6549bc [mach-o] Support data-only dylibs
In final linked shared images, the __TEXT segment contains both code and
the mach-o header/load-commands.  In the case of a data-only dylib, there is
no code, so we need to force the addition of the __TEXT segment.

llvm-svn: 220597
2014-10-24 22:19:22 +00:00
Rui Ueyama 875301b2c4 [PECOFF] Do not write duplicate directives to .def file.
This is a follow-up patch for r220333. r220333 renames exported symbols.
That raised another issue; if we have both decorated and undecorated names
for the same symbol, we'll end up have two duplicate exported symbol
entries.

This is a fix for that issue by removing duplciate entries.

llvm-svn: 220350
2014-10-22 00:05:30 +00:00
Nick Kledzik 9133f8c76d [mach-o] Support missing MH_SUBSECTIONS_VIA_SYMBOLS
All compiler generated mach-o object files are marked with MH_SUBSECTIONS_VIA_SYMBOLS.
But hand written assembly files need to opt-in if they are written correctly.
The flag means the linker can break up a sections at symbol addresses and
dead strip or re-order functions.

This change recognizes object files without the flag and marks its atoms as
not dead strippable and adds a layout-after chain of references so that the
atoms cannot be re-ordered.

llvm-svn: 220348
2014-10-21 23:45:37 +00:00
Rui Ueyama 8bae8189b2 [PECOFF] Fix exported symbol in the import library
There are two ways to specify a symbol to be exported in the module
definition file.

1) EXPORT <external name> = <symbol>
2) EXPORT <symbol>

In (1), you give both external name and internal name. In that case,
the linker tries to find a symbol using the internal name, and write
that address to the export table with the external name. Thus, from
the outer world, the symbol seems to be exported as the external name.

In (2), internal name is basically the same as the external name
with an exception: if you give an undecorated symbol to the EXPORT
directive, and if the linker finds a decorated symbol, the external
name for the symbol will become the decorated symbol.

LLD didn't implement that exception correctly. This patch fixes that.

llvm-svn: 220333
2014-10-21 21:41:28 +00:00
Nick Kledzik a721db24c0 Subclass InputGraph to get darwin linker library semantics
The darwin linker operates differently than the gnu linker with respect to
libraries. The darwin linker first links in all object files from the command
line, then to resolve any remaining undefines, it repeatedly iterates over
libraries on the command line until either all undefines are resolved or no
undefines were resolved in the last pass.

When Shankar made the InputGraph model, the plan for darwin was for the darwin
driver to place all libraries in a group at the end of the InputGraph. Thus
making the darwin model a subset of the gnu model. But it turns out that does
not work because the driver cannot tell if a file is an object or library until
it has been loaded, which happens later.

This solution is to subclass InputGraph for darwin and just iterate the graph
the way darwin linker needs.

llvm-svn: 220330
2014-10-21 21:14:11 +00:00
Rui Ueyama 1d6d08bb4d Use __cxa_demangle on FreeBSD to fix buildbots.
llvm-svn: 220326
2014-10-21 21:05:01 +00:00
Rui Ueyama e7bf4299db Assume cxxabi.h exists on FreeBSD
HAVE_CXXABI_H is not defined on FreeBSD but the system actually
has the header. CMake test fails because the header depends on size_t.

llvm-svn: 220315
2014-10-21 20:02:00 +00:00
Shankar Easwaran 1b44519a6c [Gnu] Move certain options to a different group.
The -mllvm option is not specific to LTO.

llvm-svn: 220263
2014-10-21 04:02:32 +00:00
Shankar Easwaran 322d0df309 [ELF] Remove duplicate code.
The base class ELFObjectReader/ELFDSOReader implement the canParse functionaity
with this change.

llvm-svn: 220261
2014-10-21 03:12:57 +00:00
Rui Ueyama f3208b808d [PECOFF] Look for decorated entry symbol name.
Entry symbol name can be decorated. When we look for _WinMain, we
also have to look for _WinMain@16.

llvm-svn: 220259
2014-10-21 02:28:28 +00:00
Shankar Easwaran 3dadd20fe5 [ELF] Implement demangle.
This adds functionality in the GNU flavor to demangle symbols when
undefined symbols are displayed to the user.

llvm-svn: 220184
2014-10-20 05:04:53 +00:00
Shankar Easwaran 1635f8de72 [ELF] Check for target architecture.
The canParse function for all the ELF subtargets check if the input files match
the subtarget.

There were few mismatches in the input files that didnt match the subtarget for
which the link was being invoked, which also acts as a test for this change.

llvm-svn: 220182
2014-10-20 04:00:26 +00:00
Shankar Easwaran 116ac7ce87 [ELF] Make updateReferenceForMergeStringAccess virtual.
The ELF subtargets would usually want to override the function
updateReferenceForMergeStringAccess. Allow this by making it virtual.

llvm-svn: 220180
2014-10-20 03:03:43 +00:00
Shankar Easwaran 6cfcb388b0 [ELF] Fix functionality of merging similar strings.
For PC relative accesses, negative addends were to be ignored. The linker was
not ignoring it and would fail with an assert. This fixes the issue and is able
to get Helloworld working.

llvm-svn: 220179
2014-10-20 02:59:06 +00:00
Shankar Easwaran 1175153867 [ELF][Cleanup] Remove unused code.
The old code was used as a workaround to fix how relocations are calculated for
sections with SHF_MERGE|SHF_STRINGS attribute. This patch removes the erroneous
code.

llvm-svn: 220159
2014-10-19 03:28:13 +00:00
Shankar Easwaran 69df16f619 Fix display of files processed by the linker.
This fixes the way archive members are displayed when the linker is used with a
flag to show all the files that it processes.

When an archive file member is read, we need to show the archive filename and
the member.

llvm-svn: 220144
2014-10-18 20:36:35 +00:00
Shankar Easwaran 2b67fca033 Sort include files according to convention.
llvm-svn: 220131
2014-10-18 05:33:55 +00:00
Shankar Easwaran ac23808619 [ELF] Add Readers for all the ELF subtargets.
This would permit the ELF reader to check the architecture that is being
selected by the linking process.

This patch also sorts the include files according to LLVM conventions.

llvm-svn: 220129
2014-10-18 05:23:17 +00:00
Richard Smith f83ba5eb0f Hardcode the list of ELF targets here rather than using a glob.
The code was making non-portable assumptions about the exact string returned by
the glob (possibly by the shell?); this is more robust and matches what is done
everywhere else.

llvm-svn: 220117
2014-10-18 00:56:31 +00:00
Tim Northover 24b7dd431e [mach-o] keep Windows library happy.
&v[v.size()] may be invalid C++.

llvm-svn: 220115
2014-10-18 00:36:03 +00:00
Rui Ueyama 2845fb29d8 [PECOFF] Emit x64 delay-import wrapper function
Previously we supported x86 only. This patch is to support x64.

The array of pointers to delay-loaded functions points the
DLL delay loading function at start-up. When a function is called
for the first time, the delay loading function gets called and
then rewrite the function pointer array.

llvm-svn: 220096
2014-10-17 22:03:54 +00:00
NAKAMURA Takumi a4dce82065 lld/lib/Core/Error.cpp: Appease g++-4.7, corresponding to LLVM r210687.
llvm-svn: 220039
2014-10-17 12:55:49 +00:00
NAKAMURA Takumi 8c38df4e9e [CMake] lld: Introduce ${cmake_2_8_12_INTERFACE} onto each target_link_libraries. [PR20254]
FIXME: Dependencies should be reorganized.
llvm-svn: 220000
2014-10-17 00:37:49 +00:00
Nick Kledzik 3a118aa344 [mach-o] Fix crash when -all_load used with dylibs
-all_load tells the darwin linker to immediately load all members of all
archives.  The code do that used reinterpret_cast<> instead of dyn_cast<>.
If the file was a dylib, the reinterpret_cast<> turned a pointer to a dylib
into a pointer to an archive...boom.

Added test case to reproduce the crash, simplified the code and used dyn_cast<>.

llvm-svn: 219990
2014-10-16 23:42:42 +00:00
Tim Northover 933bead97d [mach-o] update __eh_frame handling for Nick's suggestions
First, add a comment to support more variation in FDE formats. Second, refactor
fde -> function handling into a separate function living in the ArchHandler.

llvm-svn: 219959
2014-10-16 20:52:18 +00:00
Nick Kledzik 5172067391 [mach-o] Add support for upward linking
To deal with cycles in shared library dependencies, the darwin linker supports
marking specific link dependencies as "upward".  An upward link is when a
lower level library links against a higher level library.

llvm-svn: 219949
2014-10-16 19:31:28 +00:00
Rui Ueyama b38b96ab4c [PECOFF] Support delay-load import table for x86
This patch creates the import address table and sets its
address to the delay-load import table. This also creates
wrapper functions for __delayLoadHelper2.

x86 only for now.

llvm-svn: 219948
2014-10-16 19:30:44 +00:00
Tim Northover 995abe34f9 [mach-o] avoid overly clever std::find_if
The bots were complaining (possibly because of a lack of traits on the iterator
I was trying to use). No functional change.

llvm-svn: 219843
2014-10-15 20:26:24 +00:00
Tim Northover 1cc4fb76da [mach-o] make __unwind_info defer to __eh_frame when necessary.
Not all situations are representable in the compressed __unwind_info format,
and when this happens the entry needs to point to the more general __eh_frame
description.

Just x86_64 implementation for now.

rdar://problem/18208653

llvm-svn: 219836
2014-10-15 19:32:21 +00:00
Tim Northover a6a6ab9949 [macho] Create references from __eh_frame FDEs to their function.
We'll also need references back to the CIE eventually, but for now making sure
we can work out what an FDE is referring to is enough.

The actual kind of reference needs to be different between architectures,
probably because of MachO's chronic shortage of relocation types but I don't
really want to know in case I find out something that distresses me even more.

rdar://problem/18208653

llvm-svn: 219824
2014-10-15 18:19:31 +00:00
Rui Ueyama 0abf613059 Use isa<> and cast<> instead of definition().
No functionality change intended.

llvm-svn: 219727
2014-10-14 21:42:08 +00:00
Rui Ueyama 82399f96ae Remove dead code.
Because we use cast<> at the beginning of this function, it will
abort there if a given atom is not a DefinedAtom.

In the switch statement, we checked if a given atom is a DefinedAtom
again by evaluating definition() == Atom::definitionRegular.
This was always true. So we can remove the outer switch statement.

llvm-svn: 219724
2014-10-14 21:37:33 +00:00