Commit Graph

567 Commits

Author SHA1 Message Date
Benjamin Kramer 68f8699031 Add missing std:: qualifiers.
llvm-svn: 203244
2014-03-07 14:50:15 +00:00
Rui Ueyama 16e543bc02 Add "override" and remove "virtual" where appropriate.
For the record, I used clang-modernize to add "override" and perl to remove
"virtual".

llvm-svn: 203164
2014-03-06 21:14:04 +00:00
Ahmed Charles d779459f21 [C++11] Add #include's for OwningPtr.
Allows removing #include's in LLVM while switching to std::unique_ptr.

llvm-svn: 202679
2014-03-03 07:20:05 +00:00
Shankar Easwaran a328344367 [LinkerScript] parse OUTPUT_FORMAT : treat quotedStrings as identifier
llvm-svn: 202166
2014-02-25 17:02:54 +00:00
Shankar Easwaran 2ea5148eff [LinkerScript] OUTPUT_FORMAT: Parse Quoted Strings
llvm-svn: 202111
2014-02-25 05:17:24 +00:00
Shankar Easwaran 822ea4f9a3 [LinkerScript] parse OUTPUT_ARCH.
llvm-svn: 202100
2014-02-25 01:55:13 +00:00
Nico Rieck b9d84f4d14 [lld] Include reference kind in cycle detector debug output
This restores the debug output to how it was before r197727 broke it. This
went undetected because the corresponding test was never run due to broken
feature detection.

llvm-svn: 202079
2014-02-24 21:14:37 +00:00
Rui Ueyama d9e7c22ee4 [PECOFF] Driver support for /SAFESEH option.
Syntactically /SAFESEH is a boolean flag -- you can pass /SAFESEH or /SAFESEH:no.

The meaning of /SAFESEH is as follows.

 - If /SAFESEH is specified, the linker will produce an executable with SEH table.
   If any input files are not compatible with SEH, it's an error.
 - If /SAFESEH:no is specified, the linker will not emit SEH table even if all
   input files are compatible with SEH.
 - If no option is specified, the linker emits SEH table if all input files are
   compatible with SEH.

llvm-svn: 201895
2014-02-21 22:30:43 +00:00
Shankar Easwaran 9578442fe9 [ELF] Dont generate PHDR when creating dynamic libraries.
llvm-svn: 201741
2014-02-19 23:46:13 +00:00
Rui Ueyama 153ee54008 Untabify.
llvm-svn: 200712
2014-02-03 19:07:38 +00:00
Rui Ueyama d0d01c66ba MSVC2012 does not choose to use uint64_t as underlying type without this.
MSVC2012 seems to choose int as the underlying type for an enum even if one of
its member is unsigned long long.

llvm-svn: 200519
2014-01-31 06:28:32 +00:00
Rui Ueyama 8851d45cbf Replace magic numbers with enums.
llvm-svn: 200512
2014-01-31 04:57:03 +00:00
Rui Ueyama ea7e9306c1 [PECOFF] Default image base address for PE32+ is 0x140000000, not 0x400000.
llvm-svn: 200511
2014-01-31 04:49:13 +00:00
Rui Ueyama a709af2861 s/0/nullptr/
llvm-svn: 200272
2014-01-28 01:22:23 +00:00
Shankar Easwaran af7fbd8cf4 [ELF] Create Target specific Writers.
llvm-svn: 200176
2014-01-27 01:20:53 +00:00
Shankar Easwaran e7b831ad35 [ELF] Add Target specific Readers.
No change in functionality.

llvm-svn: 200175
2014-01-27 01:02:03 +00:00
Rui Ueyama 49bfd5032d [PECOFF] Accept /machine:x64 option.
This is the first patch to support PE32+ format, which is the image format
to use 64 bit address space on Windows/x86-64.

llvm-svn: 200029
2014-01-24 19:17:05 +00:00
Simon Atanasyan d8cadd6f17 [ELF] Customize a relocation table output format (rel / rela).
Add new virtual virtual function `isRelaOutputFormat` to the
`ELFLinkingContext` class. Call this function everywhere we need to
select a relocation table format.

Patch reviewed by Shankar Easwaran and Rui Ueyama.

llvm-svn: 199973
2014-01-24 05:21:21 +00:00
Rui Ueyama d9696cbda8 Using "final" as a variable name is a bit confusing in C++11, so rename it.
llvm-svn: 199526
2014-01-18 00:27:03 +00:00
Rui Ueyama ab9deb5466 [PECOFF] Support STACKSIZE module-definition file directive.
llvm-svn: 199170
2014-01-14 00:48:25 +00:00
Rui Ueyama 0c306ba08c Add comment to bit manipulation functions.
llvm-svn: 199156
2014-01-13 22:29:16 +00:00
Rui Ueyama 415625028c [PECOFF] Support VERSION directive.
llvm-svn: 199022
2014-01-11 22:45:00 +00:00
Rui Ueyama b214e1aba2 [PECOFF] Support NAME directive.
llvm-svn: 199020
2014-01-11 21:53:46 +00:00
Rui Ueyama 66a4445658 [PECOFF] Add a helper function to read an integer from .def file.
llvm-svn: 199019
2014-01-11 21:37:25 +00:00
Rui Ueyama 6a5f7c22ad [PECOFF] Support HEAPSIZE directive.
llvm-svn: 198994
2014-01-11 01:58:21 +00:00
Rui Ueyama f98a18acb7 [PECOFF] Refactor module-defintion file parser.
Refactor the parser so that the parser can return arbitrary type of parse
result other than a vector of ExportDesc. Parsers for non-EXPORTS directives
will be implemented in different patches. No functionality change.

llvm-svn: 198993
2014-01-11 01:33:42 +00:00
Nick Kledzik 6edd722a2c [mach-o] enable mach-o and native yaml to be intermixed
The main goal of this patch is to allow "mach-o encoded as yaml" and "native
encoded as yaml" documents to be intermixed.  They are distinguished via 
yaml tags at the start of the document.  This will enable all mach-o test cases
to be written using yaml instead of checking in object files.

The Registry was extend to allow yaml tag handlers to be registered.  The
mach-o Reader adds a yaml tag handler for the tag "!mach-o". 

Additionally, this patch fixes some buffer ownership issues.  When parsing
mach-o binaries, the mach-o atoms can have pointers back into the memory 
mapped .o file.  But with yaml encoded mach-o, name and content are ephemeral, 
so a copyRefs parameter was added to cause the mach-o atoms to make their
own copy.  

llvm-svn: 198986
2014-01-11 01:07:43 +00:00
Rui Ueyama 8b14d14209 [PECOFF] Support module-definition file.
Module-definition (.def) files are the file containing linker directives,
such as export symbols. Because link.exe supports the same features as command
line options, just as some Linker Script commands overlaps with command line
options, use of module-definition file is not really necessary. It provides
an alternative way to specify some linker options.

This patch implements EXPORTS directive. Other directives will be implemented
in the future.

llvm-svn: 198925
2014-01-10 10:19:47 +00:00
Rafael Espindola d28918b289 Use getError instead of the error_code operator.
llvm-svn: 198797
2014-01-08 22:00:09 +00:00
Rui Ueyama 54174c6f16 [PECOFF] Simplify: Replace two-value enum with bool.
llvm-svn: 198634
2014-01-06 19:55:58 +00:00
Rui Ueyama 76bc5157c2 Use scoped enum.
llvm-svn: 198396
2014-01-03 03:29:15 +00:00
Joerg Sonnenberger 4dcee6960f Add default search path if -nostdlib is not provided.
Add basic emulation mapping for NetBSD/amd64, so that clang -m32 works
as expected.

llvm-svn: 198337
2014-01-02 19:18:36 +00:00
Joey Gouly 600bfa42ec Remove extra semicolon.
llvm-svn: 198275
2014-01-01 10:07:45 +00:00
Joey Gouly 0518453e2e The return value of createInternalFiles is unused, so remove it.
llvm-svn: 198266
2013-12-31 19:15:42 +00:00
Rui Ueyama ad79838aa8 [PECOFF] Use std::set to store export symbol descriptors.
Each export symbol descriptor has unique name attribute, so std::set is
better container than std::vector for it. No functionality change.

llvm-svn: 198102
2013-12-28 08:11:21 +00:00
Rui Ueyama 61b851ab06 Remove duplicate methods.
llvm-svn: 198034
2013-12-26 06:35:35 +00:00
Rui Ueyama cf4616110c [PECOFF] Use the first definition of an export if specified multiple times.
If the same symbol is specified multiple times as arguments of /export, the
first definition should be used.

llvm-svn: 197998
2013-12-25 06:46:45 +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
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
Nick Kledzik f30e848432 Restore vertical alignment lost by clang-format
llvm-svn: 197834
2013-12-20 20:34:19 +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 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 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 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 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 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 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 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 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 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 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
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 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 951dd1d411 [PECOFF] Rename getFinalSectionName -> getOutputSectionName.
llvm-svn: 195855
2013-11-27 18:03:31 +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
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
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 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 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 9a01d155b6 Use early continue. Style fix. No functionality change.
llvm-svn: 195106
2013-11-19 06:10:13 +00:00
Rui Ueyama f45198b4bf Remove superfluous "explicit" keyword.
llvm-svn: 194982
2013-11-17 22:05:24 +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 014192dbda Fix include guards.
llvm-svn: 194776
2013-11-15 03:09:26 +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
Michael J. Spencer 7a2080793e Whitespace.
llvm-svn: 194643
2013-11-14 00:52:05 +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
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
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 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
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 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 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
Shankar Easwaran b1ffd99b6a [FileToMutable] Garbage collect unused private member
llvm-svn: 193588
2013-10-29 05:33:52 +00:00
Shankar Easwaran 2bc24928d3 [PassManager] add ReaderWriter{Native,YAML} to the Driver.
Enable this for the following flavors

a) core
b) gnu
c) darwin

Its disabled for the flavor PECOFF. Convenient markers are added with FIXME
comments in the Driver that would be removed and code removed from each flavor.

llvm-svn: 193585
2013-10-29 05:12:14 +00:00
Rui Ueyama 3aca58f135 Fix spelling.
llvm-svn: 193584
2013-10-29 04:54:50 +00:00
Rui Ueyama 6ecc4383fb Fix comment.
llvm-svn: 193557
2013-10-28 23:34:41 +00:00
Chandler Carruth 50e5b3298c Use equals_lower() rather than creating a temporary string with lower().
More important than any performance concerns, the code was dropping the
temporary string on the floor after assigning it to a StringRef, and
then used the StringRef later. Caught by running the LLD tests under
ASan.

llvm-svn: 193486
2013-10-26 23:53:06 +00:00
Rui Ueyama 863931c990 [PECOFF] Parse /merge command line option.
/merge:<from>=<to> option makes the linker to combine "from" section to "to"
section. This patch is to parse the option. The actual feature will be
implemented in a subsequent patch.

llvm-svn: 193454
2013-10-26 00:46:57 +00:00
Rui Ueyama 671c8013ed Revert "r193300 - [PassManager] add ReaderWriter{Native, YAML} to the Driver"
The patch have completely broken COFF port and disabled many tests.
This also reverts r193302 (comment fix).

llvm-svn: 193362
2013-10-24 18:22:16 +00:00
Shankar Easwaran 986730303f Fix Comments.
llvm-svn: 193302
2013-10-24 04:28:14 +00:00
Shankar Easwaran 89c2d8faca [PassManager] add ReaderWriter{Native,YAML} to the Driver.
Disable tests to be run with REQUIRES: disable. Note disable is not added to the
config by the test runner Mkaefiles, so essentially disables the test.

Code changes would be required to fix these tests :-

test/darwin/hello-world.objtxt
test/elf/check.test
test/elf/phdr.test
test/elf/ppc.test
test/elf/undef-from-main-dso.test
test/elf/X86_64/note-sections-ro_plus_rw.test
test/pecoff/alignment.test
test/pecoff/base-reloc.test
test/pecoff/bss-section.test
test/pecoff/drectve.test
test/pecoff/dynamic.test
test/pecoff/dynamicbase.test
test/pecoff/entry.test
test/pecoff/hello.test
test/pecoff/imagebase.test
test/pecoff/importlib.test
test/pecoff/lib.test
test/pecoff/multi.test
test/pecoff/reloc.test
test/pecoff/weak-external.test

llvm-svn: 193300
2013-10-24 03:30:03 +00:00
Rui Ueyama b32b95d814 [PECOFF] Support embedding resource file into executable.
Instead of making the linker to create a manifest XML file in the same
directory as the resulting binary, you can embed the XML as a part of
resource into the executable.

In order to do that, the linker first creates a resource script file containing
the XML file, compile it into a binary resource file with RC.EXE, and then
convert it to a COFF file with CVTRES.EXE.

llvm-svn: 193298
2013-10-24 01:39:43 +00:00
Rui Ueyama 9041c3bd5b [PECOFF] Add /manifestdependency command line option.
llvm-svn: 193201
2013-10-22 21:39:04 +00:00
Rui Ueyama 9a02765bc3 [PECOFF] Add /manifestfile command line option.
/manifestfile:<path> specifies an alternative manifest file output path.
Default is "<output-path>.manifest" where <output-path> is the executable's
path.

llvm-svn: 193195
2013-10-22 20:53:07 +00:00
Rui Ueyama 28d0f60c48 [PECOFF] Fix /manifestuac handling.
uiAccess argument's type is not really boolean. It's string.

llvm-svn: 193171
2013-10-22 17:42:42 +00:00
Rui Ueyama 139ae4c931 [PECOFF] Parse /manifest command line option.
The manifest file is an XML file that conveys some information to the loader,
such as whether the executable needs to run as Administrator or not. This patch
is to parse command line option for manifest file.

Actual XML file generation will be done in a separate patch.

llvm-svn: 193141
2013-10-22 03:49:35 +00:00
Rui Ueyama 46bf8286db Fix bug that CompareAtoms::compare is not transitive.
This patch fixes a bug in r190608. The results of a comparison function
passed to std::sort must be transitive, which is, if a < b and b < c, and if
a != b, a < c must be also true. CompareAtoms::compare did not actually
guarantee the transitivity. As a result the sort results were sometimes just
wrong.

Consider there are three atoms, X, Y, and Z, whose file ordinals are 1, 2, 3,
respectively. Z has a property "layout-after X". In this case, all the
following conditionals become true:

  X < Y because X's ordinal is less than Y's
  Y < Z because Y's ordinal is less than Z's
  Z < X because of the layout-after relationship

This is not of course transitive. The reason why this happened is because
we used follow-on relationships for comparison if two atoms falls in the same
follow-on chain, but we used each atom's properties if they did not. This patch
fixes the issue by using follow-on root atoms for comparison to get consistent
results.

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

llvm-svn: 193029
2013-10-19 03:18:18 +00:00
Rui Ueyama 6a607b6a3b Improve debug message of the layout pass.
Instead of showing multiple lines of debug messages, show only one message
by CompareAtoms::operator(). Here is an example.

Before:
  Sorting _main .text
  Sorting by sectionPos(2,2)
  Sorting by override
  Sorting _main .text
  Sorting by sectionPos(2,2)
  Sorting by override

After:
  Layout: '_main' > '.text' (override (1, 0))
  Layout: '_main' > '.text' (override (1, 0))

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

llvm-svn: 192941
2013-10-18 02:56:31 +00:00
Rui Ueyama f3630fe4be Make undefines check into an assertion.
Dead-strip root symbols can be undefined atoms, but should not really be
nonexistent, because dead-strip root symbols should be added to initial
undefined atoms at startup. Whenever you look up its name in the symbol
table, some type of atom will always exist.

llvm-svn: 192831
2013-10-16 19:21:50 +00:00
Rui Ueyama c726c1962d Fix a bug that the empty string could be added to dead strip root.
llvm-svn: 192772
2013-10-16 05:06:52 +00:00
Rui Ueyama 2847831771 Propagate deadStripOptimize()'s failure to the caller.
We want to make the program to exit with non-zero exit code if there's an error
during dead stripping.

llvm-svn: 192771
2013-10-16 05:03:39 +00:00
Rui Ueyama 2ad117db97 Propagate Resolver::resolveUndefines()'s failure to caller.
llvm-svn: 192424
2013-10-11 06:26:16 +00:00
Shankar Easwaran c5ed819b02 [ELF] Return error from invalid linker script parse.
llvm-svn: 192360
2013-10-10 16:59:53 +00:00
Rui Ueyama 85cc66d85e Do not process .objtxt file twice.
A file with .objtxt extension is parsed in readFile(), but because we did not
propagate that information to the calling side, calling side would try to parse
it again. This patch will fix the issue by adding an extra parameter to
readFile().

llvm-svn: 192311
2013-10-09 18:14:23 +00:00
Shankar Easwaran 49408ece47 [Layout] Dont set ordinals to Files by default.
This change removes code in various places which was setting the File Ordinals.
This is because the file ordinals are assigned by the way files are resolved.

There was no other way than making the getNextFileAndOrdinal be set const and
change the _nextOrdinal to mutable.

There are so many places in code, that you would need to cleanup to make
LinkingContext non-const!

llvm-svn: 192280
2013-10-09 07:32:47 +00:00
Shankar Easwaran 30c4d11395 [cleanup] remove unused private variable
llvm-svn: 192278
2013-10-09 05:37:01 +00:00
Shankar Easwaran 1d3c48f1fc [Layout] Assign ordinals in Resolution order.
llvm-svn: 192277
2013-10-09 05:23:23 +00:00
Shankar Easwaran 03f7763d21 [inputGraph] Associate Resolve state with appropriate nodes
This associates resolveState to FileNodes. The control node derive
their resolution state from the inputElements that are contained in
it.

This makes --start-group/--end-group to work with ELF linking.

llvm-svn: 192269
2013-10-09 03:40:29 +00:00
Rui Ueyama c6015f6476 Update error classes from all lowercase to camel case.
llvm-svn: 192261
2013-10-09 00:57:22 +00:00
Rui Ueyama f96416d750 Use size_t for array index.
llvm-svn: 192249
2013-10-08 23:01:49 +00:00
Rui Ueyama f890d3bf26 Fix #endif comment.
llvm-svn: 192230
2013-10-08 20:24:25 +00:00
Rui Ueyama 88b24ffe73 Use size_t instead of int64_t for the vector size.
llvm-svn: 192229
2013-10-08 20:24:23 +00:00
Shankar Easwaran 7f1146c494 [LinkingContext] make LinkingContext non-const
llvm-svn: 192183
2013-10-08 15:43:48 +00:00
Shankar Easwaran f876ecf5ed [Cleanup] Remove file thats not being used
llvm-svn: 192172
2013-10-08 06:05:38 +00:00
Rui Ueyama 9a13ac9a40 Move duplicate code in InputGraphs to the parent class.
llvm-svn: 192170
2013-10-08 05:52:01 +00:00
Rui Ueyama 492048bf60 Rename GnuLd's path() too.
llvm-svn: 192169
2013-10-08 05:23:03 +00:00
Rui Ueyama 53f31af7ea Rename path() -> getPath().
Differential Revision: http://llvm-reviews.chandlerc.com/D1853

llvm-svn: 192167
2013-10-08 04:57:08 +00:00
Rui Ueyama 7deb970d66 Use size_t instead of uint64_t to represent the vector length.
llvm-svn: 192165
2013-10-08 03:59:50 +00:00
Rui Ueyama a1d4c10c61 Remove an unnecessary local variable.
llvm-svn: 192164
2013-10-08 03:59:48 +00:00
Rui Ueyama 8b8e5216af Make bitmask an unsigned type.
llvm-svn: 192163
2013-10-08 03:59:45 +00:00
Rui Ueyama 7a633b4de5 Expand auto for readability.
llvm-svn: 192162
2013-10-08 03:59:42 +00:00
Rui Ueyama f8c54842d6 Convert error code structs to scoped enums.
Summary:
The original code with enum "_" is intended to emulate scoped enums.
Now we have real scoped enums, so use it.

Reviewers: Bigcheese

CC: llvm-commits

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

llvm-svn: 192148
2013-10-08 00:43:50 +00:00
Nick Kledzik 30332b19d3 Supoort mach-o encoded in yaml.
This is the first step in how I plan to get mach-o object files support into 
lld. We need to be able to test the mach-o Reader and Write on systems without 
a mach-o tools. Therefore, we want to support a textual way (YAML) to represent 
mach-o files.

MachONormalizedFile.h defines an in-memory abstraction of the content of mach-o  
files. The in-memory data structures are always native endianess and always
use 64-bit sizes. That internal data structure can then be converted to or
from three different formats: 1) yaml (text) encoded mach-o, 2) binary mach-o
files, 3) lld Atoms.

This patch defines the internal model and uses YAML I/O to implement the 
conversion to and from the model to yaml. The next patch will implement
the conversion from normalized to binary mach-o.

This patch includes unit tests to validate the yaml conversion APIs.

llvm-svn: 192147
2013-10-08 00:43:34 +00:00
Rui Ueyama 4c4d572795 Rename lld:*_error::_ -> lld:*_error::ErrorCode.
Summary: Rename lld:*_error::_ -> lld:*_error::ErrorCode.

Reviewers: shankarke

CC: llvm-commits

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

llvm-svn: 192138
2013-10-07 21:58:51 +00:00
Shankar Easwaran bafdf7be83 [lld][Darwin] Fix unused field warning.
This field would eventually be used.

llvm-svn: 192084
2013-10-07 03:18:33 +00:00
Shankar Easwaran 18318e32a9 [lld][inputgraph] Fix build failure on Darwin/Windows
llvm-svn: 192083
2013-10-07 03:06:04 +00:00
Shankar Easwaran d8ce00360d [lld] Add FileArchive
Fix adding a missed file in the previous commit.

llvm-svn: 192082
2013-10-07 02:55:42 +00:00
Shankar Easwaran a96f3a3da4 [lld][InputGraph] Change the Resolver to use inputGraph
Changes :-

a) Functionality in InputGraph to insert Input elements at any position
b) Functionality in the Resolver to use nextFile
c) Move the functionality of assigning file ordinals to InputGraph
d) Changes all inputs to MemoryBuffers
e) Remove LinkerInput, InputFiles, ReaderArchive

llvm-svn: 192081
2013-10-07 02:47:09 +00:00
Michael J. Spencer 4355bb9d22 [Core] Add type and size to SharedLibraryAtom.
llvm-svn: 191466
2013-09-26 22:08:43 +00:00
Michael J. Spencer 4d628347b1 [ELF] Fix use after free.
llvm-svn: 191403
2013-09-25 22:12:14 +00:00
Rui Ueyama 98f269f9d1 [PECOFF] Add /swaprun:{cd,net} options.
llvm-svn: 191276
2013-09-24 04:20:37 +00:00
Rui Ueyama f062c84aac [PECOFF] Add /nodefaultlib command line option.
llvm-svn: 191254
2013-09-24 00:16:27 +00:00
Rui Ueyama c0a6d43c92 [PECOFF] Add /allowisolation command line option.
llvm-svn: 191227
2013-09-23 21:22:01 +00:00
Rui Ueyama 6907b3df70 [PECOFF] Add /allowbind command line option.
llvm-svn: 191224
2013-09-23 20:44:20 +00:00
Rui Ueyama 9149181ae9 [PECOFF] Add /align command line option.
llvm-svn: 191218
2013-09-23 19:52:35 +00:00
Shankar Easwaran 7915ff34b7 [lld][LinkingContext][ELF] Allow different output file types.
This adds an option --output-filetype that can be set to either
YAML/Native(case insensitive). The linker would create the outputs
associated with the type specified by the user.

Changes all the tests to use the new option.

llvm-svn: 191183
2013-09-23 04:24:15 +00:00
Rui Ueyama 391ffdf70e Generalize errStr() function so that it can handle any type of errors.
llvm-svn: 191069
2013-09-20 03:18:58 +00:00
Rui Ueyama 388fbd8f31 Handle "file not found" error in the superclass's errStr().
If a subclass does not override the member function, the superclass's method
takes care of string conversion of "file not found" error. This is a reasonable
default behavior. Subclasses are still able to override to customize error
messages.

llvm-svn: 191058
2013-09-20 00:32:40 +00:00
Rui Ueyama dc30cdb18c Fix file comments and include guard
llvm-svn: 191054
2013-09-19 23:34:20 +00:00
Shankar Easwaran a17e5bc02a [lld][ELF] Support non alloc sections in the Writer.
This also makes it support debugging executables built with lld.

Initial patch done by Bigcheese. This is only a revised patch to
have the functionality in the Writer.

llvm-svn: 191032
2013-09-19 20:07:01 +00:00
Rui Ueyama 1bddfc1fc7 [PECOFF][Driver] Support /version command line option
llvm-svn: 190986
2013-09-19 02:37:36 +00:00
Joerg Sonnenberger 97fc3834b8 Output soname.
llvm-svn: 190758
2013-09-14 19:53:51 +00:00
Shankar Easwaran 4ff19b3c87 [lld][LinkingContext] Fix doxygen comment
llvm-svn: 190629
2013-09-12 20:00:15 +00:00
Rui Ueyama 55b3cc5054 Do not prepend "_" to external symbols if non-i386.
llvm-svn: 190628
2013-09-12 19:52:59 +00:00
Rui Ueyama 98896ed1b5 [PECOFF] Add a field for machine type to PECOFFLinkingContext.
So that we can determine what the target architecture is. Adding this
field does not mean that we are going to support non-i386 architectures
soon; there are many things to do to support them, and I'm focusing on
i386 now. But this is the first step toward multi architecture support.

llvm-svn: 190627
2013-09-12 19:46:53 +00:00
Rui Ueyama e5416ec2d2 Add a fallback mechanism for undefined atom.
In COFF, an undefined symbol can have up to one alternative name. If a symbol
is resolved by its regular name, then it's linked normally. If a symbol is not
found in any input files, all references to the regular name are resolved using
the alternative name. If the alternative name is not found, it's a link error.
This mechanism is called "weak externals".

To support this mechanism, I added a new member function fallback() to undefined
atom. If an undefined atom has the second name, fallback() returns a new undefined
atom that should be used instead of the original one to resolve undefines. If it
does not have the second name, the function returns nullptr.

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

llvm-svn: 190625
2013-09-12 19:14:05 +00:00
Rui Ueyama 81d0d29639 Remove hard-coded leading underscore from entry symbol.
llvm-svn: 190586
2013-09-12 05:09:01 +00:00
Rui Ueyama 1e6af15388 Do not hard code the leading underscore.
Mangling scheme varies on platform, and prepending an underscore is valid only
on 32-bit x86. Added a method to mangle name to PECOFFLinkingContext and use
it to avoid hard coding mangled names.

llvm-svn: 190585
2013-09-12 04:42:31 +00:00
Nick Kledzik e773e327d3 Support darwin linker options:
-current_version, -compatibility_version, and -install_name.

Patch by Joe Ranieri

llvm-svn: 190452
2013-09-10 23:55:14 +00:00
Nick Kledzik e850d9dedd Remove PackedVersion from MachOLinkingContext and replace with uint32_t
and a parsePackedVersion() utility.

Patch by Joe Ranieri

llvm-svn: 190451
2013-09-10 23:46:57 +00:00
Rui Ueyama fff7f8a4ed Rename GnuLDInputGraph.h -> GnuLdInputGraph.h for consistency with other files.
llvm-svn: 190332
2013-09-09 19:30:23 +00:00
Joerg Sonnenberger bd25241e0e Drop the context forceLoadAllArchives() support. Rename the isForceLoad
attribute in LinkerInput to isWholeArchive and use that for deciding
whether library archives should be expanded. Implement the -all_load
option of the Darwin linker using this flag and drop the support for it
in GNU mode.

llvm-svn: 190275
2013-09-08 13:30:14 +00:00
Joerg Sonnenberger 5e235de9d3 Change the parseFile argument from MemoryBuffer pointer to LinkerInput
reference. Move readFile logic into FileNode::createLinkerInput.

llvm-svn: 190253
2013-09-07 17:55:28 +00:00
Shankar Easwaran fc09df0fe9 [lld][cleanup] remove unused ReaderFunc to avoid confusion.
llvm-svn: 190031
2013-09-05 04:27:17 +00:00
Shankar Easwaran 8c705690ab [lld][ELF] Differentiate between Note sections(RW/RO)
It looks like there is a possibility of seeing RO/RW note sections
and we would need to create an appropriate RO/RW segment associated
with them.

Adds a test too.

llvm-svn: 189907
2013-09-04 02:42:02 +00:00
Rui Ueyama 959aebf873 [PECOFF] Ignore options starting with -?
The compiler is allowed to add a linker option starting with -?<name> to
.drectve section. If the linker can interpret -<name>, it's processed as if
there's no question mark there. If not, such option is silently ignored.

This is a COFF's feature to allow the compiler to emit new linker options
while keeping compatibility with older linkers.

llvm-svn: 189897
2013-09-04 00:51:51 +00:00
Shankar Easwaran b85f1857a1 [lld][ELF] Emit note sections
Emit note sections if the input contains a note section.

Also emit a note segment.

llvm-svn: 189896
2013-09-04 00:51:42 +00:00
Joerg Sonnenberger 33a6d3aaed Recognize -rpath-link option and add arguments to ELFLinkingContext.
llvm-svn: 189883
2013-09-03 23:28:51 +00:00
Shankar Easwaran d3b3d71a3a [lld] Remove bitfield for boolean members
llvm-svn: 189876
2013-09-03 22:55:45 +00:00
Shankar Easwaran 2f5d64062b [lld] handle the case of errors from createLinkerInput
This changes the interface of createLinkerInput to use ErrorOr, so that
errors from the linker can be captured.

Also adds a convenience function for error strings to be returned from
file nodes.

llvm-svn: 189871
2013-09-03 22:44:37 +00:00
Rui Ueyama b4170b17d4 [PECOFF] Fix fixme by making PECOFFLinkingContext non-const.
llvm-svn: 189865
2013-09-03 22:33:56 +00:00
Joerg Sonnenberger a82839593c Finish -rpath implementation to actually create the DT_RPATH entries.
llvm-svn: 189847
2013-09-03 20:45:09 +00:00
Joerg Sonnenberger 840d3daf01 Add support for --sysroot.
llvm-svn: 189826
2013-09-03 16:29:02 +00:00
Rui Ueyama 0e70a16419 Do not add entry symbol to the dead strip list. Partially revert r189776.
llvm-svn: 189778
2013-09-03 03:34:33 +00:00
Rui Ueyama 504962f714 Partially revert r189718 to add entry symbol to dead strip root.
Also added a test to verify that entry symbol is not stripped even if
dead stripping is enabled.

llvm-svn: 189776
2013-09-03 01:00:01 +00:00
Shankar Easwaran 2e4424b431 [lld][ELF] Add Init/Fini support
This creates .init_array/.fini_array section for X86_64 ELF
targets and executes init/fini functions specified by the
-init/-fini options respectively.

llvm-svn: 189719
2013-08-31 05:27:44 +00:00
Shankar Easwaran d26c8e3463 [lld][LinkingContext] Atoms created from command line options should be available in YAML
This adds an API to the LinkingContext for flavors to add Internal files
containing atoms that need to appear in the YAML output as well, when -emit-yaml
switch is used.

Flavors can add more internal files for other options that are needed.

llvm-svn: 189718
2013-08-31 05:27:38 +00:00
Rui Ueyama 981892ab71 Fix build breakage
llvm-svn: 189714
2013-08-31 01:36:36 +00:00
Rui Ueyama e45f37d238 Remove #include, for we don't need the definitions of these classes.
llvm-svn: 189713
2013-08-31 01:28:45 +00:00
Rui Ueyama 51991fed70 Remove dead code.
llvm-svn: 189708
2013-08-30 23:53:06 +00:00
Rui Ueyama bc839fcd3e [PECOFF] Enable dead-stripping by default to match link.exe behavior.
llvm-svn: 189308
2013-08-27 03:38:18 +00:00
Rui Ueyama 4c3184f3c0 Treat entry point symbol as an undefined atom.
With this patch the entry symbol is treated as an undefined symbol, to force
the resolver to resolve the entry symbol.

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

llvm-svn: 189307
2013-08-27 03:18:11 +00:00
Rui Ueyama 352e7308c0 Rename ti -> ctx.
This should have been done in r187823 when I renamed LinkingContext
from TargetInfo. I missed a few files.

llvm-svn: 189298
2013-08-27 00:04:42 +00:00
Rui Ueyama c7ef7a8dd7 [PECOFF] Add Support for entry point symbol name
Patch by Jesús Serrano García.

llvm-svn: 189267
2013-08-26 19:55:09 +00:00
Rui Ueyama 72165ec8c3 Separates /fixed (no .reloc section) and /dynamicbase (enable ASLR)
in order to match link.exe's behaviour.

Patch by Ron Ofir.

llvm-svn: 189159
2013-08-24 00:39:10 +00:00
Shankar Easwaran d9e0a49357 [lld][ELF] Rename typeTLV content type for ELF
typeTLV content type is used by Darwin to represent thread local
storage. A new contentType has to be made to represent ELF
thread local storage data. These have been set to

- typeThreadZeroFill (represents TBSS storage)
- typeThreadData     (represents TDATA storage)

llvm-svn: 189137
2013-08-23 20:03:28 +00:00
Shankar Easwaran d17ba4bd4d [lld] handle typeZeroFill atoms in ELF/Native/YAML
BSS atoms dont take any file space in the Input file. They are associated
with a contentType(typeZeroFill). Similiar zero fill types also exist which
have the same meaning in terms of occupying file space in the Input.

These atoms have to be handled seperately when writing to the
lld's intermediate file or the lld test infrastructure.

Also adds a test.

llvm-svn: 189136
2013-08-23 20:03:21 +00:00
Shankar Easwaran c48b9594b6 [lld][PECOFF] Fix use of temporary strings
llvm-svn: 189025
2013-08-22 15:37:09 +00:00
Shankar Easwaran 5677e433d6 fix build failures on platforms that use -Wunused-private-variable for builds
llvm-svn: 188983
2013-08-22 04:24:57 +00:00
Shankar Easwaran 88d0d44635 [lld] Fix unused private fields for fixing build failure on darwin
llvm-svn: 188978
2013-08-22 01:49:16 +00:00
Shankar Easwaran c4dba32d19 [lld] Fix win7 failure on adding InputGraph functionality
llvm-svn: 188961
2013-08-21 23:13:22 +00:00
Shankar Easwaran e44104b001 add InputGraph functionality
llvm-svn: 188958
2013-08-21 22:57:10 +00:00
Rui Ueyama 02d0bf0f80 Fix spelling error. s/Libary/Library/g.
llvm-svn: 188049
2013-08-09 04:19:54 +00:00
Rui Ueyama 0ca149fce9 Rename TargetInfo -> LinkingContext.
Also change some local variable names: "ti" -> "context" and
"_targetInfo" -> "_context".

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

llvm-svn: 187823
2013-08-06 22:31:59 +00:00
Rui Ueyama 3e0bbb4b02 [PECOFF][Driver] Add a library file even if it does not exist.
Missing files will be reported as errors in the later pass, so this patch
does not change the behavior of the LLD linker, but it helps writing unit
tests for the driver.

llvm-svn: 187256
2013-07-26 22:17:08 +00:00
Rui Ueyama fd50283c3c [PECOFF] Add /include command line option.
The /include command line option is equivalent to Unix --undefined
option, which forces the linker to resolve the given symbol name
as if it's an unresolved symbol in one of its input files. This feature
is used to link an additional object file or a shared library that no
input files refer to.

llvm-svn: 187084
2013-07-24 22:53:23 +00:00
Rui Ueyama fbf5763708 [PECOFF] Support -tsaware:no command line option.
llvm-svn: 186957
2013-07-23 17:17:19 +00:00
Rui Ueyama 6a41fca856 [PECOFF] Support -fixed command line option to disable base relocations.
llvm-svn: 186911
2013-07-23 01:29:50 +00:00
Nick Kledzik 91a85457e9 [mach-o] factor out all cputype <-> arch conversions to one table driven location
llvm-svn: 186755
2013-07-20 02:08:23 +00:00
Rui Ueyama 8e6c8f850d [PECOFF][Driver] Add -base command line option.
llvm-svn: 186739
2013-07-20 00:45:00 +00:00
Rui Ueyama 2897feb7e0 [PECOFF] Use library search path when looking for a .lib file.
llvm-svn: 186645
2013-07-19 02:18:25 +00:00
Rui Ueyama 9f24922bd1 [PECOFF][Driver] Add -libpath command line option.
The logic to search a library from the library paths will be implemented
in a different patch.

llvm-svn: 186644
2013-07-19 01:38:49 +00:00
Nick Kledzik 762ae82d57 Add -help option to Darwin Driver. Use grouping in Options table to better format help output
llvm-svn: 186640
2013-07-19 01:02:49 +00:00
Nick Kledzik a121053471 Add support for -all_load. Enhance DarwinLdDriverTest unit test test cases to test all options parsed so far
llvm-svn: 186626
2013-07-18 23:13:13 +00:00
Rui Ueyama b0b1d590ab [WinLink] Add /LargeAddressAware command line option.
llvm-svn: 186428
2013-07-16 17:20:38 +00:00
Rafael Espindola 66c0a65ba1 Revert "Don't pass llvm::errs() all over the place. Diagnostics always go to stderr."
This reverts commit 185657. It will be used by unit tests.

llvm-svn: 186366
2013-07-15 23:55:07 +00:00
Rui Ueyama c8a53795ab [PECOFF] Support linking against DLL.
This patch adds a new pass, IdataPass, to transform shared atom references
to real references and to construct the .idata section data. With this patch
lld can produce a working Hello World program by linking it against
kernel32.dll and user32.dll.

Reviewers: Bigcheese

CC: llvm-commits

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

llvm-svn: 186071
2013-07-11 08:46:21 +00:00
Rafael Espindola 2530f67116 Don't pass llvm::errs() all over the place. Diagnostics always go to stderr.
llvm-svn: 185657
2013-07-04 17:06:04 +00:00
Rafael Espindola 611db946c2 Return 0 when processing --help. This matches gnu ld and gold.
llvm-svn: 185655
2013-07-04 16:50:47 +00:00
Rui Ueyama 2fa2a727bb Removed unused friend declaration.
llvm-svn: 185420
2013-07-02 11:13:43 +00:00
Shankar Easwaran 2302bd5568 [lld] rename member variable name.
This renames variable name to reflect initial undefined symbols that are
defined by the linker -u option.

This doesnot change any functionality in lld, and updates code to reflect
Nick's comment.

llvm-svn: 184682
2013-06-24 03:22:51 +00:00
Rui Ueyama 7b7b0b9f7d Removed unnecessary "class" keyword.
llvm-svn: 184589
2013-06-21 19:59:15 +00:00
Rui Ueyama bf402d6643 Removed unnecessary "class" keyword.
llvm-svn: 184585
2013-06-21 19:30:16 +00:00
Rui Ueyama 55fc544e65 Fix typo in include guard.
llvm-svn: 184521
2013-06-21 02:29:54 +00:00
Shankar Easwaran 89488966bd [TargetInfo] Undefined symbols move from ELFTargetInfo to TargetInfo
This change moves the functionality of undefinedSymbols that were created in
ELFTargetInfo into TargetInfo. Looks like MachO/Windows use similiar options
like in ELF for creating undefined symbols when the linker is invoked.

Address comment from Ruiu.

(No change in functionality, except moving the functionality from ELF to
TargetInfo, so that multiple architectures can use the same)

llvm-svn: 184398
2013-06-20 04:27:21 +00:00
Shankar Easwaran 53caafebdb [ELF] add -u/--undefined option, to define undefined symbols
llvm-svn: 184266
2013-06-19 00:31:09 +00:00
Rui Ueyama d95a155af6 [PECOFF] Connect defined atoms with layout before/after edges.
Reviewers: shankarke

CC: llvm-commits

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

llvm-svn: 184085
2013-06-17 16:59:54 +00:00
Rui Ueyama e96044a370 [lld] Move AtomLayout from ELF to ReaderWriter so that it can be used by non-ELF writers.
Reviewers: Bigcheese

CC: llvm-commits

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

llvm-svn: 184061
2013-06-16 17:14:58 +00:00
Shankar Easwaran a42a473893 [ELF] add NMAGIC/OMAGIC support
llvm-svn: 184055
2013-06-16 05:06:28 +00:00
Rui Ueyama 4a4079e839 [WinLink] Support /nxcompat command line option.
llvm-svn: 184050
2013-06-16 03:07:08 +00:00
Rui Ueyama 8338716e8d [ARM] Remove isThumb() as it's not used and it's not in the right place.
Architecture specific code should reside in architecture specific directory
not in Atom. Looks like there are no efforts being made at this moment to
support ARM, so let's remove it for now.

Reviewers: Bigcheese

CC: llvm-commits

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

llvm-svn: 183877
2013-06-13 00:26:16 +00:00
Rafael Espindola c1b32686fe Factor duplicated yamlReader creation.
The yaml reader is not specific to any file format. This patch moves
it to TargetInfo and makes validate a non virtual interface so that it
can be constructed from a single location.

The same method will be used to create a reader for llvm bitcode
files.

llvm-svn: 183740
2013-06-11 12:36:05 +00:00
Rui Ueyama b07cebffb2 [PECOFF] Add comments for symbols.
llvm-svn: 183700
2013-06-10 22:09:21 +00:00
Rui Ueyama 9dd08d912d [PECOFF][Driver] Add -heap command line option.
llvm-svn: 183622
2013-06-08 22:59:10 +00:00
Rui Ueyama eb0cc96e4b [PECOFF][Driver] Add -stack command line option.
llvm-svn: 183604
2013-06-08 03:59:00 +00:00
Rui Ueyama 7b5592bc0b [WinLink] Fix use-after-return.
llvm-svn: 183603
2013-06-08 03:39:35 +00:00
Rui Ueyama a6b71cabb3 [LayoutPass] Add a method to check the followon graph structure.
Found that having a method to check the strucutre of the followon graph makes
it easy to debug file readers. The method checks if there's no wrong edge in
followOnNexts and followOnRoots. It is called only when debuggging is enabled
for LayoutPass.

Reviewers: shankarke

CC: llvm-commits

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

llvm-svn: 183553
2013-06-07 20:18:39 +00:00
Rui Ueyama 8d6151fd29 [PECOFF][Writer] Implement the writer that can emit text section.
lld can now output a valid Windows executable with a text section that does nothing
but just returns immediately. It's not able to handle relocations, symbol tables,
data sections, etc, so it still can't do anything practical, though.

Reviewers: Bigcheese

CC: llvm-commits

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

llvm-svn: 183478
2013-06-07 01:31:51 +00:00
Rui Ueyama 143672c7e5 [lld][ELF] Add parser for linker script ENTRY command
This is the parser for the ENTRY command. Note that because the parsing result
is currentlyd discarded, lld can parse but just ignore the command.

Reviewers: Bigcheese

CC: llvm-commits

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

llvm-svn: 183141
2013-06-03 18:05:21 +00:00
Rui Ueyama ce42bcc304 [WinLink][Driver] Add support for -subsystem optional OS version number.
llvm-svn: 182988
2013-05-31 06:30:10 +00:00
Shankar Easwaran a5008e3a63 [lld][elf] Add --dynamic-linker option to the ELF linker.
Users can override the default value of the dynamic linker to be set to the
one that appears in the command line. The path can even be empty!. 

Added a test for the option.

llvm-svn: 182889
2013-05-29 22:51:01 +00:00
Rui Ueyama 81247063bf [WinLink] Add -subsystem and -out command line option parsing.
The code to actually consume these flags will be added soon.

llvm-svn: 182824
2013-05-29 05:07:49 +00:00
Michael J. Spencer 5b904eccad [Core] Add parallel_for_each.
llvm-svn: 182794
2013-05-28 19:09:39 +00:00
Michael J. Spencer 0d9d3110c7 [Passes] Parallelize the layout pass sort.
llvm-svn: 182792
2013-05-28 19:03:29 +00:00
Michael J. Spencer bd66d04f34 Instrument things.
llvm-svn: 182789
2013-05-28 18:55:39 +00:00
Rui Ueyama 9e56839a83 [lld][PECOFF] Add WinLinkDriver and PECOFFTargetInfo.
Add WinLinkDriver and connect it to the existing COFF reader. Remaining
parts are still stubs, so while it can now read a COFF file, it still
cannot link or output PE/COFF files yet.

Reviewers: Bigcheese

CC: llvm-commits

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

llvm-svn: 182784
2013-05-28 18:13:31 +00:00
Rui Ueyama 25c208c020 [lld][LayoutPass] Add comment on _followOn{Nexts,Roots}.
Reviewers: shankarke

CC: llvm-commits

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

llvm-svn: 182595
2013-05-23 17:43:39 +00:00
Rui Ueyama 972b0d3b0c [lld] Fix wrong content permission bit.
Summary: "W" bit value was not consistent in ContentPermissions enum. It should always be 2.

Reviewers: kledzik

CC: llvm-commits

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

llvm-svn: 182515
2013-05-22 21:13:21 +00:00
Shankar Easwaran 9af77a2cab [lld][ELF][All Archs] Addend is used by dynamic relocations
only if they are relative. This removes the FIXME when the
relocations are being emitted and checks if the relocation
is relative and only then populates the addend information.

I couldnt add a testcase for this as llvm-readobj lacks     
functionality of printing dynamic relocations.              

When the functionality is added, remove the commented lines
from elf/ifunc.test to test functionality.

llvm-svn: 182077
2013-05-17 05:10:30 +00:00
Rui Ueyama ca8ca55b52 [lld][LayoutPass] Split buildFollowOnTable for readability.
Summary:
Split buildFollowOnTable to small functions to improve
code readability and remove code duplication. No change
in functionality.

CC: llvm-commits

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

llvm-svn: 181749
2013-05-14 00:41:52 +00:00
Rui Ueyama 980e52d7ae [lld][Core] Fix latch synchronization bug.
We need to acquire a lock before signal a condition.
Otherwise threads waiting on a condition variable can
miss a signal.

Consider two threads: Thread A executing dec() and thread
B executing sync(). The initial value of _count is 1. If
these two threads are interleaved in the following order,
thread B misses the signal sent by thread A, because at the
time thread A sends a signal, B is not waiting for it.

  Thread A                 |   Thread B
                           |   std::unique_lock<std::mutex> lock(_condMut);
                           |   while (!(_count == 0)) {
  if (--_count == 0)       |
    _cond_notify_all()     |
                           |     _cond.wait();
                           |   }

Note that "wait(lock, pred)" is equivalent to "while(!pred())
wait(lock)", so I expanded it in the above example.

Reviewers: Bigcheese

CC: llvm-commits

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

llvm-svn: 181484
2013-05-08 23:29:24 +00:00
Rui Ueyama ec504cfffd [lld] Add "explicit" to constructors where appropriate.
Summary:
Add the explicit keyword to one-parameter
constructors to prevent unintended type conversions.

CC: llvm-commits

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

llvm-svn: 181483
2013-05-08 23:20:53 +00:00