www.digitalmars.com         C & C++   DMDScript  

D - bug on linux: Error: Error reading file 'object.d'

reply Antti =?iso-8859-1?Q?Syk=E4ri?= <jsykari gamma.hut.fi> writes:
While trying the compiler on linux, I was surprised to find out that
setting default include path in /etc/dmd.conf does not seem to work. If
I set the include path on the command line, it works.

jsykari:~/work/d_tests% dmd test2.d
Error: Error reading file 'object.d'
jsykari:~/work/d_tests% dmd -I/home/jsykari/dmd/src/phobos test2.d  
gcc test2.o -o test2 -lphobos -lpthread -lm 
jsykari:~/work/d_tests%

/etc/dmd.conf:
---

[Environment]

DFLAGS=-I/home/jsykari/dmd/src/phobos/

---

I found out using strace that dmd actually reads /etc/dmd.conf, but then
fails to open object.d. Here are relevant snippets from its output,
first of the failed attempt:

jsykari:~/work/d_tests% strace dmd test.d
[...]
open("/etc/dmd.conf", O_RDONLY)         = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=61, ...}) = 0
read(3, "\r\n[Environment]\r\n\r\nDFLAGS=-I/hom"..., 61) = 61
close(3)                                = 0
unlink("test.o")                        = 0
open("test.d", O_RDONLY)                = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=403, ...}) = 0
read(3, "import c.stdio;\n\nclass Visitor {"..., 403) = 403
close(3)                                = 0
stat64("object.d", 0xbffff9c0)          = -1 ENOENT (No such file or
directory)
open("object.d", O_RDONLY)              = -1 ENOENT (No such file or
directory)
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 4), ...}) = 0
[...]

Then the succeeded attempt:

jsykari:~/work/d_tests% strace dmd test.d -I/home/jsykari/dmd/src/phobos/
[...]
open("/etc/dmd.conf", O_RDONLY)         = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=61, ...}) = 0
read(3, "\r\n[Environment]\r\n\r\nDFLAGS=-I/hom"..., 61) = 61
close(3)                                = 0
unlink("test.o")                        = -1 ENOENT (No such file or
directory)
open("test.d", O_RDONLY)                = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=403, ...}) = 0
read(3, "import c.stdio;\n\nclass Visitor {"..., 403) = 403
close(3)                                = 0
stat64("object.d", 0xbffff9a0)          = -1 ENOENT (No such file or
directory)
stat64("/home/jsykari/dmd/src/phobos/object.d", {st_mode=S_IFREG|0644,
st_size=1751, ...}) = 0
open("/home/jsykari/dmd/src/phobos/object.d", O_RDONLY) = 3
[...]

-Antti
Aug 27 2003
parent reply "Walter" <walter digitalmars.com> writes:
I have no idea why it is failing for you. It works on my linux box. Check
out \dmd\src\dmd\inifile.c and see if you see something obviously wrong?

"Antti Sykäri" <jsykari gamma.hut.fi> wrote in message
news:slrnbkqh8j.s51.jsykari pulu.hut.fi...
 While trying the compiler on linux, I was surprised to find out that
 setting default include path in /etc/dmd.conf does not seem to work. If
 I set the include path on the command line, it works.

 jsykari:~/work/d_tests% dmd test2.d
 Error: Error reading file 'object.d'
 jsykari:~/work/d_tests% dmd -I/home/jsykari/dmd/src/phobos test2.d
 gcc test2.o -o test2 -lphobos -lpthread -lm
 jsykari:~/work/d_tests%

 /etc/dmd.conf:
 ---

 [Environment]

 DFLAGS=-I/home/jsykari/dmd/src/phobos/

 ---

 I found out using strace that dmd actually reads /etc/dmd.conf, but then
 fails to open object.d. Here are relevant snippets from its output,
 first of the failed attempt:

 jsykari:~/work/d_tests% strace dmd test.d
 [...]
 open("/etc/dmd.conf", O_RDONLY)         = 3
 fstat64(3, {st_mode=S_IFREG|0644, st_size=61, ...}) = 0
 read(3, "\r\n[Environment]\r\n\r\nDFLAGS=-I/hom"..., 61) = 61
 close(3)                                = 0
 unlink("test.o")                        = 0
 open("test.d", O_RDONLY)                = 3
 fstat64(3, {st_mode=S_IFREG|0644, st_size=403, ...}) = 0
 read(3, "import c.stdio;\n\nclass Visitor {"..., 403) = 403
 close(3)                                = 0
 stat64("object.d", 0xbffff9c0)          = -1 ENOENT (No such file or
 directory)
 open("object.d", O_RDONLY)              = -1 ENOENT (No such file or
 directory)
 fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 4), ...}) = 0
 [...]

 Then the succeeded attempt:

 jsykari:~/work/d_tests% strace dmd test.d -I/home/jsykari/dmd/src/phobos/
 [...]
 open("/etc/dmd.conf", O_RDONLY)         = 3
 fstat64(3, {st_mode=S_IFREG|0644, st_size=61, ...}) = 0
 read(3, "\r\n[Environment]\r\n\r\nDFLAGS=-I/hom"..., 61) = 61
 close(3)                                = 0
 unlink("test.o")                        = -1 ENOENT (No such file or
 directory)
 open("test.d", O_RDONLY)                = 3
 fstat64(3, {st_mode=S_IFREG|0644, st_size=403, ...}) = 0
 read(3, "import c.stdio;\n\nclass Visitor {"..., 403) = 403
 close(3)                                = 0
 stat64("object.d", 0xbffff9a0)          = -1 ENOENT (No such file or
 directory)
 stat64("/home/jsykari/dmd/src/phobos/object.d", {st_mode=S_IFREG|0644,
 st_size=1751, ...}) = 0
 open("/home/jsykari/dmd/src/phobos/object.d", O_RDONLY) = 3
 [...]

 -Antti
Aug 28 2003
parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
I have been having the same problem ever since the linux version of dmd 
came out.

I went to look at inifile.c, but cannot find it anywhere in any of the 
dmd versions I've ever downloaded.
Aug 28 2003
parent reply "Walter" <walter digitalmars.com> writes:
I've attached inifile.c.

"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:bil0sp$umd$1 digitaldaemon.com...
 I have been having the same problem ever since the linux version of dmd
 came out.

 I went to look at inifile.c, but cannot find it anywhere in any of the
 dmd versions I've ever downloaded.
begin 666 inifile.c M+R!!;&P 4FEG:'1S(%)E<V5R=F5D"B\O('=R:71T96X 8GD 5V%L=&5R($)R M:6=H= HO+R!W=W<N9&EG:71A;&UA<G,N8V]M" H*(VEN8VQU9&4)/'-T9&EO M+F ^"B-I;F-L=61E"3QS=')I;F<N:#X*(VEN8VQU9&4)/'-T9&QI8BYH/ HC M:6YC;'5D90D\8W1Y<&4N:#X*"B-I;F-L=61E"2)R;V]T+F B" HC9&5F:6YE M($Q/1PDP" IC:&%R("IS:VEP<W!A8V4H8V]N<W0 8VAA<B J<"D[" HC:68 M/2!S.PH (" "B ("!W:&EL92 H*G,I"B ("![" DJ<R ]('1O=7!P97(H M*G,I.PH)<RLK.PH (" ?0H*(" (')E='5R;B!T.PI]"B-E;F1I9B O*B!U M;FEX("HO" HO*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BH*("H 4F5A M9"!A;F0 86YA;'EZ92 N:6YI(&9I;&4N"B J($EN<'5T. H * EA<F=V, EP M<F]G<F%M(&YA;64 *&%R9W9;,%TI"B J"6EN:69I;&4)+FEN:2!F:6QE(&YA M;64*("HO" IV;VED(&EN:69I;&4H8VAA<B J87)G=C L(&-H87( *FEN:69I M;&4I"GL*(" (&-H87( *G!A=& ["0DO+R!N965D('!A=& 9F]R($!0(&UA M8W)O"B ("!C:&%R("IF:6QE;F%M93L*(" ($]U=$)U9F9E<B!B=68["B M("!I;G0 :3L*(" (&EN="!K.PH (" :6YT(&5N=G-E8W1I;VX /2 P.PH* M(VEF($Q/1PH (" <')I;G1F*")I;FEF:6QE*&%R9W8P(#T )R5S)RP :6YI M9FEL92 ]("<E<R<I7&XB+"!A<F=V,"P :6YI9FEL92D["B-E;F1I9 H (" M:68 *$9I;&5.86UE.CIA8G-O;'5T92AI;FEF:6QE*2D*(" ('L*"7!A=& M/2 B(CL*"69I;&5N86UE(#T :6YI9FEL93L*(" ('T*(" (&5L<V4*(" M('L*"7!A=& /2!&:6QE3F%M93HZ<&%T:"AA<F=V,"D[" EF:6QE;F%M92 ] M($9I;&5.86UE.CIR97!L86-E3F%M92AA<F=V,"P :6YI9FEL92D[" HC:68 M3$]'" EP<FEN=&8H(EQT<&%T:" ]("<E<R<L(&9I;&5N86UE(#T )R5S)UQN M(BP <&%T:"P 9FEL96YA;64I.PHC96YD:68*(" ('T*"B ("!&:6QE(&9I M;&4H9FEL96YA;64I.PH*(" (&EF("AF:6QE+G)E860H*2D*"7)E='5R;CL) M"0DO+R!E<G)O<B!R96%D:6YG(&9I;&4*"B (" O+R!087)S92!I;G1O(&QI M;F5S"B ("!I;G0 96]F(#T ,#L M+FQE;B F)B A96]F.R!I*RLI"B ("![" EI;G0 ;&EN97-T87)T(#T :3L* M" EF;W( *#L :2 \(&9I;&4N;&5N.R!I*RLI" E[" D (" <W=I=&-H("AF M:6QE+F)U9F9E<EMI72D*"2 ("![" D)8V%S92 G7'(G. H)"2 ("!B<F5A M:SL*" D)8V%S92 G7&XG. H)"2 (" O+R!3:VEP(&EF(&ET('=A<R!P<F5C M961E9"!B>2 G7'(G" D)(" (&EF("AI("8F(&9I;&4N8G5F9F5R6VD +2 Q M72 ]/2 G7'(G*0H)"0EG;W1O($QS:VEP.PH)"2 ("!B<F5A:SL*" D)8V%S M92 P. H)"6-A<V4 ,' Q03H*"0D (" 96]F(#T ,3L*"0D (" 8G)E86L[ M" H)"61E9F%U;'0Z" D)(" (&-O;G1I;G5E.PH)(" ('T*"2 ("!B<F5A M:SL*"7T*" DO+R!4:&4 ;&EN92!I<R!F:6QE+F)U9F9E<EML:6YE<W1A<G0N M+FE=" EC:&%R("IL:6YE.PH):6YT(&QE;CL*"6-H87( *G [" EC:&%R("IP M;CL*" EL:6YE(#T *&-H87( *BDF9FEL92YB=69F97);;&EN97-T87)T73L* M"6QE;B ](&D +2!L:6YE<W1A<G0[" H)8G5F+G)E<V5T*"D[" H)+R\ 1FER M<W0L(&5X<&%N9"!T:&4 ;6%C<F]S+ H)+R\ 36%C<F]S(&%R92!B<F%C:V5T M*RD*"7L*"2 ("!I9B H;&EN95MK72 ]/2 G)2<I" D (" >PH)"6EN="!J M.PH*"0EF;W( *&H /2!K("L ,3L :B \(&QE;CL :BLK*0H)"7L*"0D (" M:68 *&QI;F5;:ET /3T )R4G*0H)"2 ("![" D)"6EF("AJ("T :R ]/2 S M" D)"2 (" O+R E0% E(&ES('-P96-I86P ;65A;FEN9R!T:&4 <&%T:"!T M;R!T:&4 +FEN:2!F:6QE" D)"2 ("!P(#T <&%T:#L*"0D)?0H)"0EE;'-E M" D)"7L ("!I;G0 ;&5N(#T :B M(&L[" D)"2 ("!C:&%R('1M<%LQ,%T[ M"2\O(&)I9R!E;F]U9V ;6]S="!O9B!T:&4 =&EM90H*"0D)(" (&EF("AL M96X /#T <VEZ96]F*'1M<"DI" D)"0EP(#T =&UP.PH)"0D (" 96QS90H) M"0D)<" ]("AC:&%R("HI86QL;V-A*&QE;BD[" D)"2 ("!L96XM+3L*"0D) M(" (&UE;6-P>2AP+" F;&EN95MK("L ,5TL(&QE;BD[" D)"2 ("!P6VQE M;ET /2 P.PH)"0D (" <W1R=7!R*' I.PH)"0D (" <" ](&=E=&5N=BAP M*3L*"0D)(" (&EF(" A<"D*"0D)"7 /2 B(CL*"0D)?0H)"0EB=68N=W)I M=&5S=')I;F<H<"D[" D)"6L /2!J.PH)"0EG;W1O($PQ.PH)"2 ("!]" D) M?0H)(" ('T*"2 ("!B=68N=W)I=&5">71E*&QI;F5;:UTI.PH)($PQ. H) M(" (#L*"7T*" DO+R!296UO=F4 =')A:6QI;F< <W!A8V5S" EW:&EL92 H M8G5F+F]F9G-E=" F)B!I<W-P86-E*&)U9BYD871A6V)U9BYO9F9S970 +2 Q M"2\O(%1H92!E>'!A;F1E9"!L:6YE(&ES(&EN(' N" DO+R!.;W< <&%R<V4 M:70 9F]R(&UE86YI;F<N" H)<" ]('-K:7!S<&%C92AP*3L*"7-W:71C:" H M*G I" E[" D (" 8V%S92 G.R<Z"0DO+R!C;VUM96YT" D (" 8V%S92 P M. D)+R\ 8FQA;FL*"0EB<F5A:SL*" D (" 8V%S92 G6R<Z"0DO+R!L;V]K M(&9O<B!;16YV:7)O;FUE;G1=" D)<" ]('-K:7!S<&%C92AP("L ,2D[" D) M9F]R("AP;B ](' [(&ES86QN=6TH*G!N*3L <&XK*RD*"0D (" .PH)"6EF M("AP;B M(' /3T ,3$ )B8*"0D (" ;65M:6-M<"AP+" B16YV:7)O;FUE M;G0B+" Q,2D /3T ," F) H)"2 (" J<VMI<'-P86-E*'!N*2 ]/2 G72<* M"0D (" I" D)(" (&5N=G-E8W1I;VX /2 Q.PH)"65L<V4*"0D (" 96YV M(&YA;64 =&\ =7!P97( 8V%S93L*"0D (" +R\ <F5M;W9E('-P86-E<R!B M<F%C:V5T:6YG(#T*"0D (" 9F]R("AP(#T <&X[("IP.R!P*RLI" D)(" M('L ("!I9B H:7-L;W=E<B J<"DI" D)"2 (" J<" F/2!^,' R,#L*"0D) M96QS92!I9B H:7-S<&%C92 J<"DI" D)"2 ("!M96UM;W9E*' L(' *R Q M+"!S=')L96XH<"DI.PH)"0EE;'-E(&EF(" J<" ]/2 G/2<I" D)"7L*"0D) M(" (' K*SL*"0D)(" ('=H:6QE("AI<W-P86-E*"IP*2D*"0D)"6UE;6UO M"2 ("!]" H)"2 ("!P=71E;G8H<&XI.PHC:68 3$]'" D)(" ('!R:6YT M9B B7'1P=71E;G8H)R5S)RE<;B(L('!N*3L*"0D (" +R]P<FEN=&8H(F=E M=&5N=BA<(E1%4U1<(BD /2 G)7,G7&XB+&=E=&5N=B B5$535"(I*3L*(V5N M9&EF" D)?0H)"6)R96%K.PH)?0H*(" ("!,<VMI<#H*"3L*(" ('T*?0H* M+RHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ"B J(%-K:7 <W!A8V5S+ H *B\*"F-H M87( *G-K:7!S<&%C92AC;VYS="!C:&%R("IP*0I["B ("!W:&EL92 H:7-S I<&%C92 J<"DI" EP*RL["B ("!R971U<FX *&-H87( *BEP.PI]" H` ` end
Aug 28 2003
parent reply Antti =?iso-8859-1?Q?Syk=E4ri?= <jsykari gamma.hut.fi> writes:
In article <bile7b$1l8e$1 digitaldaemon.com>, Walter wrote:
 I've attached inifile.c.
Thanks! That was certainly helpful. I think I might have found the source of the bug. In inifile() calls putenv() with an argument that is inside an OutBuffer and therefore gets free'd later. putenv() is defined so that it will not copy its argument but rather takes its ownership: From putenv(3) man page: The libc4 and libc5 and glibc 2.1.2 versions conform to SUSv2: the pointer string given to putenv() is used. In particular, this string becomes part of the environment; changing it later will change the environment. (Thus, it is an error is to call putenv() with an auto- matic variable as the argument, then return from the calling function while string is still part of the environment.) However, glibc 2.0-2.1.1 differs: a copy of the string is used. On the one hand this causes a memory leak, and on the other hand it violates SUSv2. This has been fixed in glibc2.1.2. So if you run dmd on libc 2.0-2.1.1 (which I could imagine your Red Hat has in /lib) it works fine, but on a newer glibc fails silently and the environment entry probably gets garbled. The fix is obvious: change putenv(pn) on line 209 to putenv(strdup(pn)). The workaround, of course, is to set DFLAGS=whatever in your shell's environment and not use /etc/dmd.conf because it could mess with it. -Antti
Aug 28 2003
parent "Walter" <walter digitalmars.com> writes:
Ah, wonderful. I made the fix. Thanks!
Aug 28 2003