aboutsummaryrefslogtreecommitdiffstats
path: root/travis/test
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2018-11-05 13:42:41 +0300
committerCyrill Gorcunov <gorcunov@gmail.com>2018-11-11 21:43:46 +0300
commit536f28188c2164e54e201aa80765bfd06f29a8f2 (patch)
tree37b7d25aa7695e181387ccacb9731c8d172f15c2 /travis/test
parent6144feac6a255385d0b02549c2c910dbd78b7fc5 (diff)
downloadnasm-536f28188c2164e54e201aa80765bfd06f29a8f2.tar.gz
nasm-536f28188c2164e54e201aa80765bfd06f29a8f2.tar.xz
nasm-536f28188c2164e54e201aa80765bfd06f29a8f2.zip
test: nasm-t -- Add elfso
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Diffstat (limited to 'travis/test')
-rw-r--r--travis/test/elfso-o0.o.tbin0 -> 1248 bytes
-rw-r--r--travis/test/elfso-o0.stderr1
-rw-r--r--travis/test/elfso-ox.o.tbin0 -> 1248 bytes
-rw-r--r--travis/test/elfso-ox.stderr1
-rw-r--r--travis/test/elfso.asm100
-rw-r--r--travis/test/elfso.json22
6 files changed, 124 insertions, 0 deletions
diff --git a/travis/test/elfso-o0.o.t b/travis/test/elfso-o0.o.t
new file mode 100644
index 00000000..7474e3e6
--- /dev/null
+++ b/travis/test/elfso-o0.o.t
Binary files differ
diff --git a/travis/test/elfso-o0.stderr b/travis/test/elfso-o0.stderr
new file mode 100644
index 00000000..77bf808f
--- /dev/null
+++ b/travis/test/elfso-o0.stderr
@@ -0,0 +1 @@
+./travis/test/elfso.asm:83: warning: label alone on a line without a colon might be in error [-w+orphan-labels] \ No newline at end of file
diff --git a/travis/test/elfso-ox.o.t b/travis/test/elfso-ox.o.t
new file mode 100644
index 00000000..1536fedb
--- /dev/null
+++ b/travis/test/elfso-ox.o.t
Binary files differ
diff --git a/travis/test/elfso-ox.stderr b/travis/test/elfso-ox.stderr
new file mode 100644
index 00000000..77bf808f
--- /dev/null
+++ b/travis/test/elfso-ox.stderr
@@ -0,0 +1 @@
+./travis/test/elfso.asm:83: warning: label alone on a line without a colon might be in error [-w+orphan-labels] \ No newline at end of file
diff --git a/travis/test/elfso.asm b/travis/test/elfso.asm
new file mode 100644
index 00000000..e72497ba
--- /dev/null
+++ b/travis/test/elfso.asm
@@ -0,0 +1,100 @@
+;Testname=unoptimized; Arguments=-O0 -felf -oelfso.o; Files=stdout stderr elfso.o
+;Testname=optimized; Arguments=-Ox -felf -oelfso.o; Files=stdout stderr elfso.o
+
+; test source file for assembling to ELF shared library
+; build with:
+; nasm -f elf elfso.asm
+; ld -shared -o elfso.so elfso.o
+; test with:
+; gcc -o elfso elftest.c ./elfso.so
+; ./elfso
+; (assuming your gcc is ELF, and you're running bash)
+
+; This file should test the following:
+; [1] Define and export a global text-section symbol
+; [2] Define and export a global data-section symbol
+; [3] Define and export a global BSS-section symbol
+; [4] Define a non-global text-section symbol
+; [5] Define a non-global data-section symbol
+; [6] Define a non-global BSS-section symbol
+; [7] Define a COMMON symbol
+; [8] Define a NASM local label
+; [9] Reference a NASM local label
+; [10] Import an external symbol
+; [11] Make a PC-relative call to an external symbol
+; [12] Reference a text-section symbol in the text section
+; [13] Reference a data-section symbol in the text section
+; [14] Reference a BSS-section symbol in the text section
+; [15] Reference a text-section symbol in the data section
+; [16] Reference a data-section symbol in the data section
+; [17] Reference a BSS-section symbol in the data section
+
+ BITS 32
+ GLOBAL lrotate:function ; [1]
+ GLOBAL greet:function ; [1]
+ GLOBAL asmstr:data asmstr.end-asmstr ; [2]
+ GLOBAL textptr:data 4 ; [2]
+ GLOBAL selfptr:data 4 ; [2]
+ GLOBAL integer:data 4 ; [3]
+ EXTERN printf ; [10]
+ COMMON commvar 4:4 ; [7]
+ EXTERN _GLOBAL_OFFSET_TABLE_
+
+ SECTION .text
+
+; prototype: long lrotate(long x, int num);
+lrotate: ; [1]
+ push ebp
+ mov ebp,esp
+ mov eax,[ebp+8]
+ mov ecx,[ebp+12]
+.label rol eax,1 ; [4] [8]
+ loop .label ; [9] [12]
+ mov esp,ebp
+ pop ebp
+ ret
+
+; prototype: void greet(void);
+greet push ebx ; we'll use EBX for GOT, so save it
+ call .getgot
+.getgot: pop ebx
+ add ebx,_GLOBAL_OFFSET_TABLE_ + $$ - .getgot wrt ..gotpc
+ mov eax,[ebx+integer wrt ..got] ; [14]
+ mov eax,[eax]
+ inc eax
+ mov [ebx+localint wrt ..gotoff],eax ; [14]
+ mov eax,[ebx+commvar wrt ..got]
+ push dword [eax]
+ mov eax,[ebx+localptr wrt ..gotoff] ; [13]
+ push dword [eax]
+ mov eax,[ebx+integer wrt ..got] ; [1] [14]
+ push dword [eax]
+ lea eax,[ebx+printfstr wrt ..gotoff]
+ push eax ; [13]
+ call printf wrt ..plt ; [11]
+ add esp,16
+ pop ebx
+ ret
+
+ SECTION .data
+
+; a string
+asmstr db 'hello, world', 0 ; [2]
+.end
+
+; a string for Printf
+printfstr db "integer==%d, localint==%d, commvar=%d"
+ db 10, 0
+
+; some pointers
+localptr dd localint ; [5] [17]
+textptr dd greet wrt ..sym ; [15]
+selfptr dd selfptr wrt ..sym ; [16]
+
+ SECTION .bss
+
+; an integer
+integer resd 1 ; [3]
+
+; a local integer
+localint resd 1 ; [6]
diff --git a/travis/test/elfso.json b/travis/test/elfso.json
new file mode 100644
index 00000000..ff7ddde1
--- /dev/null
+++ b/travis/test/elfso.json
@@ -0,0 +1,22 @@
+[
+ {
+ "description": "Test elf shared library (-Ox)",
+ "id": "elfso",
+ "format": "elf32",
+ "source": "elfso.asm",
+ "option": "-Ox",
+ "target": [
+ { "output": "elfso-ox.o" },
+ { "stderr": "elfso-ox.stderr" }
+ ]
+ },
+ {
+ "description": "Test elf shared library (-O0)",
+ "ref": "elfso",
+ "option": "-O0",
+ "target": [
+ { "output": "elfso-o0.o" },
+ { "stderr": "elfso-o0.stderr" }
+ ]
+ }
+]