Search code examples
elfdebug-symbols

different symbols with the same name in ELF binary


Can a statically linked ELF file (with symbols) have two different symbols with same name?


Solution

  • Can a statically linked ELF file (with symbols) have two different symbols with same name?

    Absolutely, provided the symbols have local linkage. Example:

    // foo.c
    static int foo1() { return 42; }
    int foo() { return foo1(); }
    
    // bar.c
    static int foo1() { return 24; }
    int main() { return foo1(); }
    
    gcc -static foo.c bar.c
    
    nm ./a.out | grep ' foo1'
    0000000000401c2d t foo1
    0000000000401c48 t foo1
    

    QED.