Commit Graph

1901 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 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 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
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 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
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
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 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
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
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
Nick Kledzik e5da30cbd3 [mach-o] fix leak in atoms -> normalized
llvm-svn: 223530
2014-12-05 22:03:28 +00:00
Nick Kledzik b7ec8ae2ab [mach-o] Switch MachOFile and MachODylibFile to use BumpPtr in lld::File
llvm-svn: 223529
2014-12-05 22:03:26 +00:00
Nick Kledzik 290cfc6ba5 [mach-o] Pass vectors by reference and name empty vector.
llvm-svn: 223527
2014-12-05 22:03:20 +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
Will Newton 0b7f842592 ELF: Use ELF reloc .def files to reduce duplication
Tested with check-lld with no regressions.

llvm-svn: 223462
2014-12-05 12:43:26 +00:00
Rui Ueyama c2576d5464 Remove extra semicolon.
llvm-svn: 223411
2014-12-04 23:26:11 +00:00
Eric Christopher e9a36eab1e Fix a bunch of -Winconsistent-missing-override warnings.
llvm-svn: 223400
2014-12-04 22:26:07 +00:00
Rui Ueyama 5ae2050420 Revert "Rewrite InputGraph's Group"
This reverts commit r223330 because it broke Darwin and ELF
linkers in a way that we couldn't have caught with the existing
test cases.

llvm-svn: 223373
2014-12-04 18:29:03 +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 60df72ff61 Rewrite InputGraph's Group
The aim of this patch is to reduce the excessive abstraction from
the InputGraph. We found that even a simple thing, such as sorting
input files (Mach-O) or adding a new file to the input file list
(PE/COFF), is nearly impossible with the InputGraph abstraction,
because it hides too much information behind it. As a result,
we invented complex interactions between components (e.g.
notifyProgress() mechanism) and tricky code to work around that
limitation. There were many occasions that we needed to write
awkward code.

This patch is a first step to make it cleaner. As a first step,
this removes Group class from the InputGraph. The grouping feature
is now directly handled by the Resolver. notifyProgress is removed
since we no longer need that. I could have cleaned it up even more,
but in order to keep the patch minimum, I focused on Group.

SimpleFileNode class, a container of File objects, is now limited
to have only one File. We shold have done this earlier.
We used to allow putting multiple File objects to FileNode.
Although SimpleFileNode usually has only one file, the Driver class
actually used that capability. I modified the Driver class a bit,
so that one FileNode is created for each input File.

We should now probably remove SimpleFileNode and directly store
File objects to the InputGraph in some way, because a container
that can contain only one object is useless. This is a TODO.

Mach-O input files are now sorted before they are passe to the
Resolver. DarwinInputGraph class is no longer needed, so removed.

PECOFF still has hacky code to add a new file to the input file list.
This will be cleaned up in another patch.

llvm-svn: 223330
2014-12-04 01:09:06 +00:00