Skip to contentSkip to conversation

patch for problem with va-ppc.h included with egcs and gcc-2.95.2

DISCUSSION Jason Kim 6 participants 13 messages Nov 30, 1999 – Dec 2, 1999

lore
Share & tools
lore
#1 lore raw
Quoted 19 lines · Jason Kim

Agreed, ssh2 code isn't necessarily the cleanest in the world, but then again the varargs situation in PPC world is a bit peculiar.

typedef struct A {
char foo;
char *bar;
} B[1], C[1];

typedef C D;

void tst(D d1)
{
D d2;
d1 = d2; // this is legal
// d2 = d1; // this is not
}

Quoted 6 lines

declaring arrays of fixed size seems a bit strange for a type which will be used by user code, since it makes d1 and d2 be different types sometimes. Not to mention, having struct _va_list_tag AS va_list seem to fix the problems neatly.

Is there a technical reason for keeping va_list as an array of 1 element? (instead of just a single element??)

1. this behaviour is mandated by the ABI
2. it nicely spots a common programming error

I see nothing peculiar about it :-).

BTW, it would be nice if you could fix your spam filter, my last message was rejected, even though there was no faked IP in it.

Franz.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#4 lore raw
Quoted 6 lines · Jason Kim

Also, in the ANSI C (9x) documentation (``n843''), taking the address of a va_list is NOT listed as one of the things that will produce an undefined result. Actually, on page 7.15 (pg246 as seen by acroread), footnote item 198 specifically states ``It is permitted to create a pointer to a va_list and pass that pointer to another function,.. in which case the original list may make further use of the original list after the other function returns.''

Well, I see this is also in ISO C9x, but unless the standard restricts the possible types for va_list (I can't find anything about that), you have still to be aware that any callee gets a reference to the va_list if va_list is an array and so the usual array handling rules apply, or?

Franz.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#6 lore raw

Hi,

My 2 cents.

Quoted 5 lines

What about double indirection? or triple, for that matter?

Not to mention implementing va_list this way explicitly breaks compatibility between gcc on ppc and gcc on SPARC, x86, clipper, alpha... etc.. You name it. Its broken.

va_lists are used heavily in the jdk and pointers to va_lists are passed in
routines. I had to track down each and every time a pointer into a va_list was
passed as a parameter to another routine and fix each one. So there needed to be ppc specific code if def'd into the Sun source code in mutliple places which otherwise worked as is on every other platform including sparc, x86, m68k, etc.

This is over and above using va_copy or memcpy trickery as required for the jdk.

And the worst part about debugging all of this is that the code which worked for all other platforms simply failed quietly on ppc. So when debugging a large source code base which you did not write and seems to be portable across a number of other platforms, silent failures are nasty (unless you luckily got a seg-fault).

The problem would just get worse with multiple indirection.

If there is any way to change this without beaking backward compatibility with pre-compiled shared libs and things, I would vote for it.

Comments?

Kevin

Quoted 14 lines

Does this make any sense?

Having a fixed size array as a user accessible item (which is TYPEDEF'ed to resemble a structure, no less) which could be passed around is just a BAD idea in C/C++. I have yet to hear any concrete reasons (besides just plain obstinacy) why va_list HAS to be implemented this way.

-jason.

Quoted 1 line

Franz.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#8 lore raw
Quoted 3 lines · Jason Kim

Well, xemacs-21.1.8, Mesa-3.0, gcc-2.95.2, xscreensaver-3.21, gle-2.3 and ssh-2.0.13 all compile and link against the older dynamic libraries, but use the va_list definition from my patch. All seem to work fine.

An interesting happy accident. The PPC SVR4 ABI passes structures by reference, which at the machine level winds up looking just like it does when the array decomposes into a pointer.

Quoted 2 lines

Anybody have any examples of where there IS va_list passage from user code to existing dynlib code (or vice versa)?

Of course -- vfprintf.

Quoted 3 lines

If that is the case, then applying the patch en-mass seems harmless way for getting rid of the array based va_list once and for all.

Except that we're not going to do that. We'll stay with the letter of the PPC SVR4 ABI law, thanks.

Despite what you may think, PPC is not unique in its use of an array definition for va_list. Whatever changes that might could be made in gcc doesn't make the code in question any more correct pedantically, and will continue to break when you go use someone else's compiler.

r~

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#9 lore raw
In reply to Jason Kim
Quoted 5 lines · Jason Kim

Anybody have any examples of where there IS va_list passage from user code to existing dynlib code (or vice versa)? I tried a bit, and couldn't find any, and am thinking that there isn't any. If that is the case, then applying the patch en-mass seems harmless way for getting rid of the array based va_list once and for all.

How about anything that calls vprintf, vsprintf, or vsnprintf?

A more concrete example: Suppose you've compiled the perl library to use the old interface and then compile an application which uses it with your va_list interface. Then suppose the application calls sv_vsetpvfn() in the perl library. Would it work?

I feel like I'm playing devil's advocate here because I would really like it if you (or someone) could straighten out the ppc va_list issues. I've been bitten by problems similar to the ones that you've encountered more than once over the years. Recently I had to fix a problem in gdb where it would've been nice to do a va_list copy. Instead, I restructured the code so that a copy wasn't necessary. It turned out to be doable in this instance, but I'm aware of some code in libiberty that can't be restructured so easily. (But for some reason, it seems to be working now on linux/ppc. I remember a time when it didn't.)

Kevin

Signature · 4 lines
Kevin Buettner
[email protected], [email protected]

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
#11 lore raw
In reply to Jason Kim
Quoted 4 lines · Jason Kim

Having a fixed size array as a user accessible item (which is TYPEDEF'ed to resemble a structure, no less) which could be passed around is just a BAD idea in C/C++. I have yet to hear any concrete reasons (besides just plain obstinacy) why va_list HAS to be implemented this way.

Years of legacy binaries that would have to be rebuilt, for one. The fact that we _just_ had a varargs-related rework of some programs (linux kernel, mach kernel, etc. come to mind) for gcc 2.95.x is another reason. Mucking with the way the compiler builds varargs can have really nasty implications. It should not be changed for trivial reasons. The macros are there to be used. Attempting to do anything else with varargs breaks spec, and changing the compiler and everything ever built with it just to make it easier for coders to be sloppy is a bad idea (tm).

David

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/