Discussion:
[ast-developers] ksh compile failure - va_copy/va_listval
Christoph Moench-Tegeder
2013-12-28 22:28:21 UTC
Permalink
Hi,
when building ast-ksh (2012-08-01, which seems to be the latest "production"
release) on freebsd10.i386 with clang, the build failed in
src/lib/libast/hash/hashalloc.c:154 with the error message
: error: non-const lvalue reference to type '__builtin_va_list' cannot bind to a temporary of type 'va_list' (aka 'char *')
The same happens in src/lib/libast/string/tokscan.c.

After tracking that down to the va_copy/va_listval #defines generated
via src/lib/libast/features/common, I found that the issue had been
addressed sometime between the 2012-08-01 release and the current alpha
(2013-12-06) with some #ifdefs in hashalloc.c and tokscan.c. (There's
no changelog entry about that, and I failed to find a public source
repository.)
The solution I came up with even does not require those #ifdef constructs,
as it takes advantages of va_listarg #define provided by features/common.
The patch is at http://burggraben.net/hacks/ksh-valist-fix.gz (as some
mail system will surely mangle it), and enclosed inline for your
convenience.
I tested the quivalent patch against ast-ksh 2012-08-01 on
- freebsd10.i386 (clang)
- freebsd10.amd64 (clang)
- freebsd9.amd64 (gcc)
and the shell works fine so far.

Here's the patch:

--- src/lib/libast/hash/hashalloc.c.orig 2013-12-28 22:54:11.000000000 +0100
+++ src/lib/libast/hash/hashalloc.c 2013-12-28 22:57:07.000000000 +0100
@@ -47,6 +47,7 @@
va_list ap;
va_list va[4];
va_list* vp = va;
+ va_listarg np;
Hash_region_f region = 0;
void* handle;

@@ -151,16 +152,8 @@
va_copy(*vp, ap);
vp++;
}
-#if __clang__ && __SIZEOF_POINTER__ == 4
- {
- va_list np;
-
- np = va_listval(va_arg(ap, va_listarg));
- va_copy(ap, np);
- }
-#else
- va_copy(ap, va_listval(va_arg(ap, va_listarg)));
-#endif
+ np = va_listval(va_arg(ap, va_listarg));
+ va_copy(ap, np);
break;
case 0:
if (vp > va)
--- src/lib/libast/string/tokscan.c.orig 2013-12-28 22:53:53.000000000 +0100
+++ src/lib/libast/string/tokscan.c 2013-12-28 22:56:11.000000000 +0100
@@ -197,6 +197,7 @@
char** p_string;
char* prv_f = 0;
va_list prv_ap;
+ va_listarg np;

va_start(ap, fmt);
if (!*s || *s == '\n')
@@ -242,16 +243,8 @@
prv_f = f;
f = va_arg(ap, char*);
va_copy(prv_ap, ap);
-#if __clang__ && __SIZEOF_POINTER__ == 4
- {
- va_list np;
-
- np = va_listval(va_arg(ap, va_listarg));
- va_copy(ap, np);
- }
-#else
- va_copy(ap, va_listval(va_arg(ap, va_listarg)));
-#endif
+ np = va_listval(va_arg(ap, va_listarg));
+ va_copy(ap, np);
continue;
case 'c':
p_char = va_arg(ap, char*);



Regards,
Christoph
--
Spare Space
Bob Krzaczek
2013-12-29 23:41:59 UTC
Permalink
Post by Christoph Moench-Tegeder
when building ast-ksh (2012-08-01, which seems to be the latest
"production" release) on freebsd10.i386 with clang, the build failed in
[ ... ]
I that the issue had been addressed sometime between the 2012-08-01
release and the current alpha (2013-12-06)
If you're interested in not running your own patches but sticking
with what's been released? You might check against the 2013-02-14
beta as well. What you found might have been addressed by then.

My production environment (made with runtime packages built from
source) is currently the last ast-open release 2012-08-01, with the
last ast-base beta 2013-02-14 layered on top (there were patches
going back to October of 2012 I wanted). So far it seems to work
pretty well. (Am I jinxing myself?) There are small parts of the
beta that will not build cleanly (e.g., the dss builtins for ksh),
but overall, everything seems to work well enough, and avoids all
the breakage in more recent alpha releases.

I'm sure someone will now tell me that it's bad to layer INIT and
ast-base 2013-02 on top of an INIT and ast-open from 2012-08 in the
same tree. I await the corrections and better advice. :-)

Cheers,
Bob
--
Bob Krzaczek, Chester F. Carlson Center for Imaging Science, RIT
phone +1-585-4757196, email krz at cis.rit.edu, icbm 43.0858N 77.6774W
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://lists.research.att.com/pipermail/ast-developers/attachments/20131229/7f5c4608/attachment.sig>
Christoph Moench-Tegeder
2013-12-30 18:59:01 UTC
Permalink
Post by Bob Krzaczek
If you're interested in not running your own patches but sticking
with what's been released? You might check against the 2013-02-14
beta as well. What you found might have been addressed by then.
I checked... and the bug is present in ast-base 2013-02-14. (As I
said, there's a fix/workaround in 2013-12-06, but without
a public repository it's hard to tell when and how this was added).
Personally, I don't mind running my own patches (In fact, I'm
using "production" 2012-08-01 with my fix on that 32bit box),
but I thought I'd share that patch just in case someone else
needs it. My googling did not turn up any hints about this problem,
but perhaps the next person will find this discussion :)

Regards,
Christoph
--
Spare Space
Loading...