<< Back to previous view

[PCC-381] Code generated by pcc causes SIGSEGV on access of struct members of function retval Created: 22/Sep/11  Updated: 31/Mar/12

Status: Resolved
Project: pcc
Component/s: i386 target
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Michael W. Bombardieri Assignee: Anders Magnusson
Resolution: Fixed Votes: 0
Environment: OpenBSD 4.9 i386

Hi pcc,

I am compiling the OpenBSD make(1) tool using pcc.
Code generated by pcc-i386 causes a segmentation fault.
The same code works fine for pcc-amd64.
The version of PCC I am using is

  pcc 1.1.0.DEVEL 20110919 for i386-unknown-openbsd4.9

Debugging "make clean" always dies at the same line of code.

(gdb) file make.pcc
Reading symbols from /home/mwb/0/src/usr.bin/make/make.pcc...done.
(gdb) run clean
Starting program: /home/mwb/0/src/usr.bin/make/make.pcc clean
rm -f a.out [Ee]rrs mklog core *.core y.tab.h make arch.o buf.o cmd_exec.o compat.o cond.o dir.o direxpand.o engine.o error.o for.o init.o job.o lowparse.o main.o make.o memory.o parse.o parsevar.o str.o stats.o suff.o targ.o targequiv.o timestamp.o var.o varmodifiers.o varname.o lstAddNew.o lstAppend.o lstConcat.o lstConcatDestroy.o lstDeQueue.o lstDestroy.o lstDupl.o lstFindFrom.o lstForEachFrom.o lstInsert.o lstMember.o lstRemove.o lstReplace.o lstRequeue.o lstSucc.o arch.ln buf.ln cmd_exec.ln compat.ln cond.ln dir.ln direxpand.ln engine.ln error.ln for.ln init.ln job.ln lowparse.ln main.ln make.ln memory.ln parse.ln parsevar.ln str.ln stats.ln suff.ln targ.ln targequiv.ln timestamp.ln var.ln varmodifiers.ln varname.ln lstAddNew.ln lstAppend.ln lstConcat.ln lstConcatDestroy.ln lstDeQueue.ln lstDestroy.ln lstDupl.ln lstFindFrom.ln lstForEachFrom.ln lstInsert.ln lstMember.ln lstRemove.ln lstReplace.ln lstRequeue.ln lstSucc.ln generate generate.o regress.o check libohash.a varhashconsts.h condhashconsts.h nodehashconsts.h

Program received signal SIGSEGV, Segmentation fault.
0x1c0036d0 in CompatMake () at compat.c:211
211 if (noExecute || is_out_of_date(Dir_MTime(gn)))
(gdb) bt
#0 0x1c0036d0 in CompatMake () at compat.c:211
#1 0x1c0039d7 in Compat_Run () at compat.c:297
#2 0x1c00ad89 in main () at main.c:814

A second debugging session produces a failure on a near-identical chunk of code..

Program received signal SIGSEGV, Segmentation fault.
0x1c0063f7 in Job_CheckCommands () at engine.c:109
109 } else if (is_out_of_date(Dir_MTime(gn))) {

Expanding the is_out_of_date() macro for the above code we get

  ((Dir_MTime(gn)).tv_sec == (-0x7fffffff-1) && (Dir_MTime(gn)).tv_nsec == 0);

Dir_MTime() returns a value of type struct timespec; I've verified that this function returns as expected.
The macro is_out_of_date() accesses a struct member of the return value of Dir_MTime()
without first assigning it into a variable.
This appears to be what causes the segmentation fault.

Comment by Anders Magnusson [ 24/Mar/12 05:59 PM ]
OpenBSD uses a non-standard way of returning small structs on i386, most likely that is where something is failing.
Comment by Anders Magnusson [ 31/Mar/12 10:56 AM ]
Should work now, thanks for the bug report!
Generated at Sun Aug 02 06:18:09 CEST 2015 using JIRA Enterprise Edition, Version: 3.13.1-#333.