Commit Graph

1008 Commits

Author SHA1 Message Date
Rui Ueyama f54e4fd3c6 PECOFF: Move error check for invalid command line combination to validateImpl.
llvm-svn: 228461
2015-02-06 23:09:13 +00:00
Rui Ueyama 0076215b88 MachO: Move LayoutPass to MachO directory.
The real user of the LayoutPass is now only Mach-O, so move that
pass out of the common directory to Mach-O directory.

"Core" architecture were using the LayoutPass. I modified that
to use a simple OrderPass. I think no one actually have authority
what feature should be in Core and what's not, but I believe the
LayoutPass is not very suitable for Core. Before more code starts
depending on the complex pass, it's better to remove that from
Core.

I could have simplified that pass because Mach-O is the only user
of the LayoutPass. For example, the second parameter of the
LayoutPass constructor can be converted from optional to mandatory.
I didn't do that in this patch to keep it simple. I'll do in a
followup patch.

http://reviews.llvm.org/D7311

llvm-svn: 228341
2015-02-05 20:05:33 +00:00
Rui Ueyama df7d133cdf PECOFF: Fix I386_DIR32 relocation to an absolute symbol
Previously, we incorrectly added the image base address to an absolute
symbol address (that calculation doesn't make any sense) if an
IMAGE_REL_I386_DIR32 relocation is applied to an absolute symbol.

This patch fixes the issue. With this fix, we can link Bochs using LLD.
(Choosing Bochs has no special meaining -- I just picked it up as a
test program and found it didn't work.) This also fixes one of the
issues we currently have to link Chromium using LLD.

llvm-svn: 228279
2015-02-05 07:22:53 +00:00
Shankar Easwaran d67bcb5f5c [ELF] Dont discard sections in the input file.
The reader was discarding certain types of sections from the input file.

llvm-svn: 228268
2015-02-05 02:56:06 +00:00
Denis Protivensky b635ae8388 [lld][ARM] Add relocations to perform function calls
Added relocations to perform function calls with and without passing arguments.
ARM-only, Thumb-only and mixed mode code generations are supported.
Only simple veneers (direct instruction modification) are supported as ARM-Thumb interwork.

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

llvm-svn: 227961
2015-02-03 10:48:37 +00:00
Davide Italiano 5cbde851ed [ELF] Support for parsing OUTPUT command in LinkerScript
Differential Revision:	D7326
Reviewed by:	rafaelauler, shankarke, ruiu

llvm-svn: 227786
2015-02-02 06:21:23 +00:00
Shankar Easwaran d6f73ac366 [test] Add test for section groups and deadstrip
This adds a test that deadstrip should preserve the section group even if there
is only one reference to a function in the group.

llvm-svn: 227711
2015-02-01 05:47:02 +00:00
Shankar Easwaran 0f011fdcdf [ELF] Set order of ctors/dtors section
llvm-svn: 227707
2015-02-01 03:21:57 +00:00
Rui Ueyama 33ab83bc4b ELF: Don't use LayoutPass.
Previously we applied the LayoutPass to order atoms and then
apply elf::ArrayOrderPass to sort them again. The first pass is
basically supposed to sort atoms in the normal fashion (which
is to sort symbols in the same order as the input files).
The second pass sorts atoms in {init,fini}_array.<priority> by
priority.

The problem is that the LayoutPass is overkill. It analyzes
references between atoms to make a decision how to sort them.
It's slow, hard to understand, and above all, it doesn't seem
that we need its feature for ELF in the first place.

This patch remove the LayoutPass from ELF pass list. Now all
reordering is done in elf::OrderPass. That pass sorts atoms by
{init,fini}_array, and if they are not in the special section,
they are ordered as the same order as they appear in the command
line. The new code is far easier to understand, faster, and
still able to create valid executables.

Unlike the previous layout pass, elf::OrderPass doesn't count
any attributes of an atom (e.g. permissions) except its
position. It's OK because the writer takes care of them if we
have to.

This patch changes the order of final output, although that's
benign. Tests are updated.

http://reviews.llvm.org/D7278

llvm-svn: 227666
2015-01-31 02:05:01 +00:00
Rui Ueyama a9a6f55840 ELF: Fix a bug in -l.
If a linker script is given with -l, LLD failed to read the file.
The bug was introduced in 227341.

llvm-svn: 227610
2015-01-30 21:03:19 +00:00
Rui Ueyama c4038ab5bf PECOFF: Do not use LayoutPass and instead use simpler one.
The LayoutPass is one of the slowest pass. This change is to skip
that pass. This change not only improve performance but also improve
maintainability of the code because the LayoutPass is pretty complex.

Previously we used the LayoutPass to sort all atoms in a specific way,
and reorder them again for PE/COFF in GroupedSectionPass.

I spent time on improving and fixing bugs in the LayoutPass (e.g.
r193029), but the pass is still hard to understand and hard to use.
It's better not to depend on that if we don't need. For PE/COFF, we
just wanted to sort atoms in the same order as the file order in the
command line.

The feature we used in the LayoutPass is now simplified to
compareByPosition function in OrderPass.cpp. The function is just 5
lines.

This patch changes the order of final output because it changes the
sort order a bit. The output is still correct, though.

llvm-svn: 227500
2015-01-29 22:12:50 +00:00
Greg Fitzgerald df0f5cd474 Remove PPC ELF target
Differential Revision: http://reviews.llvm.org/D7225

llvm-svn: 227320
2015-01-28 16:37:43 +00:00
Rui Ueyama dd88e86b57 Remove kindInGroup reference.
That kind of reference was used only in ELFFile, and the use of
that reference there didn't seem to make sense. All test still
pass (after adjusting symbol names) without that code. LLD is
still be able to link LLD and Clang. Looks like we just don't
need this.

http://reviews.llvm.org/D7189

llvm-svn: 227259
2015-01-27 22:55:29 +00:00
Simon Atanasyan 5a34d0343f [Mips] Support R_MIPS_GPREL16 relocation
llvm-svn: 227244
2015-01-27 21:11:11 +00:00
Denis Protivensky 2b5539651b [lld] Correct forming of ARM/Thumb atoms
Symbols addressing Thumb code have zero bit set in st_value to distinguish them from ARM instructions.
This caused wrong atoms' forming because of offset of one byte brought in by that corrected st_value.

Fixed reading of st_value & st_value-related things in ARMELFFile while forming atoms.
Symbol table generation is also fixed for Thumb atoms.

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

llvm-svn: 227174
2015-01-27 07:39:04 +00:00
Simon Atanasyan efdbf4c0b7 [Mips] Add checking of disassembler output in some test cases
No functional changes.

llvm-svn: 227059
2015-01-25 21:31:52 +00:00
Simon Atanasyan 0712650742 [Mips] Teach LLD to recognize one more MIPS target triple - mips64el
This is initial patch to support MIPS64 object files linking.
The patch just makes some classes more generalized, and rejects
attempts to interlinking O32 and N64 ABI object files.

I try to reuse the current MIPS target related classes as much as
possible because O32 and N64 MIPS ABI are tightly related and share
almost the same set of relocations, GOT, flags etc.

llvm-svn: 227058
2015-01-25 19:15:35 +00:00
Filipe Cabecinhas 9e804b0a2a Revert r226950. The test doesn't require the Mips target anymore
llvm-svn: 226990
2015-01-24 05:13:52 +00:00
Filipe Cabecinhas d1787adcec Fix REQUIRES lines added in r226951 and add the x86 feature if the X86 target was compiled in
llvm-svn: 226985
2015-01-24 03:55:22 +00:00
Rui Ueyama 009c1a931e Fix spelling.
llvm-svn: 226966
2015-01-23 23:39:33 +00:00
Filipe Cabecinhas d72d29b0b6 [lld] Added REQUIRES lines to tests
llvm-svn: 226951
2015-01-23 22:32:12 +00:00
Filipe Cabecinhas d9e8b06ceb [lld] Re-add REQUIRES line
Please don't remove REQUIRES lines when refreshing tests.

llvm-svn: 226950
2015-01-23 22:32:05 +00:00
Rui Ueyama 163e4768c0 Fix slow test.
yaml2obj command ran by this test took more than 15 seconds to finish
because of extremely large .bss section. Other tests only takes 3 seconds.
Reduce the size to make it faster.

llvm-svn: 226693
2015-01-21 19:15:56 +00:00
Greg Fitzgerald 8a1887f1f1 [ELF] Minimal implementation for ARM static linking
The code is able to statically link the simplest case of:

  int main() { return 0; }

* Only works with ARM code - no Thumb code, no interwork (-marm -mno-thumb-interwork)
* musl libc built with no interwork and no Thumb code

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

From: Denis Protivensky <dprotivensky@accesssoftek.com>
llvm-svn: 226643
2015-01-21 07:35:48 +00:00
Rui Ueyama e6556a9cea Fix --start-group/end-group.
We used to manage the state whether we are in a group or not
using a counter. The counter is incremented by one if we jump from
end-group to start-group, and decremented by one if we don't.
The counter was assumed to be either zero or one, but obviously it
could be negative (if there's a group which is not repeated at all).
This is a fix for that issue.

llvm-svn: 226632
2015-01-21 01:26:43 +00:00
Will Newton f1925f84ff ELF: Handle sh_addralign being set to zero
sh_addralign of zero is equivalent to sh_addralign of one, meaning
no alignment specified. Avoid calculating Log2 or modulus when
sh_addralign is zero as the results will not be useful.

llvm-svn: 226572
2015-01-20 16:10:04 +00:00
Rui Ueyama cb9b1086ff [PECOFF] Improve parallelism.
llvm-svn: 226284
2015-01-16 15:58:36 +00:00
Rui Ueyama fa7e8a663f [ELF] Add --as-needed.
The previous default behavior of LLD is --as-needed. LLD linked
against a DSO only if the DSO file was actually used to link an
executable (i.e. at least one symbol was resolved using the shared
library file.)

In this patch I added a boolean flag to FileNode for --as-needed.
I also added an accessor to DSO name to shared library file class.

llvm-svn: 226274
2015-01-16 14:27:01 +00:00
Simon Atanasyan 48b0bca7e8 [Mips] Allow linking object files with MIPS32 and MIPS64 instructions
If object files satisfy O32 ABI they can be linked together even if some
of them contains MIPS64 or MIPS64R2 instructions.

llvm-svn: 226253
2015-01-16 08:57:08 +00:00
Saleem Abdulrasool 6fffd487ee PE/COFF: use dyn_cast for the check of the target
The target may be a synthetic symbol like __ImageBase.  cast_or_null will ensure
that the atom is a DefinedAtom, which is not guaranteed, which was the original
reason for the cast_or_null.  Switch this to dyn_cast, which should enable
building of executables for WoA.  Unfortunately, the issue of missing base
relocations still needs to be investigated.

llvm-svn: 226246
2015-01-16 04:14:33 +00:00
Filipe Cabecinhas e609302ad1 Remove the slashes so they don't fail in some Windows setups
llvm-svn: 226222
2015-01-15 23:04:15 +00:00
Rui Ueyama df230b21e3 Re-commit r225674: Convert other drivers to use WrapperNode.
The original commit had an issue with Mac OS dylib files. It didn't
handle fat binary dylib files correctly. This patch includes a fix.
A test for that case has already been committed in r225764.

llvm-svn: 226123
2015-01-15 04:34:31 +00:00
Rui Ueyama a2013fa33c Make libmyshared.dylib a fat binary.
This would have caught the issue that I made in r225764.

llvm-svn: 226072
2015-01-15 01:32:00 +00:00
Rui Ueyama cfb2534ef8 Revert "Convert other drivers to use WrapperNode" and subsequent commits.
r225764 broke a basic functionality on Mac OS. This change reverts
r225764, r225766, r225767, r225769, r225814, r225816, r225829, and r225832.

llvm-svn: 225859
2015-01-14 00:21:34 +00:00
Rui Ueyama e8ecb2b144 Convert other drivers to use WrapperNode.
llvm-svn: 225764
2015-01-13 04:33:07 +00:00
Greg Fitzgerald 5a60ed7708 Remove fragile regex from test
Differential Revision: http://reviews.llvm.org/D6937

llvm-svn: 225739
2015-01-13 00:12:04 +00:00
Greg Fitzgerald cedca2f057 Remove CMake standalone build configuration
Differential Revision: http://reviews.llvm.org/D6898

llvm-svn: 225704
2015-01-12 21:41:10 +00:00
Greg Fitzgerald fcf77fd369 Don't fail if parent directory name contains a '+' character
Differential Revision: http://reviews.llvm.org/D6902

llvm-svn: 225574
2015-01-10 02:34:26 +00:00
Saleem Abdulrasool b9c402ed25 PE/COFF: add support to import functions in ARM NT
This is necessary to support linking a basic program which references symbols
outside of the module itself.  Add the import thunk for ARM NT style imports.
This allows us to create the reference.  However, it is still insufficient to
generate executables that will run due to base relocations not being emitted for
the import.

llvm-svn: 225428
2015-01-08 04:19:08 +00:00
Saleem Abdulrasool f9b99a1e07 PE/COFF: teach ARMNT backend about ADDR32NB for exports
This adds the ability to export symbols from a DLL built for ARMNT.  Add this
support first to help work towards adding support for import thunks on Windows
on ARM.  In order to generate the exports, add support for
IMAGE_REL_ARM_ADDR32NB relocations.

llvm-svn: 225339
2015-01-07 04:20:26 +00:00
Rui Ueyama a5f2816b1c Convert CoreInputGraph.
This is a part of InputGraph cleanup to represent input files as a flat
list of Files (and some meta-nodes for group etc.)

We cannot achieve that goal in one gigantic patch, so I split the task
into small steps as shown below.

(Recap the progress so far: Currently InputGraph contains a list of
InputElements. Each InputElement contain one File (that used to have
multiple Files, but I eliminated that use case in r223867). Files are
currently instantiated in Driver::link(), but I already made a change
to separate file parsing from object instantiation (r224102), so we
can safely instantiate Files when we need them, instead of wrapping
a file with the wrapper class (FileNode class). InputGraph used to
act like a generator class by interpreting groups by itself, but it's
now just a container of a list of InputElements (r223867).)

1. Instantiate Files in the driver and wrap them with WrapperNode.
WrapperNode is a temporary class that allows us to instantiate Files
in the driver while keep using the current InputGraph data structure.

This patch demonstrates how this step 1 looks like, using Core driver
as an example.

2. Do the same thing for the other drivers.

When step 2 is done, an InputGraph consists of GroupEnd objects or
WrapperNodes each of which contains one File. Other types of
FileNode subclasses are removed.

3. Replace InputGraph with std::vector<std::unique_ptr<InputElement>>.
InputGraph is already just a container of list of InputElements,
so this step removes that needless class.

4. Remove WrapperNode.

We need some code cleanup between each step, because many classes
do a bit odd things (e.g. InputGraph::getGroupSize()). I'll straight
things up as I need to.

llvm-svn: 225313
2015-01-06 23:06:49 +00:00
Saleem Abdulrasool 1e94ef5bd0 PECOFF: adjust the entry point on ARM NT
ARM NT assumes a purely THUMB execution, and as such requires that the address
of entry point is adjusted to indicate a thumb entry point.  Unconditionally
adjust the AddressOfEntryPoint in the PE header for PE/COFF ARM as we only
support ARM NT at the moment.

llvm-svn: 225139
2015-01-04 20:26:45 +00:00
Saleem Abdulrasool 4c059622d5 test: correct PE/COFF tests to build under MSVC mode
This adjusts the inputs to be compatible with armv7-windows-msvc as well as
armv7-windows-itanium.  NFC.

llvm-svn: 225105
2015-01-03 00:57:14 +00:00
Saleem Abdulrasool a09f872f58 ReaderWriter: adjust ARM target addresses for exec
ARM NT assumes a THUMB only environment.  As such, any address that is detected
as residing in an executable section is adjusted to have its bottom bit set to
indicate THUMB in case of a mode exchange.

Although the testing here seems insufficient (missing the negative cases) the
existing test cases for the IMAGE_REL_ARM_{ADDR32,MOV32T} are relevant as they
ensure that we do not incorrectly set the bit.

llvm-svn: 225104
2015-01-03 00:57:10 +00:00
Saleem Abdulrasool 434fedb8d8 ReaderWriter: teach the writer about IMAGE_REL_ARM_BRANCH24T
This adds support for IMAGE_REL_ARM_BRANCH24T relocations.  Similar to the
IMAGE_REL_ARM_BLX32T relocation, this relocation requires munging an
instruction.  The instruction encoding is quite similar, allowing us to reuse
the same munging implementation.  This is needed by the entry point stubs for
modules provided by MSVCRT.

llvm-svn: 225082
2015-01-02 18:51:59 +00:00
Saleem Abdulrasool f081873161 ReaderWriter: teach the writer about IMAGE_REL_ARM_BLX23T
This adds support for IMAGE_REL_ARM_BLX23T relocations.  Similar to the
IMAGE_REL_ARM_MOV32T relocation, this relocation requires munging an
instruction.  This inches us closer to supporting a basic hello world
application.

llvm-svn: 225081
2015-01-02 18:51:36 +00:00
Saleem Abdulrasool 017822d81a ReaderWriter: teach the writer about IMAGE_REL_ARM_MOV32T
This adds support for the IMAGE_REL_ARM_MOV32T relocation.  This is one of the
most complicated relocations for the Window on ARM target.  It involves
re-encoding an instruction to contain an immediate value which is the relocation
target.

llvm-svn: 225072
2015-01-02 02:32:05 +00:00
Saleem Abdulrasool 425505a9aa test: fix tests/buildbots
Correct the yaml definition for the object.  Adjust the symbol storage class
which was flipped for the two symbols, resulting in the link failure due to the
symbol missing.  Adjust the virtual address of the section.  This ripples into
the test case, since the data has been shifted up by 4 bytes.

llvm-svn: 225058
2015-01-01 03:39:48 +00:00
Saleem Abdulrasool 93930b65b8 ReaderWriter: teach the writer about IMAGE_REL_ARM_ADDR32
This implements the IMAGE_REL_ARM_ADDR32 relocation.  There are still a few more
relocation types that need to resolved before lld can even attempt to link a
trivial program for Windows on ARM.

llvm-svn: 225057
2015-01-01 03:11:53 +00:00
Saleem Abdulrasool 0ba09e6b84 ReaderWriter: teach PE/COFF backend about ARM NT
This teaches lld about the ARM NT object types.  Add a trivial test to ensure
that it can handle ARM NT object file inputs.  It is still unable to perform the
necessary relocations for ARM NT, but this allows the linker to at least read
the objects.

llvm-svn: 225052
2014-12-31 22:32:21 +00:00
Chandler Carruth 60617eac47 [py3] Make this test compatible with Python 3 where bytes and
strings don't mix so easily. This fixes the last remaining failure
I have in 'check-all' on a system with both Python3 and and Python2
installed.

llvm-svn: 224947
2014-12-29 19:23:31 +00:00
Chandler Carruth 24e9773fc5 [multilib] Teach LLD's CMake build to use LLVM_LIBDIR_SUFFIX which
allows it to support multilib suffixed hosts using lib64, etc. This
variable is now available both in the direct LLVM build and from the
LLVMConfig.cmake file used by standalone builds.

llvm-svn: 224925
2014-12-29 12:11:30 +00:00
Simon Atanasyan e473df2bf6 [Mips] Replace stderr output by the `llvm_unreachable` call
If a regular symbol has microMIPS-bit we need to stop linking. Now the
LLD does not check the `applyRelocation` return value and continues
linking anyway. As a temporary workaround use the `llvm_unreachable`
call to stop the linker.

llvm-svn: 224831
2014-12-25 09:23:47 +00:00
Simon Atanasyan 9af53992c8 [Mips] Make the test more tolerant to the linker output order
The LLD output in the YAML mode depends on LLD_RUN_ROUNDTRIP_TEST
environment variable. Do not check unimportant YAML items like section-name.

llvm-svn: 224830
2014-12-25 09:23:37 +00:00
Simon Atanasyan 45010c92a8 [Mips] Support linking of microMIPS 32-bit code
The change is rather large but mainly it just adds handling of new relocations,
PLT entries etc.

llvm-svn: 224826
2014-12-24 21:04:05 +00:00
Jean-Daniel Dupas edefcccd46 [macho] Minor install_name fixes
Summary:
Fix the binary file reader to properly read dyld version info.
Update the install_name test case to properly test the binary reader. We can't use '-print_atoms' as the output format is 'native' yaml and it does not contains the dyld current and compatibility versions. 

Also change the timestamp value of LD_ID_DYLD to match the one generated by ld64.
The dynamic linker (dyld) used to expects different values for timestamp in LD_ID_DYLD and LD_LOAD_DYLD for prebound images. While prebinding is deprecated, we should probably keep it safe and match ld64. 

Reviewers: kledzik

Subscribers: llvm-commits

Projects: #lld

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

llvm-svn: 224681
2014-12-20 09:22:56 +00:00
Jean-Daniel Dupas 23dd15e26d [macho] -rpath support
Summary:
Work on adding -rpath support to the mach-o linker.
This patch is based on the ld64 behavior for the command line option validation.

It includes a basic test to check that the LC_RPATH load commands are properly generated when that option is used.

It also add LC_RPATH support to the binary reader, but I don't know how to test it though.


Reviewers: kledzik

Subscribers: llvm-commits

Projects: #lld

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

llvm-svn: 224544
2014-12-18 21:33:38 +00:00
Will Newton 0b1db0a535 ELF/AArch64: Add a test for R_AARCH64_ABS32
llvm-svn: 224014
2014-12-11 12:37:35 +00:00
Will Newton e58c89b30f ELF/AArch64: Add a test for R_AARCH64_ABS64
llvm-svn: 224013
2014-12-11 12:36:58 +00:00
Simon Atanasyan 87a559212b [ELF] Allow target to adjust a symbol's value for using in a dynamic tag
Some targets like microMIPS and ARM Thumb use the last bit of a symbol's
value to mark 'compressed' code. This patch adds new virtual function
`DynamicTable::getAtomVirtualAddress` which allows to adjust a symbol's
value before using it in a dynamic table tags like DT_INIT / DT_FINI.

llvm-svn: 223963
2014-12-10 20:09:12 +00:00
Simon Atanasyan 04da06ccee [ELF] Make -init/-fini options compatible with the gnu linker
The LLD linker searches initializer and finalizer function names
and emits DT_INIT/DT_FINI dynamic table tags to point to these symbols.
The -init/-fini command line options override initializer ("_init") and
finalizer ("_fini") function names used by default.

Now the -init/-fini options do not affect .init_array/.fini_array
sections. The corresponding code has been removed.

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

llvm-svn: 223917
2014-12-10 05:38:46 +00:00
Will Newton b907542235 ELF: Add AArch64 test case missing from previous commit
llvm-svn: 223817
2014-12-09 19:31:09 +00:00
Rui Ueyama be68a99f20 [PECOFF] Fix exported symbols in an import library.
Looks like if you have symbol foo in a module-definition file
(.def file), and if the actual symbol name to match that export
description is _foo@x (where x is an integer), the exported
symbol name becomes this.

  - foo in the .dll file
  - foo@x in the .lib file

I have checked in a few fixes recently for exported symbol name mangling.
I haven't found a simple rule that governs all the mangling rules.
There may not ever exist. For now, this is a patch to improve .lib
file compatibility.

llvm-svn: 223524
2014-12-05 21:52:02 +00:00
Simon Atanasyan c9bcffd201 [ELF] Adjust ELF header entry symbol value if this symbol is microMIPS encoded
To find an AtomLayout object for the given symbol I replace the
`Layout::findAtomAddrByName` method by `Layout::findAtomLayoutByName` method.

llvm-svn: 223359
2014-12-04 13:43:35 +00:00
Rui Ueyama 0152732ef4 [PECOFF] Improve /export compatibility.
Looks like the rule of /export is more complicated than
I was thinking. If /export:foo, for example, is given, and
if the actual symbol name in an object file is _foo@<number>,
we need to export that symbol as foo, not as the mangled name.

If only /export:_foo@<number> is given, the symbol is exported
as _foo@<number>.

If both /export:foo and /export:_foo@<number> are given,
they are considered as duplicates, and the linker needs to
choose the unmangled name.

The basic idea seems that the linker needs to export a symbol
with the same name as given as /export.

We exported mangled symbols. This patch fixes that issue.

llvm-svn: 223341
2014-12-04 06:09:39 +00:00
Rui Ueyama a5e2a66dda [PECOFF] Improve compatibility of /export option.
llvm-svn: 223326
2014-12-04 00:31:34 +00:00
Rui Ueyama d31cf6065f [PECOFF] Fix a bug in /export option handler.
/export option can be given multiple times to specify multiple
symbols to be exported. /export accepts both decorated and
undecorated name.

If you give both undecorated and decorated name of the same symbol
to /export, they are resolved to the same symbol. In this case,
we need to de-duplicate the exported names, so that we don't have
duplicated items in the export symbol table in a DLL.

We remove duplicate items from a vector. The bug was there.
Because we had pointers pointing to elements of the vector,
after an item is removed, they would point wrong elements.

This patch is to remove these pointers. Added a test for that case.

llvm-svn: 223200
2014-12-03 04:34:20 +00:00
Nick Kledzik a441b7b050 [mach-o] add support for arm64 compact unwind info
Tim previously added generic compact unwind processing and x86_64 support.
This patch adds arm64 support.

llvm-svn: 223103
2014-12-02 01:50:38 +00:00
Shankar Easwaran a0184368d6 [ELF] Fix layout of output sections.
The AtomSections were improperly merging sections from various input files. This
patch fixes the problem, with an updated test that was provided by Simon.

Thanks to Simon Atanasyan for catching this issue.

llvm-svn: 222982
2014-11-30 22:36:29 +00:00
Shankar Easwaran 25c33d60c2 [ELF] Fix creation of segments.
Linker was creating a separate output segment in some cases if input sections
had huge alignments. This patch fixes the issue.

llvm-svn: 222974
2014-11-30 04:01:14 +00:00
Rui Ueyama 2343e65b14 [PECOFF] Sort export table properly.
Export table entries need to be sorted in ASCII-betical order,
so that the loader can find an entry for a function by binary search.

We sorted the entries by its mangled names. That can be different
from their exported names. As a result, LLD produces incorrect export
table, from which the loader complains that a function that actually
exists in a DLL cannot be found.

This patch fixes that issue.

llvm-svn: 222452
2014-11-20 21:05:05 +00:00
Shankar Easwaran f552996fb3 Revert "[ELF] Fix creation of segments."
This reverts commit r222312.

There looks to be an intermittent failure in the darwin buildbot.

llvm-svn: 222326
2014-11-19 05:53:13 +00:00
Shankar Easwaran 294cca1e8c [ELF] Fix creation of segments.
Linker was creating a separate output segment in some cases if input sections
had huge alignments. This patch fixes the issue.

llvm-svn: 222312
2014-11-19 03:51:48 +00:00
Nick Kledzik 5b9e48b4ce [mach-o] propagate dylib version numbers
Mach-o does not use a simple SO_NEEDED to track dependent dylibs.  Instead,
the linker copies four things from each dylib to each client: the runtime path
(aka "install name"), the build time, current version (dylib build number), and
compatibility version  The build time is no longer used (it cause every rebuild
of a dylib to be different).  The compatibility version is usually just 1.0
and never changes, or the dylib becomes incompatible.

This patch copies that information into the NormalizedMachO format and
propagates it to clients.

llvm-svn: 222300
2014-11-19 02:21:53 +00:00
Nick Kledzik 2020efb9fe [mach-o] for 32-bit arm, in -r mode support B (not BL) to undefined symbol
When fixing up BL instructions, the linker has to compare the thumbness of the
target to decide if the instruction needs to be converted to BLX.  But with B
instruction there is no BX, so the linker asserts if the target is not the
same thumbness. This assert was firing in -r mode when the target was undefined
which it interpreted as being non-thumb.

Test case change is to add a B (in both thumb and arm code) to an undefined
symbol and round trip through -r mode.

llvm-svn: 222266
2014-11-18 22:08:50 +00:00
David Majnemer 471d4f894b Update to match LLVM r222216
llvm-svn: 222218
2014-11-18 03:06:52 +00:00
Nick Kledzik b072c3673a [mach-o] zero-fill sections have no file offset
In mach-o, sections of type S_ZEROFILL are special cased and to always have
their section.offset field be zero.

llvm-svn: 222202
2014-11-18 00:30:29 +00:00
Nick Kledzik 63adb08c2c [mach-o] extract atom alignment information from mach-o files
llvm-svn: 222201
2014-11-18 00:30:25 +00:00
Nick Kledzik 60db3549e2 [mach-o] enhance arm64 reloc parser to support local pointer relocations
The arm64 assembler almost always uses r_extern=1 relocations in which the
r_symbolnum field is the index of the symbol the relocation references.  But
sometimes it will set r_extern=0 in which case the linker needs to read the
content of the reloction to determine the target.

Add test case that the r_extern=0 relocation round trips.

llvm-svn: 222198
2014-11-18 00:30:17 +00:00
Rui Ueyama 5552de51d5 [PECOFF] Fix 32-bit delay-import table.
llvm-svn: 222116
2014-11-17 02:04:54 +00:00
Rui Ueyama 71aa1a9355 [PECOFF] Fix section alignment.
If you have something like

  __declspec(align(8192)) int foo = 1;

in your code, the compiler makes the data to be aligned to 8192-byte
boundary, and the linker align the section containing the data to 8192.

LLD always aligned the section to 4192. So, as long as alignment
requirement is smaller than 4192, it was correct, but for larger
requirements, it's wrong.

This patch fixes the issue.

llvm-svn: 222043
2014-11-14 21:33:07 +00:00
Shankar Easwaran c37f8af577 [ELF] Dynamic section was not aligned properly.
The dynamic section was not aligned properly. The alignment of the section is
determined by the word size of the architecture.

llvm-svn: 221972
2014-11-14 04:57:21 +00:00
Simon Atanasyan ec2914e0f0 [Mips] Add comment to the test case
No functional changes.

llvm-svn: 221893
2014-11-13 15:29:37 +00:00
Shankar Easwaran 0769c0ed0d [ELF] Fix the fileoffset according to the ELF spec.
With --no-align-segments, there is a bug that the fileoffset may not be
congruent to virtual address modulo page alignment.

This patch fixes the problem.

llvm-svn: 221890
2014-11-13 14:30:21 +00:00
Simon Atanasyan c77f5fa4f4 [ELF] Add CodeModel attribute to the DefinedAtom class
MIPS ELF symbols might contain some additional MIPS-specific flags
in the st_other field besides visibility ones. These flags indicate
code properties like microMIPS / MIPS16 encoding, position independent
code etc. We need to transfer the flags from input objects to the
output linked file to write them into the symbol table, adjust symbols
addresses etc.

I add new attribute CodeModel to the DefinedAtom class to hold target
specific flag and to get over YAML/Native format conversion barrier.
Other architectures/targets can extend CodeModel enumeration by their
own flags.

MIPS specific part of this patch adds support for STO_MIPS_MICROMIPS
flag. This flag marks microMIPS symbols. Such symbol should:
a) Has STO_MIPS_MICROMIPS in the corresponding .symtab record.
b) Has adjusted (odd) address in the corresponding .symtab
   and .dynsym records.

llvm-svn: 221864
2014-11-13 07:03:41 +00:00
Shankar Easwaran 74ce86cb83 [ELF] Fix segment alignment.
The segment alignment for PT_LOAD segments is set to page size by default, but
if any of the sections require an alignment more than the page size, the segment
alignment property is set to the maximum alignment of the sections that are part
of the segment.

llvm-svn: 221862
2014-11-13 04:33:06 +00:00
Shankar Easwaran 2e20049260 [ELF] Fix conditions for max-page-size.
Fix comments from Rui, also adds a test.

llvm-svn: 221860
2014-11-13 04:03:46 +00:00
Shankar Easwaran b43804b6f4 [ELF] Fix max-page-size option.
The user can use the max-page-size option and set the maximum page size. Dont
check for maximum allowed values for page size, as its what the kernel is
configured with.

Fix the test as well.

llvm-svn: 221858
2014-11-13 03:25:38 +00:00
Shankar Easwaran 611e585f28 [ELF] Check linker created dynamic variables
Check the values of _GLOBAL_OFFSET_TABLE_ and _DYNAMIC variables created by
linker.

llvm-svn: 221857
2014-11-13 03:25:34 +00:00
Rui Ueyama c272dcaff6 Update COFF delay-import table tests for r221855.
This test should now have caught a bug fixed in r221853.

llvm-svn: 221856
2014-11-13 03:24:54 +00:00
Rui Ueyama 904cf593c1 [PECOFF] Fix delay-import address table contents.
Each entry in the delay-import address table had a wrong alignment
requirement if 32 bit. As a result it got wrong delay-import table.

Because llvm-readobj doesn't print out that field, we don't have a
test for that. I'll submit a test that would catch this bug after
improving llvm-readobj.

llvm-svn: 221853
2014-11-13 02:58:36 +00:00
Nick Kledzik 8870ad2439 [mach-o] Sort GOT entries by name to make links reproducible
The GOT slots were being laid out in a random order by the GOTPass which
caused randomness in the output file.

Note: With this change lld now bootstraps on darwin.  That is:
1) link lld using system linker to make lld.1
2) link lld using lld.1 to make lld.2
3) link lld using lld.2 to make lld.3
Now lld.2 and lld.3 are identical.

llvm-svn: 221831
2014-11-12 23:34:23 +00:00
Nick Kledzik 16cfa60cbd [mach-o] Support linker synthesized mach_header symbols.
On darwin in final linked images, the __TEXT segment covers that start of the
file.  That means in memory a process can see the mach_header (and load commands)
for every loaded image in a process.  There are APIs that take and return the
mach_header addresses as a way to specify a particular loaded image.

For completeness, any code can get the address of the mach_header of the image
it is in by using &__dso_handle.  In addition there are mach-o type specific
symbols like __mh_execute_header.

The linker needs to supply a definition for any of these symbols if used.  But
the address the symbol it resolves to is not in any section.  Instead it is the
address of the start of the __TEXT segment.

I needed to make a small change to SimpleFileNode to not override
resetNextIndex() because the Driver creates a SimpleFileNode to hold the
internal/implicit files that the context/writer can create. For some reason
SimpleFileNode overrode resetNextIndex() to do nothing instead of reseting
the index (which mach-o needs if the internal file is an archive).

llvm-svn: 221822
2014-11-12 22:21:56 +00:00
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
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
Nick Kledzik 4121bce3f6 [mach-o] Add Pass to create are shim Atoms for ARM interworking.
Arm code has two instruction encodings "thumb" and "arm".  When branching from
one code encoding to another, you need to use an instruction that switches
the instruction mode.  Usually the transition only happens at call sites, and
the linker can transform a BL instruction in BLX (or vice versa).  But if the
compiler did a tail call optimization and a function ends with a branch (not
branch and link), there is no pc-rel BX instruction.

The ShimPass looks for pc-rel B instructions that will need to switch mode.
For those cases it synthesizes a shim which does the transition, then modifies
the original atom with the B instruction to target to the shim atom.

llvm-svn: 219655
2014-10-14 01:51:42 +00:00
Rui Ueyama 98d703a663 [PECOFF] Emit ModuleHandle field in delay-import table.
Previously the field was not set. The field should be pointing to
a placeholder where the DLL delay-loader writes the base address
of a DLL.

llvm-svn: 219415
2014-10-09 17:43:01 +00:00
David Majnemer 1b8ae3cfc0 Update test to reflect the true section contents
Previously, LLVM object tools didn't know the true size of the sections.
This would result in tools thinking that a section with a VirtualSize
smaller than FileAlignment would end in zeros when actually those zeros
weren't really part of the section contents.

llvm-svn: 219394
2014-10-09 08:45:51 +00:00
Rui Ueyama 7be03d09cd [PECOFF] Emit the delay-import table
This is a partial patch to emit the delay-import table. With this,
LLD is now able to emit the table that llvm-readobj can read and
dump.

The table lacks a few fields, such as the address of HMODULE, the
import address table, etc. They'll be added in subsequent patches.

llvm-svn: 219384
2014-10-09 02:48:14 +00:00
Nick Kledzik cb2018f57c [mach-o] Use default for min OS version when not specified on command line.
This matches the current darwin linker.

llvm-svn: 219376
2014-10-09 01:01:16 +00:00
Rafael Auler 776293660e [ELF] Fix inclusion of weak symbols in the dynamic symbol table
This commit implements in the X86_64 ELF lld backend yet another feature that
was only available in the MIPS backend. However, this patch changes generic ELF
classes to make it trivial for other ELF backends to use this logic too. When
creating a dynamic executable that has dynamic relocations against weak
undefined symbols, these symbols must be exported to the dynamic symbol table
to seek a possible resolution at run time.

A common use case is the __gmon_start__ weak glibc undefined symbol.

Reviewer: shankarke

http://reviews.llvm.org/D5571

llvm-svn: 219349
2014-10-08 22:38:10 +00:00
Rafael Auler ce1af1a201 [ELF] Implement --export-dynamic/-E
When creating a dynamic executable and receiving the -E flag, the linker should
export all globally visible symbols in its dynamic symbol table.

This commit also moves the logic that exports symbols in the dynamic symbol
table from OutputELFWriter to the ExecutableWriter class. It is not correct to
leave this at OutputELFWriter because DynamicLibraryWriter, another subclass of
OutputELFWriter, already exports all symbols, meaning we can potentially end up
with duplicated symbols in the dynamic symbol table when creating shared libs.

Reviewers: shankarke

http://reviews.llvm.org/D5585

llvm-svn: 219334
2014-10-08 18:54:26 +00:00
Nick Kledzik 14b5d208cb [mach-o] Support fat archives
mach-o supports "fat" files which are a header/table-of-contents followed by a
concatenation of mach-o files (or archives of mach-o files) built for
different architectures.  Previously, the support for fat files was in the
MachOReader, but that only supported fat .o files and dylibs (not archives).

The fix is to put the fat handing into MachOFileNode.  That way any input file
kind (including archives) can be fat.  MachOFileNode selects the sub-range
of the fat file that matches the arch being linked and creates a MemoryBuffer
for just that subrange.

llvm-svn: 219268
2014-10-08 01:48:10 +00:00
Rui Ueyama 8f0c803c26 [PECOFF] Infer machine type from input object file
If /machine option is omitted, the linker needs to infer that from
input object files. This patch implements that.

llvm-svn: 219180
2014-10-07 01:38:46 +00:00
Saleem Abdulrasool 6211740789 PE/COFF: add a check to ensure that we dont mix up architectures
Previously, we would not check the target machine type and the module (object)
machine type.  Add a check to ensure that we do not attempt to use an object
file with a different target architecture.

This change identified a couple of tests which were incorrectly mixing up
architecture types, using x86 input for a x64 target.  Adjust the tests
appropriately.  The renaming of the input and the architectures covers the
changes to the existing tests.

One significant change to the existing tests is that the newly added test input
for x64 uses the correct user label prefix for X64.

llvm-svn: 219093
2014-10-05 23:43:59 +00:00
Nick Kledzik 09d00bb4d7 [mach-o] Add support for -dependency_info command line option
This option is added by Xcode when it runs the linker.  It produces a binary
file which contains the file the linker used.  Xcode uses the info to
dynamically update it dependency tracking.

To check the content of the binary file, the test case uses a python script
to dump the binary file as text which FileCheck can check.

llvm-svn: 219039
2014-10-04 00:16:13 +00:00
Rafael Auler 6fd0afa195 [ELF] Fix bug in ELFFile::createAtoms() that caused lld to mislink musl
When creating the graph edges of the atoms of an ELF file, special care must be
taken with atoms that represent weak symbols. They cannot be the target of any
Reference::kindLayoutAfter edge because they can be merged and point to other
code, screwing up the final layout of the atoms. ELFFile::createAtoms()
correctly handles this corner case. The problem is that createAtoms() assumed
that there can be no zero-sized weak symbols, which is not true. Consider:

my_weak_func1:
my_weak_func2:
my_weak_func3:
code

In this case, we have two zero-sized weak symbols, my_weak_func1 and
my_weak_func2, and one non-zero weak symbol my_weak_func3. createAtoms() would
correctly handle my_weak_func3, but not the first two symbols. This problem
happens in the musl C library when a zero-sized weak symbol is merged and
screws up the file layout. Since this musl code lives at the finalization hooks,
any C program linked with LLD and musl was correctly executing, but segfaulting
at the end.

Reviewers: shankarke

http://reviews.llvm.org/D5606

llvm-svn: 219034
2014-10-03 22:50:50 +00:00
Rui Ueyama 711471ea1e [PECOFF] Resolve __delayLoadHelper2 if /delayload is given
DLL delay importing is a feature to load a DLL lazily, instead of
at program start-up time.

If the feature is turned on with the /delayload flag, the linker
resolves the delay-load helper function. All function pointer table
entries for the DLL are initially pointing to the helper function.
When called, the function loads and resolves the DLL symbols using
dlopen-ish Windows system calls and then write the reuslts to the
function pointer table. The helper function is in "delayimp.lib".

Note that this feature is not completely implemented yet. LLD
also needs to emit the table that's consumed by the delay-load
helper function. That'll be done in another patch.

llvm-svn: 218943
2014-10-03 01:14:50 +00:00
Rui Ueyama 89d402f88e [PECOFF] Use "llvm-readobj -coff-imports" to test the import table.
-coff-imports is added in r218915. You may have to sync your llvm source tree.

llvm-svn: 218919
2014-10-02 22:21:48 +00:00
Nick Kledzik 7efd054479 [mach-o] preserve custom section names on coalesable strings
llvm-svn: 218894
2014-10-02 17:27:20 +00:00
Nick Kledzik 32d0d09bf8 Preserve custom section names when coalescing.
The mergeByContent attribute on DefinedAtoms triggers the symbol table to
coalesce atoms with the exact same content. The problem is that atoms can also
have a required custom section. The coalescing should never change the custom
section of an atom.

The fix is to only consider to atoms to have the same content if their
sectionChoice() and customSectionName() attributes match.

llvm-svn: 218893
2014-10-02 17:22:05 +00:00
Nick Kledzik be43d7ef29 [mach-o] Implement -demangle.
The darwin linker has the -demangle option which directs it to demangle C++
(and soon Swift) mangled symbol names. Long term we need some Diagnostics object
for formatting errors and warnings. But for now we have the Core linker just
writing messages to llvm::errs(). So, to enable demangling, I changed the
Resolver to call a LinkingContext method on the symbol name.

To make this more interesting, the demangling code is done via __cxa_demangle()
which is part of the C++ ABI, which is only supported on some platforms, so I
had to conditionalize the code with the config generated HAVE_CXXABI_H.

llvm-svn: 218718
2014-09-30 23:15:39 +00:00
Rui Ueyama 07fae9691b [PECOFF] Fix /entry option.
This is yet another edge case of ambiguous name resolution.
When a symbol is specified with /entry:SYM, SYM may be resolved
to the C++ mangled function name (?SYM@@YAXXZ).

llvm-svn: 218706
2014-09-30 21:39:49 +00:00
Tim Northover cf78d37fd6 [mach-o] create __unwind_info section on x86_64
This is a minimally useful pass to construct the __unwind_info section in a
final object from the various __compact_unwind inputs. Currently it doesn't
produce any compressed pages, only works for x86_64 and will fail if any
function ends up without __compact_unwind.

rdar://problem/18208653

llvm-svn: 218703
2014-09-30 21:29:54 +00:00
Rui Ueyama fa67adc28d [PECOFF] Allow /export:<symbol>,PRTVATE.
PRIVATE option is also an undocumented feature.

llvm-svn: 218696
2014-09-30 20:09:31 +00:00
Rui Ueyama 3837e10002 [PECOFF] Fix /export option.
MSDN doesn't say about /export:foo=bar style option, but
it turned out MSVC link.exe actually accepts that. So we need that
too.

It also means that the export directive in the module definition
file and /export command line option are functionally equivalent.

llvm-svn: 218695
2014-09-30 20:03:11 +00:00
Rui Ueyama 3041443b5c [PECOFF] Fix __imp_ prefix on x64.
"__imp_" prefix always starts with double underscores.
When I was writing the original code I misunderstood
that it's "_imp_" on x64.

llvm-svn: 218690
2014-09-30 19:42:04 +00:00
Rafael Auler 5a1000dddc [lld] [ELF] Support for general dynamic TLS relocations on X86_64
Summary:
This patch adds support for the general dynamic TLS access model for X86_64 (see www.akkadia.org/drepper/tls.pdf).

To properly support TLS, the patch also changes the __tls_get_addr atom to be a shared library atom instead of a regularly defined atom (the previous lld approach). This closely models the reality of a function that will be resolved at runtime by the dynamic linker and loader itself (ld.so). I was tempted to force LLD to link against ld.so itself to resolve these symbols, but since GNU ld does not need the ld.so library to resolve this symbol, I decided to mimic its behavior and keep hardwired a definition of __tls_get_addr in the lld code.

This patch also moves some important logic that previously was only available to the MIPS lld backend to be used to all ELF backends. This logic, which now lives in the DefaultLayout class, will monitor which external (shared lib) symbols are really imported by the current module and will only populate the dynamic symbol table with used symbols, as opposed to the previous approach of dumping all shared lib symbols in the dynamic symbol table. This is important to this patch to avoid __tls_get_addr from getting injected into all dynamic symbol tables.

By solving the previous problem of always adding __tls_get_addr, now the produced symbol tables are slightly smaller. But this impacted several tests that relied on hardwired/predefined sizes of the symbol table, requiring this patch to update such tests.

Test Plan: Added a LIT test case that exercises a simple use case of TLS variable in a shared library.

Reviewers: ruiu, rafael, Bigcheese, shankarke

Reviewed By: Bigcheese, shankarke

Subscribers: emaste, shankarke, joerg, kledzik, mcrosier, llvm-commits

Projects: #lld

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

llvm-svn: 218633
2014-09-29 22:05:26 +00:00
Rui Ueyama 1b0e68353d [PECOFF] Fix module definition file output
Previously we emit two or more identical definitions for an
exported symbol if the same /export option is given more than
once. This patch fixes that bug.

llvm-svn: 218433
2014-09-25 00:52:38 +00:00
Nick Kledzik 38cd67624b [mach-o] fix test case to work with latest llvm-objdump output
Take opporunity to clean up test to only run llvm-objdump once now that
llvm-objdump can disassemble mixed thumb and arm code.

llvm-svn: 218429
2014-09-24 23:55:06 +00:00
Rui Ueyama a370c3ee35 [PECOFF] Exported name should match C++ mangled name
Currently you can omit the leading underscore from exported
symbol name. LLD will look for mangled name for you. But it won't
look for C++ mangled name.

This patch is to support that.

If "sym" is specified to be exported, the linker looks for not
only "sym", but also "_sym" and "?sym@@<whatever>", so that you
can export a C++ function without decorating it.

llvm-svn: 218355
2014-09-24 02:01:10 +00:00
Rui Ueyama 7ea46bab26 [PECOFF] Fix duplicate /export options
If two or more /export options are given for the same symbol, we should
always print a warning message and use the first one regardless of other
parameters.
Previously there was a case that the first parameter is not used.

llvm-svn: 218342
2014-09-23 23:49:41 +00:00
Rui Ueyama a3eff3afd9 Make -core/-flavor options have higher priority than linker name
Also allows -core/flavor to appear at any position in the command line.
Patch from Oleg Ranevskyy!

http://reviews.llvm.org/D5384

llvm-svn: 218321
2014-09-23 18:09:38 +00:00
Rui Ueyama 117ef70c98 [PECOFF] Handle PRIVATE keyword in the module definition file
A symbol in a module definition file may be annotated with the
PRIVATE keyword like this.

  EXPORTS
    func PRIVATE

The PRIVATE keyword does not affect the resulting .dll file.
But it prevents the symbol to be listed in the .lib (import
library) file.

llvm-svn: 218273
2014-09-22 20:50:46 +00:00
Rui Ueyama 45f4d54c07 Re-commit r218259.
llvm-svn: 218272
2014-09-22 20:48:04 +00:00
Rui Ueyama 869c0019b1 Revert "[ELF] Fix linking when a regular object defines a symbol that is used in a DSO"
This commit reverts r218259 because it needed to be checked in with
a few binary files for the test.

llvm-svn: 218262
2014-09-22 18:08:34 +00:00
Rui Ueyama 508a007ae6 [ELF] Fix linking when a regular object defines a symbol that is used in a DSO
Patch from Rafael Auler!

When a shared lib has an undefined symbol that is defined in a regular object
(the program), the final executable must export this symbol in the dynamic
symbol table. However, in the current logic, lld only puts the symbol in the
dynamic symbol table if the symbol is weak. This patch fixes lld to put the
symbol in the dynamic symbol table regardless if it is weak or not.

This caused a problem in FreeBSD10, whose programs link against a crt1.o
that defines the symbol __progname, which is, in turn, undefined in libc.so.7
and will only be resolved in runtime.

http://reviews.llvm.org/D5424

llvm-svn: 218259
2014-09-22 17:52:50 +00:00
Rui Ueyama 44a7c7f1aa [PECOFF] Set ordinal to alias atoms
Atoms are ordered in the output file by ordinal. File has file ordinal,
and atom has atom ordinal which is unique within the file.
No two atoms should have the same combination of ordinals.

However that contract was not satisifed for alias atoms. Alias atom
is defined by /alternatename:sym1=sym2. In this case sym1 is defined
as an alias for sym2. sym1 always got ordinal 0.

As a result LLD failed with an assertion failure.

This patch assigns ordinal to alias atoms.

llvm-svn: 218158
2014-09-19 21:58:54 +00:00
Rui Ueyama 6bf091c656 [PECOFF] /safeseh:no on x64 is not an error
I made LLD to report an error if /safeseh:no option is given on x64,
but it turned out MSVC link.exe doesn't report error on it.
Removing the check.

llvm-svn: 218077
2014-09-18 21:18:05 +00:00
Rui Ueyama 9f1215b2d8 [PECOFF] Support TLS callbacks.
The contents from section .CRT$XLA to .CRT$XLZ is an array of function
pointers. They are called by the runtime when a new thread is created
or (gracefully) terminated.

You can make your own initialization function to be called by that
mechanism. All you have to do is:

- Define a pointer to a function in a .CRT$XL* section using pragma
- Make an external reference to "__tls_used" symbol

That technique is used in many projects. This patch is to support that.

What this patch does is to set the relative virtual address of
"__tls_used" to the PECOFF directory table. __tls_used is actually a
struct containing pointers to a symbol in .CRT$XLA and another symbol
in .CRT$XLZ. The runtime looks at the directory table, gets the address
of the struct, and call the function pointers between XLA and XLZ.

llvm-svn: 218007
2014-09-18 02:02:52 +00:00
Nick Kledzik b54bbe358a [mach-o] update test case to match new llvm-objdump output
llvm-svn: 217932
2014-09-17 00:51:18 +00:00
Nick Kledzik 1050b57a0b [mach-o] Fix two-level namespace ordinals
On darwin, the linker tools records which dylib (DSO) each undefined was found
in, and then at runtime, the loader (dyld) only looks in that one specific
dylib for each undefined symbol.  Now that llvm-objdump can display that info
I can write test cases.

llvm-svn: 217898
2014-09-16 20:27:28 +00:00
Ed Maste 933daef54f Add FreeBSD to system-linker-elf case
llvm-svn: 217672
2014-09-12 13:16:30 +00:00
Tim Northover 1684a614b3 [mach-o]: support optional "0x" prefix for -image_base
llvm-svn: 217578
2014-09-11 10:31:46 +00:00
Tim Northover 5d95bd7037 [mach-o]: tighten up diagnostics for -image_base option
The provided base must also be a multiple of the system's page size, which is a
reasonable enough demand.

Also check the other diagnostics more thoroughly.

llvm-svn: 217577
2014-09-11 10:31:42 +00:00
Nick Kledzik 50bda292c8 If lld is renamed (or symlinked) to "ld" automatically pick the right flavor.
The existing system linkers on Darwin and Linux are called "ld".  We'd like to
eventually drop in lld as "ld" and have it just work.  But lld is a universal
linker that requires the first option to be -flavor to know which command line
mode to emulate (gnu or darwin).

This change tests if argv[0] is "ld" and if so, if the tool was built on MacOSX
then assume the darwin flavor otherwise the gnu flavor.  There are two test
cases which copy lld to "ld" and then run it. One for darwin and one for linux.

llvm-svn: 217566
2014-09-11 00:52:05 +00:00
Tim Northover af3075b93f [mach-o]: implement -image_base option on Darwin.
As suggested by Nick, this will make __unwind_info implementation more natural,
and it'd have to be done at some point anyway.

llvm-svn: 217486
2014-09-10 10:39:57 +00:00
Nick Kledzik 1bebb2832e [mach-o] Add support for arm64 (AAarch64)
Most of the changes are in the new file ArchHandler_arm64.cpp.  But a few
things had to be fixed to support 16KB pages (instead of 4KB) which iOS arm64
requires.  In addition the StubInfo struct had to be expanded because
arm64 uses two instruction (ADRP/LDR) to load a global which requires two
relocations.  The other mach-o arches just needed one relocation.

llvm-svn: 217469
2014-09-09 23:52:59 +00:00
Nick Kledzik 8a8c3ba38c [mach-o] add testing coverage for -single_module
llvm-svn: 217412
2014-09-09 02:20:34 +00:00
Nick Kledzik 4ce63c2a54 [mach-o] Fix so no options causes usage message to be printed
llvm-svn: 217409
2014-09-09 00:45:35 +00:00
Nick Kledzik b7035ae367 [mach-o] Add support for -pie and -no_pie
There is a bit (MH_PIE) in the flags field of the mach_header which tells
the kernel is a program was built position independent (for ASLR).  The linker
automatically attempts to build programs PIE if they are built for a recent
OS version.  But the -pie and -no_pie options override that default behavior.

llvm-svn: 217408
2014-09-09 00:17:52 +00:00
Simon Atanasyan 07000878f8 [ELF] Export strong defined symbol if it coalesces away a weak symbol
defined in a shared library.

Now LLD does not export a strong defined symbol if it coalesces away a
weak symbol defined in a shared library. This bug affects all ELF
architectures and leads to segfault:

  % cat foo.c
  extern int __attribute__((weak)) flag;
  int foo() { return flag; }

  % cat main.c
  int flag = 1;
  int foo();
  int main() { return foo() == 1 ? 0 : -1; }

  % clang -c -fPIC foo.c main.c
  % lld -flavor gnu -target x86_64 -shared -o libfoo.so ... foo.o
  % lld -flavor gnu -target x86_64 -o a.out ... main.o libfoo.so
  % ./a.out
  Segmentation fault

The problem is caused by the fact that we lose all information about
coalesced symbols after the `Resolver::resolve()` method is finished.

The patch solves the problem by overriding the
`LinkingContext::notifySymbolTableCoalesce()` method and saving names
of coalesced symbols. Later in the `buildDynamicSymbolTable()` routine
we use this information to export these symbols.

llvm-svn: 217363
2014-09-08 09:43:38 +00:00
Shankar Easwaran c7701e9a8c [ELF][Driver] Produce a proper error when file is not found
When a file is not found, produce a proper error message. The previous error
message produced a file format error, which made me wonder for a while why
there is a file format error, but essentially the file was not found.

This fixes the problem by producing a proper error message.

llvm-svn: 217359
2014-09-08 04:18:11 +00:00
Shankar Easwaran 595e056dce [ELF] Implement --rosegment
By default linker would not create a separate segment to hold read only data.

This option overrides that behavior by creating the a separate read only segment
for read only data.

llvm-svn: 217358
2014-09-08 04:05:52 +00:00
Shankar Easwaran 24511fc426 [ELF] Undefined symbols should be allowed when building dynamic libraries
When dynamic libraries are built, undefined symbols should always be allowed and
the linker should not exit with an error.

llvm-svn: 217356
2014-09-08 03:11:50 +00:00
Nick Kledzik 635f9c7158 [mach-o] Let darwin driver infer arch from .o files if -arch not used.
Mach-O has a "fat" (or "universal") variant where the same contents built for
different architectures are concatenated into one file with a table-of-contents
header at the start.  But this leaves a dilemma for the linker - which
architecture to use.

Normally, the linker command line -arch is used to force which slice of any fat
files are used.  The clang compiler always passes -arch to the linker when
invoking it.  But some Makefiles invoke the linker directly and don’t specify
the -arch option.  For those cases, the linker scans all input files in command
line order and finds the first non-fat object file.  Whatever architecture it
is becomes the architecture for the link.

llvm-svn: 217189
2014-09-04 20:08:30 +00:00
Nick Kledzik 0e3e6155fe [mach-o] Improve x86_64 reference kind switch statements.
The use of default: was disabling the warning about unused enumerators. Fix
that, then fix the one enumerator that was not handled. Add coverage for
it in test suite.

llvm-svn: 217078
2014-09-03 21:09:24 +00:00
Nick Kledzik 141330aef6 [mach-o] Add support for using export tries
On Darwin at runtime, dyld will prefer to use the export trie of a dylib instead
of the traditional symbol table (which is large and requires a binary search).

This change enables the linker to generate an export trie and to prefer it if
found in a dylib being linked against.  This also simples the yaml for dylibs
because the yaml form of the trie can be reduced to just a sequence of names.

llvm-svn: 217066
2014-09-03 19:52:50 +00:00
Rui Ueyama 495a031ce4 [PECOFF] Fix AMD64_REL_[1-5] and AMD64_SECTION relocations
I hope this is the last fix for x64 relocations as I've wasted
a few days on this.

This caused a mysterious issue that some C++ programs crash on
startup. It was because a null pointer is passed as argv to main.
__tmainCRTStartup calls main, but before that it calls all
initialization routines between .text$xc_a and .text$xc_z.
pre_cpp_init is one of such routines, and it is the one who
initializes a heap pointer for argv for later use. That routine
was not called for some reason.

It turned out that __tmainCRTStartup was skipping a block of
code because of the relocation bug. A condition in the function
depends on a memory load, and that memory load was referring
a wrong location. As a result a jump instruction took the
wrong branch, skipping pre_cpp_init and so on.

This patch fixes the issue. Also added more tests to fix them
once and for all.

llvm-svn: 216772
2014-08-29 20:33:27 +00:00
Rui Ueyama 4a6ead7a9f [PECOFF] Another Win64 relocation bug fix
When a relocation is applied to a location, the new value needs
to be added to the existing value at the location. Existing
value is in most cases zero, but if not, the current code does
not work.

llvm-svn: 216680
2014-08-28 19:00:40 +00:00