Skip to content

Commit 0b4b1bd

Browse files
committed
Symbol versioning works
1 parent 5c7fed1 commit 0b4b1bd

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

shared-library/symbol-version/Makefile

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@ CC := gcc -pedantic-errors -std=c89 -Wall -Wextra
22

33
.PHONY: all clean run
44

5-
main.out: main.o libcirosantilli_a.so
6-
$(CC) -L'.' main.o -o '$@' -lcirosantilli_a
5+
all: main.out main1.out main2.out
76

8-
run: main.out
7+
run: all
98
LD_LIBRARY_PATH=. ./main.out
9+
LD_LIBRARY_PATH=. ./main1.out
10+
LD_LIBRARY_PATH=. ./main2.out
11+
12+
main.out: main.c libcirosantilli_a.so
13+
$(CC) -L'.' main.c -o '$@' -lcirosantilli_a
14+
15+
main1.out: main.c libcirosantilli_a.so
16+
$(CC) -DV1 -L'.' main.c -o '$@' -lcirosantilli_a
17+
18+
main2.out: main.c libcirosantilli_a.so
19+
$(CC) -DV2 -L'.' main.c -o '$@' -lcirosantilli_a
1020

1121
libcirosantilli_a.so: a.o
1222
$(CC) -Wl,--version-script,a.map -L'.' -shared a.o -o '$@'
1323

14-
%.o: %.c
24+
libcirosantilli_a.o: a.c
1525
$(CC) -fPIC -c '$<' -o '$@'
1626

1727
clean:

shared-library/symbol-version/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
Trying to replicate glibc's `symbol@@VERSION` madness.
44

5-
TODO: not working, and I have no idea what I'm doing.
5+
This allows you to have a single library `v2`, that also contains symbols from `v1`.
6+
7+
<https://www.technovelty.org/c/symbol-versions-and-dependencies.html> contains a nice example.

shared-library/symbol-version/a.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
__asm__(".symver a1,a@LIBA_1");
66
void a1(void) {
7-
puts("a");
7+
puts("a1");
88
}
99

10-
__asm__(".symver a2,a@LIBA_2");
10+
/* @@ means "default version". */
11+
__asm__(".symver a2,a@@LIBA_2");
1112
void a2(void) {
12-
puts("a");
13+
puts("a2");
1314
}

shared-library/symbol-version/main.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33

44
#include "a.h"
55

6-
__asm__(".symver a1,a@LIBA_1");
6+
/* TODO: any clearer way of doing this maybe
7+
* with some compilation option only? */
8+
#if defined(V1)
9+
__asm__(".symver a,a@LIBA_1");
10+
#elif defined(V2)
11+
__asm__(".symver a,a@LIBA_2");
12+
#endif
713

814
int main(void) {
915
a();

0 commit comments

Comments
 (0)