Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault on simple program (skip.occ) #19

Open
jadudm opened this issue Mar 27, 2020 · 1 comment
Open

Segfault on simple program (skip.occ) #19

jadudm opened this issue Mar 27, 2020 · 1 comment

Comments

@jadudm
Copy link
Member

jadudm commented Mar 27, 2020

Given this program:

PROC main (CHAN BYTE kyb, scr, err)
  SKIP

the TVM segfaults. (I don't know if kroc would segfault, because I'm just trying to get a TVM build going.)

building as follows:

CFLAGS=-DDEBUG_INTERPRETER ./build --prefix=/home/jadudm/local/kroc --with-toolchain=tvm --with-wrapper=posix

and compiling the program with occbuild --program skip.occ, I get a TCE and TBC file.

I get the following debug output from running tvm skip.tbc:

jadudm@lego:~/git/kroc/mcj$ tvm skip.tbc
0x565557768814 55    LDNLP 00000005 00000000 00000000 00000000
0x565557768815 56    LDNLP 00000006 00000014 00000000 00000000
0x565557768816 00        J 00000000 0000002c 00000000 00000000
0x565557768817 00        J 00000000 0000002c 00000000 00000000
0x565557768818 60     NFIX 00000000 0000002c 00000000 00000000
0x565557768819 4e      LDC fffffffe 0000002c 00000000 00000000
0x56555776881a 22     PFIX 00000002 fffffffe 0000002c 00000000
0x56555776881b f5  FFICALL 00000025 fffffffe 0000002c 00000000

Dumping the TCE file:

jadudm@lego:~/git/kroc/mcj$ tce-dump.pl skip.tce
.JUMPENTRY	main
.ALIGN	3

.L0:
.GLOBAL	main
.SETWS	4
.SETVS	0
.MS_USAGE	0
.FILENAME	skip.occ
.LINE	1
.PROC	main
	.LINE	2
	RET
.GLOBALEND	main
.ALIGN	3

I'm not sure what is going on. The LDNLP (load non-local pointer) instructions... could be loading the top-level channels (KYB, SCR, ERR)... but... Hm.

The entire program compiles down to a RET instruction. However, the actual run looks different... which I think is because the TVM wrapper/runtime for POSIX has to do some additional work (that is, making FFI calls in order to check the external channels, etc.).

I think the segfault has to do with the external channel linkages, but that's a hunch, not something supported by evidence.

This is a start, anyway.

@tomoverlund
Copy link

The segfaults are due to PIE (position independent executables) being a default in gcc now:

https://stackoverflow.com/questions/2463150/what-is-the-fpie-option-for-position-independent-executables-in-gcc-and-ld
https://wiki.ubuntu.com/SecurityTeam/PIE

$ gcc foo.c
$ file a.out
a.out: ELF 32-bit LSB pie executable...

I was able to get a working kroc by adding:
-no-pie -fno-pie
to KROC_CCSP_CFLAGS in m4/kroc.m4.

Unrelated to PIE, I also had to add an extern to harness.c to fix the following compile error:

/usr/bin/ld: harness.o:/home/virt/projects/occam/kroc/tools/occ21/misc/harness.c:567: multiple definition of 'oc_help_info'; version.o:/home/virt/projects/occam/kroc/tools/occ21/version.c:39: first defined here

Built and tested on a Debian i386 virtual machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants