Commit Graph

182 Commits

Author SHA1 Message Date
Rafael Espindola 844f6b6cfb Relax alignment fragments.
With this we don't need the EffectiveSize field anymore. Without that field
LayoutFragment only updates offsets and we don't need to invalidate the
current fragment when it is relaxed (only the ones following it).

This is also a very small improvement in the accuracy of the layout info as
we now use the after relaxation size immediately.

llvm-svn: 121857
2010-12-15 08:45:53 +00:00
Rafael Espindola 8911d03504 Patch by David Meyer to avoid a O(N^2) behaviour when relaxing fragments.
Since we now don't update addresses so early, we might relax a bit more than
we need to. This is simillar to the issue in PR8467.

llvm-svn: 121856
2010-12-15 07:39:29 +00:00
Jim Grosbach 41955ff958 ARM Fixups relative to thumb functions need to have the low bit of the value
set for interworking to work properly. rdar://8755956

llvm-svn: 121778
2010-12-14 18:46:57 +00:00
Owen Anderson 3ef19d9d48 Fix an issue in some Thumb fixups, where the effective PC address needs to be 4-byte aligned when calculating
the offset.  Add a new fixup flag to represent this, and use it for the one fixups that I have a testcase for needing
this.  It's quite likely that the other Thumb fixups will need this too, and to have their fixup encoding logic
adjusted accordingly.

llvm-svn: 121408
2010-12-09 20:27:52 +00:00
Rafael Espindola 6624f47272 Layout each section independently. With the testcase in PR8711:
before:
        4 assembler - Number of assembler layout and relaxation steps
    78563 assembler - Number of emitted assembler fragments
  8693904 assembler - Number of emitted object file bytes
   271223 assembler - Number of evaluated fixups
330771677 assembler - Number of fragment layouts
     5958 assembler - Number of relaxed instructions
  2508361 mcexpr    - Number of MCExpr evaluations

real	0m26.123s
user	0m25.694s
sys	0m0.388s

after:

      4 assembler - Number of assembler layout and relaxation steps
  78563 assembler - Number of emitted assembler fragments
8693904 assembler - Number of emitted object file bytes
 271223 assembler - Number of evaluated fixups
 231507 assembler - Number of fragment layouts
   5958 assembler - Number of relaxed instructions
2508361 mcexpr    - Number of MCExpr evaluations

real	0m2.500s
user	0m2.113s
sys	0m0.273s

And yes, the outputs are identical :-)

llvm-svn: 121207
2010-12-07 23:32:26 +00:00
Rafael Espindola 93e3cf0ebd Sorry for such a large commit. The summary is that only MachO cares about the
actuall addresses in a .o file, so it is better to let the MachO writer compute
it.

This is good for two reasons. First, areas that shouldn't care about
addresses now don't have access to it. Second, the layout of each section
is independent. I should use this in a subsequent commit to speed it up.

Most of the patch is just removing the section address computation. The two
interesting parts are the change on how we handle padding in the end
of sections and how MachO can get the address of a-b when a and b are in
different sections.

Since now the expression evaluation normally doesn't know the section address,
it will think that a-b needs relocation and let the MachO writer know. Once
it has computed the section addresses, it calls back the expression evaluation
with the section addresses to resolve these expressions.

The remaining problem is the handling of padding. Currently it will create
a special alignment fragment at the end. Since that fragment doesn't update
the alignment of the section, it needs the real address to be computed.

Since now the layout will not compute a-b with a and b in different sections,
the only effect that the special alignment fragment has is update the
address size of the section. This can also be done by the MachO writer.

llvm-svn: 121076
2010-12-07 00:27:36 +00:00
Rafael Espindola 1055f72b97 Use references to simplify the code a bit.
llvm-svn: 121050
2010-12-06 22:30:54 +00:00
Rafael Espindola 0f30fec0bd Remove the instruction fragment to data fragment lowering since it was causing
freed data to be read. I will open a bug to track it being reenabled.

llvm-svn: 121028
2010-12-06 19:08:48 +00:00
Rafael Espindola baf2f3b3eb Remove the getAddress getter, initialize Ordinal in the constructor and use
that on the ELF writer to detect a section we created.

llvm-svn: 120981
2010-12-06 03:48:09 +00:00
Rafael Espindola e7284c3671 Add a getSymbolOffset method and use it in the ELF writer.
llvm-svn: 120977
2010-12-06 02:57:26 +00:00
Rafael Espindola 8867390cf2 Once the layout is done we don't need to keep updating which fragments are
valid. Addresses will not change.

llvm-svn: 120921
2010-12-04 22:47:22 +00:00
Rafael Espindola 99e026dbca Remember the contents of leb and dwarfline fragments when relaxing. This avoids
having to evaluate the expression again when writing.

llvm-svn: 120920
2010-12-04 21:58:52 +00:00
Rafael Espindola 60ebca9aaf The sections that the ELF object writer has to create are very simple and
contain only data. Handle them specially instead of using AddSectionToTheEnd.
This moves a hack from the generic assembler to the elf writer. It is also
a bit faster and should make other improvements easier.

llvm-svn: 120683
2010-12-02 03:09:06 +00:00
Rafael Espindola 50fe5c5138 Remove unused argument.
llvm-svn: 120621
2010-12-01 22:48:11 +00:00
Rafael Espindola 5c1d4e3b1e Invalidate the layout on any relaxation, not just Instructions. Bug found by David Meyer.
While here, remove unused argument and rename UpdateForSlide to Invalidate.

llvm-svn: 120009
2010-11-23 08:08:33 +00:00
Rafael Espindola 6e13aa1d3b Reuse data fragments while lowering. Patch by David Meyer.
llvm-svn: 119999
2010-11-23 05:49:35 +00:00
Rafael Espindola 0b4c9aa9a9 Add an assert.
llvm-svn: 119788
2010-11-19 04:55:36 +00:00
Rafael Espindola 7a2cd8b540 make isVirtualSection a virtual method on MCSection. Chris' suggestion.
llvm-svn: 119547
2010-11-17 20:03:54 +00:00
Rafael Espindola 8c3039b67b Change MCExpr::EvaluateAsRelocatableImpl of variables to return the original
variable if recursing fails to simplify it.

Factor AliasedSymbol to be a method of MCSymbol.

Update MCAssembler::EvaluateFixup to match the change in
EvaluateAsRelocatableImpl.

Remove the WeakRefExpr hack, as the object writer now sees the weakref with
no extra effort needed.

Nothing else is using MCTargetExpr, but keep it for now.

Now that the ELF writer sees relocations with aliases, handle

    .weak    foo2
foo2:
    .weak    bar2
    .set    bar2,foo2
    .quad    bar2

the same way gas does and produce a relocation with bar2.

llvm-svn: 119152
2010-11-15 16:33:49 +00:00
Rafael Espindola 20b11eaa01 Speed up AddSectionToTheEnd. It was walking all fragments in all sections.
This is really slow with we have 1000s of sections each with a corresponding
relocation section. Also, it is only used by the ELF writer to add
basic data, so there is no need to force a new layout pass.

Should fix PR8563.

llvm-svn: 118377
2010-11-07 15:03:27 +00:00
Rafael Espindola 5665a93bc5 Relax dwarf line fragments. This fixes a crash in the included testcase.
llvm-svn: 118365
2010-11-07 02:07:12 +00:00
Rafael Espindola f8343f87e7 Do relaxations with FT_Org fragments. Fixes the FIXME:
// FIXME: We should compute this sooner, we don't want to recurse here, and
    // we would like to be more functional.

In MCAssembler::ComputeFragmentSize.

llvm-svn: 118080
2010-11-02 21:38:23 +00:00
Rafael Espindola 5e874982f2 Add support for expressions in .sleb/.uleb directives.
llvm-svn: 118023
2010-11-02 17:22:24 +00:00
Kevin Enderby e46564a4a8 This is the last major patch to implement support for the .loc directive
and output the dwarf line number tables.  This contains the code to emit and
encode the dwarf line tables from the previously gathered information in the
MCLineSection objects.  This contains all the details to encode the line and
address deltas into the dwarf line table.

To do this an MCDwarfLineAddrFragment has been added.

Also this moves the interface code out of Mach-O streamer into
MCDwarf so it should be useable by other object file formats.

There is now one call to be made from an MCObjectStreamer
EmitInstruction() method:
   MCLineEntry::Make(this, getCurrentSection());
to create a line entry after each instruction is assembled.

And one call call to be made from an MCObjectStreamer Finish() method:
   MCDwarfFileTable::Emit(this, DwarfLineSection);
when getContext().hasDwarfFiles() is true and is passed a object file specific
MCSection where to emit the dwarf file and the line tables.

This appears to now be correct for 32-bit targets, at least x86.  But the
relocation entries for 64-bit Darwin needs some further work which is next
up to work on.  So for now the 64-bit Mach-O target does not output the
dwarf file and line tables.

llvm-svn: 115157
2010-09-30 16:52:03 +00:00
Rafael Espindola 2ebaee9c75 Make it possible for the MCObjectWriter to decide if a given fixup is fully
resolved or not. Different object files have different restrictions and
different native assemblers have different idiosyncrasies we want to emulate
for now.

Move the existing MachO logic to the new place and implement an ELF one that
gets fixups to globals right.

llvm-svn: 115131
2010-09-30 02:22:20 +00:00
Rafael Espindola cceded493f Remove unused argument.
llvm-svn: 114852
2010-09-27 18:13:03 +00:00
Daniel Dunbar 74c1f1192c MC: Add missing ')' in diagnostic.
llvm-svn: 114717
2010-09-24 01:58:56 +00:00
Rafael Espindola dee12d8110 Avoid some Mach-O specific alignment being done on ELF.
llvm-svn: 114594
2010-09-22 22:27:05 +00:00
Rafael Espindola f667d929ce Add a InitSections method to the streamer interface.
The ELF implementation now creates text, data and bss to match the gnu as
behavior.

The text streamer still has the old MachO specific behavior since
the testsuite checks that it will error when a directive is given
before a setting the current section for example.

A nice benefit is that -n is not required anymore when producing
ELF files.

llvm-svn: 114027
2010-09-15 21:48:40 +00:00
Daniel Dunbar a90e25cc64 MC: Give a (lame) hard error if a .org directive would create an unreasonably
large object file (> 1GB).

llvm-svn: 113494
2010-09-09 16:23:33 +00:00
Daniel Dunbar 8e92d9b68d MC/ELF: Allow null values in virtual sections, ELF doesn't use special
directives for putting contents in .bss, for example.

llvm-svn: 111376
2010-08-18 18:22:37 +00:00
Matt Fleming 9cecd63b07 Layout helper function.
Introduce a helper method to add a section to the end of a layout. This
will be used by the ELF ObjectWriter code to add the metadata sections
(symbol table, etc) to the end of an object file.

llvm-svn: 111171
2010-08-16 18:35:06 +00:00
Matt Fleming c6beca522c Record a symbol's size which is needed for ELF symbol tables.
llvm-svn: 111170
2010-08-16 18:34:31 +00:00
Daniel Dunbar 5dc31317dd MC: Initialize MCFragment::Offset, noticed by Cameron Esfahani.
llvm-svn: 109875
2010-07-30 18:32:09 +00:00
Daniel Dunbar e397dded7b MC: Put back the MCFragment vtable, so subclasses are destroyed properly (duh).
llvm-svn: 109649
2010-07-28 20:28:45 +00:00
Reid Kleckner d85e3c5a86 Initial modifications to MCAssembler and TargetMachine for the MCJIT.
Patch by Olivier Meurant!

llvm-svn: 109080
2010-07-22 05:58:53 +00:00
Duncan Sands a85a90773c The variable ValueSize is set to 1 on both code paths, and then
ignored!  Remove it.

llvm-svn: 107138
2010-06-29 13:30:08 +00:00
Daniel Dunbar aa627c39e4 MC: Simplify MCAssembler::isSymbolLinkerVisible to only take an MCSymbol.
llvm-svn: 106142
2010-06-16 20:04:29 +00:00
Dan Gohman a76715fc88 Don't call flush() at a library level which isn't checking for errors
and doesn't know where the output is going.

llvm-svn: 105274
2010-06-01 16:31:34 +00:00
Daniel Dunbar b889fc987e MC: When running with -mc-relax-all, we can eagerly relax instructions and avoid creating unnecessary MCInstFragments.
llvm-svn: 104736
2010-05-26 20:37:03 +00:00
Daniel Dunbar 7c8bd0fc98 MC: Change RelaxInstruction to only take the input and output instructions.
llvm-svn: 104713
2010-05-26 18:15:06 +00:00
Daniel Dunbar a19838e107 MC: Simplify MayNeedRelaxation to not provide the fixups, so we can query it
before encoding.

llvm-svn: 104707
2010-05-26 17:45:29 +00:00
Daniel Dunbar b34440a6a8 MC: Eliminate MCAsmFixup, replace with MCFixup.
llvm-svn: 104699
2010-05-26 15:18:56 +00:00
Daniel Dunbar 353a91ff76 MC: Use accessors for access to MCAsmFixup.
llvm-svn: 104697
2010-05-26 15:18:31 +00:00
Daniel Dunbar 870e5759e7 MC: Eliminate MCFragment vtable, which was unnecessary.
llvm-svn: 104689
2010-05-26 06:50:57 +00:00
Daniel Dunbar 4bce748aa2 MC: Switch to completely lazy layout.
- The eliminates the last major algorithmic problem with MC.

llvm-svn: 103754
2010-05-14 00:51:14 +00:00
Daniel Dunbar 9abade1017 MC: Extend MCAsmLayout to explicitly track which fragments have been layed out, and enforce several invariants to LayoutFragment to ensure we only do layout in a sensible order.
llvm-svn: 103753
2010-05-14 00:37:21 +00:00
Daniel Dunbar 3eedc26e18 MC: Implicitly assign section addresses when the previous fragment is layed out.
llvm-svn: 103752
2010-05-14 00:37:17 +00:00
Daniel Dunbar 8f9d2266e6 MC: Switch MCFragment to storing the layout order index, not its index in the file.
llvm-svn: 103751
2010-05-14 00:37:14 +00:00
Daniel Dunbar a99a23b061 MC: Change LayoutSection() to only do the section initializiation.
Also, elimminate MCAsmLayout::set*, which are no longer needed.

llvm-svn: 103750
2010-05-14 00:37:11 +00:00