Commit Graph

149 Commits

Author SHA1 Message Date
Petr Hosek
bc245c01bf [MC] Ensure that pending labels are flushed when -mc-relax-all flag is used
Summary:
The current implementation doesn't always flush all pending labels
beforeemitting data which can result in an incorrectly placed labels in
case when when instruction bundling is enabled and -mc-relax-all flag is
being used. To address this issue, we always flush pending labels before
emitting data.

The change was tested by running PNaCl toolchain trybots with
-mc-relax-all flag set.

Fixes https://code.google.com/p/nativeclient/issues/detail?id=4063

Test Plan: Regression test attached

Reviewers: mseaborn

Subscribers: jfb, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240870 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-27 01:54:17 +00:00
Rafael Espindola
6c56decee0 Generalize emitAbsoluteSymbolDiff.
This makes emitAbsoluteSymbolDiff always succeed and moves logic from the asm
printer to it.

The object one now also works on ELF. If two symbols are in the same fragment,
we will never move them apart.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239552 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-11 18:58:08 +00:00
Rafael Espindola
223e58b67d Rename HasData to IsRegistered.
There is no MCSectionData, so the old name is now meaningless.

Also remove some asserts/checks that were there just because the information
they used was in MCSectionData.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238708 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-01 01:52:18 +00:00
Rafael Espindola
d1678240e5 Remove trivial forwarding function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238707 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-01 01:39:15 +00:00
Jim Grosbach
586c0042da MC: Clean up MCExpr naming. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238634 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-30 01:25:56 +00:00
Rafael Espindola
cfac75ad0e Remove getData.
This completes the mechanical part of merging MCSymbol and MCSymbolData.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238617 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-29 21:45:01 +00:00
Rafael Espindola
5760c5fe31 Remove the MCSymbolData typedef.
The getData member function is next.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238611 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-29 20:41:47 +00:00
Rafael Espindola
f00654bc0f Rename getOrCreateSymbolData to registerSymbol and return void.
Another step in merging MCSymbol and MCSymbolData.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238607 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-29 20:21:02 +00:00
Rafael Espindola
82fdcc0e7f Move common symbol related information from MCSectionData to MCSymbol.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238583 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-29 17:48:04 +00:00
Rafael Espindola
052a7becbe Store MCSymbols in PendingLabels.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238582 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-29 17:41:59 +00:00
Rafael Espindola
9886da621d Remove a trivial forwarding function. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238506 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-28 21:36:02 +00:00
Rafael Espindola
792e158397 Rename and move getCurrentSectionData.
I think this concludes the merge of MCSectionData and MCSection.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238358 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-27 21:04:14 +00:00
Rafael Espindola
41cea417fa There is only one current section.
Both MCStreamer and MCObjectStreamer were maintaining a current section
variable and they were slightly out of sync. I don't think this was observable,
but was inefficient and error prone.

Changing this requires a few cascading changes:

* SwitchSection has to call ChangeSection earlier for ChangeSection to see
  the old section.
* With that change, ChangeSection cannot call EmitLabel, since during
  ChangeSection we are still in the old section.
* When the object streamer requires a begin label, just reused the existing
  generic support for begin labels instead of calling EmitLabel directly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238357 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-27 20:52:32 +00:00
Rafael Espindola
899cab6126 Delete MCSectionData.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238331 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-27 15:14:11 +00:00
Rafael Espindola
919ce81d38 Move getSubsectionInsertionPoint to MCSection.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238320 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-27 13:37:28 +00:00
Rafael Espindola
b14ebd6a1d Replace getOrCreateSectionData with registerSection.
There is now no SectionData to be created.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238208 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-26 15:07:25 +00:00
Rafael Espindola
7ff8c5c348 Have getCurrentSectionData return a MCSection.
I will fix the name shortly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238204 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-26 14:48:11 +00:00
Rafael Espindola
68e7d22de4 Store a MCSection in MCFragment.
Part of the work to merge MCSectionData into MCSection.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238160 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-25 23:48:22 +00:00
Rafael Espindola
712c27f870 Move HasInstructions to MCSection.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238150 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-25 18:34:26 +00:00
Rafael Espindola
68c5b83e12 Move bundle info from MCSectionData to MCSection.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238143 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-25 15:04:26 +00:00
Rafael Espindola
477acf64d0 Stop forwarding (get|set)Aligment from MCSectionData to MCSection.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237956 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-21 21:02:35 +00:00
Rafael Espindola
7521964d28 Move alignment from MCSectionData to MCSection.
This starts merging MCSection and MCSectionData.

There are a few issues with the current split between MCSection and
MCSectionData.

* It optimizes the the not as important case. We want the production
of .o files to be really fast, but the split puts the information used
for .o emission in a separate data structure.

* The ELF/COFF/MachO hierarchy is not represented in MCSectionData,
leading to some ad-hoc ways to represent the various flags.

* It makes it harder to remember where each item is.

The attached patch starts merging the two by moving the alignment from
MCSectionData to MCSection.

Most of the patch is actually just dropping 'const', since
MCSectionData is mutable, but MCSection was not.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237936 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-21 19:20:38 +00:00
Duncan P. N. Exon Smith
583dac827c AsmPrinter: Compute absolute label difference directly
Create a low-overhead path for `EmitLabelDifference()` that emits a
emits an absolute number when (1) the output is an object stream and (2)
the two symbols are in the same data fragment.

This drops memory usage on Mach-O from 975 MB down to 919 MB (5.8%).
The only call is when `!doesDwarfUseRelocationsAcrossSections()` --
i.e., on Mach-O -- since otherwise an absolute offset from the start of
the section needs a relocation.  (`EmitLabelDifference()` is cheaper on
ELF anyway, since it creates 1 fewer temp symbol, and it gets called far
less often.  It's not clear to me if this is even a bottleneck there.)

(I'm looking at `llc` memory usage on `verify-uselistorder.lto.opt.bc`;
see r236629 for details.)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237876 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-21 02:41:23 +00:00
Jim Grosbach
19696daa21 MC: Clean up method names in MCContext.
The naming was a mish-mash of old and new style. Update to be consistent
with the new. NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237594 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-18 18:43:14 +00:00
Jim Grosbach
251a66ec37 MC: Update MCCodeEmitter naming. NFC.
s/EncodeInstruction/encodeInstruction/

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237469 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-15 19:13:16 +00:00
Jim Grosbach
8b22e9c00a MC: Update MCFixup naming. NFC.
s/MCFixup::Create/MCFixup::create/

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237468 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-15 19:13:05 +00:00
Rafael Espindola
c98092e28d Use raw_pwrite_stream in the object writer/streamer.
The ELF object writer will take advantage of that in the next commit.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234950 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-14 22:14:34 +00:00
Petr Hosek
054db7df5b [MC] Write padding into fragments when -mc-relax-all flag is used
Summary:
When instruction bundling is enabled and the -mc-relax-all flag is
set, we can write bundle padding directly into fragments and avoid
creating large number of fragments significantly reducing LLVM MC
memory usage.

Test Plan: Regression test attached

Reviewers: eliben

Subscribers: jfb, mseaborn

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234714 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-12 23:42:25 +00:00
Rafael Espindola
696a3454de Remove dead code. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234352 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-07 20:38:45 +00:00
Rafael Espindola
d80979b25d Don't declare all text sections at the start of the .s
The code this patch removes was there to make sure the text sections went
before the dwarf sections. That is necessary because MachO uses offsets
relative to the start of the file, so adding a section can change relaxations.

The dwarf sections were being printed at the start just to produce symbols
pointing at the start of those sections.

The underlying issue was fixed in r231898. The dwarf sections are now printed
when they are about to be used, which is after we printed the text sections.

To make sure we don't regress, the patch makes the MachO streamer assert
if CodeGen puts anything unexpected after the DWARF sections.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232842 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-20 20:00:01 +00:00
Rafael Espindola
c7c4c36694 Split the object streamer callback in one per file format.
There are two main advantages to doing this

* Targets that only need to handle one of the formats specially don't have
  to worry about the others. For example, x86 now only registers a
  constructor for the COFF streamer.

* Changes to the arguments passed to one format constructor will not impact
  the other formats.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232699 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-19 01:50:16 +00:00
Rafael Espindola
bd23c08119 Add a default implementation of createObjectStreamer.
This removes duplicated code from backends that don't need to do anything
fancy.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232658 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-18 19:08:20 +00:00
David Blaikie
7610ba7d24 Fix uses of reserved identifiers starting with an underscore followed by an uppercase letter
This covers essentially all of llvm's headers and libs. One or two weird
cases I wasn't sure were worth/appropriate to fix.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232394 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-16 18:06:57 +00:00
Michael Ilseman
3f0e8837be Clean up static analyzer warnings.
Clang's static analyzer found several potential cases of undefined
behavior, use of un-initialized values, and potentially null pointer
dereferences in tablegen, Support, MC, and ADT. This cleans them up
with specific assertions on the assumptions of the code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224154 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-12 21:48:03 +00:00
Oliver Stannard
25f4c35b22 Revert r221150, as it broke sanitizer tests
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221151 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-03 12:19:03 +00:00
Oliver Stannard
b63d71ef81 Emit .eh_frame with relocations to functions, rather than sections
When LLVM emits DWARF call frame information, it currently creates a local,
section-relative symbol in the code section, which is pointed to by a
relocation on the .eh_frame section. However, for C++ we emit some functions in
section groups, and the SysV ABI has some rules to make it easier to remove
these sections
(http://www.sco.com/developers/gabi/latest/ch4.sheader.html#section_group_rules):

  A symbol table entry with STB_LOCAL binding that is defined relative to one
  of a group's sections, and that is contained in a symbol table section that is
  not part of the group, must be discarded if the group members are discarded.
  References to this symbol table entry from outside the group are not allowed.

This means that we need to use the function symbol for the relocation, not a
temporary symbol.

There was a comment in the code claiming that the local symbol was used to
avoid creating a relocation, but a relocation must be created anyway as the
code and CFI are in different sections.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221150 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-03 12:02:51 +00:00
David Majnemer
ae3811c355 Attempt to fix the build after r220439
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220440 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-22 22:46:05 +00:00
Derek Schuff
cdb105b62f [MC] Attach labels to existing fragments instead of using a separate fragment
Summary:
Currently when emitting a label, a new data fragment is created for it if the
current fragment isn't a data fragment.
This change instead enqueues the label and attaches it to the next fragment
(e.g. created for the next instruction) if possible.

When bundle alignment is not enabled, this has no functionality change (it
just results in fewer extra fragments being created). For bundle alignment,
previously labels would point to the beginning of the bundle padding instead
of the beginning of the emitted instruction. This was not only less efficient
(e.g. jumping to the nops instead of past them) but also led to miscalculation
of the address of the GOT (since MC uses a label difference rather than
emitting a "." symbol).

Fixes https://code.google.com/p/nativeclient/issues/detail?id=3982

Test Plan: regression test attached

Reviewers: jvoung, eliben

Subscribers: jfb, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220439 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-22 22:38:06 +00:00
Rafael Espindola
4d15a2441b Make EmitDwarfSetLineAddr an static helper. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215718 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-15 14:43:02 +00:00
Rafael Espindola
305a51fec3 Make BuildSymbolDiff an static helper.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215717 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-15 14:31:47 +00:00
Rafael Espindola
216fdfe9ac Add a helper to MCExpr for when an expression is know to be absolute.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215713 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-15 14:20:32 +00:00
Rafael Espindola
91c39aa628 Merge the used symbol scanning of MCObjectStreamer and RecordStreamer.
This completes the refactoring of RecordStreamer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211727 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-25 18:37:33 +00:00
Rafael Espindola
c7abd27294 Move expression visitation logic up to MCStreamer.
Remove the duplicate from MCRecordStreamer. No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211714 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-25 15:45:33 +00:00
Rafael Espindola
d4feaf82bc Simplify the visitation of target expressions. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211707 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-25 15:29:54 +00:00
Rafael Espindola
b209f33bc7 Simplify AddValueSymbols. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211701 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-25 14:42:14 +00:00
Rafael Espindola
49b52b35d4 Simplify the handling of .cfi_endproc.
No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211651 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-25 00:13:59 +00:00
Rafael Espindola
4186005edc 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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211639 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-24 22:45:16 +00:00
Rafael Espindola
23f2d7ae23 Move EH/Debug frame handling to the object streamer.
Now that the asm streamer doesn't use it, the MCStreamer doesn't need to know
about it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208562 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-12 14:02:44 +00:00
Kevin Enderby
29c96f133e Fix the assembler to print a better relocatable expression error
diagnostic that includes location information.

Currently if one has this assembly:

	.quad (0x1234 + (4 * SOME_VALUE))

where SOME_VALUE is undefined ones gets the less than
useful error message with no location information:

% clang -c x.s
clang -cc1as: fatal error: error in backend: expected relocatable expression

With this fix one now gets a more useful error message
with location information:

% clang -c x.s 
x.s:5:8: error: expected relocatable expression
 .quad (0x1234 + (4 * SOME_VALUE))
       ^

To do this I plumbed the SMLoc through the MCObjectStreamer
EmitValue() and EmitValueImpl() interfaces so it could be used
when creating the MCFixup.

rdar://12391022


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206906 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-22 17:27:29 +00:00
Craig Topper
4266ae8067 [C++11] More 'nullptr' conversion or in some cases just using a boolean check instead of comparing to nullptr.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206129 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-13 04:57:38 +00:00