bitwiseworks / libcx

kLIBC Extension Library
GNU Lesser General Public License v2.1
11 stars 1 forks source link

LIBCx is unable to write assertions to logs in release builds #98

Closed dmik closed 3 years ago

dmik commented 3 years ago

An attempt to assert in a release build always ends up in this truncated log file contents:

Opened log at 2021-08-19 17:16:13.48 (00d15a79 ms since boot)
Process ID: 0xbbb (3003) Parent PID: 0xbba (3002) Type: 2
Exe hmte  : 0x50a (D:\CODING\LIBCX\MASTER-BUILD\STAGE\BIN\LIBCX-STATS.EXE)
Arg 0     : libcx-stats
Cur dir   : C:\var\log\app
CRT Module: LIBCN0 hmod=0xb82 (C:\USR\LIB\LIBCN0.DLL)
__libc_logInit: addr 0x1e07f8a9 iObj=0 offObj=0x4f8a9
Origin        : libcx
Enabled groups:

accompaniet by a SIGSEGV crash in LIBCn:

 Filename: C:\USR\LIB\LIBCN0.DLL (08/16/2021 23:44:02 1,225,146)
 Address:  005B:1E08008E (0001:0005008E)
 Cause:    Attempted to read from 00000004
           (not a valid address)

______________________________________________________________________

 Failing Instruction
______________________________________________________________________

 1E080080  MOV  EAX, [EDI+0x4]          (8b47 04)
 1E080083  MOV  [ESP], EAX              (890424)
 1E080086  CALL 0x1ffc5e28              (e8 9d5df401)
 1E08008B  MOV  EAX, [EDI+0x8]          (8b47 08)
 1E08008E >MOV  ECX, [EAX+0x4]          (8b48 04)
 1E080091  TEST ECX, ECX                (85c9)
 1E080093  JZ   0x1e080668              (0f84 cf050000)
 1E080099  MOV  DWORD [EBP-0x25c], 0x0  (c785 a4fdffff 00000000)

______________________________________________________________________

 Registers
______________________________________________________________________

 EAX : 00000000   EBX  : 0012F3F0   ECX : 0012F638   EDX  : 000001CB
 ESI : 20034614   EDI  : 20034600
 ESP : 0012F3A0   EBP  : 0012F878   EIP : 1E08008E   EFLG : 00010293
 CS  : 005B       CSLIM: FFFFFFFF   SS  : 0053       SSLIM: FFFFFFFF

 EAX : not a valid address
 EBX : read/write memory on this thread's stack
 ECX : read/write memory on this thread's stack
 EDX : not a valid address
 ESI : read/write memory allocated by LIBCN0
 EDI : read/write memory allocated by LIBCN0

...

  EBP     Address    Module     Obj:Offset    Nearest Public Symbol
--------  ---------  --------  -------------  -----------------------
Trap  ->  1E08008E   LIBCN0    0001:0005008E  logstrict.c#742 ___libc_LogSNPrintf + B3D 0001:0004F551 (logstrict.obj)

0012F878  1E080959   LIBCN0    0001:00050959  logstrict.c#442 ___libc_LogInitEx + E1 0001:00050878 (logstrict.obj)

Looks like some regression of either edd18962e6b6754a1966970257e08e87e7df4771 or LIBCn's https://github.com/bitwiseworks/libc/commit/a877378ac862b290bedc57f3b818c6c050842b7a or around that.

Note that for some reason it does not happen in debug builds of LIBCx.

Kind of critical as it completely breaks error condition discovery in the user environments. We need an urgent fix given that this is out in the just-released version 0.7.1 right now.

Discovered while sorting out #97.

dmik commented 3 years ago

I found out what's wrong: it's the fact that the release build of LIBCx doesn't use LIBC log groups at all (passes NULL as pGroups to __libc_LogInitEx) because it never logs anything except assertions and all log statements are turned into no-ops when compiling. Anyway, it's a LIBC regression for which I created a ticket (above) so closing this one in favor of it.