C Objects and Finding Unresolved Symbols

22 Dec in c programming

One of the issues when cross-compiling is time. As a developer I find that it really sucks after you waited for a program to compile, installed it and executed it to only find out.. its broken.

Before transfering it and installing it, there are two easy ways to see if there are undefined symbols: nm and readelf.

nm produces something like the following:

  1. 000002dc T DNP3ObjInit
  2.          U DynamicPreprocessorFatalMessage
  3.          U __ctype_b
  4.          U _dpd
  5.          U calloc
  6.          U strcmp
  7.          U strtok_r
  8.  
  9. dnp3_map.o:
  10. 00000000 t $a
  11. 00000058 t $a
  12. 000000a8 t $a
  13. 00000054 t $d
  14. 000000a4 t $d
  15. 000000f4 t $d
  16. 00000000 r $d
  17. 00000000 T DNP3FuncIsDefined
  18. 000000a8 T DNP3FuncStrToCode
  19. 00000058 T DNP3IndStrToCode
  20. 00000080 r func_map
  21. 00000000 r indication_map
  22.          U strcmp

readelf -s YourObject produces something like the following:

  1. ymbol table '.dynsym' contains 43 entries:
  2.    Num:    Value  Size Type    Bind   Vis      Ndx Name
  3.      0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
  4.      1: 00000da8     0 SECTION LOCAL  DEFAULT    8
  5.      2: 00000e94     0 SECTION LOCAL  DEFAULT   10
  6.      3: 00003570     0 SECTION LOCAL  DEFAULT   11
  7.      4: 00003588     0 SECTION LOCAL  DEFAULT   12
  8.      5: 0000460c     0 SECTION LOCAL  DEFAULT   13
  9.      6: 0000c610     0 SECTION LOCAL  DEFAULT   14
  10.      7: 0000c618     0 SECTION LOCAL  DEFAULT   15
  11.      8: 0000c620     0 SECTION LOCAL  DEFAULT   16
  12.      9: 0000c750     0 SECTION LOCAL  DEFAULT   19
  13.     10: 0000c768     0 SECTION LOCAL  DEFAULT   20
  14.     11: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND _dpd
  15.     12: 00000000   116 FUNC    GLOBAL DEFAULT  UND strtok_r
  16.     13: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND DynamicPreprocessorFatalM
  17.     14: 00000000     4 OBJECT  GLOBAL DEFAULT  UND __ctype_b
  18.     15: 0000c7b8     0 NOTYPE  GLOBAL DEFAULT  ABS _bss_end__

Comments

Post new comment

By submitting this form, you accept the Mollom privacy policy.

Pacific Simplicity 2011 All rights reserved. Contact