You copied the Doc URL to your clipboard.

Build a SysV executable

To build a SysV executable with position independence compile with the -fsysv option. Compiling with position independence is not required by some SysV systems. For example, Arm® Linux executables always execute from a fixed address of 0x8000. However, other operating systems that are based on the SysV model might decide to have position-independent executables.

Build the image and then run fromelf to examine the contents.

Prerequisites

Build the lib.o shared library as described in Build a SysV shared object.

Procedure

  1. Create the file app.c containing the following code:
    #include <stdio.h>
    
    int lib_func(int a);
    
    int main(void)
    {
        printf("Result: %d.\n", lib_func(3));
        return 0;
    }
  2. Build the main executable:
    armclang --target=arm-arm-none-eabi -march=armv8-a -c -fsysv app.c
    armlink --sysv app.o lib.so -o app.axf

    The reference to function lib_func() gets resolved by lib.so.

  3. Run fromelf with the --only option to see that the resulting image contains a DT_NEEDED tag that indicates library lib.so is needed by the executable:
    fromelf -y --only=.dynamic app.axf
    ...
    ** Section #9 '.dynamic' (SHT_DYNAMIC) [SHF_ALLOC + SHF_WRITE]
        Size   : 168 bytes (alignment 4)
        Address: 0x00012c9c
        String table #4 '.dynstr'
    
          #  Tag Name             Value
        ========================================================================
    
          0  DT_NEEDED                1 (lib.so)
          1  DT_HASH              33100 (0x0000814c)
          2  DT_STRTAB            33156 (0x00008184)
          3  DT_SYMTAB            33124 (0x00008164)
          4  DT_STRSZ                17
          5  DT_SYMENT               16
          6  DT_PLTRELSZ              8
          7  DT_PLTGOT            77124 (0x00012d44)
          8  DT_DEBUG                 0 (0x00000000)
          9  DT_JMPREL            33176 (0x00008198)
         10  DT_PLTREL               17 (DT_REL)
         11  DT_NULL                  0
    ...

    When executed, a platform-specific dynamic loader processes information in the dynamic array, loads lib.so, resolves relocations in all loaded files, and passes control to the main executable. The program then outputs:

    Result: 15.