[llvm-dev] How to distinguish two static functions with the same name?

via llvm-dev llvm-dev at lists.llvm.org
Thu Jan 10 07:05:19 PST 2019



> -----Original Message-----
> From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Peng
> Yu via llvm-dev
> Sent: Thursday, January 10, 2019 12:04 AM
> To: llvm-dev at lists.llvm.org
> Subject: [llvm-dev] How to distinguish two static functions with the same
> name?
> 
> llvm-nm does show the difference between two static functions (e.g.,
> _print  n the following example) with the same name. Is there a way of
> allowing it to show their differences (for example, the file where
> they are from)? Thanks.

You are building with -g so I would expect running addr2line on each
function's address would give you its source location.
--paulr

> 
> $ gcc -Wall -pedantic -g -c -o print1.o print1.c
> $ ar cr ./libprint1.a print1.o
> $ gcc -Wall -pedantic -g -fPIC -shared -o ./libprint3.so print3.c
> $ gcc -Wall -pedantic -g -c -o main.o main.c
> $ gcc -Wall -pedantic -g -c -o print2.o print2.c
> $ gcc -L. -lprint1 -lprint3 -o ./main.exe main.o print2.o
> $ nm ./main.exe
> 0000000100000000 T __mh_execute_header
> 0000000100000ef0 T _main
> 0000000100000f10 t _print
> 0000000100000f40 t _print
> 0000000100000ec0 T _print1
> 0000000100000f20 T _print2
>                  U _print3
>                  U _puts
>                  U dyld_stub_binder
> 
> 
> 
> 
> ==> main.c <==
> /* vim: set noexpandtab tabstop=2: */
> #include <stdio.h>
> void print1();
> static void print() {
>     print1();
> }
> 
> int main() {
>     print();
>     return 0;
> }
> 
> ==> print1.c <==
> /* vim: set noexpandtab tabstop=2: */
> #include <stdio.h>
> void print2();
> 
> void print1() {
>     puts("Hello World1!");
>     print2();
> }
> 
> ==> print2.c <==
> /* vim: set noexpandtab tabstop=2: */
> #include <stdio.h>
> void print3();
> 
> static void print() {
>     puts("Hello World2!");
> }
> 
> void print2() {
>     print();
>     print3();
> }
> 
> ==> print3.c <==
> /* vim: set noexpandtab tabstop=2: */
> #include <stdio.h>
> 
> void print3() {
>     puts("Hello World3!");
> }
> 
> 
> --
> Regards,
> Peng
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list