[lld] r234991 - [ARM] Don't generate veneers when bl->blx fixup is possible
Denis Protivensky
dprotivensky at accesssoftek.com
Wed Apr 15 03:05:12 PDT 2015
Author: denis-protivensky
Date: Wed Apr 15 05:05:12 2015
New Revision: 234991
URL: http://llvm.org/viewvc/llvm-project?rev=234991&view=rev
Log:
[ARM] Don't generate veneers when bl->blx fixup is possible
Modified:
lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp
lld/trunk/test/elf/ARM/plt-dynamic.test
lld/trunk/test/elf/ARM/plt-ifunc-interwork.test
lld/trunk/test/elf/ARM/plt-ifunc-mapping.test
Modified: lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp?rev=234991&r1=234990&r2=234991&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp Wed Apr 15 05:05:12 2015
@@ -338,10 +338,12 @@ template <class Derived> class ARMReloca
case R_ARM_CALL:
case R_ARM_JUMP24:
case R_ARM_THM_JUMP24:
- case R_ARM_THM_JUMP11:
- static_cast<Derived *>(this)->handlePlain(isThumbCode(&atom), ref);
- static_cast<Derived *>(this)->handleVeneer(atom, ref);
- break;
+ case R_ARM_THM_JUMP11: {
+ const auto actualModel = actualSourceCodeModel(atom, ref);
+ const bool fromThumb = isThumbCode(actualModel);
+ static_cast<Derived *>(this)->handlePlain(fromThumb, ref);
+ static_cast<Derived *>(this)->handleVeneer(atom, fromThumb, ref);
+ } break;
case R_ARM_TLS_IE32:
static_cast<Derived *>(this)->handleTLSIE32(ref);
break;
@@ -354,7 +356,39 @@ template <class Derived> class ARMReloca
}
protected:
- std::error_code handleVeneer(const DefinedAtom &atom, const Reference &ref) {
+ /// \brief Determine source atom's actual code model.
+ ///
+ /// Actual code model may differ from the existing one if fixup
+ /// is possible on the later stages for given relocation type.
+ DefinedAtom::CodeModel actualSourceCodeModel(const DefinedAtom &atom,
+ const Reference &ref) {
+ const auto kindValue = ref.kindValue();
+ if (kindValue != R_ARM_CALL && kindValue != R_ARM_THM_CALL)
+ return atom.codeModel();
+
+ // TODO: For unconditional jump instructions (R_ARM_CALL and R_ARM_THM_CALL)
+ // fixup isn't possible without veneer generation for archs below ARMv5.
+
+ auto actualModel = atom.codeModel();
+ if (const auto *da = dyn_cast<DefinedAtom>(ref.target())) {
+ actualModel = da->codeModel();
+ } else if (const auto *sla = dyn_cast<SharedLibraryAtom>(ref.target())) {
+ if (sla->type() == SharedLibraryAtom::Type::Code) {
+ // PLT entry will be generated here - assume we don't want a veneer
+ // on top of it and prefer instruction fixup if needed.
+ actualModel = DefinedAtom::codeNA;
+ }
+ }
+ return actualModel;
+ }
+
+ std::error_code handleVeneer(const DefinedAtom &atom, bool fromThumb,
+ const Reference &ref) {
+ // Actual instruction mode differs meaning that further fixup will be
+ // applied.
+ if (isThumbCode(&atom) != fromThumb)
+ return std::error_code();
+
const VeneerAtom *(Derived::*getVeneer)(const DefinedAtom *, StringRef) =
nullptr;
const auto kindValue = ref.kindValue();
@@ -375,9 +409,6 @@ protected:
if (!target || isThumbCode(target) == isThumbCode(&atom))
return std::error_code();
- // TODO: For unconditional jump instructions (R_ARM_CALL and R_ARM_THM_CALL)
- // fixup isn't possible without veneer generation for archs below ARMv5.
-
// Veneers may only be generated for STT_FUNC target symbols
// or for symbols located in sections different to the place of relocation.
StringRef secName = atom.customSectionName();
Modified: lld/trunk/test/elf/ARM/plt-dynamic.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/ARM/plt-dynamic.test?rev=234991&r1=234990&r2=234991&view=diff
==============================================================================
--- lld/trunk/test/elf/ARM/plt-dynamic.test (original)
+++ lld/trunk/test/elf/ARM/plt-dynamic.test Wed Apr 15 05:05:12 2015
@@ -41,6 +41,24 @@
# THM-NEXT: 400160 {{[0-9a-f]+}} fff7f4bf
# b PLT_fn ^^
+# 3. Thumb code generates PLT entries without veneers when bl->blx is done.
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-thm.o
+# RUN: lld -flavor gnu -target arm-linux-gnu \
+# RUN: --noinhibit-exec %t-thm.o -lfn -L%p/Inputs -o %t
+# RUN: llvm-objdump -s %t | FileCheck -check-prefix=THM-BLX %s
+
+# THM-BLX: Contents of section .rel.plt:
+# THM-BLX-NEXT: 400134 0c104000 16010000
+# GOT addr = 0x40100c ^^
+# THM-BLX-NEXT: Contents of section .plt:
+# THM-BLX-NEXT: 40013c 04e02de5 04e09fe5 0ee08fe0 00f0bee5
+# ^ -- PLT0 --
+# THM-BLX-NEXT: 40014c bc0e0000 00c68fe2 00ca8ce2 b4febce5
+# -- ^ ^ -- PLT_fn -- ^
+# THM-BLX: Contents of section .text:
+# THM-BLX-NEXT: 40015c {{[0-9a-f]+}} fff7f6ef
+# blx PLT_fn ^^
+
# Generation of mapping symbols.
# RUN: yaml2obj -format=elf -docnum 1 %s > %t-arm.o
# RUN: lld -flavor gnu -target arm-linux-gnu \
@@ -127,6 +145,47 @@ Sections:
- Name: .data
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x0000000000000001
+ Content: ''
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x0000000000000001
+ Content: ''
+Symbols:
+ Global:
+ - Name: main
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x0000000000000001
+ - Name: fn
+
+# thm-c.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_ARM
+ Flags: [ EF_ARM_EABI_VER5 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x0000000000000004
+ Content: 80B500AFFFF7FEFF0346184680BD00BF
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x0000000000000004
+ Info: .text
+ Relocations:
+ - Offset: 0x0000000000000004
+ Symbol: fn
+ Type: R_ARM_THM_CALL
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
AddressAlign: 0x0000000000000001
Content: ''
- Name: .bss
Modified: lld/trunk/test/elf/ARM/plt-ifunc-interwork.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/ARM/plt-ifunc-interwork.test?rev=234991&r1=234990&r2=234991&view=diff
==============================================================================
--- lld/trunk/test/elf/ARM/plt-ifunc-interwork.test (original)
+++ lld/trunk/test/elf/ARM/plt-ifunc-interwork.test Wed Apr 15 05:05:12 2015
@@ -99,6 +99,18 @@
# Next line shows that .plt section ends.
# THM-TWO-NEXT: Contents of section .text:
+# 9. Thumb code generates PLT without transition veneer when bl->blx is done.
+# RUN: yaml2obj -format=elf -docnum 6 %s > %t-f1-thm-c.o
+# RUN: lld -flavor gnu -target arm-linux-gnu \
+# RUN: -Bstatic --noinhibit-exec %t-f1-thm-c.o -o %t
+# RUN: llvm-objdump -s %t | FileCheck -check-prefix=THM-BL %s
+
+# THM-BL: Contents of section .plt:
+# THM-BL-NEXT: 40007c 00c68fe2 00ca8ce2 7cffbce5
+# ^ regular veneer ^
+# Next line shows that .plt section ends.
+# THM-BL-NEXT: Contents of section .text:
+
# f1-arm.o
---
FileHeader:
@@ -112,7 +124,7 @@ Sections:
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x0000000000000004
- Content: 04B02DE500B08DE2003000E3003040E30300A0E100D04BE204B09DE41EFF2FE100482DE904B08DE2FEFFFFEB0030A0E10300A0E10088BDE8
+ Content: 04B02DE500B08DE2003000E3003040E30300A0E100D04BE204B09DE41EFF2FE100482DE904B08DE2FEFFFFEA0030A0E10300A0E10088BDE8
- Name: .rel.text
Type: SHT_REL
Link: .symtab
@@ -127,7 +139,7 @@ Sections:
Type: R_ARM_MOVT_ABS
- Offset: 0x0000000000000028
Symbol: f1
- Type: R_ARM_CALL
+ Type: R_ARM_JUMP24
- Name: .data
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
@@ -161,7 +173,7 @@ Sections:
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x0000000000000004
- Content: 80B400AF40F20003C0F200031846BD465DF8047B704700BF80B500AFFFF7FEFF0346184680BD00BF
+ Content: 80B400AF40F20003C0F200031846BD465DF8047B704700BF80B500AFFFF7FEBF0346184680BD00BF
- Name: .rel.text
Type: SHT_REL
Link: .symtab
@@ -176,7 +188,7 @@ Sections:
Type: R_ARM_THM_MOVT_ABS
- Offset: 0x000000000000001C
Symbol: f1
- Type: R_ARM_THM_CALL
+ Type: R_ARM_THM_JUMP24
- Name: .data
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
@@ -211,7 +223,7 @@ Sections:
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x0000000000000004
- Content: 80B500AFFFF7FEFF0346184680BD00BF
+ Content: 80B500AFFFF7FEBF0346184680BD00BF
- Name: .rel.text
Type: SHT_REL
Link: .symtab
@@ -220,7 +232,7 @@ Sections:
Relocations:
- Offset: 0x0000000000000004
Symbol: f1
- Type: R_ARM_THM_CALL
+ Type: R_ARM_THM_JUMP24
- Name: .data
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
@@ -252,7 +264,7 @@ Sections:
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x0000000000000004
- Content: 04B02DE500B08DE2003000E3003040E30300A0E100D04BE204B09DE41EFF2FE100482DE904B08DE2FEFFFFEB0030A0E10300A0E10088BDE8
+ Content: 04B02DE500B08DE2003000E3003040E30300A0E100D04BE204B09DE41EFF2FE100482DE904B08DE2FEFFFFEA0030A0E10300A0E10088BDE8
- Name: .rel.text
Type: SHT_REL
Link: .symtab
@@ -267,7 +279,7 @@ Sections:
Type: R_ARM_MOVT_ABS
- Offset: 0x0000000000000028
Symbol: f2
- Type: R_ARM_CALL
+ Type: R_ARM_JUMP24
- Name: .data
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
@@ -301,7 +313,7 @@ Sections:
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x0000000000000004
- Content: 80B400AF40F20003C0F200031846BD465DF8047B704700BF80B500AFFFF7FEFF0346184680BD00BF
+ Content: 80B400AF40F20003C0F200031846BD465DF8047B704700BF80B500AFFFF7FEBF0346184680BD00BF
- Name: .rel.text
Type: SHT_REL
Link: .symtab
@@ -316,7 +328,7 @@ Sections:
Type: R_ARM_THM_MOVT_ABS
- Offset: 0x000000000000001C
Symbol: f2
- Type: R_ARM_THM_CALL
+ Type: R_ARM_THM_JUMP24
- Name: .data
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
@@ -337,4 +349,54 @@ Symbols:
Type: STT_FUNC
Section: .text
Value: 0x0000000000000019
+
+# f1-thm-c.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_ARM
+ Flags: [ EF_ARM_EABI_VER5 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x0000000000000004
+ Content: 80B400AF40F20003C0F200031846BD465DF8047B704700BF80B500AFFFF7FEFF0346184680BD00BF
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x0000000000000004
+ Info: .text
+ Relocations:
+ - Offset: 0x0000000000000004
+ Symbol: main
+ Type: R_ARM_THM_MOVW_ABS_NC
+ - Offset: 0x0000000000000008
+ Symbol: main
+ Type: R_ARM_THM_MOVT_ABS
+ - Offset: 0x000000000000001C
+ Symbol: f1
+ Type: R_ARM_THM_CALL
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x0000000000000001
+ Content: ''
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x0000000000000001
+ Content: ''
+Symbols:
+ Global:
+ - Name: f1
+ Type: STT_GNU_IFUNC
+ Section: .text
+ Value: 0x0000000000000001
+ - Name: main
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x0000000000000019
...
Modified: lld/trunk/test/elf/ARM/plt-ifunc-mapping.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/ARM/plt-ifunc-mapping.test?rev=234991&r1=234990&r2=234991&view=diff
==============================================================================
--- lld/trunk/test/elf/ARM/plt-ifunc-mapping.test (original)
+++ lld/trunk/test/elf/ARM/plt-ifunc-mapping.test Wed Apr 15 05:05:12 2015
@@ -23,7 +23,7 @@ Sections:
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x0000000000000004
- Content: 04B02DE500B08DE2003000E3003040E30300A0E100D04BE204B09DE41EFF2FE100482DE904B08DE2FEFFFFEB0030A0E10300A0E10088BDE8
+ Content: 04B02DE500B08DE2003000E3003040E30300A0E100D04BE204B09DE41EFF2FE100482DE904B08DE2FEFFFFEA0030A0E10300A0E10088BDE8
- Name: .rel.text
Type: SHT_REL
Link: .symtab
@@ -38,7 +38,7 @@ Sections:
Type: R_ARM_MOVT_ABS
- Offset: 0x0000000000000028
Symbol: f1
- Type: R_ARM_CALL
+ Type: R_ARM_JUMP24
- Name: .data
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
@@ -72,7 +72,7 @@ Sections:
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x0000000000000004
- Content: 80B400AF40F20003C0F200031846BD465DF8047B704700BF80B500AFFFF7FEFF0346184680BD00BF
+ Content: 80B400AF40F20003C0F200031846BD465DF8047B704700BF80B500AFFFF7FEBF0346184680BD00BF
- Name: .rel.text
Type: SHT_REL
Link: .symtab
@@ -87,7 +87,7 @@ Sections:
Type: R_ARM_THM_MOVT_ABS
- Offset: 0x000000000000001C
Symbol: f2
- Type: R_ARM_THM_CALL
+ Type: R_ARM_THM_JUMP24
- Name: .data
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
More information about the llvm-commits
mailing list