On Fri, 3 Feb 2017 22:52:41 +0100, Adam Wolk wrote:
> Hi ports,
>
> Two weeks ago Damien Couderc reported[1] on /r/openbd_gaming that
> games/hedgewars
> is broken on 6.0. I did a test on -current back then and found the same thing
> planning to test a bit later when I find some time to bump my box to a newer
> snapshot.
>
> I finally found some time and behold, it still crashesh with a weird
> backtrace[2].
>
> I started digging around and got upstream involved. Together with unC0Rr from
> the #hedgewars @ freenode IRC channel we reduced the breaking code to a single
> pascal file that fails the same way without any hedgewars code:
>
> $ cat hello.pas
> uses GL;
> begin
> system.writeln('hello');
> end.
>
> Now, the trick is - the failure only occurs if one compiles with:
>
> $ fpc -XLAlua=lua5.1 hello.pas
> Free Pascal Compiler version 3.0.0 [2016/12/07] for x86_64
> Copyright (c) 1993-2015 by Florian Klaempfl and others
> Target OS: OpenBSD for x86-64
> Compiling hello.pas
> Linking hello
> 4 lines compiled, 0.3 sec
> $ ./hello
> An unhandled exception occurred at $0000000223C29C43:
> EAccessViolation: Access violation
> $0000000223C29C43
>
> The -XLAlua=lua5.1 line was taken from the build output of our ports system.
> There is a way to build a pascal file without passing that flag and it doesn't
> lead to broken runtimes, redesigned example:
>
> $ cat code.pas
> {$linklib lua5.1}
> uses GL;
> begin
> system.writeln('hello');
> end.
> $ fpc code.pas
> Free Pascal Compiler version 3.0.0 [2016/12/07] for x86_64
> Copyright (c) 1993-2015 by Florian Klaempfl and others
> Target OS: OpenBSD for x86-64
> Compiling code.pas
> Linking code
> /usr/local/lib//liblua5.1.so.5.1: warning: warning: rand() may return
> deterministic values, is that what you want?
> /usr/local/lib//liblua5.1.so.5.1: warning: warning: sprintf() is often
> misused,
> please use snprintf()
> /usr/local/lib//liblua5.1.so.5.1: warning: warning: strcat() is almost always
> misused, please use strlcat()
> /usr/local/lib//liblua5.1.so.5.1: warning: warning: strcpy() is almost always
> misused, please use strlcpy()
> 5 lines compiled, 0.3 sec
> $ ./code
> hello
>
> Note in this case instead of substituting library name on the command line
> it's
> done in the source code itself with the {$linklib NAME} directive.
>
> I'm roughly looking for some feedback on what might cause such issue.
> I think the proper solution is updating the hedgewars CMakeLists.txt in this
> case to not use the XLAlua pascal flag and for this port baking it in with
> a patch to the source. I am going to work on a diff like that for a separate
> email including a hotfix for the -server package but I wanted to share the
> actual problem this will remove in case someone can spot a bigger problem.
Wow, thanks for investigating. I've taken a closer look at the binaries
produced, and - lo and behold - when passing -XAfoo, fpc will generate a
binary that is linked against /usr/libexec/ld.so twice, once as runtime
linker, once as a shared object. Ugh. The fix is straightforward:
Index: Makefile
===================================================================
RCS file: /cvs/ports/lang/fpc/Makefile,v
retrieving revision 1.13
diff -u -p -r1.13 Makefile
--- Makefile 7 May 2016 12:40:57 -0000 1.13
+++ Makefile 4 Feb 2017 09:16:30 -0000
@@ -7,7 +7,7 @@ COMMENT = open source compiler for Pasc
V = 3.0.0
DISTNAME = fpcbuild-${V}
PKGNAME = fpc-${V}
-REVISION = 1
+REVISION = 2
BOOT_GEN = 0
CATEGORIES = lang
Index: patches/patch-fpcsrc_compiler_systems_t_bsd_pas
===================================================================
RCS file: /cvs/ports/lang/fpc/patches/patch-fpcsrc_compiler_systems_t_bsd_pas,v
retrieving revision 1.3
diff -u -p -r1.3 patch-fpcsrc_compiler_systems_t_bsd_pas
--- patches/patch-fpcsrc_compiler_systems_t_bsd_pas 22 Dec 2015 14:43:55
-0000 1.3
+++ patches/patch-fpcsrc_compiler_systems_t_bsd_pas 4 Feb 2017 09:16:30
-0000
@@ -2,8 +2,10 @@ $OpenBSD: patch-fpcsrc_compiler_systems_
Correct library search path for OpenBSD; always add -nopie to linker flags.
+Do not link to /usr/libexec/ld.so as a shared library.
+
--- fpcsrc/compiler/systems/t_bsd.pas.orig Sun Dec 7 21:27:02 2014
-+++ fpcsrc/compiler/systems/t_bsd.pas Thu Nov 26 15:17:06 2015
++++ fpcsrc/compiler/systems/t_bsd.pas Sat Feb 4 09:51:46 2017
@@ -126,7 +126,10 @@ begin
Inherited Create;
if not Dontlinkstdlibpath Then
@@ -12,11 +14,21 @@ Correct library search path for OpenBSD;
+ if not(target_info.system in systems_openbsd) then
+
LibrarySearchPath.AddPath(sysrootpath,'/lib;/usr/lib;/usr/X11R6/lib',true)
+ else
-+
LibrarySearchPath.AddPath(sysrootpath,'/usr/lib;/usr/X11R6/lib;${LOCALBASE}/lib',true)
++
LibrarySearchPath.AddPath(sysrootpath,'/usr/lib;${X11BASE}/lib;${LOCALBASE}/lib',true)
else
{ Mac OS X doesn't have a /lib }
LibrarySearchPath.AddPath(sysrootpath,'/usr/lib',true)
-@@ -697,8 +700,7 @@ begin
+@@ -581,7 +584,8 @@ begin
+ { when we have -static for the linker the we also need libgcc }
+ if (cs_link_staticflag in current_settings.globalswitches) then
+ LinkRes.Add('-lgcc');
+- if linkdynamic and (Info.DynamicLinker<>'') then
++ if linkdynamic and (Info.DynamicLinker<>'') and
++ not(target_info.system in systems_openbsd) then
+ LinkRes.AddFileName(Info.DynamicLinker);
+ if not LdSupportsNoResponseFile then
+ LinkRes.Add(')');
+@@ -697,8 +701,7 @@ begin
end;
{ Use -nopie on OpenBSD }
> PS.
> While working on the port 2 things happened.
>
> 1. Upstream took some of our patches
> http://hg.hedgewars.org/hedgewars/rev/ffc7bb9fde01
> 2. The -server package didn't build for me and according to hedgewars upstream
> it's a ghc bug. FreeBSD ships a workaround patch for it
>
> https://svnweb.freebsd.org/ports/head/games/hedgewars/files/patch-CMakeLists.txt?revision=377852&view=markup
Has this happened in any bulk build? If yes, we should take the fix.
>
> This problem manifests itself with the following compile error
>
> [25 of 25] Compiling Main (
> /usr/local/pobj/hedgewars-src-0.9.22/hedgewars-src-0.9.22/gameServer/hedgewars-server.hs,
> /usr/local/pobj/hedgewars-src-0.9.22/build-amd64/gameServer/Main.o )
> *** Core Lint errors : in result of Simplifier ***
> <no location info>: Warning:
>
>
> [1]
> https://www.reddit.com/r/openbsd_gaming/comments/5phgho/hedgewars/?st=iyq4oro0&sh=46dea45e
> [2]
> https://gist.github.com/mulander/b5aa0e825b88910c6d0e446db30dd526t