llvm-mc fixups

When I use llvm-mc’s ‘-show-encoding’, it only goes as far as printing “fixups”:

$ echo -e “adr r0, lbl\nnop\nlbl:” | llvm-mc -triple=thumbv7 -show-encoding

Outputs:

@ encoding: [A,0xa0]

@ fixup A – offset: 0, value: lbl, kind: fixup_thumb_adr_pcrel_10

To find out that it is encoded as 0xa001, I can do:

$ echo -e “adr r0, lbl\nnop\nlbl:” | llvm-mc -triple=thumbv7 -show-encoding -filetype=obj > tmp.o

$ llvm-objdump -d tmp.o

Is there a way to get that encoding directly from llvm-mc?

Thanks,

Greg

Showing the value for the fixup requires full object code layout and relaxation, which isn’t done is the text-to-text path.

–Owen

Showing the value for the fixup requires full object
code layout and relaxation, which isn’t done is the text-to-text path.

Their are 2 problems I’m looking to solve:

  1. How do we unit-test the integrated assembler when there are fixups?
  2. Can we avoid the duplication in encoding a fixup versus encoding an immediate?

In the case of ADR, the fixup was properly being shifted for Thumb mode, but the immediate was not. In my first attempt to fix this (and another developer as well), we patched the .td file, which fixed the immediate and broke the fixup.

So I wonder, do all fixups require full object code layout? For example, in the context of Thumb, can we always convert:

adr r0, lbl
nop
lbl:

into:

adr.n r0, #0

I understand why clang’s “-S” option would never want to output this syntax (GCC doesn’t grok all UAL syntax). But for LLVM’s internal assembler, should we be trying to remove some fixups with a text-to-text pass before encoding? I see llvm-mc has a ‘-mc-relax-all’ option, but doesn’t seem to do anything for me - unrelated?

Thanks,
Greg

  1) How do we unit-test the integrated assembler when there are fixups?

The tests we have right now produce an object and dump it (using
elf-dump for example).

I understand why clang's "-S" option would never want to output this syntax
(GCC doesn't grok all UAL syntax). But for LLVM's internal assembler,
should we be trying to remove some fixups with a text-to-text pass before
encoding? I see llvm-mc has a '-mc-relax-all' option, but doesn't seem to
do anything for me - unrelated?

It still kicks in only during direct object emission. Its objective is
just to speed up object emission by producing fewer fragments.

Thanks,
Greg

Cheers,
Rafael