Bug 190751 - [PATCH] devel/lua-alien: mark as SSP_UNSAFE
Summary: [PATCH] devel/lua-alien: mark as SSP_UNSAFE
Status: Closed Unable to Reproduce
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-ports-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-07 13:32 UTC by Axel Low
Modified: 2014-08-11 13:52 UTC (History)
2 users (show)

See Also:


Attachments
fix (500 bytes, patch)
2014-06-07 13:32 UTC, Axel Low
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Axel Low 2014-06-07 13:32:56 UTC
Created attachment 143489 [details]
fix

Lua interpreter aborts with exit code 1 shortly after the first
foreign function if using alien built with Clang.

The following snippet successfully calls sleep(3) but aborts shortly after:

  require 'alien'

  local libc = alien.default
  libc.sleep:types('int', 'int')

  print "foo"
  libc.sleep(3)
  print "bar"

With clang -O0 a crash can be seen instead:

  (gdb) r
  Starting program: /usr/local/bin/lua52 test.lua
  [New LWP 101132]
  [New Thread 801c06400 (LWP 101132)]
  foo

  Program received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 801c06400 (LWP 101132)]
  0x0000000000407421 in lua_pushnumber (L=0x800000000, n=0) at lapi.c:475
  475       setnvalue(L->top, n);
  (gdb) bt
  #0  0x0000000000407421 in lua_pushnumber (L=0x800000000, n=0) at lapi.c:475
  #1  0x00000008014e84aa in ?? () from /usr/local/lib/lua/5.2/alien_c.so
  #2  0x000000000040bf66 in luaD_precall (L=0x801c17300, func=0x801c8d570, nresults=0) at ldo.c:319
  #3  0x000000000040c1d0 in luaD_precall (L=0x801c17300, func=0x801c8d570, nresults=0) at ldo.c:356
  #4  0x000000000041f64f in luaV_execute (L=0x801c17300) at lvm.c:709
  #5  0x000000000040c779 in luaD_call (L=0x801c17300, func=0x801c200d0, nResults=-1, allowyield=0) at ldo.c:402
  #6  0x0000000000408bd4 in f_call (L=0x801c17300, ud=0x7fffffffe080) at lapi.c:923
  #7  0x000000000040b78f in luaD_rawrunprotected (L=0x801c17300, f=0x408ba0 <f_call>, ud=0x7fffffffe080) at ldo.c:131
  #8  0x000000000040cf19 in luaD_pcall (L=0x801c17300, func=0x408ba0 <f_call>, u=0x7fffffffe080, old_top=80, ef=64) at ldo.c:603
  #9  0x0000000000408a90 in lua_pcallk (L=0x801c17300, nargs=0, nresults=-1, errfunc=3, ctx=0, k=0x0) at lapi.c:949
  #10 0x0000000000405694 in docall (L=0x801c17300, narg=0, nres=-1) at lua.c:179
  #11 0x00000000004053b5 in handle_script (L=0x801c17300, argv=0x7fffffffe4a0, n=1) at lua.c:337
  #12 0x0000000000404a9c in pmain (L=0x801c17300) at lua.c:465
  #13 0x000000000040bf66 in luaD_precall (L=0x801c17300, func=0x801c20090, nresults=1) at ldo.c:319
  #14 0x000000000040c765 in luaD_call (L=0x801c17300, func=0x801c20090, nResults=1, allowyield=0) at ldo.c:401
  #15 0x0000000000408bd4 in f_call (L=0x801c17300, ud=0x7fffffffe3d0) at lapi.c:923
  #16 0x000000000040b78f in luaD_rawrunprotected (L=0x801c17300, f=0x408ba0 <f_call>, ud=0x7fffffffe3d0) at ldo.c:131
  #17 0x000000000040cf19 in luaD_pcall (L=0x801c17300, func=0x408ba0 <f_call>, u=0x7fffffffe3d0, old_top=16, ef=0) at ldo.c:603
  #18 0x0000000000408a90 in lua_pcallk (L=0x801c17300, nargs=2, nresults=1, errfunc=0, ctx=0, k=0x0) at lapi.c:949
  #19 0x00000000004047a2 in main (argc=2, argv=0x7fffffffe4a0) at lua.c:491

The workaround is to build with GCC, otherwise use the attached patch.
Comment 1 Adam Weinberger freebsd_committer freebsd_triage 2014-07-06 00:30:10 UTC
It works for me.....

[root@apnoea /usr/ports/BUILD/head/devel/lua-alien] uname -a
FreeBSD apnoea.adamw.org 10.0-STABLE FreeBSD 10.0-STABLE #12: Tue Jul  1 10:27:40 EDT 2014     root@apnoea.adamw.org:/usr/obj/usr/src/sys/PEEP  i386
root@apnoea /usr/ports/BUILD/head/devel/lua-alien] make -V WITH_SSP_PORTS
yes
[root@apnoea /usr/ports/BUILD/head/devel/lua-alien] cc --version
FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
Target: i386-unknown-freebsd10.0
Thread model: posix
[root@apnoea /usr/ports/BUILD/head/devel/lua-alien] lua52 file
foo
bar
[root@apnoea /usr/ports/BUILD/head/devel/lua-alien] cat file
require 'alien'

local libc = alien.default
libc.sleep:types('int', 'int')

print "foo"
libc.sleep(3)
print "bar"
Comment 2 John Marino freebsd_committer freebsd_triage 2014-08-11 10:01:55 UTC
Adam, there is no maintainer for this port.  Do you want to take this PR since you tested the patch?
Comment 3 Adam Weinberger freebsd_committer freebsd_triage 2014-08-11 13:52:28 UTC
I'm closing the PR. I couldn't reproduce the problem, and submitter hasn't provided any new information in two months. Axel, if you're still having trouble feel free to update us with more information.