Commit Graph

1922 Commits

Author SHA1 Message Date
Rui Ueyama
286691ad5e [PECOFF] Set DLL bit in PE header if DLL.
Windows loader can load a DLL without this bit but it wouldn't
call the initializer function in the DLL if the bit is absent.

llvm-svn: 213216
2014-07-17 00:22:26 +00:00
Nick Kledzik
9185115abb Update .gitignore to ignore hidden MacOSX Finder droppings
llvm-svn: 213195
2014-07-16 21:01:17 +00:00
Nick Kledzik
2458bec7e7 [mach-o] refactor KindHandler into ArchHandler and simplify passes.
All architecture specific handling is now done in the appropriate
ArchHandler subclass.

The StubsPass and GOTPass have been simplified.  All architecture specific
variations in stubs are now encoded in a table which is vended by the
current ArchHandler.

llvm-svn: 213187
2014-07-16 19:49:02 +00:00
Simon Atanasyan
64c0ac2b35 [ELF] Implement parsing -l prefixed items in the GROUP linker script command.
There are two forms of `-l` prefixed expression:

* -l<libname>
* -l:<filename>

In the first case a linker should construct a full library name
`lib + libname + .[so|a]` and search this library as usual. In the second case
a linker should use the `<filename>` as is and search this file through library
search directories.

The patch reviewed by Shankar Easwaran.

llvm-svn: 213077
2014-07-15 17:17:30 +00:00
Simon Atanasyan
35ad71adad [Mips] Fix test case expectations due the latest changes in the LLVM.
llvm-svn: 212949
2014-07-14 15:31:47 +00:00
Simon Atanasyan
355f7ed602 [Mips] Remove unused test input file.
llvm-svn: 212927
2014-07-14 08:54:40 +00:00
Simon Atanasyan
c97126b1c9 [Mips] Make rel-dynamic-11.test test case independent from external input files.
llvm-svn: 212813
2014-07-11 13:42:04 +00:00
Rui Ueyama
aea2bcf559 [PECOFF] s/context/ctx/ for consistency.
llvm-svn: 212766
2014-07-10 21:55:28 +00:00
Rui Ueyama
8cb0f1e3c0 [PECOFF] Set resource table entry in header.
The resource table entry should have the RVA of the
embedded resource file.

llvm-svn: 212765
2014-07-10 21:43:19 +00:00
Rui Ueyama
31fd9d09b2 [PECOFF] Invoke cvtres.exe in the driver.
Previously we invoked cvtres.exe for each compiled Windows
resource file. The generated files were then concatenated
and embedded to the executable.

That was not the correct way to merge compiled Windows
resource files. If you just concatenate generated files,
only the first file would be recognized and the rest would
be ignored as trailing garbage.

The right way to merge them is to call cvtres.exe with
multiple input files. In this patch we do that in the
Windows driver.

llvm-svn: 212763
2014-07-10 20:53:37 +00:00
Simon Atanasyan
d092f0e64a [Mips] Make rel-dynamic-10.test test case independent from external input files.
llvm-svn: 212758
2014-07-10 19:47:23 +00:00
Tim Northover
73c532e8a9 [mach-o]: support -Z option to skip standard library paths
llvm-svn: 212713
2014-07-10 11:46:13 +00:00
Tim Northover
18af0573df [mach-o]: support user-specified (-L) library search paths
llvm-svn: 212712
2014-07-10 11:46:08 +00:00
Tim Northover
77d82202d1 [mach-o]: support -syslibroot and -l options
These behave slightly idiosyncratically in the best of cases, and have
additional hacks layered on top of that for compatibility with badly behaved
build systems (via ld64).

For -lXYZ:
  + If XYZ is actually XY.o then search all library paths for XY.o
  + Otherwise search all library paths, first for libXYZ.dylib, then libXYZ.a
  + By default the library paths are /usr/lib and /usr/local/lib in that order.

For -syslibroot:
  + -syslibroot options apply to absolute paths in the search order.
  + All -syslibroot prefixes that exist are added to the search path *instead*
    of the original.
  + If no -syslibroot prefixed path exists, the original is kept.
  + Hacks^WExceptions:
      + If only 1 -syslibroot is given and doesn't contain /usr/lib or
        /usr/local/lib, that path is dropped entirely. (rdar://problem/6438270).
      + If the last -syslibroot is "/", all of them are ignored entirely.
        (rdar://problem/5829579).

At least, that's my best interpretation of what ld64 does in buildSearchPaths.

llvm-svn: 212706
2014-07-10 11:21:06 +00:00
Nick Kledzik
0edfdeb0be Move GOTPass and StubsPass from Core to MachO
llvm-svn: 212652
2014-07-09 21:04:24 +00:00
Tim Northover
b44143f496 [all]: Use range-based ArgList adapter instead of filtered_begin/filtered_end
Some of those loops were pretty monstrous.

llvm-svn: 212616
2014-07-09 13:03:54 +00:00
Simon Atanasyan
0acd5447b4 [Mips] Make rel-dynamic-08.test test case independent from external input files.
llvm-svn: 212613
2014-07-09 12:31:11 +00:00
Nick Kledzik
2552a09978 Change llvm-nm to use -M instead of -s to work with latest llvm-nm
llvm-svn: 212579
2014-07-09 00:25:52 +00:00
Rui Ueyama
39dc40af07 [PECOFF] Fix .bss section alignment
Previously the alignment of the .bss section was not
properly set because of a bug in AtomizeDefinedSymbolsInSection.
We set the alignment of the section at the end of the function,
but we use an eraly return for the .bss section, so the code had
been skipped.

llvm-svn: 212571
2014-07-08 23:11:01 +00:00
Simon Atanasyan
e693e8f8f0 [Mips] Make rel-dynamic-07.test test case independent from external input files.
llvm-svn: 212542
2014-07-08 15:47:55 +00:00
Simon Atanasyan
49eafe909b [Mips] Make rel-dynamic-05.test test case independent from external input files.
llvm-svn: 212480
2014-07-07 20:14:49 +00:00
Simon Atanasyan
611b7a11b5 [Mips] Make rel-dynamic-04.test test case independent from external input files.
llvm-svn: 212409
2014-07-06 17:44:40 +00:00
Rafael Espindola
c2199ecf1e Update for llvm api change.
llvm-svn: 212407
2014-07-06 17:43:22 +00:00
Iain Sandoe
9734a53cf0 Fix build of DriverTests for config & make.
This adjusts the USED library list following recent changes in the object
file heirarchy.

llvm-svn: 212400
2014-07-06 11:28:56 +00:00
Rafael Espindola
22c187be1d Update for llm api change.
llvm-svn: 212372
2014-07-05 11:39:02 +00:00
Simon Atanasyan
778c029e04 Remove redundant "Standard: Cpp11" tag. The LLVM style has used the
Cpp11 standard since r202637.

llvm-svn: 212336
2014-07-04 12:08:03 +00:00
Nick Kledzik
4576c115ac [mach-o] Add parsing of arm/thumb relocations
This converts the very complicated mach-o arm
relocations into the simple Reference Kinds in lld.

The next patch will use the internal Reference kinds
to fix up arm/thumb code.

llvm-svn: 212306
2014-07-04 00:11:09 +00:00
Tim Northover
ca2e63daf8 [mach-o]: remove dylib install-name test with a.out
Unfortunately, the creation of (the default) output file, a.out races with all
the other tests in this directory. When the wrong one is read by macho-dump,
the test fails.

llvm-svn: 212269
2014-07-03 12:50:23 +00:00
Nick Kledzik
b6e8ce8250 [mach-o] add x86 test case to build hello world. Fix bugs it uncovered.
llvm-svn: 212247
2014-07-03 02:01:21 +00:00
Nick Kledzik
cd2e17bd9c [mach-o] Fix warning on enumeration cases not handled
llvm-svn: 212241
2014-07-03 00:13:26 +00:00
Nick Kledzik
de0860aae4 [mach-o] add parsing of x86 relocations
llvm-svn: 212239
2014-07-02 23:52:22 +00:00
Rui Ueyama
408d4d470d Add missing dependency to macho-dump.
r212094 added a few tests that use macho-dump.

llvm-svn: 212200
2014-07-02 18:16:31 +00:00
Tim Northover
9bdf90e5c2 [mach-o]: make the default dylib install-name the output filename.
llvm-svn: 212094
2014-07-01 08:41:45 +00:00
Tim Northover
301c4e690a [mach-o] add representation for LC_ID_DYLIB to MachONormalizedFile
It still needs to be tied into BinaryReader, but this allows reasonably
sensible creation of SharedLibrary atoms on MachO.

llvm-svn: 212093
2014-07-01 08:15:41 +00:00
Nick Kledzik
378066c80e [mach-o] improve errors when mixing architectures
llvm-svn: 212072
2014-06-30 22:57:33 +00:00
Nick Kledzik
b201cf8883 [mach-o] x86_64 relocation code review fixes
llvm-svn: 212068
2014-06-30 20:44:47 +00:00
Tim Northover
b5bf686b58 MachO: stop iterating past the end of an array
When trying to map atom types to sections, we were iterating through an array
until we hit a sentinel value. There's no need for such dances when range-based
for loops are available.

llvm-svn: 212035
2014-06-30 10:30:00 +00:00
Tim Northover
9ee9935358 MachO: re-enable writing of compact-unwind sections.
This isn't really the right place to put them in final object files (that would
be __TEXT,__unwind_info), but the format is different between relocatable and
final objects, which means we really need a pass to handle the translation.

For now, re-emitting in __LD,__compact_unwind is harmless (dyld ignores it and
moves straight on to inspecting __TEXT,__eh_frame), and sidesteps an assertion
failure when processing files containing compact-unwind info.

llvm-svn: 212032
2014-06-30 09:49:37 +00:00
Tim Northover
7b0a1306b4 MachO: align segment virtual addresses to page size.
Segments must occupy a multiple of the page size in memory (4096 currently). We
check for this when emitting files, but the placement algorithm broke down for
the second non-__TEXT segment encountered: the offset wasn't aligned up to 4096
before starting its layout.

llvm-svn: 212031
2014-06-30 09:49:33 +00:00
Tim Northover
08d6a7bfef MachO: calculate segment offsets in final MachO files properly.
Because of how we were calculating fileOffset and fileSize for segments, most
ended up at a single offset in a finalised MachO file. This meant the data
often didn't even get written in the final object, let alone where it would be
useful.

llvm-svn: 212030
2014-06-30 09:49:30 +00:00
Tim Northover
f9b13d6766 MachO: support atomization of dylibs.
For .dylib files, we refrain from actually creating any atoms until they're
requested via the "exports" method.

llvm-svn: 212027
2014-06-30 09:11:38 +00:00
Nick Kledzik
07d2c313a9 [mach-o] fix struct initialization to work with Windows compiler
llvm-svn: 211951
2014-06-27 19:08:56 +00:00
Nick Kledzik
3f69076278 [mach-o] refactor x86_64 relocation handling.
This is first step in reworking how mach-o relocations are processed.
The existing KindHandler is going to become a delgate/helper object for
processing architecture specific references.  The KindHandler knows how
to convert mach-o relocations into References and back, as well, as fixing
up the content the relocation is on.

One of the messy things about mach-o relocations is that they sometime 
come in pairs, but the pairs still convert to one lld::Reference. So, the
conversion has to detect pairs (arch specific) and change the stride.

llvm-svn: 211921
2014-06-27 18:25:01 +00:00
Nick Kledzik
1e8dbd360d Add const to sort() comparator function. Caught by gcc but not clang
llvm-svn: 211833
2014-06-27 01:04:01 +00:00
Nick Kledzik
728d606689 Add utility to SimpleDefinedAtom to sort references
llvm-svn: 211825
2014-06-27 00:30:31 +00:00
Simon Atanasyan
65e2464667 [Driver] Improve the isPathUnderSysroot() function. Now it returns a
correct result even if checking paths: a) symlinks and/or b) contains relative
parts like /dir1/dir2/../dir2.

llvm-svn: 211772
2014-06-26 10:48:52 +00:00
Tim Northover
1565e56785 [mach-o]: make sure custom sort method is irreflexive.
The previous function returned true for "s < s", which could completely mess up
the sorting of symbols within a section.

Unfortunately, I don't think there's a robust way to write a test for this.
Anything I come up with will be making assumptions about the particular
implementation of std::sort.

llvm-svn: 211704
2014-06-25 15:12:55 +00:00
Tim Northover
f48f0620ed [mach-o]: atomize zero-terminated literals correctly.
When looking through sections with zero-terminated string-literals (__cstring
or __ustring) we were constantly rechecking the first few bytes of the string
for '\0' rather than advancing along. This obviously failed unless all strings
within the section had the same length as that first one.

llvm-svn: 211682
2014-06-25 11:21:51 +00:00
Tim Northover
36bd9ab2c5 [mach-o] don't assume all sections have symbols
We were trying to examine the first symbol in a section that we wanted to
atomize by symbols, even when there wasn't one. Instead, we should make the
initial anonymous symbol cover the entire section in that situation.

llvm-svn: 211681
2014-06-25 10:59:37 +00:00
Simon Atanasyan
d449fc8671 [ELF] Add two new virtual functions to the OutputELFWriter class to control
dynamic symbol table populating and DT_NEEDED tag creation.

The `isDynSymEntryRequired` function returns true if the specified shared
library atom requires a dynamic symbol table entry. The `isNeededTagRequired`
function returns true if we need to create DT_NEEDED tag for the shared
library defined specified shared atom.

By default the both functions return true. So there is no functional changes
for all targets except MIPS. Probably we need to spread the same modifications
on other ELF targets but I want to implement and fully tested complete set of
changes for MIPS target first.

For MIPS we create a dynamic symbol table entry for a shared library atom iif
this atom is referenced by a regular defined atom. For example, if library L1
defines symbol T1, library L2 defines symbol T2 and uses symbol T1
and executable file E1 uses symbol T2 but does not use symbol T1 we create
an entry in the E1 dynamic symbol table for symbol T2 and do not create
an entry for T1.

The patch creates DT_NEEDED tags for shared libraries contain shared library
atoms which a) referenced by regular defined atoms; b) have corresponding
copy dynamic relocations (R_MIPS_COPY).

Now the patch does not take in account --as-needed / --no-as-needed command
line options. So it is too restrictive and create DT_NEEDED tags for really
needed shared libraries only. I plan to fix that by subsequent patches.

llvm-svn: 211674
2014-06-25 07:55:55 +00:00