Simple functions in Rust in the release version do not appear in the symbol table

65 Views Asked by At

I created a Rust crate with cargo new --lib zero_obj,then write a very simple function:

pub fn test_function_base001() -> i32 {
    2
}

and compile the release version with cargo build --release.

When I look at the symbol table of the rlib file:

readelf -sW libzero_obj.rlib 

File: libzero_obj.rlib(lib.rmeta)

Symbol table '.symtab' contains 1 entry:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 

File: libzero_obj.rlib(zero_obj-68a8e959160a6c87.zero_obj.e381423afbee4894-cgu.0.rcgu.o)

Symbol table '.symtab' contains 3 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS zero_obj.e381423afbee4894-cgu.0
     2: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT    3 $d.0

I found that the pub fn test_function_base001 I wrote was not in the symbol table, so where did my function go? It is defined as a public function, which may be referenced by any other crate.

When the output file is a shared library, with a [lib] section like this:

[lib]
name = "zero_obj"
crate-type = ["dylib"]

the function is not available in the produced .so-file either.

0

There are 0 best solutions below