Commit Graph

2666 Commits

Author SHA1 Message Date
Benjamin Kramer dd13643b97 MC: Shrink MCSymbolRefExpr by only storing the bits we need.
32 -> 16 bytes on x86_64. NFC.

llvm-svn: 219574
2014-10-11 17:57:27 +00:00
Benjamin Kramer 3e67db92bc MC: Bit pack MCSymbolData.
On x86_64 this brings it from 80 bytes to 64 bytes. Also make any member
variables private and clean up uses to go through the existing accessors.

NFC.

llvm-svn: 219573
2014-10-11 15:07:21 +00:00
Sanjay Patel 352fb46d4f delete function name from comment
llvm-svn: 219443
2014-10-09 21:23:39 +00:00
Timur Iskhodzhanov 5fcaeebb72 Fix COFF section index relocation should be 16 bits, not 32
Original patch by Andrey Guskov!
http://reviews.llvm.org/D5651

llvm-svn: 219327
2014-10-08 18:01:49 +00:00
David Majnemer d7586046ee COFF: Don't oversize COMMON symbols when targeting BFD ld
COFF normally doesn't allow us to describe the alignment of COMMON
symbols.

It turns out that most linkers use the symbol size as a hint as to how
aligned the symbol should be.

However the BFD folks have added a .drectve command, which we
now support as of r219229, that allows us to specify the alignment
precisely.  With this in mind, stop rounding sizes up.

llvm-svn: 219281
2014-10-08 06:38:53 +00:00
Saleem Abdulrasool 64d491e488 MC: add support for -aligncomm GNU extension
The GNU linker supports an -aligncomm directive that allows for power-of-2
alignment of common data.  Add support to emit this directive.

llvm-svn: 219229
2014-10-07 19:37:57 +00:00
Yuri Gorshenin e8c81fd25a [asan-asm-instrumentation] CFI directives are generated for .S files.
Summary: CFI directives are generated for .S files.

Reviewers: eugenis

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D5520

llvm-svn: 219199
2014-10-07 11:03:09 +00:00
Hans Wennborg 1b1a399489 MachObjectWriter: optimize the string table for common suffices
This is a follow-up to r207670 (ELF) and r218636 (COFF).

Differential Revision: http://reviews.llvm.org/D5622

llvm-svn: 219126
2014-10-06 17:05:19 +00:00
Rafael Espindola 11527a1d71 Note that a gold bug has been fixed.
We should be able to stop working around it at some point in the future.

llvm-svn: 219115
2014-10-06 12:33:27 +00:00
Benjamin Kramer cb3e06ba00 MCParser: Modernize memory handling.
NFC.

llvm-svn: 218998
2014-10-03 18:32:55 +00:00
Daniel Sanders ef638fea2d [mips] Print warning when using register names not available in N32/64
Summary:
The register names t4-t7 are not available in the N32 and N64 ABIs.
This patch prints a warning, when those names are used in N32/64,
along with a fix-it with the correct register names.

Patch by Vasileios Kalintiris

Reviewers: dsanders

Reviewed By: dsanders

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D5272

llvm-svn: 218989
2014-10-03 15:37:37 +00:00
Bradley Smith 7a77075530 Extend C disassembler API to allow specifying target features
llvm-svn: 218682
2014-09-30 16:31:40 +00:00
Hans Wennborg f26bfc1671 WinCOFFObjectWriter: optimize the string table for common suffices
This is a follow-up from r207670 which did the same for ELF.

Differential Revision: http://reviews.llvm.org/D5530

llvm-svn: 218636
2014-09-29 22:43:20 +00:00
Hans Wennborg ba80b5d43c WinCOFFObjectWriter.cpp: make write_uint32_le more efficient
llvm-svn: 218574
2014-09-28 00:22:27 +00:00
Reid Kleckner 81782f0cb8 MC: Use @IMGREL instead of @IMGREL32, which we can't parse
Nico Rieck added support for this 32-bit COFF relocation some time ago
for Win64 stuff. It appears that as an oversight, the assembly output
used "foo"@IMGREL32 instead of "foo"@IMGREL, which is what we can parse.

Sadly, there were actually tests that took in IMGREL and put out
IMGREL32, and we didn't notice the inconsistency. Oh well. Now LLVM can
assemble it's own output with slightly more fidelity.

llvm-svn: 218437
2014-09-25 02:09:18 +00:00
Akira Hatanaka 8e77dbbf5a Revert r218380. This was breaking Apple internal build bots.
llvm-svn: 218409
2014-09-24 20:37:14 +00:00
Benjamin Kramer ce246a13ea Replace a hand-written suffix compare with std::lexicographical_compare.
No functionality change.

llvm-svn: 218380
2014-09-24 13:19:28 +00:00
Oliver Stannard 14f97d0017 Downgrade DWARF2 section limit error to a warning
We currently emit an error when trying to assemble a file with more
than one section using DWARF2 debug info. This should be a warning
instead, as the resulting file will still be usable, but with a
degraded debug illusion.

llvm-svn: 218241
2014-09-22 10:45:16 +00:00
Ehsan Akhgari db0e7061c6 ms-inline-asm: Add a sema callback for looking up label names
The implementation of the callback in clang's Sema will return an
internal name for labels.

Test Plan: Will be tested in clang.

Reviewers: rnk

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D4587

llvm-svn: 218229
2014-09-22 02:21:35 +00:00
David Majnemer 48227a3759 MC: Support aligned COMMON symbols for COFF
link.exe:
Fuzz testing has shown that COMMON symbols with size > 32 will always
have an alignment of at least 32 and all symbols with size < 32 will
have an alignment of at least the largest power of 2 less than the size
of the symbol.

binutils:
The BFD linker essentially work like the link.exe behavior but with
alignment 4 instead of 32.  The BFD linker also supports an extension to
COFF which adds an -aligncomm argument to the .drectve section which
permits specifying a precise alignment for a variable but MC currently
doesn't support editing .drectve in this way.

With all of this in mind, we decide to play a little trick: we can
ensure that the alignment will be respected by bumping the size of the
global to it's alignment.

llvm-svn: 218201
2014-09-21 09:18:07 +00:00
David Majnemer 7d0dc3ef18 MC: Fix MCSectionCOFF::PrintSwitchToSection
We had a few bugs:
- We were considering the GVKind instead of just looking at the section
  characteristics
- We would never print out 'y' when a section was meant to be unreadable
- We would never print out 's' when a section was meant to be shared
- We translated IMAGE_SCN_MEM_DISCARDABLE to 'n' when it should've meant
  IMAGE_SCN_LNK_REMOVE

llvm-svn: 218189
2014-09-20 20:40:50 +00:00
David Majnemer b8dbebb31c MC: Treat ReadOnlyWithRel and ReadOnlyWithRelLocal as ReadOnly for COFF
A problem with our old behavior becomes observable under x86-64 COFF
when we need a read-only GV which has an initializer which is referenced
using a relocation: we would mark the section as writable.  Marking the
section as writable interferes with section merging.

This fixes PR21009.

llvm-svn: 218179
2014-09-20 07:31:46 +00:00
Benjamin Kramer 04f9da8f21 Elide unnecessary DenseMap copy.
No functionality change.

llvm-svn: 218122
2014-09-19 12:26:38 +00:00
Yaron Keren d122211e60 Another required re-setting for MCStreamer::reset().
llvm-svn: 217970
2014-09-17 17:50:34 +00:00
Yaron Keren 559b47d051 Add and update reset() and doInitialization() methods to MC* and passes.
This enables reusing a PassManager instead of re-constructing it every time.

llvm-svn: 217948
2014-09-17 09:25:36 +00:00
Yaron Keren cca43c15b5 This add a reset method for WinCOFFObjectWriter, like other MC* classes.
llvm-svn: 217907
2014-09-16 21:31:04 +00:00
David Majnemer 15f7ed96ac Fix the build for MSVC, it doesn't support extended sizeof
llvm-svn: 217820
2014-09-15 20:28:38 +00:00
David Majnemer 4d57159c09 MC: Add support for BigObj
Teach WinCOFFObjectWriter how to write -mbig-obj style object files;
these object files allow for more sections inside an object file.

Our support for BigObj is notably different from binutils and cl: we
implicitly upgrade object files to BigObj instead of asking the user to
compile the same file *again* but with another flag.  This matches up
with how LLVM treats ELF variants.

This was tested by forcing LLVM to always emit BigObj files and running
the entire test suite.  A specific test has also been added.

I've lowered the maximum number of sections in a normal COFF file,
VS "14" CTP 3 supports no more than 65279 sections.  This is important
otherwise we might not switch to BigObj quickly enough, leaving us with
a COFF file that we couldn't link.

yaml2obj support is all that remains to implement.

Differential Revision: http://reviews.llvm.org/D5349

llvm-svn: 217812
2014-09-15 19:42:42 +00:00
David Majnemer 44f51e5113 Object: Add support for bigobj
This adds support for reading the "bigobj" variant of COFF produced by
cl's /bigobj and mingw's -mbig-obj.

The most significant difference that bigobj brings is more than 2**16
sections to COFF.

bigobj brings a few interesting differences with it:
- It doesn't have a Characteristics field in the file header.
- It doesn't have a SizeOfOptionalHeader field in the file header (it's
  only used in executable files).
- Auxiliary symbol records have the same width as a symbol table entry.
  Since symbol table entries are bigger, so are auxiliary symbol
  records.

Write support will come soon.

Differential Revision: http://reviews.llvm.org/D5259

llvm-svn: 217496
2014-09-10 12:51:52 +00:00
Saleem Abdulrasool fcefa21b08 MC: correct DWARF line info for PE/COFF
DWARF address ranges contain a reference to the debug_info section.  This offset
is an absolute relocation except on non-PE/COFF targets where it is section
relative.  We would emit this incorrectly, and trying to map the debug info from
the address would fail.

llvm-svn: 217317
2014-09-06 19:57:48 +00:00
Saleem Abdulrasool 5c70de1072 MC: correct DWARF header for PE/COFF assembly input
The header contains an offset to the DWARF line table for the CU.  The offset
must be section relative for COFF and absolute for others.  The non-assembly
code path for the DWARF header generation already has the correct emission for
the headers.  This corrects the assembly input path.

This was identified by BFD objecting to the LLVM generated DWARF information.

llvm-svn: 217222
2014-09-05 04:15:00 +00:00
Reid Kleckner 7c4059eb89 MC Win64: Put unwind info for COMDAT code into the same COMDAT group
Summary:
This fixes a long standing issue where we would emit many little .text
sections and only one .pdata and .xdata section. Now we generate one
.pdata / .xdata pair per .text section and associate them correctly.

Fixes PR19667.

Reviewers: majnemer

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D5181

llvm-svn: 217176
2014-09-04 17:42:03 +00:00
Benjamin Kramer 8c90fd71f7 Add override to overriden virtual methods, remove virtual keywords.
No functionality change. Changes made by clang-tidy + some manual cleanup.

llvm-svn: 217028
2014-09-03 11:41:21 +00:00
Sean Silva 888320e9fa Nuke MCAnalysis.
The code is buggy and barely tested. It is also mostly boilerplate.
(This includes MCObjectDisassembler, which is the interface to that
functionality)

Following an IRC discussion with Jim Grosbach, it seems sensible to just
nuke the whole lot of functionality, and dig it up from VCS if
necessary (I hope not!).

All of this stuff appears to have been added in a huge patch dump (look
at the timeframe surrounding e.g. r182628) where almost every patch
seemed to be untested and not reviewed before being committed.
Post-review responses to the patches were never addressed. I don't think
any of it would have passed pre-commit review.

I doubt anyone is depending on this, since this code appears to be
extremely buggy. In limited testing that Michael Spencer and I did, we
couldn't find a single real-world object file that wouldn't crash the
CFG reconstruction stuff. The symbolizer stuff has O(n^2) behavior and
so is not much use to anyone anyway. It seemed simpler to remove them as
a whole. Most of this code is boilerplate, which is the only way it was
able to scrape by 60% coverage.

HEADSUP: Modules folks, some files I nuked were referenced from
include/llvm/module.modulemap; I just deleted the references. Hopefully
that is the right fix (one was a FIXME though!).

llvm-svn: 216983
2014-09-02 22:32:20 +00:00
Pete Cooper 1175945710 Change MCSchedModel to be a struct of statically initialized data.
This removes static initializers from the backends which generate this data, and also makes this struct match the other Tablegen generated structs in behaviour

Reviewed by Andy Trick and Chandler C

llvm-svn: 216919
2014-09-02 17:43:54 +00:00
Alexey Samsonov 1b0713ce09 Fix left shifts by too large exponents in MCParser
(which happened only on error recovery path).

This bug was reported by UBSan.

llvm-svn: 216915
2014-09-02 17:25:29 +00:00
Saleem Abdulrasool d458091907 MC: remove unnecessary enumeration prefix
This is an enum class, and will be appropriately prefixed, making the encoding
type prefix redundant.  No change to any uses as the use of this was not yet
introduced.

llvm-svn: 216893
2014-09-01 23:48:29 +00:00
Craig Topper 6dc4a8bc2c Fix some cases where StringRef was being passed by const reference. Remove const from some other StringRefs since its implicitly const already.
llvm-svn: 216820
2014-08-30 16:48:02 +00:00
Aaron Ballman a4aa0d7cc0 Silence a -Wsign-compare warning. NFC.
llvm-svn: 216666
2014-08-28 13:23:26 +00:00
David Majnemer 9ab5ff1c5b MC: Don't crash when the COFF section limit is reached
I've decided not to commit a test, it takes 2.5 seconds to run on my an
incredibly strong machine.

llvm-svn: 216647
2014-08-28 04:02:50 +00:00
Rafael Espindola 3560ff2c1f Return a std::unique_ptr when creating a new MemoryBuffer.
llvm-svn: 216583
2014-08-27 20:03:13 +00:00
Rafael Espindola 9eef18c58c Remove unused argument.
llvm-svn: 216580
2014-08-27 19:49:03 +00:00
Craig Topper e1d1294853 Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or just letting them be implicitly created.
llvm-svn: 216525
2014-08-27 05:25:25 +00:00
Joerg Sonnenberger 2981591f7f Convert MC command line option for fatal assembler warnings into a
proper flag.

llvm-svn: 216471
2014-08-26 18:39:50 +00:00
Rafael Espindola 3fd1e9933f Modernize raw_fd_ostream's constructor a bit.
Take a StringRef instead of a "const char *".
Take a "std::error_code &" instead of a "std::string &" for error.

A create static method would be even better, but this patch is already a bit too
big.

llvm-svn: 216393
2014-08-25 18:16:47 +00:00
David Blaikie 1961f14cf9 Explicitly pass ownership of the MemoryBuffer to AddNewSourceBuffer using std::unique_ptr
llvm-svn: 216223
2014-08-21 20:44:56 +00:00
Alexey Samsonov e5864c69a8 Don't allow MCStreamer::EmitIntValue to output 0-byte integers.
It makes no sense and can hide bugs. In particular, it lead
to left shift by 64 bits, which is an undefined behavior,
properly reported by UBSan.

llvm-svn: 216134
2014-08-20 22:46:38 +00:00
Rafael Espindola 1c509715e6 Remove unused field.
llvm-svn: 216086
2014-08-20 17:33:44 +00:00
Tim Northover 26bb14e6a7 TableGen: allow use of uint64_t for available features mask.
ARM in particular is getting dangerously close to exceeding 32 bits worth of
possible subtarget features. When this happens, various parts of MC start to
fail inexplicably as masks get truncated to "unsigned".

Mostly just refactoring at present, and there's probably no way to test.

llvm-svn: 215887
2014-08-18 11:49:42 +00:00
Rafael Espindola f43a94e75e Remove unused member variable.
llvm-svn: 215860
2014-08-17 22:48:55 +00:00
Rafael Espindola c23174b990 Make EmitAbsValue an static helper.
llvm-svn: 215721
2014-08-15 15:12:13 +00:00
Rafael Espindola 7bb91d942b Delete dead code. NFC.
llvm-svn: 215720
2014-08-15 14:58:22 +00:00
Rafael Espindola 5e955fbd27 Make EmitDwarfSetLineAddr an static helper. NFC.
llvm-svn: 215718
2014-08-15 14:43:02 +00:00
Rafael Espindola 3851808e40 Make BuildSymbolDiff an static helper.
llvm-svn: 215717
2014-08-15 14:31:47 +00:00
Rafael Espindola ed735d3360 Make ForceExpAbs an static helper.
llvm-svn: 215715
2014-08-15 14:24:41 +00:00
Rafael Espindola adbe02435d Add a helper to MCExpr for when an expression is know to be absolute.
llvm-svn: 215713
2014-08-15 14:20:32 +00:00
Rafael Espindola d610ba99cb Remove HasLEB128.
We already require CFI, so it should be safe to require .leb128 and .uleb128.

llvm-svn: 215712
2014-08-15 14:01:07 +00:00
Rafael Espindola fe963b1764 Don't print comments to an object streamer :-)
llvm-svn: 215689
2014-08-15 03:07:13 +00:00
Rafael Espindola 91f6621edb EmitAbsValue is the same as EmitValue on non-darwin. NFC.
llvm-svn: 215688
2014-08-15 02:51:31 +00:00
Saleem Abdulrasool bb67af44e1 MC: AsmLexer: handle multi-character CommentStrings correctly
As X86MCAsmInfoDarwin uses '##' as CommentString although a single '#' starts a
comment a workaround for this special case is added.

Fixes divisions in constant expressions for the AArch64 assembler and other
targets which use '//' as CommentString.

Patch by Janne Grunau!

llvm-svn: 215615
2014-08-14 02:51:43 +00:00
Benjamin Kramer a7c40ef022 Canonicalize header guards into a common format.
Add header guards to files that were missing guards. Remove #endif comments
as they don't seem common in LLVM (we can easily add them back if we decide
they're useful)

Changes made by clang-tidy with minor tweaks.

llvm-svn: 215558
2014-08-13 16:26:38 +00:00
Reid Kleckner 21aedc4b83 MC: Diagnose an unexpected token in COFF .section instead of asserting
This can easily arise when trying to assemble and ELF style .section
directive for a COFF object file.

llvm-svn: 215373
2014-08-11 18:34:43 +00:00
Hans Wennborg 4fa2fd12ca SubTargetFeature.cpp: it seems the size of this SmallVector should be 3
because some subtarget feature strings have three components.

llvm-svn: 215339
2014-08-11 02:21:32 +00:00
Joerg Sonnenberger b696d46045 Fix tabs.
llvm-svn: 215311
2014-08-10 11:37:07 +00:00
Joerg Sonnenberger 752b91bd82 If available, pass down the Fixup object to EvaluateAsRelocatable.
At least on PowerPC, the interpretation of certain modifiers depends on
the context they appear in.

llvm-svn: 215310
2014-08-10 11:35:12 +00:00
Saleem Abdulrasool 1d0d00f4e4 MC: remove duplicated code
This removes the duplicate definition of GetXDataSection.  This function is
available as a static method and is identical to the previous implementation.
This just cleans up the unnecessary duplication.

llvm-svn: 215289
2014-08-09 17:21:36 +00:00
Saleem Abdulrasool 87a54c46b0 MC: cleanup includes
Cleanup Win64EH header inclusion.  NFC.

llvm-svn: 215288
2014-08-09 17:21:33 +00:00
Saleem Abdulrasool 64a8cc7d0d MC: split Win64EHUnwindEmitter into a shared streamer
This changes Win64EHEmitter into a utility WinEH UnwindEmitter that can be
shared across multiple architectures and a target specific bit which is
overridden (Win64::UnwindEmitter).  This enables sharing the section selection
code across X86 and the intended use in ARM for emitting unwind information for
Windows on ARM.

llvm-svn: 215050
2014-08-07 02:59:41 +00:00
Kevin Enderby e3c13468bf Enable Darwin vararg parameters support in assembler macros.
Duplicate the vararg tests for linux and add a tests which mixed
vararg arguments with darwin positional parameters.

Patch by: Janne Grunau <j@jannau.net>

llvm-svn: 214799
2014-08-04 23:14:37 +00:00
Saleem Abdulrasool 4544c16eab MC: virtualise EmitWindowsUnwindTables
This makes EmitWindowsUnwindTables a virtual function and lowers the
implementation of the function to the X86WinCOFFStreamer.  This method is a
target specific operation.  This enables making the behaviour target dependent
by isolating it entirely to the target specific streamer.

llvm-svn: 214664
2014-08-03 18:51:26 +00:00
Saleem Abdulrasool b3be7371d5 MC: rename Win64EHFrameInfo to WinEH::FrameInfo
The frame information stored in this structure is driven by the requirements for
Windows NT unwinding rather than Windows 64 specifically.  As a result, this
type can be shared across multiple architectures (ARM, AXP, MIPS, PPC, SH).
Rename this class in preparation for adding support for supporting unwinding
information for Windows on ARM.

Take the opportunity to constify the members as everything except the
ChainedParent is read-only.  This required some adjustment to the label
handling.

llvm-svn: 214663
2014-08-03 18:51:17 +00:00
Philip Reames 7684618401 Add support for StackMap section for ELF/Linux systems
This patch adds code to emits the StackMap section on ELF systems. This section is required to support llvm.experimental.stackmap and llvm.experimental.patchpoint intrinsics.

Reviewers: ributzka, echristo

Differential Revision: http://reviews.llvm.org/D4574

llvm-svn: 214538
2014-08-01 18:47:09 +00:00
Eric Christopher 59265af9eb Revert "Remove MCObjectDisassembler.cpp as it is untested and unused." as it is apparently used, but the build didn't return errors weirdly.
This reverts commits 214437 and 214438.

llvm-svn: 214444
2014-07-31 21:18:38 +00:00
Aaron Ballman 3866a8f2ca Fixing CMake problems with MCObjectDisassembler.cpp not existing.
llvm-svn: 214438
2014-07-31 20:48:54 +00:00
Eric Christopher 90a06fa97a Remove MCObjectDisassembler.cpp as it is untested and unused.
llvm-svn: 214437
2014-07-31 20:44:46 +00:00
Rafael Espindola 3f0549f66b Move MCObjectSymbolizer.h to MC/MCAnalysis.
The cpp file is already in lib/MC/MCAnalysis.

llvm-svn: 214424
2014-07-31 19:29:23 +00:00
Eric Christopher 5a298679d5 Fix loop end condition.
Note: This code appears to be untested.
llvm-svn: 214416
2014-07-31 18:28:08 +00:00
David Blaikie 29459ae83c Reapply "DebugInfo: Don't put fission type units in comdat sections."
This recommits r208930, r208933, and r208975 (by reverting r209338) and
reverts r209529 (the FIXME to readd this functionality once the tools
were fixed) now that DWP has been fixed to cope with a single section
for all fission type units.

Original commit message:

"Since type units in the dwo file are handled by a debug aware tool,
they don't need to leverage the ELF comdat grouping to implement
deduplication. Avoid creating all the .group sections for these as a
space optimization."

llvm-svn: 213956
2014-07-25 17:11:58 +00:00
Joerg Sonnenberger 6637d4e2e7 Use the same .eh_frame encoding for 32bit PPC as on i386.
llvm-svn: 213890
2014-07-24 19:25:16 +00:00
Nico Weber 155dccd1eb Let the integrated assembler understand .exitm, PR20426.
llvm-svn: 213876
2014-07-24 17:08:39 +00:00
Nico Weber 2a8f922b1c Remove unused field MacroInstantiation::TheMacro. No behavior change.
llvm-svn: 213874
2014-07-24 16:29:04 +00:00
Nico Weber 404012b7dc Let the integrated assembler understand .warning, PR20428.
llvm-svn: 213873
2014-07-24 16:26:06 +00:00
Rafael Espindola 5addace56d Finish inverting the MC -> Object dependency.
There were still some disassembler bits in lib/MC, but their use of Object
was only visible in the includes they used, not in the symbols.

llvm-svn: 213808
2014-07-23 22:26:07 +00:00
Tim Northover e19bed7d33 AArch64: remove arm64 triple enumerator.
Having both Triple::arm64 and Triple::aarch64 is extremely confusing, and
invites bugs where only one is checked. In reality, the only legitimate
difference between the two (arm64 usually means iOS) is also present in the OS
part of the triple and that's what should be checked.

We still parse the "arm64" triple, just canonicalise it to Triple::aarch64, so
there aren't any LLVM-side test changes.

llvm-svn: 213743
2014-07-23 12:32:47 +00:00
Ulrich Weigand 46797c6960 [MC] Pass MCSymbolData to needsRelocateWithSymbol
As discussed in a previous checking to support the .localentry
directive on PowerPC, we need to inspect the actual target symbol
in needsRelocateWithSymbol to make the appropriate decision based
on that symbol's st_other bits.

Currently, needsRelocateWithSymbol does not get the target symbol.
However, it is directly available to its sole caller.  This patch
therefore simply extends the needsRelocateWithSymbol by a new
parameter "const MCSymbolData &SD", passes in the target symbol,
and updates all derived implementations.

In particular, in the PowerPC implementation, this patch removes
the FIXME added by the previous checkin.

llvm-svn: 213487
2014-07-20 23:15:06 +00:00
Saleem Abdulrasool 00426d9c19 MC: permit emitting a symbol value as section relative
This adds an optional parameter to the EmitSymbolValue method in MCStreamer to
permit emitting a symbol value as a section relative value.  This is to cover
the use in MCDwarf which should not really know about how to emit a section
relative value for a given target.

This addresses post-review comments from Eric Christopher in SVN r213275.

llvm-svn: 213463
2014-07-19 21:01:58 +00:00
David Peixotto b0b3e66ed4 Fix build failure on windows
Add explicit constructor to struct instead of using brace initialization.

llvm-svn: 213389
2014-07-18 16:41:58 +00:00
David Peixotto ae5ba76221 MC: support different sized constants in constant pools
On AArch64 the pseudo instruction ldr <reg>, =... supports both
32-bit and 64-bit constants. Add support for 64 bit constants for
the pools to support the pseudo instruction fully.

Changes the AArch64 ldr-pseudo tests to use 32-bit registers and
adds tests with 64-bit registers.

Patch by Janne Grunau!

Differential Revision: http://reviews.llvm.org/D4279

llvm-svn: 213387
2014-07-18 16:05:14 +00:00
Nico Weber 42f79dbf02 ms inline asm: Don't add x86 segment registers to the clobber list.
Clang tries to check the clobber list but doesn't list segment registers in its
x86 register list. This fixes PR20343.

llvm-svn: 213303
2014-07-17 20:24:55 +00:00
Saleem Abdulrasool 7d09530cef MC: correct DWARF header for PE/COFF assembly input
The header contains an offset to the DWARF abbreviations for the CU.  The offset
must be section relative for COFF and absolute for others.  The non-assembly
code path for the DWARF header generation already had the correct emission for
the headers.  This corrects just the assembly path.  Due to the invalid
relocation, processing of the debug information would halt previously on the
first assembly input as the associated abbreviations would be out of range as
they would have the location increased by image base and the section offset.

This address PR20332.

llvm-svn: 213275
2014-07-17 16:27:44 +00:00
Saleem Abdulrasool 19f8bc65f6 MC: collapse emission of producer
Rather than use three EmitBytes, concatenate the string at compile time,
constructing a single StringRef and emitting the data in one shot.  This also
creates nicer assembly output.  NFC.

llvm-svn: 213273
2014-07-17 16:27:35 +00:00
Saleem Abdulrasool ab820860fa MC: make WinEH opcode an opaque value
This makes the opcode an opaque value (unsigned int) rather than the
enumeration.  This permits the use of target specific operands.

Split out the generic type into a MCWinEH header and add a supporting
MCWin64EH::Instruction to abstract out the selection of the opcode and
construction of the actual instruction.

llvm-svn: 213221
2014-07-17 03:08:50 +00:00
David Majnemer 8bce66b093 CodeGen: Stick constant pool entries in COMDAT sections for WinCOFF
COFF lacks a feature that other object file formats support: mergeable
sections.

To work around this, MSVC sticks constant pool entries in special COMDAT
sections so that each constant is in it's own section.  This permits
unused constants to be dropped and it also allows duplicate constants in
different translation units to get merged together.

This fixes PR20262.

Differential Revision: http://reviews.llvm.org/D4482

llvm-svn: 213006
2014-07-14 22:57:27 +00:00
Saleem Abdulrasool c7c3cb1f4e MC: make MCWin64EHInstruction a POD-like struct
This is the first of a number of changes designed to generalise
MCWin64EHInstruction to support different target architectures.  An ordered set
(vector) of these instructions is saved per frame to permit the emission of
information for Windows NT style unwinding.  The only bit of information which
is actually target specific here is the Opcode for the unwinding bytecode.  The
remainder of the information is simply generic information that is relevant to
the Windows NT unwinding model.

Remove the accessors for the fields, making them const and public instead.  Sink
the knowledge of the alias'ed name into the single source and sink a single-use
check method into the use.

llvm-svn: 212914
2014-07-13 19:03:45 +00:00
Saleem Abdulrasool 5705cd8cf6 MC: make helper function be more const-correct
Introduce const-ness on parameters, they are used as read-only and should not be
modified.  NFC.

llvm-svn: 212913
2014-07-13 19:03:40 +00:00
Saleem Abdulrasool 3f3cefd392 MC: make DWARF and Windows unwinding handling more similar
Rename member variables and functions for the MCStreamer for DWARF-like
unwinding management.  Rename the Windows ones as well and make the naming and
handling similar across the two.  No functional change intended.

llvm-svn: 212912
2014-07-13 19:03:36 +00:00
David Majnemer 299674e94f MC: Let non-temporary COFF aliases be in symtab
MC was aping a binutils bug where aliases would default their linkage to
private instead of internal.

I've sent a patch to the binutils maintainers and they've recently
applied it to the GNU assembler sources.

This fixes PR20152.

Differential Revision: http://reviews.llvm.org/D4395

llvm-svn: 212899
2014-07-13 04:31:19 +00:00
Saleem Abdulrasool db514056de MC: remove use of unnecessary variable
Due to the fact that the windows unwinding has the concept of chained frames, we
maintain a current frame info pointer that is adjusted on any push and pop of a
unwinding context.  This just removes an unnecessary variable that was used to
mirror the DWARF unwinding code.

llvm-svn: 212882
2014-07-12 20:49:13 +00:00
Saleem Abdulrasool 4a1a2f7790 MC: rename MCW64UnwindInfo to MCWinFrameInfo
This structure contains information related to the call frame used to generate
unwinding information.  Rename this to reflect the future use to represent the
shared state between various architectures for WinCFI information.

llvm-svn: 212881
2014-07-12 20:49:09 +00:00
Ulrich Weigand 0a51abc100 [MC] Constify MCELF::GetVisibility and MCELF::getOther
These two routines didn't take a "const MCSymbolData &SD"
like the other MCELF::Get routines for some reason ...

llvm-svn: 212834
2014-07-11 17:34:44 +00:00
Saleem Abdulrasool 1e76cbdff7 MC: modernise for loop
Convert a for loop to range bsaed form.  NFC.

llvm-svn: 212684
2014-07-10 04:50:09 +00:00
Saleem Abdulrasool 427c08d48b MC: add and use an accessor for WinCFI
This adds a utility method to access the WinCFI information in bulk and uses
that to iterate rather than requesting the count and individually iterating
them.  This is in preparation for restructuring WinCFI handling to enable more
clear sharing across architectures to enable unwind information emission for
Windows on ARM.

llvm-svn: 212683
2014-07-10 04:50:06 +00:00
Vladimir Medic fb8a2a95cd Mips.abiflags is a new implicitly generated section that will be present on all new modules. The section contains a versioned data structure which represents essentially information to allow a program loader to determine the requirements of the application. This patch implements mips.abiflags section and provides test cases for it.
llvm-svn: 212519
2014-07-08 08:59:22 +00:00
Rafael Espindola 8026bd0b2a This only needs a StringRef.
llvm-svn: 212401
2014-07-06 14:17:29 +00:00
Alp Toker a55b95b58a SourceMgr: make valid buffer IDs start from one
Use 0 for the invalid buffer instead of -1/~0 and switch to unsigned
representation to enable more idiomatic usage.

Also introduce a trivial SourceMgr::getMainFileID() instead of hard-coding 0/1
to identify the main file.

llvm-svn: 212398
2014-07-06 10:33:31 +00:00
David Majnemer 82cb0309e2 MC: make MCSymbolData::dump work on const objects
This just lets us dump a const MCSymbolData object, no functionality
changed.

llvm-svn: 212365
2014-07-05 00:39:52 +00:00
David Majnemer e0950ee85c MC: Correct comment in ExportSymbol
No functionality changed, just make it so that the code _could_ be
uncommented.

llvm-svn: 212363
2014-07-04 23:20:46 +00:00
David Majnemer bee5f754f2 MC: Cleanup COFFAsmParser::ParseSectionFlags
Switch a normal for-loop to a range-based for. No functionality changed.

llvm-svn: 212362
2014-07-04 23:15:28 +00:00
Rafael Espindola 97de474a36 Invert the MC -> Object dependency.
Now that we have a lib/MC/MCAnalysis, the dependency was there just because
of two helper classes. Move the two over to MC.

This will allow IRObjectFile to parse inline assembly.

llvm-svn: 212248
2014-07-03 02:01:39 +00:00
Rafael Espindola e1865a8e8c Fix configure+make build.
llvm-svn: 212210
2014-07-02 20:05:48 +00:00
Rafael Espindola cbc5ac7a7e Move CFG building code to a new lib/MC/MCAnalysis library.
The new library is 150KB on a Release+Asserts build, so it is quiet a bit of
code that regular users of MC don't need to link with now.

llvm-svn: 212209
2014-07-02 19:49:34 +00:00
Rafael Espindola 83120cdf68 Avoid revocations when possible.
This is a small targeted fix for pr20119. The code needs quiet a bit of
refactoring and I added some FIXMEs about it, but I want to get the testcase
passing first.

llvm-svn: 212101
2014-07-01 14:34:30 +00:00
Reid Kleckner b5dd9452b4 Fix .seh_stackalloc 0
seh_stackalloc 0 is not representable in Win64 SEH info, so emitting it
is a bug.

Reviewers: rnk

Differential Revision: http://reviews.llvm.org/D4334

Patch by Vadim Chugunov!

llvm-svn: 212081
2014-07-01 00:42:47 +00:00
Saleem Abdulrasool 7206a52522 MC: rename EmitWin64EH routines
Rename the routines to reflect the reality that they are more related to call
frame information than to Win64 EH. Although EH is implemented in an intertwined
manner by augmenting with an exception handler and an associated parameter, the
majority of these routines emit information required to unwind the frames. This
also helps identify that these routines are generic for most windows platforms
(they apply equally to nearly all architectures except x86) although the
encoding of the information is architecture dependent.

Unwinding data is emitted via EmitWinCFI* and exception handling information via
EmitWinEH*.

llvm-svn: 211994
2014-06-29 01:52:01 +00:00
David Majnemer c57d038240 MC: Fix associative sections on COFF
COFF sections in MC were represented by a tuple of section-name and
COMDAT-name.  This is not sufficient to represent a .text section
associated with another .text section; we need a way to distinguish
between the key section and the one marked associative.

llvm-svn: 211913
2014-06-27 17:19:44 +00:00
Alp Toker e69170a110 Revert "Introduce a string_ostream string builder facilty"
Temporarily back out commits r211749, r211752 and r211754.

llvm-svn: 211814
2014-06-26 22:52:05 +00:00
Alp Toker 614717388c Introduce a string_ostream string builder facilty
string_ostream is a safe and efficient string builder that combines opaque
stack storage with a built-in ostream interface.

small_string_ostream<bytes> additionally permits an explicit stack storage size
other than the default 128 bytes to be provided. Beyond that, storage is
transferred to the heap.

This convenient class can be used in most places an
std::string+raw_string_ostream pair or SmallString<>+raw_svector_ostream pair
would previously have been used, in order to guarantee consistent access
without byte truncation.

The patch also converts much of LLVM to use the new facility. These changes
include several probable bug fixes for truncated output, a programming error
that's no longer possible with the new interface.

llvm-svn: 211749
2014-06-26 00:00:48 +00:00
Rafael Espindola 591c641920 Merge the used symbol scanning of MCObjectStreamer and RecordStreamer.
This completes the refactoring of RecordStreamer.

llvm-svn: 211727
2014-06-25 18:37:33 +00:00
Rafael Espindola e2c6624475 Move expression visitation logic up to MCStreamer.
Remove the duplicate from MCRecordStreamer. No functionality change.

llvm-svn: 211714
2014-06-25 15:45:33 +00:00
Rafael Espindola 2be1281d43 Simplify the visitation of target expressions. No functionality change.
llvm-svn: 211707
2014-06-25 15:29:54 +00:00
Rafael Espindola 9364ac69d8 Simplify AddValueSymbols. No functionality change.
llvm-svn: 211701
2014-06-25 14:42:14 +00:00
NAKAMURA Takumi 1db5995d14 Re-apply r211399, "Generate native unwind info on Win64" with a fix to ignore SEH pseudo ops in X86 JIT emitter.
--
This patch enables LLVM to emit Win64-native unwind info rather than
DWARF CFI.  It handles all corner cases (I hope), including stack
realignment.

Because the unwind info is not flexible enough to describe stack frames
with a gap of unknown size in the middle, such as the one caused by
stack realignment, I modified register spilling code to place all spills
into the fixed frame slots, so that they can be accessed relative to the
frame pointer.

Patch by Vadim Chugunov!

Reviewed By: rnk

Differential Revision: http://reviews.llvm.org/D4081

llvm-svn: 211691
2014-06-25 12:41:52 +00:00
Rafael Espindola 6804d450cd Fix another asserting method in the null streamer.
llvm-svn: 211668
2014-06-25 05:37:58 +00:00
Rafael Espindola c00d875d35 Fix a regression from r211653.
The method was empty in the null streamer but I mistakenly replaced it with
the aborting one in MCStreamer.

llvm-svn: 211666
2014-06-25 05:31:22 +00:00
NAKAMURA Takumi 6d9bb5cbb7 MCNullStreamer.cpp: Roll back a few empty methods that have been marked as unreachable in MCStreamer.cpp.
void EmitCOFFSecRel32(MCSymbol const *Symbol) override {}
  void EmitGPRel32Value(const MCExpr *Value) override {}

It should fix crash like "llc -mtriple=i686-cygwin -filetype=null".

llvm-svn: 211664
2014-06-25 04:34:36 +00:00
Rafael Espindola 624ac24da9 Move some trivial methods up to MCStreamer.
This saves some duplicated boilerplate in RecordStreamer and NullStreamer.

llvm-svn: 211653
2014-06-25 00:27:53 +00:00
Rafael Espindola 49bbfd026a Simplify the handling of .cfi_endproc.
No functionality change.

llvm-svn: 211651
2014-06-25 00:13:59 +00:00
Rafael Espindola c607d8e7be Simplify EmitLabel.
All the "real" streamers were already calling to MCStreamer::EmitLabel
to do part of the work.

llvm-svn: 211646
2014-06-24 23:54:40 +00:00
Rafael Espindola f491704e22 Print a=b as an assignment.
In assembly the expression a=b is parsed as an assignment, so it should be
printed as one.

This remove a truly horrible hack for producing a label with "a=.". It would
be used by codegen but would never be reached by the asm parser. Sorry I
missed this when it was first committed.

llvm-svn: 211639
2014-06-24 22:45:16 +00:00
Rafael Espindola 886048276f Allow using .cfi_startproc without a leading symbol.
This is possible now that we don't produce .eh symbols. This fixes pr19430.

llvm-svn: 211502
2014-06-23 15:34:32 +00:00
Rafael Espindola 440bb21b5a Stop producing func.eh symbols on Darwin.
According Nick Kledzik (http://llvm.org/bugs/show_bug.cgi?id=19430#c2):
"... mach-o no longer needs names in the __eh_frame section (and has not for
years)."

Iain Sandoe confirms it is also unnecessary for their old darwin support.

llvm-svn: 211500
2014-06-23 15:13:23 +00:00
David Majnemer 8114c1ae17 MC: Cleanup parseMSInlineAsm
Utilize range based for-loops to simplify some code.
Use insert() instead of a loop for simplicity/efficiency.

No functionality change.

llvm-svn: 211486
2014-06-23 02:17:16 +00:00
Saleem Abdulrasool bdbc0088da MC: adjust text section flags for WoA
Correct the section flags for code built for Windows on ARM with
`-ffunction-sections`.  Windows on ARM uses solely Thumb-2 instructions, and
indicates that the function is thumb by placing it in a text section that has
IMAGE_SCN_MEM_16BIT flag set.

When we encounter a .section directive, a new section is constructed.  This may
be a text segment.  In order to identify that we need the additional flag,
expose the target triple through the ObjectFileInfo as this information is lost
otherwise.

Since any modern ARM targeting environment on Windows would be Thumb-2 (Windows
ARM NT or Windows Embedded Compact), introducing a new flag to indicate the
section attribute seems to be a bit overkill.  Simply depend on the target
triple.  Since there is one location that this information is currently needed,
creating a target specific assembly parser and delegating the parsing of section
switches also feels a bit heavy handed.  If it turns out that this information
ends up changing additional behaviour, then it may be worth considering that
alternative.

llvm-svn: 211481
2014-06-22 22:25:01 +00:00
NAKAMURA Takumi d77cefe633 Revert r211399, "Generate native unwind info on Win64"
It broke Legacy JIT Tests on x86_64-{mingw32|msvc}, aka Windows x64.

llvm-svn: 211480
2014-06-22 22:00:56 +00:00
Weiming Zhao 58eb5ab326 Report error for non-zero data in .bss
User may initialize a var with non-zero value and specify .bss section.
E.g. : int a __attribute__((section(".bss"))) = 2;

This patch converts an assertion to error report for better user
experience.

Differential Revision: http://reviews.llvm.org/D4199

llvm-svn: 211455
2014-06-22 00:33:44 +00:00
Rafael Espindola b4076b290e Always use a temp symbol for CIE.
Fixes pr19185.

llvm-svn: 211423
2014-06-20 23:54:32 +00:00
Rafael Espindola c3510c74f7 Use compact unwind for the iOS simulator.
Another step in fixing pr19185.

llvm-svn: 211416
2014-06-20 22:40:55 +00:00
Rafael Espindola becdf63f7d Use a helper function and clang-format.
No functionality change.

llvm-svn: 211415
2014-06-20 22:37:01 +00:00
Reid Kleckner 4a01230db4 Generate native unwind info on Win64
This patch enables LLVM to emit Win64-native unwind info rather than
DWARF CFI.  It handles all corner cases (I hope), including stack
realignment.

Because the unwind info is not flexible enough to describe stack frames
with a gap of unknown size in the middle, such as the one caused by
stack realignment, I modified register spilling code to place all spills
into the fixed frame slots, so that they can be accessed relative to the
frame pointer.

Patch by Vadim Chugunov!

Reviewed By: rnk

Differential Revision: http://reviews.llvm.org/D4081

llvm-svn: 211399
2014-06-20 20:35:47 +00:00
Eric Christopher d29430dae9 Fix up a few formatting issues.
llvm-svn: 211307
2014-06-19 20:00:09 +00:00
Alp Toker 660839f210 MCNullStreamer: assign file IDs to resolve crashes and errors
Use the MCStreamer base implementations for file ID tracking instead of
overriding them as no-ops.

Avoids assertions when streaming Dwarf debug info, and fixes ASM parsing of loc
and file directives.

llvm-svn: 211282
2014-06-19 17:15:36 +00:00
Oliver Stannard 8b27308617 Emit DWARF info for all code section in an assembly file
Currently, when using llvm as an assembler, DWARF debug information is only
generated for the .text section. This patch modifies this so that DWARF info
is emitted for all executable sections.

llvm-svn: 211273
2014-06-19 15:52:37 +00:00
Oliver Stannard f7693f4c1f Emit DWARF3 call frame information when DWARF3+ debug info is requested
Currently, llvm always emits a DWARF CIE with a version of 1, even when emitting
DWARF 3 or 4, which both support CIE version 3. This patch makes it emit the
newer CIE version when we are emitting DWARF 3 or 4. This will not reduce
compatibility, as we already emit other DWARF3/4 features, and is worth doing as
the DWARF3 spec removed some ambiguities in the interpretation of call frame
information.

It also fixes a minor bug where the "return address" field of the CIE was
encoded as a ULEB128, which is only valid when the CIE version is 3. There are
no test changes for this, because (as far as I can tell) none of the platforms
that we test have a return address register with a DWARF register number >127.

llvm-svn: 211272
2014-06-19 15:39:33 +00:00
Eric Christopher 4c5bff36ad Move -dwarf-version to an MC level command line option so it's
used by all of the MC level tools and codegen. Fix up all uses
in the compiler to use this and set it on the context accordingly.

llvm-svn: 211257
2014-06-19 06:22:08 +00:00
Craig Topper 35b2f75733 Convert some assert(0) to llvm_unreachable or fold an 'if' condition into the assert.
llvm-svn: 211254
2014-06-19 06:10:58 +00:00
David Majnemer 6a5b812c7b MS asm: Properly handle quoted symbol names
We would get confused by '@' characters in symbol names, we would
mistake the text following them for the variant kind.

When an identifier a string, the variant kind will never show up inside
of it.  Instead, check to see if there is a variant following the
string.

This fixes PR19965.

llvm-svn: 211249
2014-06-19 01:25:43 +00:00
Saleem Abdulrasool 71ede29e9c MC: do not add comment string to the AsmToken in AsmLexer::LexLineComment
Fixes macros with varargs if the macro instantiation has a trailing comment.

Patch by Janne Grunau!

llvm-svn: 211219
2014-06-18 20:57:32 +00:00
Saleem Abdulrasool 763e2cb6e5 MCAsmParser: full support for gas' '.if{cond} expression' directives
Patch by Janne Grunau!

llvm-svn: 211218
2014-06-18 20:57:28 +00:00
Weiming Zhao 8c89973462 [ARM] [MC] Refactor the constant pool classes
ARMTargetStreamer implements ConstantPool and AssmeblerConstantPools
to keep track of assembler-generated constant pools that are used for
ldr-pseudo.

When implementing ldr-pseudo for AArch64, these two classes can be reused.
So this patch factors them out from ARM target to the general MC lib.

llvm-svn: 211198
2014-06-18 18:17:25 +00:00
Artyom Skrobov 9aea8432c5 Using llvm::sys::swapByteOrder() for the common case of byte-swapping a value in place
llvm-svn: 210978
2014-06-14 13:18:07 +00:00