This is an archive of the discontinued LLVM Phabricator instance.

Support ARM_V4BX relocation
ClosedPublic

Authored by yinma on Oct 19 2018, 11:30 AM.

Details

Summary

This patch implementation the handler for ARM_V4BX. This relocation is used by GNU runtime files and other armv4 applications.

Diff Detail

Repository
rL LLVM

Event Timeline

yinma created this revision.Oct 19 2018, 11:30 AM
yinma added a reviewer: pcc.Oct 19 2018, 12:18 PM
ruiu added inline comments.Oct 19 2018, 1:52 PM
ELF/Arch/ARM.cpp
522 ↗(On Diff #170224)

This is little weird that you can just ignore the relocation. Is this correct?

test/ELF/Inputs/v4bx.yaml
1 ↗(On Diff #170224)

Assembly is preferred over YAML. I'm not sure if you can express this file in .s, but if you can, please do. If you can't, YAML is fine though.

test/ELF/v4bx.s
10 ↗(On Diff #170224)

Remove the trailing blank line.

efriedma added inline comments.
ELF/Arch/ARM.cpp
522 ↗(On Diff #170224)

Yes, it's correct to ignore it; it's just a marker to indicate there's a "bx rN" instruction at the given address. (It can be used to implement a special linker mode which rewrites ARMv4T inputs to ARMv4.)

test/ELF/Inputs/v4bx.yaml
1 ↗(On Diff #170224)

LLVM currently never generates R_ARM_V4BX relocations.

This change looks fine to me. Just to check what CPU you are intending to run the output on. The LLD interworking, Thunk and PLT support assumes the presence of the BLX instruction which is only present on ARMv5 CPUs and above (LLD will warn if it doesn't detect at least one object compiled for ARMv5 or above).

Do you actually need ARMv4t support? I can work on supporting it but it probably wouldn't be optimal. At a minimum we'd need to insert Thunks for every interworking BL, including all Thumb calls to PLT sequences, prevent ARM and Thumb callers from sharing the a Thunk that starts in a different state, and have a new set of Thunks that avoid v5t instructions.

From memory, when the ABI was created the number of ARM only ARMv4 CPUs was tiny compared to those supporting ARM and Thumb, and all future CPUs would support Thumb so to simplify code generation it was assumed that BX reg could always be generated and a linker could translate it if needed.

From the ABI for the ARM Architecture:
R_ARM_V4BX records the location of an ARMv4t BX instruction. This enables a static linker to generate ARMv4 compatible images from ARMv4t objects containing only ARM code by converting the instruction to MOV PC, r, where r is the register used in the BX instruction. See [AAPCS] for details. The symbol is unused and may even be the NULL symbol (index 0).

Do you actually need ARMv4t support?

No, we don't target anything older than ARMv5. This issue showed up because some of our tests use an ARMv4 sysroot.

This may be a silly question, but what is ARMv4 sysroot, and why do you
need this patch for "ARMv4 sysroot"?

By "ARMv4 sysroot", I mean a Linux sysroot that supports ARMv4T. So libc etc. are built with gcc, targeting ARMv4T, which generates these relocations.

ruiu added a comment.Oct 22 2018, 2:02 PM

I'm confused. You wrote that you don't want to target anything older than ARMv5, and this patch fixes an issue for ARMv4T, which look inconsistent as long as ARMv4T < ARMv5.

Some of the input object files are built for ARMv4T. The output executable is not; it's something like ARMv7, because some of the input object files are built for ARMv7.

ruiu added inline comments.Oct 22 2018, 2:24 PM
ELF/Arch/ARM.cpp
520–521 ↗(On Diff #170224)

Please elaborate a bit more based on Eli's comment. I'd write

V4BX is just a marker to indicate there's a "bx rN" instruction at the given address. It can be used to implement a special linker mode which rewrites ARMv4T inputs to ARMv4. Since we support only ARMv4 input and not ARMv4 output, we can just ignore it.
yinma updated this revision to Diff 172187.Nov 1 2018, 11:18 AM
yinma marked 6 inline comments as done.
ruiu added inline comments.Nov 1 2018, 11:26 AM
test/ELF/v4bx.s
1 ↗(On Diff #172187)

I think you don't need two input files. This main test file can be written in YAML which contains _start symbol.

yinma updated this revision to Diff 173033.Nov 7 2018, 2:28 PM
ruiu added inline comments.Nov 7 2018, 2:35 PM
test/ELF/v4bx.s
1 ↗(On Diff #172187)

Hmm, do you still need this empty object file?

yinma added inline comments.Nov 7 2018, 2:38 PM
test/ELF/v4bx.s
1 ↗(On Diff #172187)

I need lld to link an object containing a V4BX relocation.

MaskRay added inline comments.Nov 10 2018, 12:50 PM
test/ELF/v4bx.s
1 ↗(On Diff #172187)

I think @ruiu means: as you don't use test/ELF/v4bx.s to produce an object file. You could mv test/ELF/Inputs/v4bx.yaml test/ELF/v4bx.yaml and put check lines in v4bx.yaml. v4bx.s is not necessary.

ruiu added inline comments.Nov 11 2018, 6:13 PM
test/ELF/v4bx.s
1 ↗(On Diff #172187)

Yeah, right. That's what I meant.

yinma updated this revision to Diff 174142.Nov 14 2018, 6:00 PM
ruiu added inline comments.Nov 14 2018, 8:05 PM
test/ELF/v4bx.yaml
2 ↗(On Diff #174142)

nit: since now you have only one object file, %tv4x.o -> %t.o.

4–6 ↗(On Diff #174142)

Does this really check anything? My understanding is that if ld.lld succeeds, then the test succeeded. So you don't really need readelf, no?

yinma updated this revision to Diff 174245.Nov 15 2018, 10:30 AM
yinma added inline comments.Nov 15 2018, 10:46 AM
test/ELF/v4bx.yaml
4–6 ↗(On Diff #174142)

We cannot assume ld.lld succeeds without checking the output. Without readelf checking, if lld just simply returns 0 without producing a correct .o, the test will still pass. Actually it is good practice to check something in the output for all unit tests.

ruiu accepted this revision.Nov 15 2018, 5:48 PM

LGTM

test/ELF/v4bx.yaml
4–6 ↗(On Diff #174142)

Please rename this file arm-v4bx.test to follow the local convention.

This revision is now accepted and ready to land.Nov 15 2018, 5:48 PM
This revision was automatically updated to reflect the committed changes.

Contacted by the author to commit on behalf of him.