mirror of
https://github.com/netwide-assembler/nasm.git
synced 2024-11-27 08:10:07 +08:00
elftest64: both Small PIC and Medium PIC model tests
Try both Small PIC and Medium PIC model references. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
parent
70e6c2a6cb
commit
15ed768673
@ -27,7 +27,8 @@
|
|||||||
|
|
||||||
BITS 64
|
BITS 64
|
||||||
GLOBAL lrotate:function ; [1]
|
GLOBAL lrotate:function ; [1]
|
||||||
GLOBAL greet:function ; [1]
|
GLOBAL greet_s:function ; [1]
|
||||||
|
GLOBAL greet_m:function ; [1]
|
||||||
GLOBAL asmstr:data asmstr.end-asmstr ; [2]
|
GLOBAL asmstr:data asmstr.end-asmstr ; [2]
|
||||||
GLOBAL textptr:data 8 ; [2]
|
GLOBAL textptr:data 8 ; [2]
|
||||||
GLOBAL selfptr:data 8 ; [2]
|
GLOBAL selfptr:data 8 ; [2]
|
||||||
@ -50,10 +51,14 @@ lrotate: ; [1]
|
|||||||
pop rbp
|
pop rbp
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; prototype: void greet(void);
|
;; prototype: void greet_*(void);
|
||||||
;; rdi - rsi - rdx - rcx - r8 - r9
|
;;
|
||||||
;; rbx, rbp, r12-r15 are saved
|
;; Arguments are: rdi - rsi - rdx - rcx - r8 - r9
|
||||||
greet:
|
;; Registers: rbx, rbp, r12-r15 are saved
|
||||||
|
;; greet_s() is Small PIC model, greet_m() is Medium PIC model
|
||||||
|
;; (Large model cannot be linked with other code)
|
||||||
|
;;
|
||||||
|
greet_s:
|
||||||
mov rax,[rel commvar wrt ..got] ; &commvar
|
mov rax,[rel commvar wrt ..got] ; &commvar
|
||||||
mov rcx,[rax] ; commvar
|
mov rcx,[rax] ; commvar
|
||||||
mov rax,[rel integer wrt ..got] ; &integer
|
mov rax,[rel integer wrt ..got] ; &integer
|
||||||
@ -66,6 +71,25 @@ greet:
|
|||||||
xor eax,eax ; No fp arguments
|
xor eax,eax ; No fp arguments
|
||||||
jmp printf wrt ..plt ; [10]
|
jmp printf wrt ..plt ; [10]
|
||||||
|
|
||||||
|
greet_m:
|
||||||
|
push r15 ; Used by convention...
|
||||||
|
lea r15,[rel _GLOBAL_OFFSET_TABLE_]
|
||||||
|
mov rax,[rel commvar wrt ..got] ; &commvar
|
||||||
|
mov rcx,[rax] ; commvar
|
||||||
|
mov rax,[rel integer wrt ..got] ; &integer
|
||||||
|
mov rsi,[rax]
|
||||||
|
lea rdx,[rsi+1]
|
||||||
|
mov rax,localint wrt ..gotoff ; &localint - r15
|
||||||
|
mov [rax+r15],rdx ; localint = integer+1
|
||||||
|
mov rax,localptr wrt ..gotoff ; &localptr - r15
|
||||||
|
mov rax,[rax+r15] ; localptr
|
||||||
|
mov rdx,[rax] ; *localptr = localint
|
||||||
|
mov rdi,printfstr wrt ..gotoff ; &printfstr - r15
|
||||||
|
add rdi,r15 ; &printfstr
|
||||||
|
xor eax,eax ; No fp arguments
|
||||||
|
pop r15
|
||||||
|
jmp printf wrt ..plt ; [10]
|
||||||
|
|
||||||
SECTION .data
|
SECTION .data
|
||||||
|
|
||||||
; a string
|
; a string
|
||||||
@ -77,7 +101,7 @@ printfstr db "integer=%ld, localint=%ld, commvar=%ld", 10, 0
|
|||||||
|
|
||||||
; some pointers
|
; some pointers
|
||||||
localptr dq localint ; [5] [17]
|
localptr dq localint ; [5] [17]
|
||||||
textptr dq greet wrt ..sym ; [15]
|
textptr dq greet_s wrt ..sym ; [15]
|
||||||
selfptr dq selfptr wrt ..sym ; [16]
|
selfptr dq selfptr wrt ..sym ; [16]
|
||||||
|
|
||||||
SECTION .bss
|
SECTION .bss
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
extern long lrotate(long, int);
|
extern long lrotate(long, int);
|
||||||
extern void greet(void);
|
extern void greet_s(void);
|
||||||
|
extern void greet_m(void);
|
||||||
extern int8_t asmstr[];
|
extern int8_t asmstr[];
|
||||||
extern void *selfptr;
|
extern void *selfptr;
|
||||||
extern void *textptr;
|
extern void *textptr;
|
||||||
@ -31,10 +32,10 @@ int main(void)
|
|||||||
printf("The integers here should be 1234, 1235 and 4321:\n");
|
printf("The integers here should be 1234, 1235 and 4321:\n");
|
||||||
integer = 1234;
|
integer = 1234;
|
||||||
commvar = 4321;
|
commvar = 4321;
|
||||||
|
greet_s();
|
||||||
|
greet_m();
|
||||||
|
|
||||||
greet();
|
printf("These pointers should be equal: %p and %p\n", &greet_s, textptr);
|
||||||
|
|
||||||
printf("These pointers should be equal: %p and %p\n", &greet, textptr);
|
|
||||||
|
|
||||||
printf("So should these: %p and %p\n", selfptr, &selfptr);
|
printf("So should these: %p and %p\n", selfptr, &selfptr);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user