Commit Graph

2372 Commits

Author SHA1 Message Date
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
Simon Atanasyan 926f79f44f [Mips] Join two if statements
No functional changes.

llvm-svn: 224817
2014-12-24 12:19:42 +00:00
Simon Atanasyan 1a978ed9ac [Mips] Make the comment more descriptive
No functional changes.

llvm-svn: 224816
2014-12-24 12:19:36 +00:00
Simon Atanasyan 4360be5d26 [Mips] Factor out the code checks a symbol's binding
No functional changes.

llvm-svn: 224815
2014-12-24 12:19:30 +00:00
Simon Atanasyan eab5dc815a [Mips] Rename the function s/readAddend/getAddend/
No functional changes.

llvm-svn: 224814
2014-12-24 12:19:24 +00:00
Simon Atanasyan 375f07a919 [Mips] Use OR operation to set the microMIPS bit
llvm-svn: 224813
2014-12-24 12:19:18 +00:00
Nico Weber 9b839f8ced Tweak lld's checkout instructions.
llvm-svn: 224778
2014-12-23 18:52:41 +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
Ed Maste aaa317a1eb lld self-hosts on FreeBSD too
llvm-svn: 224448
2014-12-17 19:14:57 +00:00
Rui Ueyama 7da4037c81 Replace ReaderError with DynamicError.
ReaderErrorCategory was used only at one place. We now have a
DynamicErrorCategory for this kind of one-time error, so use it.
The calling function doesn't really care the type of an error, so
ReaderErrorCategory was actually dead code.

llvm-svn: 224245
2014-12-15 12:20:13 +00:00
Rui Ueyama c1eeb310d4 Remove dead code.
This field was not even initialized properly.

llvm-svn: 224236
2014-12-15 07:22:29 +00:00
Rui Ueyama 0a2c2dbfc2 Protect doParse() because that's not a public interface.
llvm-svn: 224235
2014-12-15 07:14:32 +00:00
Rui Ueyama 0b23c37413 Clean up #include dependency.
Core/File.h does not use LinkingContext.h, so remove that dependency.

llvm-svn: 224214
2014-12-14 07:57:35 +00:00
Rui Ueyama 0215c88f00 Remove PECOFFLibraryNode.
This class is empty, provides no additional feature to the base class.

llvm-svn: 224212
2014-12-14 05:08:53 +00:00
Rui Ueyama c39120e101 More WinLinkInputGraph cleanup.
This function is called only from WinLinkDriver.cpp.
Move the function to that file and mark as static.

llvm-svn: 224211
2014-12-14 05:04:22 +00:00
Rui Ueyama 11c4874d83 [PECOFF] Resolve file name in the driver, not in InputElement.
llvm-svn: 224209
2014-12-14 02:50:29 +00:00
Rui Ueyama e9b455184f Simplify InputGraph API.
These member functions returns either no_more_files error or a File object.
We could simply return a nullptr instead of a no_more_files.
This function will be removed soon as a part of InputGraph cleanup.
I had to do that step by step.

llvm-svn: 224208
2014-12-14 02:04:01 +00:00
Rui Ueyama 83220a00ea Remove dead code.
llvm-svn: 224207
2014-12-14 02:03:54 +00:00
Rui Ueyama 4726967a51 Remove code duplication.
llvm-svn: 224206
2014-12-14 02:03:47 +00:00
Rui Ueyama 92cdfc7cb8 [ELF] Clean up OPT_INPUT handler. NFC.
llvm-svn: 224192
2014-12-13 09:36:44 +00:00
Rui Ueyama a60a75e566 Make YAML files own MemoryBuffer.
YAML files have references such as StringRef to the underlying
MemoryBuffer, so we shouldn't deallocate the buffer.

llvm-svn: 224191
2014-12-13 08:59:50 +00:00
Rui Ueyama ecf28e25de Move definitions to the correct file.
llvm-svn: 224190
2014-12-13 08:59:46 +00:00
Rui Ueyama 961f43fb70 Make File always take the ownership of a MemoryBuffer.
The documentation of parseFile() said that "the resulting File
object may take ownership of the MemoryBuffer." So, whether or not
the ownership of a MemoryBuffer would be taken was not clear.
A FileNode (a subclass of InputElement, which is being deprecated)
keeps the ownership if a File doesn't take it.

This patch makes File always take the ownership of a buffer.
Buffers lifespan is not always the same as File instances.
Files are able to deallocate buffers after parsing the contents.

llvm-svn: 224113
2014-12-12 10:27:33 +00:00
Rui Ueyama 1d510428e8 Separate file parsing from File's constructors.
This is a second patch for InputGraph cleanup.

Sorry about the size of the patch, but what I did in this
patch is basically moving code from constructor to a new
method, parse(), so the amount of new code is small.
This has no change in functionality.

We've discussed the issue that we have too many classes
to represent a concept of "file". We have File subclasses
that represent files read from disk. In addition to that,
we have bunch of InputElement subclasses (that are part
of InputGraph) that represent command line arguments for
input file names. InputElement is a wrapper for File.

InputElement has parseFile method. The method instantiates
a File. The File's constructor reads a file from disk and
parses that.

Because parseFile method is called from multiple worker
threads, file parsing is processed in parallel. In other
words, one reason why we needed the wrapper classes is
because a File would start reading a file as soon as it
is instantiated.

So, the reason why we have too many classes here is at
least partly because of the design flaw of File class.
Just like threads in a good threading library, we need
to separate instantiation from "start" method, so that
we can instantiate File objects when we need them (which
should be very fast because it involves only one mmap()
and no real file IO) and use them directly instead of
the wrapper classes. Later, we call parse() on each
file in parallel to let them do actual file IO.

In this design, we can eliminate a reason to have the
wrapper classes.

In order to minimize the size of the patch, I didn't go so
far as to replace the wrapper classes with File classes.
The wrapper classes are still there.

In this patch, we call parse() immediately after
instantiating a File, so this really has no change in
functionality. Eventually the call of parse() should be
moved to Driver::link(). That'll be done in another patch.

llvm-svn: 224102
2014-12-12 07:31:09 +00:00
Shankar Easwaran 15b8b94918 [ELF] Remove isThumb().
llvm-svn: 224099
2014-12-12 05:20:28 +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
Rui Ueyama 643f94bc62 [ELF] Remove duplicate constructor code.
This piece of code was copied multiple times to each archs.

llvm-svn: 224001
2014-12-11 06:22:45 +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
Rui Ueyama 72bdc270cc Remove unreachable return statement.
llvm-svn: 223920
2014-12-10 08:12:06 +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
Rui Ueyama 00eb257f2e Re-commit r223330: Rewrite InputGraph's Group
llvm-svn: 223867
2014-12-10 00:33:00 +00:00
Rui Ueyama e4814d0dee Fix Darwin linker. Patch from Jean-Daniel Dupas.
llvm-svn: 223865
2014-12-10 00:24:37 +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
Hans Wennborg 9cceddd074 Fix the MSVC build
llvm-svn: 223796
2014-12-09 17:46:06 +00:00
Will Newton 4c81bb7e3f ELF: Add a standard method for unknown relocation errors
At present each TargetRelocationHandler generates a pretty similar error
string and calls llvm_unreachable() when encountering an unknown
relocation. This is not ideal for two reasons:

1. llvm_unreachable disappears in release builds but we still want to
   know if we encountered a relocation we couldn't handle in release
   builds.

2. Duplication is bad - there is no need to have a per-architecture error
   message.

This change adds a test for AArch64 to test whether or not the error
message actually works. The other architectures have not been tested
but they compile and check-lld passes.

llvm-svn: 223782
2014-12-09 16:29:39 +00:00