Skip to content

Commit 83c842d

Browse files
committed
update fixture
1 parent cd18868 commit 83c842d

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

src/ch04-symbol-tables.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,11 @@ A symbol with global binding should be defined exactly once (across all input fi
259259

260260
```bash
261261
$ gcc -c file1.c -o file1.o # defines 'foo'
262-
cc1: fatal error: file1.c: No such file or directory
263-
compilation terminated.
264262
$ gcc -c file2.c -o file2.o # also defines 'foo'
265-
cc1: fatal error: file2.c: No such file or directory
266-
compilation terminated.
267263
$ gcc file1.o file2.o -o out
268-
/usr/bin/ld: cannot find file1.o: No such file or directory
269-
/usr/bin/ld: cannot find file2.o: No such file or directory
264+
/usr/bin/ld: file2.o:(.data+0x0): multiple definition of `foo'; file1.o:(.data+0x0): first defined here
265+
/usr/bin/ld: /lib/aarch64-linux-gnu/crt1.o: in function `__wrap_main':
266+
(.text+0x38): undefined reference to `main'
270267
collect2: error: ld returned 1 exit status
271268
```
272269

src/ch06-static-linking.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ This is **selective linking**—you don't pay for what you don't use.
180180

181181
```bash
182182
$ ar -t libc.a | wc -l
183-
0
183+
2021
184184
$ nm hello | grep ' T ' | wc -l
185-
0
185+
5
186186
```
187187

188-
The library has 1552 object files, but only ~42 functions end up in your hello world. The rest are discarded.
188+
The library has ~2000 object files, but only a handful of functions end up in your hello world. The rest are discarded.
189189

190190
### Link Order Matters
191191

src/ch07-dynamic-linking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ libmath.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
4343
dynamically linked, not stripped
4444

4545
$ readelf -h libmath.so | grep Type
46-
readelf: Error: 'libmath.so': No such file
46+
Type: DYN (Shared object file)
4747
```
4848

4949
Type `DYN` (not `EXEC`). It has:

tools/mdbook-exec/src/main.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,37 @@ cat > simple.c << 'FIXTURE_EOF'
117117
int main() { return 42; }
118118
FIXTURE_EOF
119119
120+
# For ch04 - demonstrating multiple definition errors
121+
cat > file1.c << 'FIXTURE_EOF'
122+
int foo = 1;
123+
FIXTURE_EOF
124+
125+
cat > file2.c << 'FIXTURE_EOF'
126+
int foo = 2;
127+
FIXTURE_EOF
128+
129+
# Compile object files
120130
gcc -c math.c -o math.o
121131
gcc -c main.c -o main.o
122132
gcc main.o math.o -o program
123133
gcc -c simple.c -o simple.o
124134
gcc simple.c -o simple
135+
136+
# For ch07 - shared library example
137+
gcc -fPIC -shared math.c -o libmath.so
138+
139+
# For ch06 - static linking examples
140+
cat > hello.c << 'FIXTURE_EOF'
141+
#include <stdio.h>
142+
int main() { printf("Hello, world!\n"); return 0; }
143+
FIXTURE_EOF
144+
gcc hello.c -o hello
145+
146+
# Create symlink for libc.a if it exists (location varies by distro)
147+
LIBC_PATH=$(find /usr/lib -name 'libc.a' 2>/dev/null | head -1)
148+
if [ -n "$LIBC_PATH" ]; then
149+
ln -sf "$LIBC_PATH" libc.a
150+
fi
125151
"#;
126152

127153
let output = Command::new("docker")

0 commit comments

Comments
 (0)