1 ; test source file for assembling to NetBSD/FreeBSD a.out shared library
3 ; nasm -f aoutb aoutso.asm
4 ; ld -Bshareable -o aoutso.so aoutso.o
6 ; cc -o aoutso aouttest.c aoutso.so
9 ; This file should test the following:
10 ; [1] Define and export a global text-section symbol
11 ; [2] Define and export a global data-section symbol
12 ; [3] Define and export a global BSS-section symbol
13 ; [4] Define a non-global text-section symbol
14 ; [5] Define a non-global data-section symbol
15 ; [6] Define a non-global BSS-section symbol
16 ; [7] Define a COMMON symbol
17 ; [8] Define a NASM local label
18 ; [9] Reference a NASM local label
19 ; [10] Import an external symbol
20 ; [11] Make a PC-relative call to an external symbol
21 ; [12] Reference a text-section symbol in the text section
22 ; [13] Reference a data-section symbol in the text section
23 ; [14] Reference a BSS-section symbol in the text section
24 ; [15] Reference a text-section symbol in the data section
25 ; [16] Reference a data-section symbol in the data section
26 ; [17] Reference a BSS-section symbol in the data section
29 EXTERN __GLOBAL_OFFSET_TABLE_
30 GLOBAL _lrotate:function
; [1]
31 GLOBAL _greet:function
; [1]
32 GLOBAL _asmstr:data _asmstr.
end-_asmstr
; [2]
33 GLOBAL _textptr:data
4 ; [2]
34 GLOBAL _selfptr:data
4 ; [2]
35 GLOBAL _integer:data
4 ; [3]
37 COMMON _commvar
4 ; [7]
41 ; prototype: long lrotate(long x, int num);
47 .
label rol eax,1 ; [4] [8]
48 loop .
label ; [9] [12]
53 ; prototype: void greet(void);
54 _greet
push ebx ; we'll use EBX for GOT, so save it
57 add ebx,__GLOBAL_OFFSET_TABLE_
+ $$
- .getgot wrt ..gotpc
58 mov eax,[ebx+_integer wrt ..got
] ; [14]
61 mov [ebx+localint wrt ..gotoff
],eax ; [14]
62 mov eax,[ebx+_commvar wrt ..got
]
64 mov eax,[ebx+localptr wrt ..gotoff
] ; [13]
66 mov eax,[ebx+_integer wrt ..got
] ; [1] [14]
68 lea eax,[ebx+_printfstr wrt ..gotoff
]
70 call _printf wrt ..plt
; [11]
78 _asmstr
db 'hello, world', 0 ; [2]
82 _printfstr
db "integer==%d, localint==%d, commvar=%d"
86 localptr
dd localint
; [5] [17]
87 _textptr
dd _greet wrt ..sym
; [15]
88 _selfptr
dd _selfptr wrt ..sym
; [16]