Commit Graph

765 Commits

Author SHA1 Message Date
Nick Kledzik f373c77f50 [mach-o] Fix lazy binding offsets
The way lazy binding works in mach-o is that the linker generates a helper
function and has the stub (PLT) initially jump to it.  The helper function
pushes an extra parameter then jumps into dyld.  The extra parameter is an
offset into the lazy binding info where dyld will find the information about
which symbol to bind and way lazy binding pointer to update.

llvm-svn: 221654
2014-11-11 01:31:18 +00:00
Shankar Easwaran 156ffbc4c0 [ELF] add missing test for max-page-size
llvm-svn: 221594
2014-11-10 15:16:31 +00:00
Shankar Easwaran 7757f1ace6 [Gnu] Support --image-base option
The value for --image-base is used as the base address of the program.

llvm-svn: 221589
2014-11-10 14:55:21 +00:00
Shankar Easwaran 7a82510348 [ELF] Fix DT_INIT_ARRAY{SZ} and DT_FINI_ARRAY{SZ}
The dynamic table was creating the entry DT_FINI_ARRAY{SZ} even when there was
no .fini_array section. The entries should be creating in the dynamic section
only if there are sections .init_array/.fini_array in the output.

Fixes the tests that checked for errroneous outputs.

llvm-svn: 221588
2014-11-10 14:55:11 +00:00
Shankar Easwaran 0abfc278f0 [ELF] Fix values of linker created dynamic variables.
The value of _DYNAMIC should be pointing at the start of the .dynamic segment.
This was pointing to the end of the dynamic segment. Similarly the value of
_GLOBAL_OFFSET_TABLE_ was not proper too.

llvm-svn: 221587
2014-11-10 14:55:07 +00:00
Shankar Easwaran 38d187021f [ELF] .dynamic should have SHT_DYNAMIC flag
llvm-svn: 221586
2014-11-10 14:54:53 +00:00
Shankar Easwaran 22c76a5d79 [ELF] Support --no-align-segments.
lld generates an ELF by adhering to the ELF spec by aligning vma/fileoffset to a
page boundary, but this becomes an issue when dealing with large pages. This
adds support so that lld generated executables adheres to the ELF spec with the
rule vma % p_align = offset % p_align.

This is supported by the flag --no-align-segments.

This could be the default in few targets like X86_64 to save space on disk.

llvm-svn: 221571
2014-11-08 03:44:49 +00:00
Nick Kledzik 82d24bc932 [mach-o] Add support for -order_file option
The darwin linker lets you rearrange functions and data for better locality
(less paging).  You do this with the -order_file option which supplies a text
file containing one symbol per line.

Implementing this required a small change to LayoutPass to add a custom sorter
hook.

llvm-svn: 221545
2014-11-07 21:01:21 +00:00
Rui Ueyama 2685de1077 Disable a Mach-O test on Windows that depends on Unix path separator.
llvm-svn: 221506
2014-11-07 01:51:00 +00:00
Rui Ueyama 81d9e09090 Add missing -target triple to ELF tests.
llvm-svn: 221505
2014-11-07 01:45:32 +00:00
Rui Ueyama 6dca8d1c36 XFAIL elf/demangle.test on Windows.
Because LLD on that platform can't demangle symbols.

llvm-svn: 221504
2014-11-07 01:30:49 +00:00
Rui Ueyama 2d220ab9b4 [PECOFF] Improve subsystem inference
If /subsystem option is not given, the linker needs to infer the
subsystem based on the entry point symbol. If it fails to infer
that, the linker should error out on it.

LLD was almost correct, but it would fail to infer the subsystem
if the entry point is specified with /entry. This is because the
subsystem inference was coupled with the entry point function
searching (if no entry point name is specified, the linker needs
to find the right entry name).

This patch makes the subsystem inference an independent pass to
fix the issue. Now, as long as an entry point function is defined,
LLD can infer the subsystem no matter how it resolved the entry
point.

I don't think scanning all the defined symbols is fast, although
it shouldn't be that slow. The file class there does not provide
any easy way to find an atom by name, so this is what we can do
at this moment. I'd like to revisit this later to make it more
efficient.

llvm-svn: 221499
2014-11-06 23:50:48 +00:00
Nick Kledzik 24f504001d [mach-o] Add support for -force_load option
The darwin linker has two ways to force all members of an archive to be loaded.
The -all_load option applies to all static libraries.  The -force_load takes
a path to a library and just that library's members are force loaded.

llvm-svn: 221477
2014-11-06 19:33:57 +00:00
Kevin Enderby 3b47e1f7e2 [mach-o] Update test case to work with latest llvm-objdump output for ARM thumb
code.  Same basic change that was done in r218429 for ARM code.

Where the ARM thumb symbolizer in llvm-objdump’s Mach-O disassembler is now
plumbed in with r221470 from the llvm trunk.

llvm-svn: 221473
2014-11-06 19:12:28 +00:00
Simon Atanasyan c88db09cc5 [Mips] Take into account that PIC code is inherently CPIC
Follow-up to r221439.

llvm-svn: 221442
2014-11-06 07:07:29 +00:00
Simon Atanasyan b915d07a8e [Mips] Check ELF flags to prevent linking of incompatible files
1. The path checks ELF header flags to prevent linking of incompatible files.
   For example we do not allow to link files with different ABI, -mnan
   flags, some combination of target CPU etc.
2. The patch merge ELF header flags from input object files to put their
   combination to the generated file. For example, if some input files
   have EF_MIPS_NOREORDER flag we need to put this flag to the output
   file header.

I use the `parseFile()` (not `canParse()`) method because in case of
recognition of incorrect input flags combination we should show detailed
error message and stop the linking process and should not try to use
another `Reader`.

llvm-svn: 221439
2014-11-06 05:53:10 +00:00
Simon Atanasyan 4c6bd6a10d [Mips] Fix ELF flags for the non-PIC object file used in the test
No functional changes.

llvm-svn: 221438
2014-11-06 05:52:54 +00:00
Nick Kledzik 37d1aa715a [mach-o] remove extra leading underscore on __bss and __got
llvm-svn: 221425
2014-11-06 01:14:12 +00:00
Nick Kledzik 0b1ef201b9 [mach-o] Add support for interposing tuples section
Darwin uses two-level-namespace lookup for symbols which means the static
linker records where each symbol must be found at runtime.  Thus defining a
symbol in a dylib loaded earlier will not effect where symbols needed by
later dylibs will be found.  Instead overriding is done through a section
of type S_INTERPOSING which contains tuples of <interposer, interposee>.

llvm-svn: 221424
2014-11-06 01:14:09 +00:00
Rui Ueyama 30804c4220 [PECOFF] Fix SECREL relocations.
SECREL relocation's value is the offset to the beginning of the section.
Because of the off-by-one error, if a SECREL relocation target is at the
beginning of a section, it got wrong value.

Added a test that would have caught this.

llvm-svn: 221420
2014-11-06 01:03:23 +00:00
David Majnemer ff9848ab08 PECOFF: Set the AddressOfRelocationTable in the DOS header
Many programs, for reasons unknown, really like to look at the
AddressOfRelocationTable to determine whether or not they are looking at
a bona fide PE file.  Without this, programs like the UNIX `file'
utility will insist that they are looking at a MS DOS executable.

llvm-svn: 221335
2014-11-05 06:37:08 +00:00
Rui Ueyama cace52091b [PECOFF] Do not skip COMDAT section symbols.
LLD skipped COMDAT section symbols when reading them because
I thought we don't want to have symbols with the same name.
But they are actually needed because relocations may refer to
the section symbols. So we shoulnd't skip them.

llvm-svn: 221329
2014-11-05 02:21:39 +00:00
Rui Ueyama 4f5cbc1a1e [PECOFF] Fix symbols in module-definition file.
llvm-svn: 221303
2014-11-04 22:09:13 +00:00
Tim Northover f98b1c9960 [mach-o] remove __compact_unwind atoms once __unwind_info has been generated
The job of the CompactUnwind pass is to turn __compact_unwind data (and
__eh_frame) into the compressed final form in __unwind_info. After it's done,
the original atoms are no longer relevant and should be deleted (they cause
problems during actual execution, quite apart from the fact that they're not
needed).

llvm-svn: 221301
2014-11-04 21:57:32 +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 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
Simon Atanasyan c375809781 [Mips] Add ABI and ARCH flags to the object files.
No functional changes.

llvm-svn: 220931
2014-10-30 21:20:27 +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
Rui Ueyama 44067eead1 Update compile target dependency.
test/elf/Mips/hilo16-*.test depends on llvm-mc, so we need to
make CMake to build that before running the tests.

llvm-svn: 220768
2014-10-28 06:30:34 +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 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
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 4804aedd24 [ELF] Add demangle test to XFAIL
This test is failing for some reason on freebsd.

Not sure why it should fail, need to investigate.

llvm-svn: 220185
2014-10-20 05:33:42 +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 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 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 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
NAKAMURA Takumi 9758bc473b [CMake] check-lld: Prune llvm-mc. It is unused.
llvm-svn: 220040
2014-10-17 12:55:58 +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
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