[PowerPC] ELFv2 MC support for .localentry directive
A second binutils feature needed to support ELFv2 is the .localentry
directive. In the ELFv2 ABI, functions may have two entry points:
one for calling the routine locally via "bl", and one for calling the
function via function pointer (either at the source level, or implicitly
via a PLT stub for global calls). The two entry points share a single
ELF symbol, where the ELF symbol address identifies the global entry
point address, while the local entry point is found by adding a delta
offset to the symbol address. That offset is encoded into three
platform-specific bits of the ELF symbol st_other field.
The .localentry directive instructs the assembler to set those fields
to encode a particular offset. This is typically used by a function
prologue sequence like this:
func:
addis r2, r12, (.TOC.-func)@ha
addi r2, r2, (.TOC.-func)@l
.localentry func, .-func
Note that according to the ABI, when calling the global entry point,
r12 must be set to point the global entry point address itself; while
when calling the local entry point, r2 must be set to point to the TOC
base. The two instructions between the global and local entry point in
the above example translate the first requirement into the second.
This patch implements support in the PowerPC MC streamers to emit the
.localentry directive (both into assembler and ELF object output), as
well as support in the assembler parser to parse that directive.
In addition, there is another change required in MC fixup/relocation
handling to properly deal with relocations targeting function symbols
with two entry points: When the target function is known local, the MC
layer would immediately handle the fixup by inserting the target
address -- this is wrong, since the call may need to go to the local
entry point instead. The GNU assembler handles this case by *not*
directly resolving fixups targeting functions with two entry points,
but always emits the relocation and relies on the linker to handle
this case correctly. This patch changes LLVM MC to do the same (this
is done via the processFixupValue routine).
Similarly, there are cases where the assembler would normally emit a
relocation, but "simplify" it to a relocation targeting a *section*
instead of the actual symbol. For the same reason as above, this
may be wrong when the target symbol has two entry points. The GNU
assembler again handles this case by not performing this simplification
in that case, but leaving the relocation targeting the full symbol,
which is then resolved by the linker. This patch changes LLVM MC
to do the same (via the needsRelocateWithSymbol routine).
NOTE: The method used in this patch is overly pessimistic, since the
needsRelocateWithSymbol routine currently does not have access to the
actual target symbol, and thus must always assume that it might have
two entry points. This will be improved upon by a follow-on patch
that modifies common code to pass the target symbol when calling
needsRelocateWithSymbol.
Reviewed by Hal Finkel.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213485 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-20 23:06:03 +00:00
|
|
|
|
|
|
|
# RUN: llvm-mc -triple powerpc64-unknown-unknown -filetype=obj %s | \
|
|
|
|
# RUN: llvm-readobj -h -r -symbols | FileCheck %s
|
|
|
|
# RUN: llvm-mc -triple powerpc64le-unknown-unknown -filetype=obj %s | \
|
|
|
|
# RUN: llvm-readobj -h -r -symbols | FileCheck %s
|
|
|
|
|
|
|
|
.type callee1, @function
|
|
|
|
callee1:
|
|
|
|
nop
|
|
|
|
nop
|
|
|
|
.localentry callee1, .-callee1
|
|
|
|
nop
|
|
|
|
nop
|
|
|
|
.size callee1, .-callee1
|
|
|
|
|
|
|
|
.type callee2, @function
|
|
|
|
callee2:
|
|
|
|
nop
|
|
|
|
nop
|
|
|
|
.size callee2, .-callee2
|
|
|
|
|
|
|
|
.type caller, @function
|
|
|
|
caller:
|
|
|
|
bl callee1
|
|
|
|
nop
|
|
|
|
bl callee2
|
|
|
|
nop
|
|
|
|
.size caller, .-caller
|
|
|
|
|
2014-07-20 23:15:06 +00:00
|
|
|
.section .text.other
|
|
|
|
caller_other:
|
|
|
|
bl callee1
|
|
|
|
nop
|
|
|
|
bl callee2
|
|
|
|
nop
|
|
|
|
.size caller_other, .-caller_other
|
|
|
|
|
2014-11-24 18:09:47 +00:00
|
|
|
copy1 = callee1
|
|
|
|
copy2 = callee2
|
|
|
|
|
[PowerPC] ELFv2 MC support for .localentry directive
A second binutils feature needed to support ELFv2 is the .localentry
directive. In the ELFv2 ABI, functions may have two entry points:
one for calling the routine locally via "bl", and one for calling the
function via function pointer (either at the source level, or implicitly
via a PLT stub for global calls). The two entry points share a single
ELF symbol, where the ELF symbol address identifies the global entry
point address, while the local entry point is found by adding a delta
offset to the symbol address. That offset is encoded into three
platform-specific bits of the ELF symbol st_other field.
The .localentry directive instructs the assembler to set those fields
to encode a particular offset. This is typically used by a function
prologue sequence like this:
func:
addis r2, r12, (.TOC.-func)@ha
addi r2, r2, (.TOC.-func)@l
.localentry func, .-func
Note that according to the ABI, when calling the global entry point,
r12 must be set to point the global entry point address itself; while
when calling the local entry point, r2 must be set to point to the TOC
base. The two instructions between the global and local entry point in
the above example translate the first requirement into the second.
This patch implements support in the PowerPC MC streamers to emit the
.localentry directive (both into assembler and ELF object output), as
well as support in the assembler parser to parse that directive.
In addition, there is another change required in MC fixup/relocation
handling to properly deal with relocations targeting function symbols
with two entry points: When the target function is known local, the MC
layer would immediately handle the fixup by inserting the target
address -- this is wrong, since the call may need to go to the local
entry point instead. The GNU assembler handles this case by *not*
directly resolving fixups targeting functions with two entry points,
but always emits the relocation and relies on the linker to handle
this case correctly. This patch changes LLVM MC to do the same (this
is done via the processFixupValue routine).
Similarly, there are cases where the assembler would normally emit a
relocation, but "simplify" it to a relocation targeting a *section*
instead of the actual symbol. For the same reason as above, this
may be wrong when the target symbol has two entry points. The GNU
assembler again handles this case by not performing this simplification
in that case, but leaving the relocation targeting the full symbol,
which is then resolved by the linker. This patch changes LLVM MC
to do the same (via the needsRelocateWithSymbol routine).
NOTE: The method used in this patch is overly pessimistic, since the
needsRelocateWithSymbol routine currently does not have access to the
actual target symbol, and thus must always assume that it might have
two entry points. This will be improved upon by a follow-on patch
that modifies common code to pass the target symbol when calling
needsRelocateWithSymbol.
Reviewed by Hal Finkel.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213485 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-20 23:06:03 +00:00
|
|
|
# Verify that use of .localentry implies ABI version 2
|
|
|
|
# CHECK: ElfHeader {
|
|
|
|
# CHECK: Flags [ (0x2)
|
|
|
|
|
|
|
|
# Verify that fixups to local function symbols are performed only
|
|
|
|
# if the target symbol does not use .localentry
|
|
|
|
# CHECK: Relocations [
|
|
|
|
# CHECK: Section ({{[0-9]*}}) .rela.text {
|
|
|
|
# CHECK-NEXT: R_PPC64_REL24 callee1
|
|
|
|
# CHECK-NEXT: }
|
|
|
|
# CHECK-NOT: R_PPC64_REL24 callee2
|
2014-07-20 23:15:06 +00:00
|
|
|
# CHECK: Section ({{[0-9]*}}) .rela.text.other {
|
|
|
|
# CHECK-NEXT: R_PPC64_REL24 callee1
|
|
|
|
# CHECK-NEXT: R_PPC64_REL24 .text
|
|
|
|
# CHECK-NEXT: }
|
[PowerPC] ELFv2 MC support for .localentry directive
A second binutils feature needed to support ELFv2 is the .localentry
directive. In the ELFv2 ABI, functions may have two entry points:
one for calling the routine locally via "bl", and one for calling the
function via function pointer (either at the source level, or implicitly
via a PLT stub for global calls). The two entry points share a single
ELF symbol, where the ELF symbol address identifies the global entry
point address, while the local entry point is found by adding a delta
offset to the symbol address. That offset is encoded into three
platform-specific bits of the ELF symbol st_other field.
The .localentry directive instructs the assembler to set those fields
to encode a particular offset. This is typically used by a function
prologue sequence like this:
func:
addis r2, r12, (.TOC.-func)@ha
addi r2, r2, (.TOC.-func)@l
.localentry func, .-func
Note that according to the ABI, when calling the global entry point,
r12 must be set to point the global entry point address itself; while
when calling the local entry point, r2 must be set to point to the TOC
base. The two instructions between the global and local entry point in
the above example translate the first requirement into the second.
This patch implements support in the PowerPC MC streamers to emit the
.localentry directive (both into assembler and ELF object output), as
well as support in the assembler parser to parse that directive.
In addition, there is another change required in MC fixup/relocation
handling to properly deal with relocations targeting function symbols
with two entry points: When the target function is known local, the MC
layer would immediately handle the fixup by inserting the target
address -- this is wrong, since the call may need to go to the local
entry point instead. The GNU assembler handles this case by *not*
directly resolving fixups targeting functions with two entry points,
but always emits the relocation and relies on the linker to handle
this case correctly. This patch changes LLVM MC to do the same (this
is done via the processFixupValue routine).
Similarly, there are cases where the assembler would normally emit a
relocation, but "simplify" it to a relocation targeting a *section*
instead of the actual symbol. For the same reason as above, this
may be wrong when the target symbol has two entry points. The GNU
assembler again handles this case by not performing this simplification
in that case, but leaving the relocation targeting the full symbol,
which is then resolved by the linker. This patch changes LLVM MC
to do the same (via the needsRelocateWithSymbol routine).
NOTE: The method used in this patch is overly pessimistic, since the
needsRelocateWithSymbol routine currently does not have access to the
actual target symbol, and thus must always assume that it might have
two entry points. This will be improved upon by a follow-on patch
that modifies common code to pass the target symbol when calling
needsRelocateWithSymbol.
Reviewed by Hal Finkel.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213485 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-20 23:06:03 +00:00
|
|
|
|
|
|
|
# Verify that .localentry is encoded in the Other field.
|
|
|
|
# CHECK: Symbols [
|
|
|
|
# CHECK: Name: callee1
|
|
|
|
# CHECK-NEXT: Value:
|
|
|
|
# CHECK-NEXT: Size: 16
|
|
|
|
# CHECK-NEXT: Binding: Local
|
|
|
|
# CHECK-NEXT: Type: Function
|
|
|
|
# CHECK-NEXT: Other: 96
|
|
|
|
# CHECK-NEXT: Section: .text
|
|
|
|
# CHECK: Name: callee2
|
|
|
|
# CHECK-NEXT: Value:
|
|
|
|
# CHECK-NEXT: Size: 8
|
|
|
|
# CHECK-NEXT: Binding: Local
|
|
|
|
# CHECK-NEXT: Type: Function
|
|
|
|
# CHECK-NEXT: Other: 0
|
|
|
|
# CHECK-NEXT: Section: .text
|
|
|
|
|
2014-11-24 18:09:47 +00:00
|
|
|
# Verify that symbol assignment copies the Other bits.
|
|
|
|
# CHECK: Name: copy1
|
|
|
|
# CHECK-NEXT: Value:
|
|
|
|
# CHECK-NEXT: Size: 16
|
|
|
|
# CHECK-NEXT: Binding: Local
|
|
|
|
# CHECK-NEXT: Type: Function
|
|
|
|
# CHECK-NEXT: Other: 96
|
|
|
|
# CHECK-NEXT: Section: .text
|
|
|
|
# CHECK: Name: copy2
|
|
|
|
# CHECK-NEXT: Value:
|
|
|
|
# CHECK-NEXT: Size: 8
|
|
|
|
# CHECK-NEXT: Binding: Local
|
|
|
|
# CHECK-NEXT: Type: Function
|
|
|
|
# CHECK-NEXT: Other: 0
|
|
|
|
# CHECK-NEXT: Section: .text
|
|
|
|
|