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 launching coroutine on M1 OSX #208

Open
MobiusHorizons opened this issue Mar 7, 2021 · 4 comments
Open

segfault launching coroutine on M1 OSX #208

MobiusHorizons opened this issue Mar 7, 2021 · 4 comments

Comments

@MobiusHorizons
Copy link

Attempting to run a trivial example (the one from the libdill homepage) on osx on an M1 (arm 64) results in a segfault.

Debugging the code points to an invalid memory access in the ___chkstk_darwin function, which seems to have been added by the compiler, since I don't see any references to it in the code.

I attempted to build the code with -fno-stack-protector but that didn't fix the problem.

cc -g3 -gdwarf-4  -fno-stack-protector test-dill.c -o test-dill -ldill

If you anyone can point me in the right direction I will be happy to work on a fix.

@MobiusHorizons
Copy link
Author

(lldb) target create "bin/test-dill"
Current executable set to '/Users/paulmartin/src/c_modules/bin/test-dill' (arm64).
(lldb) r
Process 98145 launched: '/Users/paulmartin/src/c_modules/bin/test-dill' (arm64)
Process 98145 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x16f603ff8)
    frame #0: 0x0000000188a04de4 libsystem_pthread.dylib`___chkstk_darwin + 64
libsystem_pthread.dylib`___chkstk_darwin:
->  0x188a04de4 <+64>: ldur   x11, [x11, #-0x8]
    0x188a04de8 <+68>: mov    x10, sp
    0x188a04dec <+72>: cmp    x9, #0x1, lsl #12         ; =0x1000
    0x188a04df0 <+76>: b.lo   0x188a04e08               ; <+100>
Target 0: (test-dill) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x16f603ff8)
  * frame #0: 0x0000000188a04de4 libsystem_pthread.dylib`___chkstk_darwin + 64
    frame #1: 0x0000000100003db0 test-dill`main at test-dill.c:16:2
    frame #2: 0x0000000188a25f34 libdyld.dylib`start + 4
(lldb) f 1
frame #1: 0x0000000100003db0 test-dill`main at test-dill.c:16:2
   13  	}
   14
   15  	int main () {
-> 16  		go(worker("HELLO"));
   17  		go(worker("WORLD"));
   18  		msleep(now() + 5000);
   19  		return 0;

@MobiusHorizons
Copy link
Author

Interestingly this only happens when using the apple provided compiler cc when using clang installed from homebrew it works fine.

❯ cc --version
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

vs

❯ clang --version
clang version 11.0.1
Target: arm64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin

@smurfd
Copy link

smurfd commented Jun 26, 2021

Thanks MobiusHorizons, has the same issue.
you should be able to use gcc aswell, if you use the one provided by homebrew, like : /opt/homebrew/bin/gcc-11

@joemoulton
Copy link

-fno-stack-check

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

3 participants