You copied the Doc URL to your clipboard.

Build a SysV shared object

To build SysV shared libraries, compile the code for position independence using the -fsysv and -fpic options. Compiling for position independence is required because a shared library can load to any suitable address in the memory map. The linker options that are required to build a SysV shared library are --sysv, --shared, and --fpic.

Build the shared library and then run fromelf to examine the contents.

Procedure

  1. Create the file lib.c containing the following code:
    __attribute__((visibility("default")))
    int lib_func(int a)
    {
        return 5 * a;
    }
  2. Build the library:
    armclang --target=arm-arm-none-eabi -march=armv8-a -c -fsysv -fpic lib.c
    armlink --sysv --shared --fpic lib.o -o lib.so
  3. Run fromelf with the --only option to see that the function lib_func() has the visibility set to default and is present in the dynamic symbol table:
    fromelf -s --only=.dynsym lib.so
    ...
    ** Section #2 '.dynsym' (SHT_DYNSYM) [SHF_ALLOC]
        Size   : 32 bytes (alignment 4)
        Address: 0x00000110
        String table #3 '.dynstr'
        Last local symbol no. 0
    
        Symbol table .dynsym (1 symbols, 0 local)
    
          #  Symbol Name                Value      Bind  Sec  Type  Vis  Size
        ========================================================================
    
          1  lib_func                   0x00000144   Gb    4  Code  De   0x1c
    ...