[llvm] r235513 - Support arm32 R_ARM_V4BX relocation format

Adhemerval Zanella azanella at linux.vnet.ibm.com
Wed Apr 22 08:26:44 PDT 2015


Author: azanella
Date: Wed Apr 22 10:26:43 2015
New Revision: 235513

URL: http://llvm.org/viewvc/llvm-project?rev=235513&view=rev
Log:
Support arm32 R_ARM_V4BX relocation format

ARM32 ELF R_ARM_V4BX relocation format is a special relocation type
that records the location of an ARMv4t BX instruction to enable a
static linker to generate ARMv4 compatible instructions.  This
relocation does not contain a reference symbol.

This patch enabled its creation by removing the requeriment of a
relocation symbol target in ELFState<ELFT>::writeSectionContent.


Added:
    llvm/trunk/test/Object/yaml2obj-elf-rel-noref.yaml
Modified:
    llvm/trunk/tools/yaml2obj/yaml2elf.cpp

Added: llvm/trunk/test/Object/yaml2obj-elf-rel-noref.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/yaml2obj-elf-rel-noref.yaml?rev=235513&view=auto
==============================================================================
--- llvm/trunk/test/Object/yaml2obj-elf-rel-noref.yaml (added)
+++ llvm/trunk/test/Object/yaml2obj-elf-rel-noref.yaml Wed Apr 22 10:26:43 2015
@@ -0,0 +1,77 @@
+# RUN: yaml2obj -format=elf %s | llvm-readobj -sections -relocations - | FileCheck %s
+
+!ELF
+FileHeader:        !FielHeader
+  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:         03308FE0022093E7000052E31EFF2F01
+  - Name:            .rel.text
+    Type:            SHT_REL
+    Flags:           [ SHF_INFO_LINK ]
+    Link:            .symtab
+    AddressAlign:    0x0000000000000004
+    Info:            .text
+    Relocations:     
+      - Offset:          0x000000000000000C
+        Symbol:          ''
+        Type:            R_ARM_V4BX
+  - 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:         ''
+  - Name:            .ARM.attributes
+    Type:            SHT_ARM_ATTRIBUTES
+    AddressAlign:    0x0000000000000001
+    Content:         4115000000616561626900010B000000060208010901
+Symbols:         
+  Local:           
+    - Name:            .text
+      Type:            STT_SECTION
+      Section:         .text
+    - Name:            .data
+      Type:            STT_SECTION
+      Section:         .data
+    - Name:            .bss
+      Type:            STT_SECTION
+      Section:         .bss
+    - Name:            '$a'
+      Section:         .text
+    - Name:            call_weak_fn
+      Type:            STT_FUNC
+      Section:         .text
+    - Name:            .ARM.attributes
+      Type:            STT_SECTION
+      Section:         .ARM.attributes
+
+# CHECK:        Section {
+# CHECK-NEXT:     Index: 0
+# CHECK:        }
+# CHECK:        Section {
+# CHECK-NEXT:     Index: 1
+# CHECK-NEXT:     Name: .text (5)
+# CHECK:        }
+# CHECK-NEXT:   Section {
+# CHECK-NEXT:     Index: 2
+# CHECK-NEXT:     Name: .rel.text (1)
+# CHECK-NEXT:     Type: SHT_REL (0x9)
+# CHECK-NEXT:     Flags [ (0x40)
+# CHECK:	}
+# CHECK:        Relocations [
+# CHECK-NEXT:     Section (2) .rel.text {
+# CHECK-NEXT:       0xC R_ARM_V4BX - 0x0
+# CHECK-NEXT:     }
+# CHECK-NEXT:   ]

Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=235513&r1=235512&r2=235513&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Wed Apr 22 10:26:43 2015
@@ -357,12 +357,11 @@ ELFState<ELFT>::writeSectionContent(Elf_
   auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset);
 
   for (const auto &Rel : Section.Relocations) {
-    unsigned SymIdx;
-    if (SymN2I.lookup(Rel.Symbol, SymIdx)) {
-      errs() << "error: Unknown symbol referenced: '" << Rel.Symbol
-             << "' at YAML relocation.\n";
-      return false;
-    }
+    unsigned SymIdx = 0;
+    // Some special relocation, R_ARM_v4BX for instance, does not have
+    // an external reference.  So it ignores the return value of lookup()
+    // here.
+    SymN2I.lookup(Rel.Symbol, SymIdx);
 
     if (IsRela) {
       Elf_Rela REntry;





More information about the llvm-commits mailing list