logo
Tags down

shadow

Check that all symbols defined in static library


By : lurkin
Date : September 16 2020, 07:00 AM
wish of those help A static library is just a bunch of .o files and those are expected to have undefined references. No linking is involved when producing a .a from .o files.
You can run nm --undefined-only libmylib.a and that produces a list of all undefined symbols. That list will include all the symbols you use from C standard library because, again, no linking is involved when producing .a files.
code :


Share : facebook icon twitter icon

How to check value of defined symbols (Eclipse->Paths & Symbols) in a makefile?


By : 45H
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Use environment variables and conditionals to tell your options to make. Something like:
code :
DEFINES = -DFOO

ifeq ($(COMPILE_FOR_A),1)
    DEFINES += -DBAR
else
    DEFINES += -DBAZ
endif
~$ COMPILE_FOR_A=1 make

link a static library to a shared library and hide exported symbols


By : Med Oumalk
Date : March 29 2020, 07:55 AM

Why doesn't this create multiple defined symbols in this static library?


By : Luka Marinovic
Date : March 29 2020, 07:55 AM
With these it helps The key fact that was added to this question is the fact that the two modules with the duplicate symbol were linked into a static library.
A static library works very different than a shared library. When linking, the linker searches static libraries for referenced symbols. The first module that defines the referenced symbol gets linked to produce the final executable. The fact that another module defines the same symbol is irrelevant. If the other module with the duplicate symbol does not define any other symbol that the executable needs it does not get linked into the executable.

How to prevent all symbols from static library to load and why other symbols from same .o file get exported to test whil


By : user1734643
Date : March 29 2020, 07:55 AM
help you fix your problem Suppose there are three c files, say a.c contains functions xx(), yy() and b.c contains nn(), mm() and c.c contains qq(), rr(). , Here is an implementation of your scenario:
a.c
code :
#include <stdio.h>

void xx(void)
{
    puts(__func__);
}

void yy(void)
{
    puts(__func__);
}
#include <stdio.h>

void nn(void)
{
    puts(__func__);
}

void mm(void)
{
    puts(__func__);
}
#include <stdio.h>

void qq(void)
{
    puts(__func__);
}

void rr(void)
{
    puts(__func__);
}
extern void xx(void);

int main(void)
{
    xx();
    return 0;
}
$ gcc -Wall -c a.c b.c c.c test.c
$ ar rcs stat.a a.o b.o c.o
$ gcc -o test test.o stat.a
$ ./test
xx
$ nm stat.a

a.o:
0000000000000000 r __func__.2250
0000000000000003 r __func__.2254
                 U _GLOBAL_OFFSET_TABLE_
                 U puts
0000000000000000 T xx
0000000000000013 T yy

b.o:
0000000000000000 r __func__.2250
0000000000000003 r __func__.2254
                 U _GLOBAL_OFFSET_TABLE_
0000000000000013 T mm
0000000000000000 T nn
                 U puts

c.o:
0000000000000000 r __func__.2250
0000000000000003 r __func__.2254
                 U _GLOBAL_OFFSET_TABLE_
                 U puts
0000000000000000 T qq
0000000000000013 T rr
$ nm test | egrep 'T (xx|yy|qq|rr|nn|mm)'
000000000000064a T xx
000000000000065d T yy
$ gcc -o test test.o stat.a -Wl,--trace
/usr/bin/x86_64-linux-gnu-ld: mode elf_x86_64
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
test.o
(stat.a)a.o
libgcc_s.so.1 (/usr/lib/gcc/x86_64-linux-gnu/7/libgcc_s.so.1)
/lib/x86_64-linux-gnu/libc.so.6
(/usr/lib/x86_64-linux-gnu/libc_nonshared.a)elf-init.oS
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
libgcc_s.so.1 (/usr/lib/gcc/x86_64-linux-gnu/7/libgcc_s.so.1)
/usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
test.o
(stat.a)a.o
$ gcc -o test test.o stat.a
$ gcc -o test test.o a.o
$ objdump -d a.o

a.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <xx>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 8d 3d 00 00 00 00    lea    0x0(%rip),%rdi        # b <xx+0xb>
   b:   e8 00 00 00 00          callq  10 <xx+0x10>
  10:   90                      nop
  11:   5d                      pop    %rbp
  12:   c3                      retq

0000000000000013 <yy>:
  13:   55                      push   %rbp
  14:   48 89 e5                mov    %rsp,%rbp
  17:   48 8d 3d 00 00 00 00    lea    0x0(%rip),%rdi        # 1e <yy+0xb>
  1e:   e8 00 00 00 00          callq  23 <yy+0x10>
  23:   90                      nop
  24:   5d                      pop    %rbp
  25:   c3                      retq
$ gcc -Wall -ffunction-sections -fdata-sections -c a.c b.c c.c test.c
$ objdump -d a.o

a.o:     file format elf64-x86-64


Disassembly of section .text.xx:

0000000000000000 <xx>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 8d 3d 00 00 00 00    lea    0x0(%rip),%rdi        # b <xx+0xb>
   b:   e8 00 00 00 00          callq  10 <xx+0x10>
  10:   90                      nop
  11:   5d                      pop    %rbp
  12:   c3                      retq

Disassembly of section .text.yy:

0000000000000000 <yy>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 8d 3d 00 00 00 00    lea    0x0(%rip),%rdi        # b <yy+0xb>
   b:   e8 00 00 00 00          callq  10 <yy+0x10>
  10:   90                      nop
  11:   5d                      pop    %rbp
  12:   c3                      retq
$ rm stat.a
$ ar rcs stat.a a.o b.o c.o
$ gcc -o test test.o stat.a -Wl,-gc-sections,-trace,-Map=mapfile
/usr/bin/x86_64-linux-gnu-ld: mode elf_x86_64
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
test.o
(stat.a)a.o
libgcc_s.so.1 (/usr/lib/gcc/x86_64-linux-gnu/7/libgcc_s.so.1)
/lib/x86_64-linux-gnu/libc.so.6
(/usr/lib/x86_64-linux-gnu/libc_nonshared.a)elf-init.oS
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
libgcc_s.so.1 (/usr/lib/gcc/x86_64-linux-gnu/7/libgcc_s.so.1)
/usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
$ nm test | egrep 'T (xx|yy|qq|rr|nn|mm)'
000000000000064a T xx
$ ./test
xx
...
Discarded input sections
...
...
 .text.yy       0x0000000000000000       0x13 stat.a(a.o)
...
...

Linking a dynamic library that links in symbols from a static library: macOS vs Linux


By : user3574531
Date : March 29 2020, 07:55 AM
Related Posts Related Posts :
  • Is there a switch-like keyword that would accept string (char *) instead of just char?
  • Using bitwise operation to multiply by 3
  • C array of pointers changing address randomly
  • How to convert integer to binary form in C
  • Is there a way to implement macros (#define) into a C conversion program?
  • C memcpy to struct allocation
  • How do I get sscanf to run in unix with a structure?
  • Returning a struct by value gives the same wrong answer every time
  • Can an array be statically alocated if we don't know the length of the array during compilation in c99?
  • What is the best method to implement function overloading in C?
  • Inventing a simple argument parser in c
  • Difference between s[++i]; and s[i]; ++i;
  • lvalue required as left operand of assignment - function pointer
  • how to remove a node from a linked list
  • beginner: How to convert random generated number into number from 1 to 7
  • Use a base struct to extract values from void*
  • Getting 0x55555555 just using numbers less then 0xFF, | and <<
  • Problem drawing a triangle int with asterisk
  • How to get the exit status of a child process?
  • Why is my pointer array returning a character in unicode?
  • Weird code interaction when scanning and printing chars in C
  • How can i find a pattern in an array of integers?
  • Where is linux-vdso.so.1 present on the file system
  • How to write a function that would check whether two arrays are horrizontally symmetrical?
  • I use while(scanf("%[^\n]", input)!=EOF), but even I haven't entered anything, it goes into infinite loop
  • Checking bits of ints to see if they share binary with the power of 2 (bitwise only)
  • Calculating average of pair numbers
  • How to convert an integer into char array and reverse to get the same number?
  • Binary Search dosen't find the right value
  • How to create a variable number of pthreads?
  • Why am I getting a segmentation fault when trimming a string in a recursive function?
  • Do you specifically need malloc to allocate memory to new elements of a linked list
  • why set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ldl") does not work?
  • I need to check whether input is a number in an IF statement
  • Valgrind reports memory leak on freed pointer after getline from stdin
  • Why is "static" ignored?
  • My Program do not take input from the scanf command
  • Scanf reads wrong value
  • How to get the result 2^100 * 3^3 in modulo 1000000007
  • Why do C11 global and local static asserts behave differently?
  • Can someone tell me why the math is not printing?
  • Is it possible to implement JIT for bytecode interpreter in C without resorting to assembly?
  • Can I make a terminal program in C to edit photos in GIMP [macOS]?
  • Fibonacci sequence using only 1 recursive call C
  • Why heap memory still accessible after HeapFree
  • How to create custom datatype String in C Programming language?
  • Bit vector operation with AVX2 and SSE2
  • Is there a real difference between int main() and int main(void) in C?
  • How to link functions to a menu in C
  • C Modify Array in Struct
  • Why the value of a integer variable is changing after reading a string with scanf?
  • C : How to use a struct, declared and defined in function A, in another function B
  • how to get rid of the "unknown" section in the perf
  • Same string but different result
  • Why am I getting an error saying that my function type is conflicting? (edited)
  • Can a variable be both static and volatile in a multi threaded environment
  • while giving string value to integer what is happening?
  • I wrote this C program but Array doesn't work properly
  • Why do arrays not grow in stack direction when used in functions as local variables?
  • Switch case 0: entering 0 and entering a letter
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk