[klibc] [PATCH] klcc on multiple files

Daniel Thaler daniel at dthaler.de
Wed May 25 13:12:30 PDT 2005


H. Peter Anvin wrote:
> Erik van Konijnenburg wrote:
> 
>> There's a problem in klibc 1.0.12:
>>
>>     klcc -c t.c  && klcc t.o && ./a.out
>>
>> works, but
>>
>>     klcc t.c && ./a.out
>>
>> fails because open3() wants to close its input,
>> and you can do that only once to STDIN.
>>
>> Attached patch makes "klcc t.c" work again.
>>
>> This might break the klcc from stdin option, but I can't
>> tell because I've got no idea how it's supposed to be invoked
>> and what gcc command line should result.  If you can mail
>> a command line example I'll look for a cleaner solution.
>>
> 
> I have released 1.0.13 which backs out the stdin patch.  Daniel, could
> you perhaps revise your patch to fix the various problems, and give a
> real-life usage example?
> 
>     -hpa

First the real-life example (from the Makefile of iptables 1.3.1):
./Makefile:60:  32bituser := $(shell echo -e "\#include <stdio.h>\n\#if
!defined(__sparcv9) && !defined(__arch64__) &&
!defined(_LP64)\nuserspace_is_32bit\n\#endif" | $(CC) $(CFLAGS) -E - |
grep userspace_is_32bit)

The fix to Erik's problem is to dup STDIN (patch attached), because open3
only insists on closing STDIN, but not other random filehandles.

However you said "various problems", so what else did I break :( ?

Daniel Thaler
-------------- next part --------------
--- klcc.in.old	2005-05-25 13:56:20.000000000 -0600
+++ klcc.in	2005-05-25 13:57:30.000000000 -0600
@@ -82,7 +82,8 @@
 sub mysystem(@) {
     print STDERR join(' ', @_), "\n" if ( $verbose );
     my $cmd = shift;
-    my $childpid = open3("<&STDIN", ">&STDOUT", ">&STDERR", $cmd, @_);
+    open(INPUT, "<&STDIN");	# dup STDIN filehandle to INPUT
+    my $childpid = open3("<&INPUT", ">&STDOUT", ">&STDERR", $cmd, @_);
     waitpid ($childpid, 0);
     return $?;
 }


More information about the klibc mailing list