Commit Graph

1441 Commits

Author SHA1 Message Date
Joey Gouly 2008d31d06 Fix copy/paste error.
llvm-svn: 197990
2013-12-24 20:43:54 +00:00
Rui Ueyama 090a7cd76d [PECOFF] Fix /export option in the .drectve section.
/EXPORT option has slightly different semantics if it appears in the .drectve
section. This patch implements it.

llvm-svn: 197970
2013-12-24 09:15:57 +00:00
Joey Gouly b275d7f8f3 Fix indentation in the MachO writer.
llvm-svn: 197925
2013-12-23 23:29:50 +00:00
Nick Kledzik 6960b07b92 [mach-o] add MachOLinkingContext::configure(type, arch, os)
It will configure resonable defaults for other settings in the 
MachOLinkingContext object based on the parameters.  

Patch by Joe Ranieri

llvm-svn: 197851
2013-12-21 01:47:17 +00:00
Joey Gouly 72c5d3d7c1 REQUIRES: debug doesn't actually do anything!
Makes the tests pass (rather, not run) on release builds.

llvm-svn: 197838
2013-12-20 22:01:26 +00:00
Nick Kledzik f30e848432 Restore vertical alignment lost by clang-format
llvm-svn: 197834
2013-12-20 20:34:19 +00:00
Rui Ueyama d4f66c7d5f [PECOFF] Create noname or data symbols as such.
If a symbol in an import library is marked as "data", the linker will not
create a jump table entry for the symbol, since jump table makes sense only
for a symbol pointing to a function.

I don't think NONAME attribute has a meaning when creating an import library.
The attribute is emitted for debugging purpose.

llvm-svn: 197803
2013-12-20 11:50:19 +00:00
Rui Ueyama d07c1be171 [PECOFF] Create the import library file.
If the linker is instructed to create a DLL, it will also create an import
library (.lib file) to describe the symbols exported by the DLL. This patch is
to create the import library file.

There is a convenient command "lib.exe" which can create an import library
from a module definition file (.def file). The command is used in this patch.

llvm-svn: 197801
2013-12-20 11:35:40 +00:00
Rui Ueyama 4af032dce7 [PECOFF] Assign default export ordinals in LinkingContext::verify().
Default ordinals were assigned in EdataPass, and the assigned values were
then discarded in the pass. No code other than EdataPass would not be able
to get all of the information about ordinals. That's not ideal since I'm
writing code to emit an Import Library file, which also needs ordinals.

This is a patch to move the code to assign default ordinals from EdataPass
to LinkingContext::verify(), so that assigned ordinals will be available
anywhere.

No functionality change.

llvm-svn: 197797
2013-12-20 10:02:59 +00:00
Rui Ueyama 170a1a892e Run clang-format on r197727.
llvm-svn: 197788
2013-12-20 07:48:29 +00:00
Joey Gouly 86409e1cde Fix the build by adding back a comma...
llvm-svn: 197754
2013-12-20 00:01:00 +00:00
Joey Gouly f39ec17371 Fix some typos of 'extension'.
llvm-svn: 197753
2013-12-19 23:52:00 +00:00
Joey Gouly 6eb02ef568 Make SimpleFileNode inherit from FileNode.
This removes a lot of duplicated code.

llvm-svn: 197751
2013-12-19 23:39:02 +00:00
Nick Kledzik fc3a975d85 [lld] fix unused variable warnings
llvm-svn: 197737
2013-12-19 22:50:08 +00:00
Nick Kledzik 58089e1362 [lld] fix build when LLVM_HAS_VARIADIC_TEMPLATES is false
llvm-svn: 197734
2013-12-19 22:40:17 +00:00
Nick Kledzik a1a22edd17 [lld] fix unused variable warning in non-debug builds
llvm-svn: 197732
2013-12-19 22:29:07 +00:00
Nick Kledzik e555277780 [lld] Introduce registry and Reference kind tuple
The main changes are in:
  include/lld/Core/Reference.h
  include/lld/ReaderWriter/Reader.h
Everything else is details to support the main change.

1) Registration based Readers
Previously, lld had a tangled interdependency with all the Readers.  It would
have been impossible to make a streamlined linker (say for a JIT) which
just supported one file format and one architecture (no yaml, no archives, etc).
The old model also required a LinkingContext to read an object file, which
would have made .o inspection tools awkward.

The new model is that there is a global Registry object. You programmatically 
register the Readers you want with the registry object. Whenever you need to 
read/parse a file, you ask the registry to do it, and the registry tries each 
registered reader.

For ease of use with the existing lld code base, there is one Registry
object inside the LinkingContext object. 


2) Changing kind value to be a tuple
Beside Readers, the registry also keeps track of the mapping for Reference
Kind values to and from strings.  Along with that, this patch also fixes
an ambiguity with the previous Reference::Kind values.  The problem was that
we wanted to reuse existing relocation type values as Reference::Kind values.
But then how can the YAML write know how to convert a value to a string? The
fix is to change the 32-bit Reference::Kind into a tuple with an 8-bit namespace
(e.g. ELF, COFFF, etc), an 8-bit architecture (e.g. x86_64, PowerPC, etc), and
a 16-bit value.  This tuple system allows conversion to and from strings with 
no ambiguities.

llvm-svn: 197727
2013-12-19 21:58:00 +00:00
Joey Gouly 61a57138c2 Remove redundant 'classof' functions.
llvm-svn: 197726
2013-12-19 21:51:13 +00:00
Joey Gouly b46cf50205 [cleanup] Random assortment of simple cleanups.
Pruning header includes and forward references and fixing comments.

llvm-svn: 197720
2013-12-19 21:08:23 +00:00
Rui Ueyama c83e1730c5 Remove dead code.
llvm-svn: 197662
2013-12-19 08:05:34 +00:00
Rui Ueyama 1fc1bab8a8 [PECOFF] Truncate long section name.
Executable files do not use a string table, so section names longer than 8
characters are not permitted. Long section names should just be truncated.

llvm-svn: 197470
2013-12-17 06:15:09 +00:00
Rui Ueyama c1ecfb2d46 Remove obsolete comment.
llvm-svn: 197375
2013-12-16 09:34:20 +00:00
Rui Ueyama 0b05509d79 [PECOFF] Rename ExecutableWriter -> PECOFFWriter.
Because it's now able to emit not only executable but DLL.

llvm-svn: 197374
2013-12-16 09:29:59 +00:00
Rui Ueyama a6fddabbf1 [PECOFF] Add a check for duplicate export ordinals.
llvm-svn: 197373
2013-12-16 09:15:58 +00:00
Rui Ueyama 64d491d118 [PECOFF] Support export-only-by-ordinal exports.
If NONAME option is given for an export, that symbol will be exported only by
its ordinal. LLD will not emit the symbol name to the export table.

llvm-svn: 197371
2013-12-16 09:02:43 +00:00
Rui Ueyama 69b899a127 [PECOFF] Set OrdinalBase field in the export table.
OrdinalBase is an addend to the ordinals. We used to always set 1 to the field.
Although it produced a valid a DLL export table, it'd be a waste if the first
ordinal does not start with 1 -- we had to have NULL fields at the beginning of
the export address table. By setting the ordinal base, we can eliminate the
NULL fields.

llvm-svn: 197367
2013-12-16 07:14:40 +00:00
Rui Ueyama 0e05713d47 [PECOFF] Export ordinal must be in the range 1 through 65535.
llvm-svn: 197365
2013-12-16 06:41:06 +00:00
Rui Ueyama fe1b3c0933 [PECOFF] Make it possible to specify export ordinals.
You can specify exported function's ordinal by /export:func,@<number> command
line option, but LLD ignored the option until now. This patch implements the
feature.

Ordinal is basically the index into the exported function address table. So,
for example, if /export:foo,@42 is specified, the linker writes foo's address
to 42th entry in the address table. Windows supports import-by-ordinal; you
can not only import a function by name, but by its ordinal. If you want to
allow your DLL users to import your functions by their ordinals, you need to
make sure that your functions are always exported with the same ordinals.
This is the feature for that situation.

llvm-svn: 197364
2013-12-16 05:46:07 +00:00
Simon Atanasyan 735a29b267 [Mips] Explicitly cast ulittle32_t to the uint32_t to fix Visual Studio
compile error.

llvm-svn: 197344
2013-12-15 13:22:24 +00:00
Simon Atanasyan 9931f95bac Linking of shared libraries for MIPS little-endian 32-bit target.
The following are the most significant peculiarities of MIPS target:
- MIPS ABI requires some special tags in the dynamic table.
- GOT consists of two parts local and global. The local part contains
  entries refer locally visible symbols. The global part contains entries
  refer global symbols.
- Entries in the .dynsym section which have corresponded entries in the
  GOT should be:
  * Emitted at the end of .dynsym section
  * Sorted accordingly to theirs GOT counterparts
- There are "paired" relocations. One or more R_MIPS_HI16 and R_MIPS_GOT16
  relocations should be followed by R_MIPS_LO16 relocation. To calculate
  result of R_MIPS_HI16 and R_MIPS_GOT16 relocations we need to combine
  addends from these relocations and paired R_MIPS_LO16 relocation.

The patch reviewed by Michael Spencer, Shankar Easwaran, Rui Ueyama.
http://llvm-reviews.chandlerc.com/D2156

llvm-svn: 197342
2013-12-15 12:57:28 +00:00
Rui Ueyama abc227be82 [PECOFF] Export undecorated symbols from DLL.
Symbol names exported from a DLL should be undecorated, not prefixed by
an underscore ones.

llvm-svn: 197307
2013-12-14 04:32:29 +00:00
Rui Ueyama 1293106fdb [PECOFF] Simplify EdataPass by sorting atoms from the beginning.
llvm-svn: 197306
2013-12-14 03:54:15 +00:00
Rui Ueyama fa561713f3 [PECOFF] Parse /export optional arguments.
/EXPORT command line option can take an ordinal, NONAME flag, and DATA flag.
This patch is to parse these optional arguments.

llvm-svn: 197217
2013-12-13 08:42:52 +00:00
Rui Ueyama c4123a5782 Run clang-format on the new files.
I should have run it before submitting but forgot to do that. Doing it now...

llvm-svn: 197214
2013-12-13 07:37:52 +00:00
Rui Ueyama 3a136547d7 [PECOFF] Align .edata fields on natural boundaries.
The only data in .edata whose length varies is the string. This patch moves
all the strings to the end of the section, so that 16-bit or 32-bit integers
are aligned on correct boundaries.

llvm-svn: 197213
2013-12-13 07:34:40 +00:00
Rui Ueyama c91c24e33d [PECOFF] Create .edata section for the DLL export table.
This is the first patch to emit data for the DLL export table. The DLL export
table is the data used by the Windows loader to find the address of exported
function from DLL. With this patch, LLD is able to emit a valid DLL export
table which the Windows loader can interpret and load.

The data structure of the DLL export table is described in the Microsoft
PE/COFF Specification, section 5.3.

DLL support is not complete yet; the linker needs to emit an import library
for a DLL, otherwise the linker cannot link against the DLL. We also do not
support export-only-by-ordinal yet.

llvm-svn: 197212
2013-12-13 06:58:27 +00:00
Rui Ueyama 091071ff0b [PECOFF] Rename lld::coff -> lld::pecoff.
We had lld::coff and lld::pecoff namespaces for no reason. Unify them.

llvm-svn: 197201
2013-12-13 02:58:27 +00:00
Rui Ueyama d68304eeee [PECOFF] Move a utility function used in a pass to Pass.cpp.
The file currently has only one function. Function that is useful both for
IdataPass and EdataPass will be added to that file.

llvm-svn: 197140
2013-12-12 10:01:14 +00:00
Rui Ueyama a92e2311bb [PECOFF] Replace DLLNameAtom with COFFStringAtom.
DLLNameAtom is an atom whose content is a string. IdataAtom is not going to
be the only place we need such atom, so I want to generalize it.

llvm-svn: 197137
2013-12-12 08:53:46 +00:00
Rui Ueyama 5a10da129f [PECOFF] Rename IdataPassFile and move it to Atoms.h.
I'm planning to create a new pass for the DLL export table, and I want to use
the class both from IdataPass and the new pass, EdataPass. So move the class to
a common place.

llvm-svn: 197132
2013-12-12 06:58:00 +00:00
Rui Ueyama d3199fdd2e [PECOFF] Parse /dll command line option.
llvm-svn: 197123
2013-12-12 03:21:45 +00:00
Rui Ueyama 4cf5a16117 [PECOFF] Add /dllexport option.
/DLLEXPORT is a command line option to export a symbol. __declspec(dllexport)
uses that to make the linker to export DLLExport'ed functions, by adding the
option to .drectve section.

This patch implements the parser of the command line option.

llvm-svn: 197122
2013-12-12 03:11:26 +00:00
Rui Ueyama 9e7b3cb024 Add .clang-format file to ensure C++11 LLVM coding style.
llvm-svn: 197085
2013-12-11 22:39:33 +00:00
Rui Ueyama bb08e62dd6 Run clang-format for PECOFF reader/writer code. No other changes.
llvm-svn: 197039
2013-12-11 14:10:25 +00:00
Rui Ueyama 93961d8e2a [PECOFF] Writer: Refactor the chunk class hierarchy.
Before this patch, we had the following class hierarchy.

  Chunk -> AtomChunk -> SectionChunk -> GenericSectionChunk
                                     -> BaseRelocChunk
        -> HeaderChunk

Chunk represented the generic concept of contiguous range in an output
file. AtomChunk represented a chunk consists of atoms.

That class hierarchy had many issues: 1) BaseRelocChunk does not really
consist of atoms, so inheriting from AtomChunk was plainly wrong, and 2)
the hierarchy is unecessarily too deep.

This patch correct them. The new hierachy is shown below.

  Chunk -> SectionChunk -> AtomChunk
                        -> BaseRelocChunk
        -> HeaderChunk

In the new hierarchy, AtomChunk represents a chunk consists of atoms. Other
types of sections (currently only BaseRelocChunk) should inherit directly
from SectionChunk.

llvm-svn: 197038
2013-12-11 14:00:10 +00:00
Rui Ueyama 5dd609206d [PECOFF] Add "const" qualifiers to BaseRelocChunk methods.
Also removed unused field.

llvm-svn: 197027
2013-12-11 10:57:36 +00:00
Rui Ueyama 338d70c0bb [PECOFF] Writer: Remove BaseRelocAtom.
No functionality change.

llvm-svn: 197025
2013-12-11 10:44:04 +00:00
Rui Ueyama 7e4660508d [PECOFF] Writer: Remove rawSize().
Because sections no longer have trailing NULL bytes, size() and rawSize() now
return the same value.

llvm-svn: 197020
2013-12-11 09:00:08 +00:00
Rui Ueyama 148049b0e8 [PECOFF] Remove enum for Data Directory atom which no longer exist.
llvm-svn: 197019
2013-12-11 08:53:24 +00:00
Rui Ueyama 1e26c74878 [PECOFF] Remove code which is no longer needed because of r197016.
llvm-svn: 197018
2013-12-11 08:40:40 +00:00
Rui Ueyama 6a2e745351 [PECOFF] Refactor IdataPass.
This patch is to basically move the functionality to construct Data Directory
from IdataPass to WriterPECOFF.

Data Directory is a part of the PE/COFF header and contains the addresses of
the import tables.

We used to represent the link from Data Directory to the import tables as
relocation references. The idea behind it is that, because relocation
references are processed by the Writer, we wouldn't have to do anything special
to fill the addresses of the import tables. I thought that the addresses would
be set "automatically".

But it turned out that that design made the pass and the writer rather
complicated. In order to make relocation references between Data Directory to
the import tables, these data structures needed to be represented as Atom.
However, because Data Directory is not a section content but a part of the
PE/COFF header, it did not fit well as an Atom. So we ended up having
complicated code both in IdataPass and the writer.

This patch simplifies it.

One side effect of this patch is that we now have ".idata.a", ".idata.d" and
"idata.t" sections for the import address table, the import directory table,
and the import lookup table. The writer looks for the sections by name to find
the start addresses of the sections. We probably should have a better way to
find a specific atom from the core linking result, but currently using the
section name seems to be the easiest way to do that. The Windows loader do not
care about the import table's section layout.

llvm-svn: 197016
2013-12-11 08:23:37 +00:00
Rui Ueyama 64a406b20b Simplify code a bit. No functionality change.
llvm-svn: 197009
2013-12-11 04:58:34 +00:00
Rui Ueyama f946424bd8 [PECOFF] Writer: Move SectionChunk's ctor inline.
llvm-svn: 197008
2013-12-11 04:36:19 +00:00
Rui Ueyama a63760592b Use "static" instead of anonymous namespace.
llvm-svn: 197007
2013-12-11 04:30:15 +00:00
Rui Ueyama 65827a9f77 [PECOFF] Make a member functions non-virtual.
llvm-svn: 197006
2013-12-11 04:30:06 +00:00
Rui Ueyama 0d4d40cfee [PECOFF] Writer: Remove NULL padding at the end of each section.
If section size is not multiple of 512, the writer added NULL bytes at the end
of it to make it so. That is not required by the PE/COFF spec, and the MSVC's
linker does not do that too. So we don't need to do that, too.

llvm-svn: 197002
2013-12-11 04:06:26 +00:00
Rui Ueyama 5c65a0efd1 s/NULL/nullptr/
llvm-svn: 196994
2013-12-11 01:31:54 +00:00
Rui Ueyama 2b7bb6c1f1 [PECOFF] WriterPECOFF: Rename getCharacteristics -> computeCharacteristics.
The base class has a member function with the same name. We should avoid it
being shadowed.

llvm-svn: 196992
2013-12-11 01:17:11 +00:00
Rui Ueyama 4b6b266823 [PECOFF] WriterPECOFF::ExecutableWriter: Small cleanup.
llvm-svn: 196991
2013-12-11 01:07:52 +00:00
Rui Ueyama 0bf1381902 Add explicit keyword.
llvm-svn: 196898
2013-12-10 09:12:07 +00:00
Rui Ueyama 3619f00ad5 [PECOFF] Make more member functions non-virtual.
llvm-svn: 196897
2013-12-10 09:02:00 +00:00
Rui Ueyama 9c922dd6ae [PECOFF] Optimize the writer a bit by removing a loop.
llvm-svn: 196896
2013-12-10 08:59:12 +00:00
Rui Ueyama d9d4be6993 [PECOFF] Refactor COFF section header creation.
Code to create COFF section header was scattered across many member functions
of SectionChunk. Consolidate it to a member function of SectionHeaderTableChunk.

llvm-svn: 196895
2013-12-10 08:39:06 +00:00
Rui Ueyama 27964e663b Add more const qualifiers.
llvm-svn: 196891
2013-12-10 07:15:57 +00:00
Rui Ueyama 17e663154a Remove data members used for relocations
... because they are used only in the function for relocations.

llvm-svn: 196890
2013-12-10 06:54:13 +00:00
Rui Ueyama 906d93432e Skip the body of a loop as early as possible.
llvm-svn: 196884
2013-12-10 06:32:21 +00:00
Rui Ueyama c53b3b0809 Style fixes. No functionality change.
llvm-svn: 196883
2013-12-10 06:19:09 +00:00
Rui Ueyama 2f47acfd6a Make anonymous namespace as small as possible.
Use of static is recommended by the style guide.

llvm-svn: 196877
2013-12-10 05:15:38 +00:00
Rui Ueyama 5ae0e5bffc Add const qualifiers.
llvm-svn: 196867
2013-12-10 03:57:59 +00:00
Rui Ueyama e46a06361c [PECOFF] Make some member functions non-virtual.
These member functions are not overriden and not intended to be, so adding
virtual does not make sense.

llvm-svn: 196866
2013-12-10 03:17:51 +00:00
Rui Ueyama c12f2a1121 Revert "Remove makeArrayRef() calls."
This reverts commit r196475 because it made the build to fail with
GCC 4.7/4.8/4.9. Reported by Mikael Lyngvig.

llvm-svn: 196853
2013-12-10 00:42:52 +00:00
Joey Gouly 34ec7f7411 Fix a copy/paste error.
llvm-svn: 196770
2013-12-09 10:23:27 +00:00
Rui Ueyama 681cabfc75 [PECOFF] Simplify PE/COFF header writer.
llvm-svn: 196767
2013-12-09 09:02:10 +00:00
Rui Ueyama d4339076c6 [PECOFF] Simplify WriterPECOFF.
llvm-svn: 196762
2013-12-09 08:47:20 +00:00
Rui Ueyama dc3e6d2c1b Fix broken test.
llvm-svn: 196756
2013-12-09 05:18:56 +00:00
Rui Ueyama 61580376b6 [PECOFF] Implement /alternatename weak symbols.
llvm-svn: 196754
2013-12-09 05:02:57 +00:00
Rui Ueyama 34d6e9b371 [PECOFF] Add /alternatename option parser.
/ALTERNATENAME is a rarely-used, undocumented command line option that is
needed to link LLD for release build. It seems that the option is for defining
an weak alias; /alternatename:foo=bar defines weak symbol "foo" for "bar".
If "foo" is defined in an input file, it'll be linked normally and the command
line option will have no effect. If it's not defined, "foo" will be handled
as an alias for "bar".

This patch implements the parser for the option. The actual weak alias handling
will be implemented in a separate patch.

llvm-svn: 196743
2013-12-09 01:47:32 +00:00
Rui Ueyama a930d12fe3 Move scattered debug functions into one #ifndef-guarded place.
llvm-svn: 196741
2013-12-09 00:37:19 +00:00
Rui Ueyama 2994f6f772 Fix -Wunused-function to unbreak buildbot.
llvm-svn: 196716
2013-12-08 03:37:58 +00:00
Rui Ueyama 5af4622f30 Move static member functions out of a class.
Because compare() and its heper functions no longer have to be members of
LayoutPass class, we can remove it from the class. No functionality change.

llvm-svn: 196715
2013-12-08 03:24:09 +00:00
Rui Ueyama 37c43e9f21 Optimize the layout pass.
The comparator used in the layout pass has many calls of map::find(). Because
std::sort runs the comparator N*log2(N) times, the maps are looked up with the
same key again and again. The map lookup is not a very fast operation. It made
the pass slow.

This patch eliminates the duplicate map lookups using decorate-sort-undecorate
idiom. The pass used to take 1.1 seconds when linking LLD with LLD on Windows,
but it now takes only 0.3 seconds. Overall performance gain in that case is from
6.1 seconds to 5.2 seconds.

Differential Revision: http://llvm-reviews.chandlerc.com/D2358

llvm-svn: 196714
2013-12-08 03:12:08 +00:00
Rui Ueyama 32c3f17d36 Re-submit r195852 with GroupedSectionsPass change.
GroupedSectionsPass was a complicated pass. That pass's job was to reorder
atoms by section name, so that the atoms with the same section prefix will be
emitted consecutively to the executable. The pass added layout edges to atoms,
and let the layout pass to actually reorder them.

This patch simplifies the design by making GroupedSectionPass to directly
reorder atoms, rather than adding layout edges. This resembles ELF's
ArrayOrderPass.

This patch improves the performance of LLD; it used to take 7.1 seconds to
link LLD with LLD on my Macbook Pro, but it now takes 6.1 seconds.

llvm-svn: 196628
2013-12-07 00:27:17 +00:00
Rui Ueyama 6031c37050 Make error code variables to have narrower scope.
llvm-svn: 196564
2013-12-06 04:48:05 +00:00
Rui Ueyama 34efe77742 Move definitions to cpp file. No functionality change.
llvm-svn: 196563
2013-12-06 04:43:01 +00:00
Rui Ueyama b1c2015203 Move a private field to private section.
llvm-svn: 196562
2013-12-06 04:34:04 +00:00
Rui Ueyama d2014f196b Use !! to convert to a boolean value.
llvm-svn: 196505
2013-12-05 13:11:33 +00:00
Rui Ueyama 16c025e212 [PECOFF] Handle .lib files as if they are grouped by --{start,end}-group.
Currently we do not de-duplicate library files specified by /defaultlib option.
As a result, the same files are added multiple times to the input graph. In
particular, some popular files, such as kernel32.lib or oldnames.lib, are added
more than 10 times during linking of LLD. That makes the linker slower, as it
needs to parse the same file again and again.

This patch solves the issue by de-duplicating. The same file will be added only
once to the input graph. This patch improved the LLD linking time from 10.5
seconds to 7.7 seconds on my 4-core Core i7 Macbook Pro.

llvm-svn: 196504
2013-12-05 13:07:49 +00:00
Rui Ueyama 7b4721048c Remove makeArrayRef() calls.
Because ArrayRef has implicit conversion from C arrays, we don't need
makeArrayRef.

llvm-svn: 196475
2013-12-05 06:55:26 +00:00
Rui Ueyama 62acf8624c Use makeArrayRef to construct ArrayRefs from C arrays.
llvm-svn: 196465
2013-12-05 04:41:10 +00:00
Rui Ueyama 6cfe07b9eb [PECOFF] Emit the import table to .idata section.
Emitting idata atoms to their own section would make debugging easier.
The Windows loader do not really care about whether the DLL import table is
in .rdata or its own .idata section, so there is no change in functionality.

llvm-svn: 196458
2013-12-05 02:27:30 +00:00
Rui Ueyama 8cb02d7aab Delete dead code.
llvm-svn: 196366
2013-12-04 08:38:38 +00:00
Rui Ueyama ea35c0ba0a [PECOFF] Ignore /functionpadmin option.
If /functionpadmin is specified, the linker is supposed to make room at the
beginning of each function, so that self-modifying program would easily
hotpatch existing functions. Since I'm not sure if this feature is really used,
I'll make LLD to ignore the option for now.

llvm-svn: 196363
2013-12-04 08:15:05 +00:00
Rui Ueyama f389e5c093 [PECOFF] Do not strip .debug section.
llvm-svn: 196332
2013-12-03 23:52:10 +00:00
Rui Ueyama fac7332d71 [PECOFF] Implement IMAGE_REL_I386_{SECTION,SECREL} relocations.
These relocations are used in .debug section.

llvm-svn: 196262
2013-12-03 09:18:31 +00:00
Rui Ueyama eb5162f2ad Simplify a switch statement.
llvm-svn: 196200
2013-12-03 04:18:55 +00:00
Rui Ueyama 98b28a1eaa [PECOFF] Print input file names if /verbose is specified.
llvm-svn: 196196
2013-12-03 02:21:52 +00:00
Rui Ueyama a4b97dcbe6 [PECOFF] Print reason if file parsing failed.
llvm-svn: 196185
2013-12-03 00:57:19 +00:00
Rui Ueyama 2f52222a10 [PECOFF] Make /subsystem option parser a separate function.
llvm-svn: 196092
2013-12-02 11:11:47 +00:00
Rui Ueyama 0156afb0ed Revert "[PECOFF] Fix atom ordinals."
This reverts commit r195852 because LLD seems to create broken executables
with that patch when compiled with MSVC 2013.

llvm-svn: 196078
2013-12-02 08:00:01 +00:00
Alp Toker 22593769a3 Fix "doesnot", "endsup" typos and "lets" grammar issues
llvm-svn: 196056
2013-12-02 01:28:14 +00:00
Rui Ueyama e68abc630e Update supported compiler list. Patch by Mikael Lyngvig!
llvm-svn: 196055
2013-12-02 01:22:17 +00:00
Alp Toker 79d0c1c4f7 Fix "don't" typos missed in previous commit
llvm-svn: 196054
2013-12-01 23:58:45 +00:00
Alp Toker 32e8beff89 Fix a variety of typos in function names and comments
No change in functionality.

llvm-svn: 196053
2013-12-01 23:51:36 +00:00
Rui Ueyama 8de2250ae9 [PECOFF] Fix /debug option.
/DEBUG option is to make the linker to emit debug information to the resulting
executable. It's not for enable debugging of the linker itself.

llvm-svn: 196040
2013-12-01 06:25:30 +00:00
Rui Ueyama 83bc3c84af [PECOFF] Set section characteristics based /section options.
This is a patch to let the PECOFF writer to use the information passed
by the parser for /section option. The implementation of /section should
now be complete.

llvm-svn: 195893
2013-11-27 23:44:58 +00:00
Rui Ueyama 615b200cc2 [PECOFF] Improve /merge option handling.
/MERGE option is a bit complicated for many reasons. Firstly, it takes both
positive and negative arguments. That means we have to have one of three
distinctive values (set, clear or unchange) for each permission bit. In this
patch we represent the three values using two bitmasks.

Secondly, the permissions specified by the parameter is bitwise or-ed with the
default permissions of a section. There is an exception for that rule; if one
of READ, WRITE or EXECUTE bit is specified, unspecified bits need to be
cleared. (So if you specify only WRITE for example, the resulting section will
not have WRITE nor EXECUTE bits.)

Lastly, multiple /merge options are allowed.

llvm-svn: 195882
2013-11-27 21:34:16 +00:00
Rui Ueyama ccb8f16891 Refactor tests by using short identifiers.
This patch is to improve the readability of the tests before making a change
to /merge option.

llvm-svn: 195863
2013-11-27 19:07:28 +00:00
Rui Ueyama a5e09c84ca [PECOFF] Implement /merge option.
/MERGE:foo=bar command line option merges section foo to section bar. If
section bar does not exist, foo is just renamed as bar.

llvm-svn: 195856
2013-11-27 18:03:34 +00:00
Rui Ueyama 951dd1d411 [PECOFF] Rename getFinalSectionName -> getOutputSectionName.
llvm-svn: 195855
2013-11-27 18:03:31 +00:00
Rui Ueyama 26c191aec6 [PECOFF] Remove extraneous command line options from tests.
llvm-svn: 195854
2013-11-27 17:43:54 +00:00
Rui Ueyama 60bbba6578 [PECOFF] Add a test for r195797.
llvm-svn: 195853
2013-11-27 17:34:24 +00:00
Rui Ueyama 878a8c90ea [PECOFF] Fix atom ordinals.
Atom ordinals are the indeces in a file. Currently the PECOFF reader assigns
ordinals for each section, so it's (incorrectly) assigning duplicate ordinals.

llvm-svn: 195852
2013-11-27 17:31:53 +00:00
Rui Ueyama cd4807595d Print a bit more information before aborting.
llvm-svn: 195801
2013-11-27 01:33:42 +00:00
Rui Ueyama 3e873b0578 [PECOFF] Add a generic section writer.
Instead of having multiple SectionChunks for each section (.text, .data,
.rdata and .bss), we could have one chunk writer that can emit any sections.
This patch does that -- removing all section-sepcific chunk writers and
replace them with one "generic" writer.

This change should simplify the code because it eliminates similar-but-
slightly-different classes.

It also fixes an issue in the previous design. Before this patch, we could
emit only limited set of sections (i.e. .text, .data, .rdata and .bss). With
this patch, we can emit any sections.

llvm-svn: 195797
2013-11-27 00:55:45 +00:00
Rui Ueyama 57b4da5874 Revert "WriterPECOFF"
This reverts accidental commit r195794.

llvm-svn: 195795
2013-11-27 00:25:17 +00:00
Rui Ueyama 6dc6d18f7a WriterPECOFF
llvm-svn: 195794
2013-11-27 00:23:31 +00:00
Rui Ueyama 912e65ef4b [PECOFF] Fix parameter mapping for /section.
The current mapping for /section one character options is really bogus.
Map to the correct flags.

llvm-svn: 195774
2013-11-26 17:57:05 +00:00
Rui Ueyama 50e2d7aeea [PECOFF] Skip sections with LNK_INFO.
According to the PE/COFF spec, a section with IMAGE_SCN_LNK_INFO should only
appear in an object file, and not allowed in an executable. So I believe
treating it as the same way as IMAGE_SCN_LNK_INFO is the right thing.

llvm-svn: 195692
2013-11-25 22:43:42 +00:00
Rui Ueyama 69cec146c7 [PECOFF] String pointed by StringRef is not always NUL-terminated.
In order not to overrun a StringRef and copy the trailing garbage, we need to
set the maximum length to be copied by strncpy.

llvm-svn: 195688
2013-11-25 21:33:01 +00:00
Rui Ueyama 8b08c3796b Early return.
llvm-svn: 195663
2013-11-25 17:09:29 +00:00
Rui Ueyama 17e899c967 Use range-based for loop.
llvm-svn: 195662
2013-11-25 17:09:27 +00:00
Rui Ueyama 5a3804f9c8 Indentation.
llvm-svn: 195661
2013-11-25 17:09:25 +00:00
Rui Ueyama 52b9cbf880 [PECOFF] Move definitions to IdataPass.cpp.
llvm-svn: 195618
2013-11-25 06:21:42 +00:00
Rui Ueyama 6194109c29 [PECOFF] Set ordinals to linker internal atoms.
This patch won't change the output because the layout of linker internal
atoms is forced by layout-{before,after} references. Ordinals of the linker
internal atoms are not currently used. (That's why it's working even if there
are atoms having the same ordinals.)

llvm-svn: 195610
2013-11-25 05:38:20 +00:00
Shankar Easwaran 89d0335a5c [Gnu] Set the defaults in the ELFLinkingContext.
Comment from Rui Ueyema.

llvm-svn: 195598
2013-11-25 04:28:57 +00:00
Shankar Easwaran 709447847a [Gnu] Ignore unknown arguments, and print message.
llvm-svn: 195597
2013-11-25 04:22:11 +00:00
Shankar Easwaran f6ec3faf18 [Gnu] Set the type of binary that lld would generate.
This is needed before any of the search paths are searched for.

llvm-svn: 195596
2013-11-25 04:14:38 +00:00
Rui Ueyama 2e36c8de3f [PECOFF] Change sectionChoice attribute.
Change the attribute from sectionBasedOnContent to sectionCustomRequired
because its the right attribute for atoms read from COFF files to have.
COFF atoms should basically be emitted to the section having the same name
as input. Permissions/attributes should not affect that.

There's no functionality change because the writer doesn't yet use the
section name. The writer will be modified in a following patch, so that atoms
are written to its customSectionName()'s section.

llvm-svn: 195595
2013-11-25 04:12:24 +00:00
Shankar Easwaran a27fe1c918 [Gnu] -L paths is not positional.
Looks like -L paths are not positional. They need to be added to a list of
search paths and those needs to be searched when lld looks for a library.

llvm-svn: 195594
2013-11-25 03:55:34 +00:00
Rui Ueyama ffbf4c39cc Fix MSVC buildbot.
llvm-svn: 195593
2013-11-25 02:51:33 +00:00
Rui Ueyama 1a11b3b001 [PECOFF] Infer subsystem from the entry point function.
If /subsystem option is not specified, the linker needs to infer it from the
entry point function. If "main" or "wmain" is defined, it's a console
application. If "WinMain" or "wWinMain" is defined, it's a GUI application.

llvm-svn: 195592
2013-11-25 02:00:00 +00:00
Shankar Easwaran 95678d4eff [InputGraph] Fix comment.
llvm-svn: 195584
2013-11-24 23:15:37 +00:00
Shankar Easwaran d87a021c79 [InputGraph][Gnu] Add LinkerScript support.
This adds LinkerScript support by creating a type Script which is of type
FileNode in the InputGraph. Once the LinkerScript Parser converts the
LinkerScript into a sequence of command, the commands are handled by the
equivalent LinkerScript node for the current Flavor/Target. For ELF, a
ELFGNULdScript gets created which converts the commands to ELF nodes and ELF
control nodes(ELFGroup for handling Group nodes).

Since the Inputfile type has to be determined in the Driver, the Driver needs
to determine the complete path of the file that needs to be processed by the
Linker. Due to this, few tests have been removed since the Driver uses paths
that doesnot exist.

llvm-svn: 195583
2013-11-24 23:12:36 +00:00
Shankar Easwaran 98758cbe85 [Gnu] Move code from .h to .cpp.
No change in functionality.

llvm-svn: 195582
2013-11-24 22:29:19 +00:00
Shankar Easwaran 67e98f5197 [InputGraph] Add capability to process Hidden nodes.
Hidden nodes could be a result of expansion, where a flavor might decide to keep
the node that we want to expand but discard it from being processed by the
resolver.

Verifies with unittests.

llvm-svn: 195516
2013-11-22 23:19:53 +00:00
Shankar Easwaran 3ac09bcb8f [InputGraph] Expand InputGraph nodes.
Flavors may like to expand InputGraph nodes, when a filenode after parsing
results in more elements. One such example is while parsing GNU linker scripts.
The linker scripts after parsing would result in a lot of filenodes and probably
controlnodes too.

Adds unittests to verify functionality.

llvm-svn: 195515
2013-11-22 23:08:24 +00:00
Rui Ueyama 82e366e78f [PECOFF] Do not set the entry address if /noentry option is given.
This is the first step towards DLL creation support. Resource-only DLLs
don't have entry point address.

llvm-svn: 195510
2013-11-22 22:52:15 +00:00
Rui Ueyama 340cdda2f6 Fix file header comment.
llvm-svn: 195393
2013-11-21 23:54:13 +00:00
Rui Ueyama fd133b300c Fix indentation and whitespace.
llvm-svn: 195389
2013-11-21 23:41:53 +00:00
Shankar Easwaran fb473c280f [test] Add InputGraph tests
llvm-svn: 195388
2013-11-21 23:37:45 +00:00
Shankar Easwaran 178324d903 [LinkingContext] Limit shared library undefined atoms to be added.
This adds functionality to limit shared library undefined atoms to be added
only once by the Resolver.

Dynamic libraries may be processed more than once if they exist within a
Group.

Also adds a test to verify the change.

llvm-svn: 195307
2013-11-21 03:50:59 +00:00
Rui Ueyama dae2ef47f1 [PECOFF] Move files with ".lib" extension to the end of the input file list.
It's allowed to specify library files *before* object files in the command
line. Object files seems to be processed first, and then their undefined
symbols are resolved from the libraries. This patch implements the compatible
behavior.

llvm-svn: 195295
2013-11-21 01:08:53 +00:00
Rui Ueyama 2a10b6401b [PECOFF] Do not check if library is already added.
llvm-svn: 195289
2013-11-21 00:43:46 +00:00
Rui Ueyama 90bcd114ac Rename allocateString -> allocate.
llvm-svn: 195284
2013-11-21 00:17:31 +00:00
Rui Ueyama 9c9d7d14d1 Reverse the condition for readability.
llvm-svn: 195282
2013-11-20 23:54:52 +00:00
Rui Ueyama 9114439df2 Move member functions to its own cpp file.
llvm-svn: 195281
2013-11-20 23:51:41 +00:00
Rui Ueyama 56215d84dc Remove blank return at the end of a function returning void.
llvm-svn: 195279
2013-11-20 23:12:03 +00:00
Rui Ueyama f8b41867c8 [PECOFF] Recognize but ignore /implib and /safeseh for now.
So that the LLD won't print error message saying that it couldn't find
/implib or /safeseh files.

llvm-svn: 195276
2013-11-20 21:57:30 +00:00
Rui Ueyama e05b629d39 Use NativeReferenceIvarsV2 if necessary.
NativeReferenceIvarsV1 cannot handle more than 65535 relocation targets
because its field to point to the target table is of type uint16_t. Because
of that limitation, the LLD couldn't link a file containing more than 65535
relocations. 65535 is not a big number - the LLD couldn't even link itself
with V1.

This patch solves the issue by adding NativeReferenceIvarsV2 support. The
new structure has more bits for the target table, so it can handle a large
number of relocatinos.

V2 structure is larger than V1. In order to prevent file bloating, V2 format
is used only when the resulting file cannot be represented in V1 format. The
writer and the reader support both V1 and V2 formats.

Differential Revision: http://llvm-reviews.chandlerc.com/D2217

llvm-svn: 195270
2013-11-20 20:54:18 +00:00
Rui Ueyama 70f11d7589 Fix Weak External symbol handling.
The fallback atom was used only when it's searching for a symbol in a library;
if an undefined symbol was not found in a library, the LLD looked for its
fallback symbol in the library.

Although it worked in most cases, because symbols with fallbacks usually occur
only in OLDNAMES.LIB (a standard library), that behavior was incompatible with
link.exe. This patch fixes the issue so that the semantics is the same as
MSVC's link.exe

The new (and correct, I believe) behavior is this:

 - If there's no definition for an undefined atom, replace the undefined atom
   with its fallback and then proceed (e.g. look in the next file or stop
   linking as usual.)

Weak External symbols are underspecified in the Microsoft PE/COFF spec. However,
as long as I observed the behavior of link.exe, this seems to be what we want
for compatibility.

Differential Revision: http://llvm-reviews.chandlerc.com/D2162

llvm-svn: 195269
2013-11-20 20:51:55 +00:00
Rui Ueyama 7b3c42a508 Do not inline large member functions. No functionality change.
llvm-svn: 195169
2013-11-19 23:40:44 +00:00
Rui Ueyama 4eb61120b5 Do not inline large member functions.
This should improve code readability as the class definitions are now
more readable than before.

llvm-svn: 195159
2013-11-19 22:12:26 +00:00
Rui Ueyama 935c5eda6f [PECOFF] Now that identify_magic() recognizes COFF import library.
No need to do that in ReaderCOFF.cpp.

llvm-svn: 195109
2013-11-19 06:29:57 +00:00
Rui Ueyama 03198d7cfa Remove meaningless "explicit" keywords.
llvm-svn: 195108
2013-11-19 06:20:56 +00:00
Rui Ueyama d9b26dc84b Remove extraneous curly braces and blank lines.
llvm-svn: 195107
2013-11-19 06:18:39 +00:00
Rui Ueyama 9a01d155b6 Use early continue. Style fix. No functionality change.
llvm-svn: 195106
2013-11-19 06:10:13 +00:00
Rui Ueyama d52cfdc9ab [PECOFF] Ignore /tlbid, /tlbout, /idlout and /ignoreigl for now.
llvm-svn: 195105
2013-11-19 05:55:08 +00:00
Rui Ueyama 86f32f40cf Use UINT16_MAX instead of 0xFFFF.
llvm-svn: 195096
2013-11-19 03:48:23 +00:00
Rui Ueyama 265134c731 Write temporary file names if debugging is enabled.
llvm-svn: 195062
2013-11-19 00:11:28 +00:00
Rui Ueyama 69c71cc827 Simplify. No functionality change.
llvm-svn: 195051
2013-11-18 22:42:03 +00:00
Rui Ueyama 11d1f18783 Replace unnecessary vector copy with reference.
llvm-svn: 194988
2013-11-18 04:05:28 +00:00
Rui Ueyama 2bafe7353e Add an assert for NativeReferenceIvarsV1.
The maximum number of references the file with NativeReferenceIvarsV1 can
contain is 65534. If a file larger than that is converted to Native format,
the conversion will fail without any error message. This caused a subtle bug
that the LLD would produce a broken executable only when input files contain
too many references.

This issue exists since the RoundTripNativeTest is introduced in r193585. Since
then, it seems that nobody have linked any program having more than 65534
relocations with the LLD. Otherwise we would have found it earlier.

llvm-svn: 194987
2013-11-18 03:50:50 +00:00
Rui Ueyama f45198b4bf Remove superfluous "explicit" keyword.
llvm-svn: 194982
2013-11-17 22:05:24 +00:00
Rui Ueyama b37c431d53 Move the entire debug print loop into DEBUG_WITH_TYPE.
No functionality change.

llvm-svn: 194914
2013-11-16 01:41:47 +00:00
Rui Ueyama a3ada6b0f7 Replace one more magic number with sizeof().
llvm-svn: 194913
2013-11-16 01:31:24 +00:00
Rui Ueyama 5dcabbc9e8 Use early continue.
llvm-svn: 194911
2013-11-16 01:14:37 +00:00
Rui Ueyama e4d20ab786 Simplify. No functionality change.
llvm-svn: 194909
2013-11-16 01:01:35 +00:00
Rui Ueyama 4072d91a58 Replace duplicate code with calls to getOrPushAttribute().
llvm-svn: 194908
2013-11-16 00:55:08 +00:00
Rui Ueyama 12027e58e1 Use range-based for loop.
end() was evaluated every time through a loop. This patch eliminates it.

llvm-svn: 194894
2013-11-15 23:53:32 +00:00
Rui Ueyama 249becb831 Use llvm_unreachable() instead of assert() at where control should never get.
llvm-svn: 194890
2013-11-15 23:36:48 +00:00
Rui Ueyama 559b0aa89e Duplicate code removal.
llvm-svn: 194887
2013-11-15 23:28:58 +00:00
Rui Ueyama 085886430a Replace magic number with sizeof(). No functionality change.
llvm-svn: 194877
2013-11-15 23:11:00 +00:00
Rui Ueyama 3f823e3af1 Remove duplicate code.
llvm-svn: 194866
2013-11-15 22:37:34 +00:00
Rui Ueyama fbd82d0813 [PECOFF] Use INT3 instead of NOP.
This patch does not change the meaning of the program, but if something's wrong
in the linker or the compiler and the control reaches to the gap of imported
function table, it will stop immediately because of the presence of INT3. If
NOP, it'd fall through to the next call instruction, which is usually a
completely foreign function call.

llvm-svn: 194860
2013-11-15 22:11:43 +00:00
Rui Ueyama 94f2271d63 [PECOFF] Remove unnecessary static member.
llvm-svn: 194851
2013-11-15 21:12:11 +00:00
Rui Ueyama 9442a79914 [PECOFF] Give a better name to the linker generated file.
llvm-svn: 194847
2013-11-15 21:04:23 +00:00
Rui Ueyama 9a4fd7e582 Fix Windows buildbot on which size_t is not unsinged long.
llvm-svn: 194793
2013-11-15 08:08:29 +00:00
Rui Ueyama dbce022caf [PECOFF] Minimum size of DOS stub is 64 byte.
llvm-svn: 194791
2013-11-15 08:00:22 +00:00
Rui Ueyama 478d9f9e7d [PECOFF] Avoid using statically initialized std::vector.
Also slightly reduces PECOFFLinkingContext's memory footprint (~128B).

llvm-svn: 194787
2013-11-15 05:45:20 +00:00
Rui Ueyama 3429d01f1a Refactor copy-paste-and-modifed code using callback.
llvm-svn: 194784
2013-11-15 04:58:54 +00:00
Rui Ueyama b4dca7f065 Select new undefined atom rather than old one if other conditions are the same.
We can add multiple undefined atoms having the same name to the symbol table.
If such atoms are added, the symbol table compares their canBeNull attributes,
and select one having a stronger constraint. If their canBeNulls are the same,
the choice is arbitrary. Currently it choose the existing one.

This patch changes the preference, so that the symbol table choose the new one
if the new atom has a greater canBeNull or a fallback atom. This shouldn't
change the behavior except the case described below.

A new undefined atom may have a new fallback atom attribute. By choosing the new
atom, we can update the fallback atom during Core Linking. PE/COFF actually need
that. For example, _lseek is an alias for __lseek on Windows. One of an object
file in OLDNAMES.LIB has an undefined atom for _lseek with the fallback to
__lseek. When the linker tries to resolve _read, it supposed to read the file
from OLDNAMES.LIB and use the new fallback from the file. Currently LLD cannot
handle such case because duplicate undefined atoms with the same attributes are
ignored.

Differential Revision: http://llvm-reviews.chandlerc.com/D2161

llvm-svn: 194777
2013-11-15 03:12:24 +00:00
Rui Ueyama 014192dbda Fix include guards.
llvm-svn: 194776
2013-11-15 03:09:26 +00:00
Rui Ueyama 1c6fd20427 [PECOFF] Add tests for r194757.
llvm-svn: 194768
2013-11-15 02:31:47 +00:00
Rui Ueyama e60d6e1b07 [PECOFF] Add /stub option.
llvm-svn: 194757
2013-11-15 00:18:41 +00:00
Rui Ueyama 5fe806e7a4 Move DOS stub data to PECOFFLinkingContext for /stub option.
llvm-svn: 194754
2013-11-14 23:54:24 +00:00
Rui Ueyama 9c082cd8dd Don't use getFileOrStdin() at where we don't want to read from stdin.
llvm-svn: 194746
2013-11-14 23:21:25 +00:00
Rui Ueyama 7eaa44c0bc Test: Move input redirections at the end of the line.
Writing arguments after the redirection of input ("< somefile") seems a bit
strange. Changes the order.

llvm-svn: 194727
2013-11-14 20:52:28 +00:00
Rui Ueyama 73ca00ca72 Test for r194671.
llvm-svn: 194723
2013-11-14 19:18:54 +00:00
Rui Ueyama fef5d42ef3 Fix trailing whitespace and indentation.
llvm-svn: 194722
2013-11-14 19:18:52 +00:00
Rui Ueyama 83ad675dd3 Use makeArrayRef(). No functionality change.
llvm-svn: 194721
2013-11-14 18:57:34 +00:00
Rui Ueyama aa85517303 Fix indentation and delete trailing whitespace.
llvm-svn: 194677
2013-11-14 06:58:32 +00:00
Rui Ueyama 519b9e357f Use makeArrayRef() to make ArrayRef from C array.
llvm-svn: 194675
2013-11-14 06:52:35 +00:00
Rui Ueyama 9310e01ea9 Terminate if there are un-mergeable duplicate atoms.
llvm-svn: 194671
2013-11-14 06:39:31 +00:00
Rui Ueyama 657ec494fa [PECOFF] Make the import library file magic more accurate.
llvm-svn: 194668
2013-11-14 06:15:18 +00:00
Rui Ueyama 404e97c3a2 Avoid parsing large YAML file.
YAML files tend to be very large compared to binary formats because of ASCII
format inefficiency. And the YAML reader consumes an excessively large amount
of memory when parsing a large file. It's very slow too.

For example, I observed that 6MB executable became 120MB YAML file, and the
YAML reader consumed more than 1.5GB memory to load it. The YAML reader even
caused OOM error on 32 bit, causing the entire process to fail.

This patch sets the limit on the YAML file size the linker will try to load in
the RoundTripYAML test as a safeguard.

llvm-svn: 194666
2013-11-14 05:57:54 +00:00
Michael J. Spencer 7a2080793e Whitespace.
llvm-svn: 194643
2013-11-14 00:52:05 +00:00
Michael J. Spencer db52824dfa [PECOFF] Add missing dependency.
This dependency needs to be cleaned up at some point. .directve handling needs the link.exe option parser.

llvm-svn: 194642
2013-11-14 00:51:51 +00:00
Michael J. Spencer bb0919968b Move InputGraph from Driver to Core. LinkingContext depends on it.
llvm-svn: 194641
2013-11-14 00:51:33 +00:00
Rui Ueyama 0acd8243e3 Remove default label from fully covered switch.
llvm-svn: 194624
2013-11-13 23:33:49 +00:00
Rui Ueyama bcccb5db2e Show error message if two atoms are not mergeable.
llvm-svn: 194620
2013-11-13 23:23:38 +00:00
Rui Ueyama f347e7533f Fix indentation, use early return.
llvm-svn: 194619
2013-11-13 23:22:00 +00:00
Rui Ueyama cc10b5b07e [PECOFF] Make ReaderCOFF more robust against planned identity_magic() changes.
No functionality change.

llvm-svn: 194560
2013-11-13 07:04:33 +00:00
Rui Ueyama 6ac5dc379b Re-submit r194551: Use empty() instead of size() == 0.
llvm-svn: 194556
2013-11-13 05:19:47 +00:00
Rui Ueyama e20474d38c Revert "Use empty() instead of size() == 0."
This reverts commit r194551 because it broke the buildbot.

llvm-svn: 194552
2013-11-13 03:30:29 +00:00
Rui Ueyama 2235bff2b9 Use empty() instead of size() == 0.
llvm-svn: 194551
2013-11-13 03:09:20 +00:00
Rui Ueyama 12f390856c Fix misleading indentation.
llvm-svn: 194550
2013-11-13 03:00:48 +00:00
Rui Ueyama e653f1d12c [PECOFF] Fix use-after-return.
llvm-svn: 194545
2013-11-13 02:21:51 +00:00
Rui Ueyama 3314f56ca8 [PECOFF] Do not print error if length of .drectve is 0.
llvm-svn: 194539
2013-11-13 01:19:08 +00:00
Rui Ueyama 3f902b2788 [MachO] Simplify conditionals. No functionality change.
llvm-svn: 194492
2013-11-12 17:46:55 +00:00
Alp Toker c544d5b7e8 Get lld building with MSVC2013
llvm-svn: 194481
2013-11-12 15:14:33 +00:00
Rui Ueyama 5c2ed5f154 Delete unused constructor.
llvm-svn: 194364
2013-11-11 05:03:31 +00:00
Shankar Easwaran 29ffee7af9 [cleanup] remove readFile and replace with getBuffer.
no functionality change.

llvm-svn: 194360
2013-11-11 02:13:30 +00:00
Shankar Easwaran ba470fa875 [InputGraph] remove unused functions.
llvm-svn: 194359
2013-11-11 01:03:49 +00:00
Rui Ueyama 78d1acb3af [ELF] Un-break undef-from-main-dso.test on MSVC 2012.
The result of sizeof(SymbolTable<ELFT>::SymbolEntry) in DynamicSymbolTable
<ELFT>::write() was different from the same expression in RelocationTable
<ELFT>::write(), although the same template parameters were passed. They were
40 and 32, respectively. As a result, the same vector was treated as a
vector of 40 byte values in some places and a vector of 32 values in other
places. That caused an weird issue, resulting in collapse of the rela.dyn
section.

I suspect that this is a padding size calculation bug in MSVC 2012, but I
may be wrong. Reordering the fields to eliminate padding seems to fix the
issue.

llvm-svn: 194349
2013-11-10 07:48:33 +00:00
Rui Ueyama 980c6d518e Remove empty namespace.
llvm-svn: 194322
2013-11-09 05:57:20 +00:00
Nick Kledzik 00a15d9428 [mach-o] Use LEB128 stuff from llvm/Support. No functionality change.
llvm-svn: 194305
2013-11-09 01:00:51 +00:00
Nick Kledzik 29f749eef8 [mach-o] reduce duplicate source code by using a templated method. No functionality change.
llvm-svn: 194299
2013-11-09 00:07:28 +00:00
Nick Kledzik 1b30228994 [mach-o] revert gunk added to test cases to debug build bot failures
llvm-svn: 194292
2013-11-08 23:18:51 +00:00
Nick Kledzik 705cbc1733 [mach-o] fix uninitialized variable
llvm-svn: 194290
2013-11-08 23:00:26 +00:00
Nick Kledzik 5eb9bfc863 [mach-o] add debugging to help explain one build bot failure
llvm-svn: 194280
2013-11-08 21:43:28 +00:00
Michael J. Spencer b8ab9f52ca Add explictly exported atoms and export R_*_COPY'ed atoms.
llvm-svn: 194278
2013-11-08 21:04:20 +00:00
Nick Kledzik d0784941fe [mach-o] fix memory ownership in test case
llvm-svn: 194187
2013-11-07 02:56:53 +00:00
Nick Kledzik 3c686e3561 add debug logging to help figure out why some tests fail on some build bots
llvm-svn: 194186
2013-11-07 01:27:47 +00:00
Nick Kledzik 471c00cfcb Hopefully fix latent bug where lldCore dependency on lldYAML was not in CMake files
llvm-svn: 194177
2013-11-06 22:56:42 +00:00
Nick Kledzik f3e89cb802 [mach-o] fix EXPECT_EQ types
llvm-svn: 194173
2013-11-06 22:20:56 +00:00
Nick Kledzik 020fa7f080 [mach-o] add llvm_unreachable
llvm-svn: 194172
2013-11-06 22:18:09 +00:00
Nick Kledzik 020a49c95d [mach-o] fix DEBUG_WITH_TYPE to compile without warnings in non-debug case
llvm-svn: 194171
2013-11-06 21:57:52 +00:00
Nick Kledzik 143b5e8237 [mach-o] make unspecifiedPageZeroSize const to fix VC++ error
llvm-svn: 194169
2013-11-06 21:47:37 +00:00
Nick Kledzik e34182f396 [mach-o] binary reader and writer
This patch adds support for converting normalized mach-o to and from binary
mach-o. It also changes WriterMachO (which previously directly wrote a 
mach-o binary given a set of Atoms) to instead do it in two steps. The first 
step uses normalizedFromAtoms() to convert Atoms to normalized mach-o, and the
second step uses writeBinary() which to generate the mach-o binary file.  

llvm-svn: 194167
2013-11-06 21:36:55 +00:00
Nick Kledzik 3df8104eee rename local variable to avoid shadowing warning
llvm-svn: 194166
2013-11-06 21:30:15 +00:00
Rui Ueyama 41b99dce59 [PECOFF] Rename getSectionAlignment -> getSectionDefaultAlignment.
These fields are for /align option. Section alignment can be set per-section
basis with /section option too. In order to avoid name conflicts, rename the
existing identifiers to become more specific. No functionality change.

llvm-svn: 194160
2013-11-06 19:30:14 +00:00
Rui Ueyama 108b371373 [PECOFF] Add /section option.
/section command line option is to set/reset attributes of the Characteristics
field in the section header. You can set non-default values with this option.
You can make .data section executable with this, for example.

This patch implements the parser of the command line option. The code to use
the parsed values will be committed in a separate patch.

llvm-svn: 194133
2013-11-06 07:31:55 +00:00
Rui Ueyama 67b277c34f [PECOFF] Make /disallowlib an alias for /nodefaultlib.
I'm not sure if it is really an alias for /nodefaultlib, but I can say that
they are at least similar. Making it an alias would be better than ignoring it.

llvm-svn: 194131
2013-11-06 05:48:45 +00:00
Rui Ueyama 589276cd25 [PECOFF] Do not expose _noDefaultLibs. No functionality change.
llvm-svn: 194130
2013-11-06 05:17:00 +00:00
Rui Ueyama 249c7b335e [PECOFF] Do not add the same library to the input graph more than once.
/defaultlib options can be specified implicitly via the .drectve section, and
it's pretty common that multiple object files add the same library, such as
user32.lib, to the input. We shouldn't add the same library multiple times.

llvm-svn: 194129
2013-11-06 05:13:20 +00:00
Rui Ueyama e1c30a4e04 Undef a local macro after use.
llvm-svn: 194128
2013-11-06 04:47:19 +00:00
Rui Ueyama d213a9ed3c [PECOFF] Do not wrap the linker internal file with an archive file.
We wrapped the linker internal file with a virtual archive file, so that the
linker internal file was linked only when it's actually used. This was to avoid
__ImageBase being included to the resulting executable. __ImageBase used to
occupy four bytes when emitted to executable.

And then it turned out that the implementation of __ImageBase was wrong -- it
shouldn't have been a regular atom but an absolute atom. Absolute atoms point
to some memory location, but they don't occupy disk space themselves. So it
wouldn't increase executable size (except the symbol table.) That means that
it's OK to link the linker internal file unconditionally.

So this patch does that, removing the wrapper archive file. Doing this
simplifies the code.

llvm-svn: 194127
2013-11-06 04:30:55 +00:00
Rui Ueyama c13f43f4f9 [PECOFF] Ignore /disallowlib.
msvcrt.lib contains "/disallowlib" command line option in its .drectve section.
I couldn't spot any documentation for the option. Ignore it for now so that we
can link the library without error.

llvm-svn: 194114
2013-11-06 00:44:10 +00:00
Rui Ueyama 7e77a294dc [PECOFF] Report error if there's unknown flag in .drectve
Errors in .drectve section were silently ignored. This patch fixes the issue.

llvm-svn: 194110
2013-11-05 23:53:15 +00:00
Rui Ueyama aa1335990f Remove extraneous parentheses.
llvm-svn: 194089
2013-11-05 18:43:10 +00:00
Rui Ueyama c1800beb55 Remove unnecessary namespace qualifier.
llvm-svn: 194037
2013-11-05 01:37:40 +00:00
Rafael Espindola 75c2ae9664 Replace ErrorOr<void> with error_code.
It was never transporting any value in addition to the error_code.

llvm-svn: 194028
2013-11-05 00:09:36 +00:00
Simon Atanasyan 8ef39b53e5 [ELF] Fix typo in the expression calculates an absolute atom offset.
Patch reviewed by Shankar Easwaran.

llvm-svn: 194010
2013-11-04 19:40:02 +00:00
Rui Ueyama 5efbc6379e [PECOFF] Fix the test to run.
llvm-svn: 194003
2013-11-04 19:01:57 +00:00
Rui Ueyama f23b27a837 [PECOFF] Add a test for the resource file.
llvm-svn: 193982
2013-11-04 05:17:54 +00:00
Rui Ueyama 2c717faa19 [ELF] Allow colons in the path.
This patch should fix the test when it runs on Windows, by allowing drive
letter separator (colon) in the path. Now all LLD ELF tests passed on MSVC
2012 32-bit. Hooray!

llvm-svn: 193978
2013-11-04 04:30:37 +00:00
Rui Ueyama 1c392a5611 [ELF] Simplify SectionTable::getSymbolTableIndex. No functionality change.
MSVC 2012 raises an error in the lambda passed to vector::find_if, while it
seems valid code. Rewrote without high-order functions.

llvm-svn: 193975
2013-11-04 03:24:14 +00:00
Rui Ueyama 0a5802a260 [ELF] Add missing -target option.
llvm-svn: 193974
2013-11-04 03:08:55 +00:00
Rafael Espindola 3c4739cc11 Update test now that llvm-nm prints the correct value.
llvm-svn: 193913
2013-11-02 05:21:29 +00:00
Rui Ueyama 329211bbb7 [ELF] One more file for missing -target option.
llvm-svn: 193911
2013-11-02 03:55:51 +00:00