1 ;Testname=unoptimized; Arguments=-O0 -faoutb -oaoutso.o; Files=.stdout .stderr aoutso.o
2 ;Testname=optimized; Arguments=-Ox -faoutb -oaoutso.o; Files=.stdout .stderr aoutso.o
4 ; test source file for assembling to NetBSD/FreeBSD a.out shared library
6 ; nasm -f aoutb aoutso.asm
7 ; ld -Bshareable -o aoutso.so aoutso.o
9 ; cc -o aoutso aouttest.c aoutso.so
12 ; This file should test the following:
13 ; [1] Define and export a global text-section symbol
14 ; [2] Define and export a global data-section symbol
15 ; [3] Define and export a global BSS-section symbol
16 ; [4] Define a non-global text-section symbol
17 ; [5] Define a non-global data-section symbol
18 ; [6] Define a non-global BSS-section symbol
19 ; [7] Define a COMMON symbol
20 ; [8] Define a NASM local label
21 ; [9] Reference a NASM local label
22 ; [10] Import an external symbol
23 ; [11] Make a PC-relative call to an external symbol
24 ; [12] Reference a text-section symbol in the text section
25 ; [13] Reference a data-section symbol in the text section
26 ; [14] Reference a BSS-section symbol in the text section
27 ; [15] Reference a text-section symbol in the data section
28 ; [16] Reference a data-section symbol in the data section
29 ; [17] Reference a BSS-section symbol in the data section
32 EXTERN __GLOBAL_OFFSET_TABLE_
33 GLOBAL _lrotate:function
; [1]
34 GLOBAL _greet:function
; [1]
35 GLOBAL _asmstr:data _asmstr.
end-_asmstr
; [2]
36 GLOBAL _textptr:data
4 ; [2]
37 GLOBAL _selfptr:data
4 ; [2]
38 GLOBAL _integer:data
4 ; [3]
40 COMMON _commvar
4 ; [7]
44 ; prototype: long lrotate(long x, int num);
50 .
label rol eax,1 ; [4] [8]
51 loop .
label ; [9] [12]
56 ; prototype: void greet(void);
57 _greet
push ebx ; we'll use EBX for GOT, so save it
60 add ebx,__GLOBAL_OFFSET_TABLE_
+ $$
- .getgot wrt ..gotpc
61 mov eax,[ebx+_integer wrt ..got
] ; [14]
64 mov [ebx+localint wrt ..gotoff
],eax ; [14]
65 mov eax,[ebx+_commvar wrt ..got
]
67 mov eax,[ebx+localptr wrt ..gotoff
] ; [13]
69 mov eax,[ebx+_integer wrt ..got
] ; [1] [14]
71 lea eax,[ebx+_printfstr wrt ..gotoff
]
73 call _printf wrt ..plt
; [11]
81 _asmstr
db 'hello, world', 0 ; [2]
85 _printfstr
db "integer==%d, localint==%d, commvar=%d"
89 localptr
dd localint
; [5] [17]
90 _textptr
dd _greet wrt ..sym
; [15]
91 _selfptr
dd _selfptr wrt ..sym
; [16]