The R_X86_64_JUMP_SLOT relocations are applied to the GOT (global offset table) slots, not to the call instructions you're seeing.
The call instructions go to the PLT (Program linkage table) stubs in the .plt section, and those, in turn, use the GOT and the .rela.plt relocations to resolve and jump to the final symbol in the external shared object. This process happens with the help of the dynamic linker (ld.so) and is a little too complicated to explain in this answer box, but you can find more information by searching for these terms.
To add a symbol to an ELF file you can use objcopy --add-symbol (how logical!).
--add-symbol name=[section:]value[,flags]Add a new symbol named name while copying the file. This option may be specified multiple times. If the section is given, the symbol will be associated with and relative to that section, otherwise it will be an ABS symbol. Specifying an undefined section will result in a fatal error. There is no check for the value, it will be taken as specified. Symbol flags can be specified and not all flags will be meaningful for all object file formats. By default, the symbol will be global. The special flag ’before=othersym’ will insert the new symbol in front of the specified othersym, otherwise the symbol(s) will be added at the end of the symbol table in the order they appear.
For example:
Copy❯ file test
test: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=b41a48662a58bb74c584e5208bea0d3c8452695d, not stripped
❯ objcopy --add-symbol mysym=5 test test2
❯ nm test | grep mysym
❯ nm test2 | grep mysym
0000000000000005 A mysym
You can add absolute symbols and section-relative symbols as described. The flags can be used to set the symbol flags.
The LLVM version of objcopy has a better description:
--add-symbol <name>=[<section>:]<value>[,<flags>]Add a new symbol called to the output symbol table, in the section named , with value . If is not specified, the symbol is added as an absolute symbol. The affect the symbol properties. Accepted values are:
Copyglobal = the symbol will have global binding. local = the symbol will have local binding. weak = the symbol will have weak binding. default = the symbol will have default visibility. hidden = the symbol will have hidden visibility. protected = the symbol will have protected visibility. file = the symbol will be an STT_FILE symbol. section = the symbol will be an STT_SECTION symbol. object = the symbol will be an STT_OBJECT symbol. function = the symbol will be an STT_FUNC symbol. indirect-function = the symbol will be an STT_GNU_IFUNC symbol.Additionally, the following flags are accepted but ignored: debug, constructor, warning, indirect, synthetic, unique-object, before.
Can be specified multiple times to add multiple symbols.
Flags are comma separated.
ELF has nothing to do with the symbols stored in it by programs. It is just a format to encode everything. Symbols are generated normally by compilers, like the C compiler, fortran compiler or an assembler, while sections are fixed by the programming language (e.g. the C compiler only uses a limited number of sections, depending on the kind of data you are using in your programs). Some compilers have extensions to associate a variable to a section, so the linke will consider it special in some way. The compiler/assembler generates a symbol table in order for the linker to be able to use it to resolve dependencies.
If you want to add symbols to your program, the easiest way it to create an assembler module with the sections and symbols you want to add to the executable, then assemble it and link to the final executable.
Read about ld(1) program (the linker), and how it uses the link scripts (special hidden files that direct the linker on how to organize the sections in the different modules at link time) to handle the sections in an object file. ELF is just a format. If you use a link script and the help of the assembler, you'll be able to add any section you want or modify the normal memory map that programs use to have.