2.6 Using fromelf to find where a symbol is placed in an executable ELF image

You can find where a symbol is placed in an executable ELF image.

To find where a symbol is placed in an ELF image file, use the --text -s -v options to view the symbol table and detailed information on each segment and section header, for example:

The symbol table identifies the section where the symbol is placed.

Procedure

  1. Create the file s.c containing the following source code:
    long long arr[10] __attribute__ ((section ("ARRAY")));
    int main()
    {
        return sizeof(arr);
    }
  2. Compile the source:

    armclang --target=arm-arm-none-eabi -march=armv8-a -c s.c -o s.o

  3. Link the object s.o and keep the ARRAY symbol:
    armlink --cpu=8-A.32 --keep=s.o(ARRAY) s.o --output=s.axf
  4. Run the fromelf command to display the symbol table and detailed information on each segment and section header:
    fromelf --text -s -v s.o
  5. Locate the arr symbol in the fromelf output, for example:
              ...
        ** Section #24
        Name        : .symtab
        Type        : SHT_SYMTAB (0x00000002)
        Flags       : None (0x00000000)
        Addr        : 0x00000000
        File Offset : 868 (0x364)
        Size        : 464 bytes (0x1d0)
        Link        : Section 1 (.strtab)
        Info        : Last local symbol no = 26
        Alignment   : 4
        Entry Size  : 16
              
        Symbol table .symtab (28 symbols, 26 local)
              
          #  Symbol Name                Value      Bind  Sec  Type  Vis  Size
        =========================================================================
         ...
         27  arr                        0x00000000   Gb    5  Data  De   0x50
              ...

    The Sec column shows the section where the stack is placed. In this example, section 5.

  6. Locate the section identified for the symbol in the fromelf output, for example:
    ...
    ====================================
    ** Section #5
        Name        : ARRAY
        Type        : SHT_PROGBITS (0x00000001)
        Flags       : SHF_ALLOC + SHF_WRITE (0x00000003)
        Addr        : 0x00000000
        File Offset : 88 (0x58)
        Size        : 80 bytes (0x50)
        Link        : SHN_UNDEF
        Info        : 0
        Alignment   : 8
        Entry Size  : 0
        ====================================
        ...

    This shows that the symbols are placed in an ARRAY section.

Non-ConfidentialPDF file icon PDF version100071_0609_00_en
Copyright © 2014–2017 Arm Limited (or its affiliates). All rights reserved.