Commit Graph

1101 Commits

Author SHA1 Message Date
Shankar Easwaran 178324d903 [LinkingContext] Limit shared library undefined atoms to be added.
This adds functionality to limit shared library undefined atoms to be added
only once by the Resolver.

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

Also adds a test to verify the change.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

llvm-svn: 194727
2013-11-14 20:52:28 +00:00
Rui Ueyama 73ca00ca72 Test for r194671.
llvm-svn: 194723
2013-11-14 19:18:54 +00:00
Rui Ueyama fef5d42ef3 Fix trailing whitespace and indentation.
llvm-svn: 194722
2013-11-14 19:18:52 +00:00
Rui Ueyama 83ad675dd3 Use makeArrayRef(). No functionality change.
llvm-svn: 194721
2013-11-14 18:57:34 +00:00