1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
;
;Copyright 2017 Pavel Roskin
;Copyright 2017 mirabilos
;
;Permission to use, copy, modify, distribute, and sell this software and its
;documentation for any purpose is hereby granted without fee, provided that
;the above copyright notice appear in all copies and that both that
;copyright notice and this permission notice appear in supporting
;documentation.
;
;The above copyright notice and this permission notice shall be included in
;all copies or substantial portions of the Software.
;
;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
;AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
;CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
;
;Common nasm code
;
; Detect ELF formats
%ifidn __OUTPUT_FORMAT__,elf
%define is_elf 1
%endif
%ifidn __OUTPUT_FORMAT__,elf32
%define is_elf 1
%endif
%ifidn __OUTPUT_FORMAT__,elf64
%define is_elf 1
%endif
; Mark stack non-executable
%ifdef is_elf
section .note.GNU-stack noalloc noexec nowrite progbits
%endif
; Global function header
%macro PROC 1
align 16
%ifdef is_elf
global %1:function
%1:
%else
global _%1
_%1:
%endif
%endmacro
; Macros for relative access to local data
%undef lsym
%ifdef ASM_ARCH_AMD64
; amd64; don't define or call RETRIEVE_RODATA
%define lsym(name) rel name
; default case for PREPARE_RODATA
%endif
%ifdef ASM_ARCH_I386
%ifdef is_elf
%ifdef PIC
; i386 ELF PIC
%macro PREPARE_RODATA 0
section .text
..@get_caller_address:
mov ebx, [esp]
ret
section .data
align 16
..@rodata_begin:
%endmacro
%macro RETRIEVE_RODATA 0
call ..@get_caller_address
%%the_caller_address:
sub ebx, %%the_caller_address - ..@rodata_begin
%endmacro
%define lsym(name) ebx + name - ..@rodata_begin
%else
; i386 ELF, not PIC, default case (see below)
%endif
%else
; i386 not ELF
%ifdef PIC
%error "Position-Independent Code is currently only supported for ELF"
%endif
; i386 not ELF, not PIC, default case (see below)
%endif
%endif
%ifndef lsym
%macro RETRIEVE_RODATA 0
%endmacro
%define lsym(name) name
%endif
%ifnmacro PREPARE_RODATA
%macro PREPARE_RODATA 0
section .data
align 16
%endmacro
%endif
section .text
|