Skip to content

Commit f4e46e4

Browse files
committed
Merge branch 'dev' of github.com:kristjanvalur/stackman into dev
2 parents 9a537aa + ac24664 commit f4e46e4

File tree

15 files changed

+642
-49
lines changed

15 files changed

+642
-49
lines changed

.gitignore

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@
4242
*.idb
4343
*.pdb
4444

45-
# Kernel Module Compile Results
46-
*.mod*
47-
*.cmd
48-
.tmp_versions/
49-
modules.order
50-
Module.symvers
51-
Mkfile.old
52-
dkms.conf
5345

5446
# custom
5547
bin/

.travis.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
language: c
2+
dist: bionic
3+
script: make && make test
4+
jobs:
5+
include:
6+
- name: x86_64_gcc
7+
- name: x86_gcc
8+
before_install: sudo apt install -y gcc-multilib g++-multilib
9+
env: PLATFORMFLAGS=-m32
10+
- arch: arm64
11+
- name: arm32_xcompile
12+
before_install:
13+
- sudo apt update
14+
- sudo apt install -y gcc-arm-linux-gnueabi g++-arm-linux-gnueabi
15+
- sudo apt install -y qemu-user
16+
env:
17+
- PLATFORM_PREFIX=arm-linux-gnueabi-
18+
- EMULATOR=qemu-arm
19+
- os: windows
20+
name: x64_msvc
21+
script:
22+
- cd vs2017
23+
- ./build.cmd x64 && x64/Debug/test.exe
24+
- os: windows
25+
name: x86_msvc
26+
script:
27+
- cd vs2017
28+
- ./build.cmd x86 && Win32/Debug/test.exe
29+
- os: windows
30+
name: arm_msvc
31+
before_install: choco install --force VisualStudio2017-workload-vctools --params"--add Microsoft.VisualStudio.Component.VC.Tools.ARM"
32+
script:
33+
- cd vs2017
34+
- ./build.cmd ARM
35+
- os: windows
36+
name: arm64_msvc
37+
before_install: choco install --force VisualStudio2017-workload-vctools --params"--add Microsoft.VisualStudio.Component.VC.Tools.ARM64"
38+
script:
39+
- cd vs2017
40+
- ./build.cmd ARM64

Makefile

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11

22

3-
CPPFLAGS += -Isrc $(PLATFORM)
4-
CFLAGS += -fPIC -g $(PLATFORM)
5-
CXXFLAGS += -fPIC -g $(PLATFORM)
6-
LDFLAGS += -L$(LIB) -g $(PLATFORM)
3+
CPPFLAGS += -Isrc $(PLATFORMFLAGS)
4+
CFLAGS += -fPIC -g $(PLATFORMFLAGS)
5+
CXXFLAGS += -fPIC -g $(PLATFORMFLAGS)
6+
LDFLAGS += -L$(LIB) -g $(PLATFORMFLAGS)
77

88
# add flag to disable Intel CET
99
NO_CET := $(shell ./disable_cet $(CC))
1010
CFLAGS += $(NO_CET)
1111
CXXFLAGS += $(NO_CET)
1212

13+
OLDCC := $(CC)
14+
ifdef PLATFORM_PREFIX
15+
CC = $(PLATFORM_PREFIX)gcc
16+
CXX = $(PLATFORM_PREFIX)g++
17+
LD = $(PLATFORM_PREFIX)ld
18+
AR = $(PLATFORM_PREFIX)ar
19+
endif
1320
# run c preprocessor with any cflags to get cross compilation result, then run regular compile in native
1421
ABI := $(shell ./abiname.sh "$(CC)" "$(CFLAGS)")
1522
ifndef ABI
@@ -41,10 +48,10 @@ DEBUG = #-DDEBUG_DUMP
4148
.PHONY: test tests
4249

4350
test: tests
44-
bin/test
45-
bin/test_cc
46-
bin/test_static
47-
bin/test_asm
51+
$(EMULATOR) bin/test
52+
$(EMULATOR) bin/test_cc
53+
$(EMULATOR) bin/test_static
54+
$(EMULATOR) bin/test_asm
4855
@echo "*** All test suites passed ***"
4956

5057
tests: bin/test
@@ -54,13 +61,13 @@ tests: bin/test_asm
5461
tests: LDLIBS := -lstackman
5562

5663
bin/test: tests/test.o $(LIB)/libstackman.a
57-
$(CC) $(LDFLAGS) -o $@ $< ${DEBUG} $(LDLIBS)
64+
$(CC) $(LDFLAGS) -static -o $@ $< ${DEBUG} $(LDLIBS)
5865

5966
bin/test_cc: tests/test_cc.o $(LIB)/libstackman.a
60-
$(CXX) $(LDFLAGS) -o $@ $< ${DEBUG} $(LDLIBS)
67+
$(CXX) $(LDFLAGS) -static -o $@ $< ${DEBUG} $(LDLIBS)
6168

6269
bin/test_static: tests/test_static.o
63-
$(CC) $(LDFLAGS) -o $@ $^ ${DEBUG}
70+
$(CC) $(LDFLAGS) -static -o $@ $^ ${DEBUG}
6471

6572
bin/test_asm: tests/test_asm.o tests/test_asm_s.o
66-
$(CC) $(LDFLAGS) -o $@ $^ ${DEBUG}
73+
$(CC) $(LDFLAGS) -static -o $@ $^ ${DEBUG}

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Build Status](https://travis-ci.org/kristjanvalur/stackman.svg?branch=master)](https://travis-ci.org/kristjanvalur/stackman)
2+
13
# stackman
24
Simple low-level stack manipulation API and implementation for common platforms
35

@@ -119,4 +121,21 @@ src/platform/gen_asm.c
119121

120122
The x86 tools require the **gcc-multilib** and **g++-multilib** packages to be installed. They, however, can't co-exist with the **gcc-arm-linux-gnueabi** or
121123
**gcc-aarch64-linux-gnu** packages on some distributions, and so development for these
122-
platforms may need to be done independently.
124+
platforms may need to be done independently.
125+
126+
### Cross compiling for x86 (32 bit) on Linux
127+
- install __gcc-multilib__ and __g++-multilib__
128+
- *compile* **gen_asm.c** using `gcc -m32`
129+
- *make* using `make PLATFORMFLAGS=-m32 test`
130+
131+
### Cross compiling for ARM (32 bit) on Linux
132+
- install __gcc-arm-linux-gnueabi__ and __g++-arm-linux-gnueabi__
133+
- install __qemu-user__ for hardware emulation
134+
- *compile* **gen_asm.c** using `arm-linux-gnueabi-gcc`
135+
- *make* using `make PLATFORM_PREFIX=arm-linux-gnueabi- EMULATOR=qemu-arm test`
136+
137+
### Cross compiling for Arm64 on Linux
138+
- install **gcc-aarch64-linux-gnu** and **g++-aarch64-linux-gnu**
139+
- install __qemu-user__ for hardware emulation
140+
- *compile* using `aarch64-linux-gnu-gcc`
141+
- *make* using `make PLATFORM_PREFIX=aarch64-linux-gnu- EMULATOR=qemu-arm64 test`

lib/aarch64/libstackman.a

3.81 KB
Binary file not shown.

lib/arm32/libstackman.a

2.66 KB
Binary file not shown.

src/platforms/switch_aarch64_gcc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ void *STACKMAN_SWITCH_INASM_NAME(stackman_cb_t callback, void *context)
6464
sp = callback(context, STACKMAN_OP_RESTORE, sp);
6565
return sp;
6666
}
67-
#endif
6867

6968
/*
7069
* Similar, but we want the frame pointer so that a debugger
@@ -90,6 +89,8 @@ void *stackman_call(stackman_cb_t callback, void *context, void *stack_pointer)
9089
return result;
9190
}
9291

92+
#endif
93+
9394
#if __ASSEMBLER__ && defined(STACKMAN_ASSEMBLY_SRC)
9495
/* pre-generated assembly code */
9596
#include STACKMAN_ASSEMBLY_SRC

src/platforms/switch_arm64_msvc.asm

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@
1313
; args "callback", "context" are in x0, x1
1414
; push non-volatile x18-x28 registers, in addition to fp,rl pair.
1515
; x29 is fp, x30 is lr.
16-
stp x29, x30, [sp, -176]! ; store fp,lr pair, allocate stack space
16+
stp x29, x30, [sp, #-176]! ; store fp,lr pair, allocate stack space
1717
mov x29, sp ; and set fp pointing to old fp on stack
1818
; push non-volatile registers 18-x28 and fp regs d8-d15)
1919
; also fpcr (fp control register)
2020
mrs x2,fpcr
21-
stp x2, x18, [sp, 16]
22-
stp x19, x20, [sp, 32]
23-
stp x21, x22, [sp, 48]
24-
stp x23, x24, [sp, 64]
25-
stp x25, x26, [sp, 80]
26-
stp x27, x28, [sp, 96]
27-
stp d8, d9, [sp, 112]
28-
stp d10, d11, [sp, 128]
29-
stp d12, d13, [sp, 144]
30-
stp d14, d15, [sp, 160]
21+
stp x2, x18, [sp, #16]
22+
stp x19, x20, [sp, #32]
23+
stp x21, x22, [sp, #48]
24+
stp x23, x24, [sp, #64]
25+
stp x25, x26, [sp, #80]
26+
stp x27, x28, [sp, #96]
27+
stp d8, d9, [sp, #112]
28+
stp d10, d11, [sp, #128]
29+
stp d12, d13, [sp, #144]
30+
stp d14, d15, [sp, #160]
3131

3232
; args are x0=callback, x1=context
3333
; shuffle calling arguments into r0, r1 and r2
@@ -50,19 +50,19 @@
5050
blr x18 ;second callback
5151

5252
; restore registers from stack
53-
ldp x2, x18, [sp, 16]
54-
ldp x19, x20, [sp, 32]
55-
ldp x21, x22, [sp, 48]
56-
ldp x23, x24, [sp, 64]
57-
ldp x25, x26, [sp, 80]
58-
ldp x27, x28, [sp, 96]
59-
ldp d8, d9, [sp, 112]
60-
ldp d10, d11, [sp, 128]
61-
ldp d12, d13, [sp, 144]
62-
ldp d14, d15, [sp, 160]
63-
msr fpcr,x2
53+
ldp x2, x18, [sp, #16]
54+
ldp x19, x20, [sp, #32]
55+
ldp x21, x22, [sp, #48]
56+
ldp x23, x24, [sp, #64]
57+
ldp x25, x26, [sp, #80]
58+
ldp x27, x28, [sp, #96]
59+
ldp d8, d9, [sp, #112]
60+
ldp d10, d11, [sp, #128]
61+
ldp d12, d13, [sp, #144]
62+
ldp d14, d15, [sp, #160]
63+
msr fpcr, x2
6464
;return
65-
ldp x29, x30, [sp], 176
65+
ldp x29, x30, [sp], #176
6666
ret
6767
ENDP
6868

@@ -72,10 +72,10 @@
7272
; args "callback", "context" are in x0, x1
7373
; push non-volatile x18-x28 registers, in addition to fp,rl pair.
7474
; x29 is fp, x30 is lr.
75-
stp x29, x30, [sp, -32]! ; store fp,lr pair, allocate stack space
75+
stp x29, x30, [sp, #-32]! ; store fp,lr pair, allocate stack space
7676
mov x29, sp ; and set fp pointing to old fp on stack
7777
; push non-volatile register 18
78-
str x18, [sp, 16]
78+
str x18, [sp, #16]
7979
8080
; args are x0 = callback, x1 = context, x2=stack
8181
mov x3, x0
@@ -94,8 +94,8 @@
9494
mov sp, x18
9595

9696
; return
97-
ldr x18, [sp, 16]
98-
ldp x29, x30, [sp], 32
97+
ldr x18, [sp, #16]
98+
ldp x29, x30, [sp], #32
9999
ret
100100
ENDP
101101

vs2017/build.cmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
rem Build with visualstudio2017buildtools
2+
echo Building %1
3+
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat"
4+
msbuild stackman.sln /p:Platform=%1

vs2017/stackman.sln

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30717.126
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test\test.vcxproj", "{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}"
7+
ProjectSection(ProjectDependencies) = postProject
8+
{BF7D0638-AC4F-4206-B426-66CDDD468281} = {BF7D0638-AC4F-4206-B426-66CDDD468281}
9+
EndProjectSection
10+
EndProject
11+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stackman", "stackman\stackman.vcxproj", "{BF7D0638-AC4F-4206-B426-66CDDD468281}"
12+
EndProject
13+
Global
14+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
15+
Debug|ARM = Debug|ARM
16+
Debug|ARM64 = Debug|ARM64
17+
Debug|x64 = Debug|x64
18+
Debug|x86 = Debug|x86
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|ARM.ActiveCfg = Debug|ARM
22+
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|ARM.Build.0 = Debug|ARM
23+
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|ARM64.ActiveCfg = Debug|ARM64
24+
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|ARM64.Build.0 = Debug|ARM64
25+
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|x64.ActiveCfg = Debug|x64
26+
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|x64.Build.0 = Debug|x64
27+
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|x86.ActiveCfg = Debug|Win32
28+
{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|x86.Build.0 = Debug|Win32
29+
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|ARM.ActiveCfg = Debug|ARM
30+
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|ARM.Build.0 = Debug|ARM
31+
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|ARM64.ActiveCfg = Debug|ARM64
32+
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|ARM64.Build.0 = Debug|ARM64
33+
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|x64.ActiveCfg = Debug|x64
34+
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|x64.Build.0 = Debug|x64
35+
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|x86.ActiveCfg = Debug|Win32
36+
{BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|x86.Build.0 = Debug|Win32
37+
EndGlobalSection
38+
GlobalSection(SolutionProperties) = preSolution
39+
HideSolutionNode = FALSE
40+
EndGlobalSection
41+
GlobalSection(ExtensibilityGlobals) = postSolution
42+
SolutionGuid = {A71982F0-A89C-45AB-9F23-149A1983A11B}
43+
EndGlobalSection
44+
EndGlobal

0 commit comments

Comments
 (0)