Commit Graph

1124 Commits

Author SHA1 Message Date
Rui Ueyama 4072d91a58 Replace duplicate code with calls to getOrPushAttribute().
llvm-svn: 194908
2013-11-16 00:55:08 +00:00
Rui Ueyama 12027e58e1 Use range-based for loop.
end() was evaluated every time through a loop. This patch eliminates it.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

llvm-svn: 193975
2013-11-04 03:24:14 +00:00
Rui Ueyama 0a5802a260 [ELF] Add missing -target option.
llvm-svn: 193974
2013-11-04 03:08:55 +00:00
Rafael Espindola 3c4739cc11 Update test now that llvm-nm prints the correct value.
llvm-svn: 193913
2013-11-02 05:21:29 +00:00
Rui Ueyama 329211bbb7 [ELF] One more file for missing -target option.
llvm-svn: 193911
2013-11-02 03:55:51 +00:00
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 d19d0bc5d2 [MachO] Fix uninitialized field bug found on Windows.
n_desc field in MachO string table was not initialized. On Unix,
test/darwin/hello-world.objtxt did not fail because I think an nlist object
is always allocated to a fresh heap initialized with zeros. On Windows,
uninitialized fields are filled with 0xCC when compiled with /GZ. Because
of that the test was failing on Windows.

llvm-svn: 193909
2013-11-02 03:35:45 +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
Rui Ueyama 450f422b49 [PECOFF] Remove unnecessary assertion.
Bugs that would be caught by this assertion would also be caught by
RoundTripYAMLPass test. We've enabled the pass for PECOFF, so we can remove
this.

llvm-svn: 193886
2013-11-01 21:11:43 +00:00
Rui Ueyama aa5b4dc868 Remove duplicate calls of pm.add() for RoundTrip tests.
llvm-svn: 193885
2013-11-01 21:05:42 +00:00
Rui Ueyama c74157ca30 Remove redundant std::move().
llvm-svn: 193883
2013-11-01 20:40:33 +00:00
Rui Ueyama 31e44e964d Whitespace
llvm-svn: 193882
2013-11-01 19:54:29 +00:00
Rui Ueyama c9752fa66d [PECOFF] Enable RoundTrip{YAML,Native}Pass.
llvm-svn: 193881
2013-11-01 19:52:37 +00:00
Rui Ueyama 1d1debf126 [PECOFF] Change data directory atom structure.
The data directory in the PE/COFF header consisted of list of data directory
atoms. This patch changes it -- now there's only one data directory entry that
contains former data directories. That's easier to handle in the writer as well
as to write to/read from YAML/Native files. The main purpose of this refactoring
is to enable RoundTrip tests for PE/COFF.

There's no functionality change.

llvm-svn: 193854
2013-11-01 05:51:15 +00:00
Rui Ueyama 39233f252b [PECOFF] File extension is case-insensitive on Windows.
llvm-svn: 193797
2013-10-31 20:06:48 +00:00
Rui Ueyama bad4565be0 Revert "[PECOFF] Add atoms to the PassManager file"
This reverts commit r193479.

The atoms are already added to the file, so re-adding them caused the YAML
writer to write the same atoms twice. That made the YAML reader to fail with
"duplicate atom name" error.

This is not the only error we've got for RoundTripYAMLPass for PECOFF, so we
cannot enable the test yet. More fixes will come.

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

llvm-svn: 193762
2013-10-31 16:59:49 +00:00
Rui Ueyama 7a1ac04fe2 Use StringRef::startswith_lower().
llvm-svn: 193712
2013-10-30 20:33:51 +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
Rui Ueyama 5c8d4dd73f [PECOFF] Suppress startup message of background processes.
llvm-svn: 193646
2013-10-29 19:52:44 +00:00
Shankar Easwaran b1ffd99b6a [FileToMutable] Garbage collect unused private member
llvm-svn: 193588
2013-10-29 05:33:52 +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