[Driver] Pass --target2= to linker from baremetal toolchain
authorMikhail Maltsev <mikhail.maltsev@arm.com>
Fri, 28 Apr 2023 17:30:49 +0000 (18:30 +0100)
committerMikhail Maltsev <mikhail.maltsev@arm.com>
Fri, 28 Apr 2023 17:30:49 +0000 (18:30 +0100)
commit024bb62ffd072e9a90343e88c92e40b5849c2632
treec468c7de5918c692b389aa193c363907c58b1137
parent15f0491d3963d91202aef659acc20f59aa83fae7
[Driver] Pass --target2= to linker from baremetal toolchain

According to the GNU ld manual
https://sourceware.org/binutils/docs/ld/ARM.html#ARM the R_ARM_TARGET2
relocation (used in exception handling tables) is treated differently
depending on the target. By default, LLD treats R_ARM_TARGET2 as
R_ARM_GOT_PREL (--target2=got-rel), which is correct for Linux but not
for embedded targets.

This patch adds --target2=rel to linker options in the baremetal
toolchain driver so that on baremetal targets, R_ARM_TARGET2 is
treated as R_ARM_REL32. Such behavior is compatible with GNU ld and
unwinding libraries (e.g., libuwind).

Reviewed By: peter.smith, phosek

Differential Revision: https://reviews.llvm.org/D149458
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/test/Driver/baremetal.cpp