Open stormalf opened 10 months ago
With the last version of chibicc 1.0.22.5, the issue is now different later in hash_initial_lookup : Program received signal SIGSEGV, Segmentation fault. 0x0000000001af1374 in hash_initial_lookup () at dynahash.c:1769 1769 segp = hashp->dir[segment_num]; (gdb) bt
The segment_num value is incorrect : 658106 hashvalue: 3926571702 segment_num: 658106 hashp->dsize: 256 hashp->dir: 0x2d84d48 Segmentation fault If we compile with gcc and debug with gdb the values are completely different : 1===bucket=97, max_bucket=8191 2===bucket=97, max_bucket=8191 bucket: 97 sshift: 8 hashvalue: 4194828385 segment_num: 0 hashp->dsize: 256 hashp->dir: 0x7ffff70c0e50
the issue was caused by incorrect __builtin_clz. I used the implementation from @cosmopolitan that seems to work better. No more segmentation fault in postgres execution. It will be solved in 1.0.22.5
program initdb produced by chibicc during postgres compile failed at running with segmentation fault Program received signal SIGSEGV, Segmentation fault. 0x0000000001efd454 in MemoryChunkSetHdrMask () at ../../../../src/include/utils/memutils_memorychunk.h:164 164 chunk->hdrmask = (((uint64) blockoffset) << MEMORYCHUNK_BLOCKOFFSET_BASEBIT) | (gdb) bt
0 0x0000000001efd454 in MemoryChunkSetHdrMask ()
1 0x0000000001f001b9 in AllocSetAlloc () at aset.c:885
2 0x0000000001f243ba in MemoryContextAllocExtended () at mcxt.c:1150
3 0x0000000001e441b9 in DynaHashAlloc () at dynahash.c:292
4 0x0000000001e47998 in hash_create () at dynahash.c:391
5 0x0000000001f817d3 in init_timezone_hashtable () at pgtz.c:209
6 0x0000000001f83317 in pg_tzset () at pgtz.c:246
7 0x0000000001f8396f in pg_timezone_initialize () at pgtz.c:370
8 0x0000000001ec921f in InitializeGUCOptions () at guc.c:1504
9 0x0000000001393be9 in PostmasterMain () at postmaster.c:682
10 0x0000000001014950 in main () at main.c:198