Search code examples
cgccbinarysymbolsnm

Easy way to verify symbol changes in nm report


I am compiling my library(C programing) using Suse gcc compiler and then I am generating nm report of that library. I have to compare that nm report with the previous version library to check what are the symbols are present and not present in current version library.

nm libxxx0.1.a > nm_0.1.txt
nm libxxx0.2.a > nm_0.2.txt

Now I am just comparing nm_0.1.txt and nm_0.2.txt files with some text compare tool. Along with that symbol differences, I am getting offset differences also. I dont worry about offset differences.

Is there any command(in windows or suse) available to highlight only the symbol differences in a nm report, in easy way.

Note : Generated nm report will be very big. Manually opening that text file and using some tool to delete first column of that nm report is not an easy task for that big nm file.


Solution

  • This is for Linux. You must first prepare and sort your nm output

    nm -g libxxx0.1.a | awk '{print $3}' | sort -u >nm_0.1.txt
    nm -g libxxx0.2.a | awk '{print $3}' | sort -u >nm_0.2.txt
    

    If you are interested in all symbols, leave out -g and use cut instead of awk

    nm libxxx0.1.a | cut -c20- | sort -u >nm_0.1.txt
    nm libxxx0.2.a | cut -c20- | sort -u >nm_0.2.txt
    

    Then you can show the differences with diff

    diff -U0 nm_0.1.txt nm_0.2.txt
    

    or comm

    comm -3 nm_0.1.txt nm_0.2.txt