Commit Graph

517 Commits

Author SHA1 Message Date
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 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
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 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 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 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 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 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 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 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 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 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 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
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 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 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 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 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
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
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 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 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 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 dbce022caf [PECOFF] Minimum size of DOS stub is 64 byte.
llvm-svn: 194791
2013-11-15 08:00:22 +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 1c6fd20427 [PECOFF] Add tests for r194757.
llvm-svn: 194768
2013-11-15 02:31:47 +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 12f390856c Fix misleading indentation.
llvm-svn: 194550
2013-11-13 03:00:48 +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 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 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 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 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 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
Rui Ueyama 2ccdfb219d [ELF] Add missing -target options.
These tests assume that the created objects are for x86_64. These tests
failed on non-x86_64 environments, such as 32 bit Windows.

llvm-svn: 193910
2013-11-02 03:50:03 +00:00
Rui Ueyama e4aaa335dd Single-quotes to quote parentheses.
On Windows, neither "(" nor ")" are shell special characters, so -\( is passed
as-is to LLD. Because of that this test was failing on Windows.

llvm-svn: 193905
2013-11-02 02:07:37 +00:00
Rui Ueyama 9625b5435b Fix test on 32 bit.
This patch adds "-target x86_64" to the command line. Without this option,
a 32 bit object file would be created on 32 bit machine, resulting in test
failure.

llvm-svn: 193904
2013-11-02 01:55:42 +00:00
Michael J. Spencer 5fbce5bd56 [ELF] Implement minimal support for .eh_frame_hdr.
llvm-svn: 193662
2013-10-30 00:02:04 +00:00
Shankar Easwaran 51bfb820cc [test] Fix a test failure, this test is only applicable in debug mode
llvm-svn: 193586
2013-10-29 05:26:49 +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 90173df289 [PECOFF] Fix __ImageBase symbol.
__ImageBase is an absolute symbol whose address is the same as the image base
address. What we did before this patch was to create __ImageBase symbol as a
symbol whose *contents* (not location) is the image base address, which is
clearly wrong.

llvm-svn: 193565
2013-10-29 00:33:34 +00:00
Shankar Easwaran fe0b80b321 [ELF][test] Remove default section names for known contentTypes.
llvm-svn: 193483
2013-10-26 19:38:42 +00:00
Shankar Easwaran b0022c00a3 [X86_64] Fix the atom that need to be exported.
llvm-svn: 193481
2013-10-26 19:38:37 +00:00
Michael J. Spencer 707f591fa0 [ELF] Implement .{init,fini}_array ordering.
llvm-svn: 193451
2013-10-25 23:59:06 +00:00
Rui Ueyama 0145c56306 [PECOFF] Handle edge case where no section alignment is specified.
llvm-svn: 193385
2013-10-25 00:54:13 +00:00
Michael J. Spencer 28c7a21b29 [ELF] Refactor x86-64 relocation pass.
This renames the GOTPLTPass to RelocationPass and refactors it to better
represent the different types of relocations.

llvm-svn: 193379
2013-10-24 22:46:48 +00:00
Rui Ueyama 5d32d96f91 [PECOFF] Fix spelling in manifest XML.
llvm-svn: 193375
2013-10-24 22:08:19 +00:00
Michael J. Spencer 2fd6c7d91c [ELF][x86-64] Generate PLT for R_*_32S relocs.
llvm-svn: 193369
2013-10-24 21:00:25 +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 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 99d7013ef2 Run layout-transitivity test only when debugging is enabled.
Because it depends on "-mllvm -debug" flag, the test fails in Release build.

llvm-svn: 193271
2013-10-23 21:15:48 +00:00
Rui Ueyama c05fa0beab Disable layout-transitivity test on FreeBSD for now.
llvm-svn: 193259
2013-10-23 18:22:26 +00:00
Rui Ueyama af589f70d0 [PECOFF] Emit the side-by-side manifest file.
llvm-svn: 193207
2013-10-22 22:58:07 +00:00
Rui Ueyama 53e77efac3 Disable layout-transitivity test on Darwin for now.
llvm-svn: 193121
2013-10-21 22:19:27 +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 1ce8a0a8ed [PECOFF] Only COMDAT symbols are allowed to be dead-stripped.
We should dead-strip atoms only if they are created for COMDAT symbols. If we
remove non-COMDAT atoms from a binary, it will no longer be guaranteed that
the binary will work correctly.

In COFF, you can manipulate the order of section contents in the resulting
binary by section name. For example, if you have four sections
.data$unique_prefix_{a,b,c,d}, it's guaranteed that the contents of A, B, C,
and D will be consecutive in the resulting .data section in that order.
Thus, you can access B's and C's contents by incrementing a pointer pointing
to A until it reached to D. That's why we cannot dead-strip B or C even if
no one is directly referencing to them.

Some object files in the standard library actually use that technique.

llvm-svn: 193017
2013-10-18 23:54:55 +00:00
Shankar Easwaran b6c825a5cf [ELF] Set ordinals properly to all atoms.
llvm-svn: 192939
2013-10-18 02:12:17 +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 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
Shankar Easwaran 11202deb4a [ELF] Add alias options for start-group/end-group options.
There are aliases for --start-group/--end-group options represented
by -( and -) respectively in the command line.

This change adds and improves the test for the alias options to be
tested.

Looks like users use this option widely than explicitly using
--start-group/--end-group.

llvm-svn: 192470
2013-10-11 17:59:47 +00:00
Shankar Easwaran bcf36560fd [ELF] Fix Atoms in the same file had overlapping ordinals.
This also reverts the LayoutPass to use std::sort as all files
have an ordinal now.

llvm-svn: 192409
2013-10-11 01:50:04 +00:00
Shankar Easwaran 5d859e05f2 [test] Ignore failure for now for Darwin.
This is only a step to clean the buildbot.

llvm-svn: 192368
2013-10-10 17:12:50 +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 9f3a77a9f4 [PECOFF] Add files appear in .drectve to input graph
-- so that command line options to specify new input files, such as
/defaultlib:foo, is handled properly. Such options were ignored before
this patch.

llvm-svn: 192342
2013-10-10 05:39:43 +00:00
Shankar Easwaran 95d4e61411 [ELF] Change MaxAlignment to 2.
llvm-svn: 192310
2013-10-09 18:12:31 +00:00
Shankar Easwaran 091a18070b [test] Just use the exit code from the test for now.
Will fix this in later commits. Not sure why the regex is not passing.

llvm-svn: 192273
2013-10-09 04:30:17 +00:00
Shankar Easwaran 127d04a440 [test] Fix regex for failing test on bot
llvm-svn: 192270
2013-10-09 03:53:32 +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
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 d419dbcc48 [ELF] Fix uninitalized value.
llvm-svn: 191924
2013-10-03 19:25:34 +00:00
Michael J. Spencer c80f88a94e [Core] Fix heap overflow in LayoutPass.
Found this with asan. Code assumes that find doesn't return end, thus if
both atoms didn't have followon roots it would still compare their positions.

llvm-svn: 191865
2013-10-02 23:21:07 +00:00
Rui Ueyama 053d9313f2 Re-submit [PECOFF] Add a test for the import table.
llvm-svn: 191580
2013-09-27 22:48:06 +00:00
Michael J. Spencer 102f82a74e [ELF] Handle copy relocations for PC32.
This will eventually need to be refactored to better handle COPY relocations,
as other relocations can also generate them. I'm not yet sure the exact
circumstances in which they are needed yet.

llvm-svn: 191567
2013-09-27 21:30:27 +00:00
Michael J. Spencer 3b36473007 [ELF] Mark STT_GNU_IFUNC symbols as code.
llvm-svn: 191566
2013-09-27 21:30:04 +00:00
Rui Ueyama a7ec3898d6 Revert "[PECOFF] Add a test for the import table."
This reverts r191469 because the original patch this one depends on (r191472)
was reverted.

llvm-svn: 191479
2013-09-27 01:26:53 +00:00
Rui Ueyama 9eb1432a99 [PECOFF] Add a test for the import table.
llvm-svn: 191475
2013-09-27 00:56:37 +00:00
Michael J. Spencer 32a3f9ee29 [ELF] Add COPY relocations.
llvm-svn: 191467
2013-09-26 22:09:16 +00:00
Michael J. Spencer 4355bb9d22 [Core] Add type and size to SharedLibraryAtom.
llvm-svn: 191466
2013-09-26 22:08:43 +00:00
Rui Ueyama 27c88dab08 [PECOFF] Fix /? option and add a test for the flag.
llvm-svn: 191320
2013-09-24 17:59:30 +00:00
Rui Ueyama 98f269f9d1 [PECOFF] Add /swaprun:{cd,net} options.
llvm-svn: 191276
2013-09-24 04:20:37 +00:00
Rui Ueyama 456740c740 [PECOFF] Do not allow space to separate command line option and its value.
We used to support both Windows and Unix style command line options. In Windows
style, an option and its value are separated by ":" (colon). In Unix, separator
is a space. Accepting both styles were convenient, but we can no longer allow
Unix style because I found that can be ambiguous.

For example, /nodefaultlib option takes an optional argument. In Windows style
it's going to be something like "/nodefaultlib:foo". There's no ambiguity what
"foo" means. However, if the option is "/nodefaultlib foo", "foo" can be
interpreted either an optional argument for "/nodefaultlib" or an input file
"foo.obj". We should just stop accepting the non-standard command line style.

llvm-svn: 191247
2013-09-23 23:51:31 +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 724d75b2c8 [PECOFF] Add one more test for r191218
llvm-svn: 191221
2013-09-23 20:24:12 +00:00
Ron Ofir b7d3e6b76b [lld][PECOFF] Fix data directory entry RVA of base relocations section
Summary:
This patch changes WriterPECOFF to actually write down the address instead of ignoring it.
Also, it changes the order of adding the BaseReloc chunk as otherwise the address wasn't set yet.

I think a better way of doing it would be to change DataDirectoryAtom to create a Reference
instead of using a number, and to change IdataPass accordingly, but I'm not sure how to do that.

Reviewers: ruiu

Reviewed By: ruiu

CC: llvm-commits

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

llvm-svn: 191220
2013-09-23 20:21:24 +00:00
Ron Ofir 41dcb848a7 [lld][PECOFF] Calculate SizeOfHeaders field instead of using a hard-coded value
Summary: This patch changes WritePECOFF to calculate the value of the SizeOfHeaders PE header field instead of just using 512.

Reviewers: rui314, ruiu

Reviewed By: ruiu

CC: llvm-commits, ruiu

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

llvm-svn: 191212
2013-09-23 18:08:51 +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
Shankar Easwaran 70fefd515a [lld][ELF] Group command line options for better usage
llvm-svn: 191033
2013-09-19 20:07:06 +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
Shankar Easwaran 1b0256c379 [lld][YAML] RefNameResolver : add only if name/refname is not empty
llvm-svn: 190903
2013-09-17 23:38:04 +00:00
Shankar Easwaran 063b75013f [lld][ELF] Assign sectionChoice properly to ELF atoms
This sets the sectionChoice property for DefinedAtoms. The output section name
is derived by the property of the atom. This also decreases native file size.

Adds a test.

llvm-svn: 190840
2013-09-17 02:56:22 +00:00
Rui Ueyama e0e28d059b [PECOFF] Take into account all sections when setting size fields in the PE header
This patch changes lld to go through all sections while calculating the size
for SizeOfCode, SizeOfInitializedData and SizeOfUninitializedData fields in the
PE header, instead of using only a small set of hard-coded sections.

This only really changes SizeOfInitializedData which didn't include .reloc
section before this patch.

Patch by Ron Ofir.

llvm-svn: 190799
2013-09-16 17:39:26 +00:00
Rui Ueyama d5e4f637ef [PECOFF] Add DISCARDABLE characteristic to .reloc section
This patch sets the IMAGE_SCN_MEM_DISCARDABLE characteristic to the base
relocations section in order to match MS PECOFF specification.

Patch by Ron Ofir.

llvm-svn: 190798
2013-09-16 17:35:13 +00:00
Joerg Sonnenberger 97fc3834b8 Output soname.
llvm-svn: 190758
2013-09-14 19:53:51 +00:00
Joerg Sonnenberger 4263d8b35d Add _end symbol for dynamic libraries. At least brk/sbrk in libc on
NetBSD need it.

llvm-svn: 190752
2013-09-14 13:45:29 +00:00
Rui Ueyama a8ce9529c3 [PECOFF] Fix alignment bug.
There was a bug that if a section has an alignment requirement and there are
multiple symbols at offset 0 in the section, only the last atom at offset 0
would be aligned properly. That bug would move only the last symbol to an
alignment boundary, leaving other symbols unaligned, although they should be at
the same location. That caused a mysterious SEGV error of the resultant
executable.

With this patch, we manage all symbols at the same location properly, rather
than keeping the last one.

llvm-svn: 190724
2013-09-13 21:11:00 +00:00
Joerg Sonnenberger 3c6b056186 Add test case for the not-yet implemented copy relocations.
llvm-svn: 190714
2013-09-13 18:32:34 +00:00
Shankar Easwaran 2a92c18ba3 [lld][ELF] Handle multiple weak symbols
This handles multiple weak symbols which appear back to back. This fix is needed
which otherwise will lead to symbols getting initialized to arbitrary values.

There was a constructor/destructor test that really triggered this to be fixed
on X86_64.

Adds a test.

llvm-svn: 190658
2013-09-13 04:25:44 +00:00
Rui Ueyama 6f32549623 [PECOFF] Handle weak external symbols.
Used the fallback mechanism to implement COFF weak external symbols.

llvm-svn: 190633
2013-09-12 21:42:52 +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
Shankar Easwaran 2206d5ad7d [lld][tests] Fix buildbot failure on darwin
llvm-svn: 190619
2013-09-12 18:10:20 +00:00
Shankar Easwaran 2734d79d94 [lld][ELF] Fix vaddr of the first section
The first section in the output was not aligned to the alignment of the section.

llvm-svn: 190610
2013-09-12 15:43:17 +00:00
Shankar Easwaran df2dd193ee [lld][ELF] Fix the readonly section order.
This associates rodata and sections which just have the SHF_ALLOC flag
to be set to typeConstant.

llvm-svn: 190609
2013-09-12 15:43:13 +00:00
Shankar Easwaran f1b341c80e [lld][LayoutPass] Order the atoms that are in the same chain
We need to order atoms that exist in the same chain. This is to make sure that
the command line order is preserved when we emit the atoms to the output file.

Credits: BigCheese for finding the bug.

Adds a test which otherwise would fail.

llvm-svn: 190608
2013-09-12 15:43:09 +00:00
Rui Ueyama 81d0d29639 Remove hard-coded leading underscore from entry symbol.
llvm-svn: 190586
2013-09-12 05:09:01 +00:00
Joerg Sonnenberger ecd1d9bc1d Handle _DYNAMIC correctly in the x86_64 backend.
llvm-svn: 190302
2013-09-09 12:19:28 +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
Rui Ueyama 97086a5a4f [PECOFF] Fix section alignment bug in ReaderCOFF.
Patch by Ron Ofir.

llvm-svn: 190198
2013-09-06 20:08:57 +00:00
Rui Ueyama 030fe96ff3 [PECOFF] Align section contents as specified by the object file's section header.
llvm-svn: 190120
2013-09-06 04:06:58 +00:00
Shankar Easwaran 176e7fd05f [lld][ELF] Change the order of the writable note section
Writable note sections if they exist should not appear before text
they belong in the data segment

llvm-svn: 190024
2013-09-05 01:50:21 +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
Rui Ueyama 530488c92a [PECOFF] Verify parameter in validateImpl() not in the driver.
llvm-svn: 189877
2013-09-03 22:57:00 +00:00
Shankar Easwaran c16b5e76fc [lld][ELF][X86_64] Test alignment for init_array/fini_array sections
llvm-svn: 189875
2013-09-03 22:46:54 +00:00
Shankar Easwaran 2b9d1025d6 [lld][ELF] Change the InitFini atom type from Stub to Data
llvm-svn: 189873
2013-09-03 22:44:44 +00:00
Shankar Easwaran fce7952b79 [lld][ELF][Hexagon] add Init/Fini option for hexagon
This adds init/fini support for Hexagon.

llvm-svn: 189872
2013-09-03 22:44:42 +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
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
Joerg Sonnenberger 7d5aed5ce5 A weak reference to a symbol that is only weakly referenced in
dependencies should remain weak, not get promoted to undef or dropped.

llvm-svn: 189793
2013-09-03 12:06: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
Rui Ueyama 900a501bdd Add llc to check-lld deps. We use the command in lit.cfg.
llvm-svn: 189774
2013-09-02 23:26:00 +00:00
Shankar Easwaran df4f12bb65 [lld][test] organize test directory. No change in functionality
* Renames few tests which had extension objtxt to test
* created core directory that contains all the core tests

llvm-svn: 189720
2013-08-31 05:59:52 +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 d4b9d068f0 [PECOFF] Fix bug that section grouping may lay out atoms in a wrong order.
We added layout edges to the head atoms in grouped sections. That was wrong,
because the head atom needs to be followed by the other atoms in the *same*
section, not by the other section contents. With this patch, layout edges are
added from tail atom, which is the last atom in a section, to head atom.

llvm-svn: 189573
2013-08-29 07:46:23 +00:00
Rui Ueyama 79e8215f96 [PECOFF] Fix bug that atom size was sometimes wrong.
Because of a bug, the last atom of each section contained a garbage at the
end of its data. In most cases the garbage is harmless but it could have cause
SEGV.

llvm-svn: 189572
2013-08-29 07:34:58 +00:00
Rui Ueyama 9d52a94cd1 [PECOFF] Make command line options case insensitive to match link.exe's behavior.
llvm-svn: 189505
2013-08-28 20:27:41 +00:00
Rui Ueyama c4d793f2ad Remove an option starting an uppercase character so that the test does not depends on sort order.
llvm-svn: 189423
2013-08-28 00:01:57 +00:00
Rui Ueyama b5292e6295 Modify test to adopt r189416.
r189416 changed the order of command line options shown in help message,
so the test needs adjusting.

llvm-svn: 189417
2013-08-27 23:48:49 +00:00
Rui Ueyama 488d41e6ef [PECOFF] Add the entry symbol and /include symbols to dead strip root set.
Differential Revision: http://llvm-reviews.chandlerc.com/D1527

llvm-svn: 189318
2013-08-27 05:15:20 +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
Shankar Easwaran be81dd757e [lld][ELF] process fini_array sections
This change processes fini_array section in addition to processing
init_array sections. This also makes functions registered at compile
time for initialization and finalization to be run during execution

llvm-svn: 189196
2013-08-25 18:05:12 +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
Tim Northover 274a023d70 Check for "asserts" rather than "debug" on test
The debug flag being checked for seems to be controlled by whether the
build is asserts/non-asserts rather than debug/non-debug. Mostly these
correlate, but not necessarily.

As far as I can tell with various combinations of debug/assetions this
change makes no difference on autotools builds, but fixes a check-all
failure with CMake.

llvm-svn: 189147
2013-08-23 21:10:37 +00:00
Shankar Easwaran f9fe6250ff [lld][ELF] Dont ignore zero sized sections.
There may be relocations that may be pointing to the section
even if the section sizes are 0. We shouldnot ignore them
for that regard.

llvm-svn: 189139
2013-08-23 20:03:35 +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 b8b42658ea [lld][Driver] Fix the unit test for lld gnu flavor
llvm-svn: 188982
2013-08-22 03:18:01 +00:00
Shankar Easwaran c1ea4572ba [lld][Hexagon] Enable Hexagon sdata sorting test
llvm-svn: 188981
2013-08-22 03:02:17 +00:00
Shankar Easwaran e44104b001 add InputGraph functionality
llvm-svn: 188958
2013-08-21 22:57:10 +00:00
Rui Ueyama 8432d32c67 [PECOFF] Treat the common symbol as mergeable symbol.
This is a temporary measure because the semantics of the common symbol is
actually more compilcated than the simple mergeable symbol.

llvm-svn: 188235
2013-08-13 00:03:21 +00:00
Rui Ueyama 43e5fd224a [PECOFF] Fixed base images now have the IMAGE_FILE_RELOCS_STRIPPED flag
Patch by Ron Ofir.

llvm-svn: 188187
2013-08-12 18:11:35 +00:00
Rui Ueyama f1ffe8abbf [PECOFF] Trim at most one character from imported symbols.
The import name is not always the same as the symbol name. If the name/type
field in the import header is NOPREFIX or UNDECORATE, we need to strip some
characters from symbol to get its import name.

The Microsoft PE/COFF spec is vague if symbol contains more than two
consecutive characters to be stripped. We used to strip all characters,
but it doesn't seem right as we couldn't link against the system library
because of this name mangling. Looks like we shouldn't strip more than one
character.

llvm-svn: 188154
2013-08-12 04:10:00 +00:00
Daniel Dunbar bc7bfb1bee [tests] Update to use lit_config and lit package, as appropriate.
llvm-svn: 188093
2013-08-09 18:51:17 +00:00
Rui Ueyama 908606d0a9 [PECOFF] Create __ImageBase symbol.
__ImageBase is a symbol having 4 byte integer equal to the image base address
of the resultant executable. The linker is expected to create the symbol as if
it were read from a file.

In order to emit the symbol contents only when the symbol is actually
referenced, we created a pseudo library file to wrap the linker generated
symbol. The library file member is emitted to the output only when the member
is actually referenced, which is suitable for our purpose.

llvm-svn: 188052
2013-08-09 04:44:15 +00:00
Rui Ueyama dd72278fea [PECOFF] Support COMDAT section that contains mergeable atoms.
The COMDAT section is a section with a special attribute to tell the linker
whether the symbols in the section are allowed to be merged or not. This patch
add a function to interpret the COMDAT data and set "merge" attribute to the
atoms accordingly.

LLD supports multiple policies to merge atoms; atoms can be merged by name or
by content. COFF supports them, and in addition to that, it supports
choose-the-largest-atom policy, which LLD currently does not support. I simply
mapped it to merge-by-name attribute for now, but we eventually have to support
that policy in the core linker.

llvm-svn: 188025
2013-08-08 23:31:50 +00:00
Michael J. Spencer 238cc72ec5 Update to llvm changes.
llvm-svn: 188021
2013-08-08 22:26:50 +00:00
Rui Ueyama a05adfaa90 Update the .drectve section to remove reference to nonexistent files.
llvm-svn: 188011
2013-08-08 21:04:09 +00:00
Rui Ueyama 4ecc59afce [PECOFF] Handle .drectve section.
Summary:
The .drectve section contains linker command line options, and the linker is
expected to interpret them as if they were given via the command line. In this
patch, the command line parser in the driver is called from the object file
reader to parse the string.

I think this patch is important, because this is the first step towards mutable
TargetInfo. We had a discussion about that on llvm-commits mailing list before.
I haven't removed "const" from the function signature yet. Instead, I just use
cast to remove "const". This is a temporary aid for an experiment. If we don't
see any issue with this mutable TargetInfo appraoch, I'll change the function
signature, and rename the class LinkerContext from TargetInfo.

Reviewers: kledzik

CC: llvm-commits

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

llvm-svn: 187677
2013-08-02 21:26:14 +00:00
Rui Ueyama 8a14aa1bd9 [PECOFF] Relocations now take into account the address which is stored at the relocation site
Patch by Ron Ofir.

llvm-svn: 187664
2013-08-02 18:40:50 +00:00
Rui Ueyama 8344be8407 [PECOFF] A symbol with symbol with section number 0 and non-zero value represents a BSS atom.
llvm-svn: 187645
2013-08-02 05:25:31 +00:00
Rui Ueyama dcf09476ff [PECOFF] Emit BSS section.
llvm-svn: 187460
2013-07-30 22:56:46 +00:00
Rui Ueyama b469aeb164 [PECOFF] Process Import Name/Type field in the import library.
This patch removes hacky mangle() function, which strips all decorations
uncondtitionally. LLD now interprets Import Name/Type field in the import
library properly as described in the Microsoft PE/COFF Spec.

llvm-svn: 187388
2013-07-29 22:55:39 +00:00
Rui Ueyama 5b274f3414 Fix test failure introduced in r187271 by enabling pipefail.
llvm-svn: 187381
2013-07-29 21:50:33 +00:00
Rui Ueyama c3ab5117c9 [PECOFF] Skip a section if there's no atom in the section.
Some sections, such as with IMAGE_SCN_LNK_REMOVE attribute, is skipped
in the first pass. Such sections need to be skipped in the latter passes.

llvm-svn: 187281
2013-07-27 00:37:50 +00:00
Rui Ueyama d5b49de621 [PECOFF] Don't set IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE if "-fixed" is provided
Based on Ron Ofir's patch.

llvm-svn: 187221
2013-07-26 17:30:39 +00:00
Reid Kleckner f33c0e3a5f Use env in a pecoff test so it passes with the lit shell test runner
llvm-svn: 187170
2013-07-25 23:20:21 +00:00
Reid Kleckner 818104899e Add yaml2obj to check-lld deps, since the PECOFF tests need it
llvm-svn: 187165
2013-07-25 23:05:13 +00:00
Rui Ueyama de25a69531 [PECOFF][Driver] Allow multiple /include options.
llvm-svn: 187100
2013-07-25 02:57:39 +00:00
Rui Ueyama d1d116aa89 [PECOFF] Use Windows style options instead of Unix style as primary options.
LLD still accepts both Unix and Windows style options when it's run as
link.exe. This patch does not change functionality.

llvm-svn: 187086
2013-07-24 23:18:02 +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
Nick Kledzik 2815782831 Add lit magic so that lld unittests are run as part of lld test suite
llvm-svn: 187005
2013-07-23 23:42:17 +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
Rui Ueyama 8e6c8f850d [PECOFF][Driver] Add -base command line option.
llvm-svn: 186739
2013-07-20 00:45:00 +00:00
Rui Ueyama 99f80cf4a7 [PECOFF][Driver] Process "LINK" environment variable.
llvm-svn: 186654
2013-07-19 05:06:20 +00:00
Rui Ueyama 64b29d616b [PECOFF][Driver] Add -defaultlib command line option.
llvm-svn: 186650
2013-07-19 04:11:37 +00:00
Rui Ueyama 5a7bbce587 [PECOFF][Driver] Interpret "LIB" environment variable.
llvm-svn: 186648
2013-07-19 03:27:03 +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
Nick Kledzik 4f44eff707 build lld unittests as part of lld-test target
llvm-svn: 186441
2013-07-16 18:46:48 +00:00
Rui Ueyama 341a2b4b5d [PECOFF][Writer] Emit .reloc section.
Emit .reloc section. This is the first step to support DLL creation. The
executable doesn't need .reloc section, but the DLL does.

Reviewers: Bigcheese

CC: llvm-commits

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

llvm-svn: 186336
2013-07-15 18:43:01 +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
Rui Ueyama a3635b7b3b [PECOFF][Writer] Fixed a bug that an empty section is emit to the section header.
llvm-svn: 186066
2013-07-11 05:43:38 +00:00
Rui Ueyama d769cec6e3 [PECOFF] Use yaml2obj to avoid checking in binary files.
llvm-svn: 185690
2013-07-05 10:41:44 +00:00
Rafael Espindola 305ac7ebe6 Add 'not' to command lines that are expected to fail.
llvm-svn: 185658
2013-07-04 17:08:11 +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 130a6eb7fa Try to guard a test that requires DEBUG().
This is a follow-up patch for r185524. Being assert enabled does not mean
that DEBUG() is enabled, so we need to check the existence of DEBUG() itself.

llvm-svn: 185619
2013-07-04 09:29:47 +00:00
Rui Ueyama 4eca75df00 [PECOFF][Writer] Fix SizeOfImage header. It should include the first unmapped page.
llvm-svn: 185534
2013-07-03 12:55:56 +00:00