Skip to content

Segmentation fault when running Borland linker tlink32.exe #107

@miried

Description

@miried

I'm trying to compile applications with Borland C++ 5.2 via wibo. With my preliminary fix mentioned in #106 I can execute bcc32.exe (the compiler itself) but the linking fails due to a segmentation fault in tlink32.exe. It has a segmentation fault at 0x00401120 (EDX and EAX are both 0), the function seems to be GetTls (FS:[0x2c] would be thread local storage array pointer from what I can tell).

The disassembly is this:

                             **************************************************************
                             *                          FUNCTION                          *
                             **************************************************************
                             void * __stdcall ___System__GetTls(void)
             void *            EAX:4          <RETURN>
                             ___System__GetTls
        00401115 a1 5b d0        MOV        EAX,[_tls_index]
                 42 00
        0040111a 64 67 8b        MOV        EDX,dword ptr FS:[0x2c]
                 16 2c 00
        00401120 8b 04 82        MOV        EAX,dword ptr [EDX + EAX*0x4]
        00401123 c3              RET

Any ideas why the TLS pointer could be NULL?

Reproduce:
./wibo -D Borland/BC5/BIN/tlink32.exe

Output (tested on macos sonoma via Rosetta and linux x64 VM):

➜ ./wibo -D Borland/BC5/BIN/tlink32.exe
[thread aaa15] heap: no arena available, creating new arena
[thread aaa15] heap: found free mapping at 6c000000
[thread aaa15] heap: created arena 1811939328 at 0x6c000000..0x70000000 (64 MiB)
[thread aaa15] heap: found free mapping at 7def0000
[thread aaa15] heap: reserved guest stack limit=0x7def1000 base=0x7dff1000 (total=1028 KiB)
[thread aaa15] initializeTibStackInfo: using guest stack base=0x7dff1000 limit=0x7def1000
[thread aaa15] setup_darwin: Allocating LDT entry 3
[thread aaa15] setup_darwin: Code LDT selector 1f
[thread aaa15] setup_darwin: Allocating LDT entry 4
[thread aaa15] setup_darwin: Data LDT selector 27
[thread aaa15] setup_darwin: Allocating LDT entry 5
[thread aaa15] setup_darwin: Installing cs 31, ds 39, fs 47
[thread aaa15] Command line: Z:\Users\x\projects\decomp\Borland\BC5\BIN\tlink32.exe
[thread aaa15] Sections: 8 / Size of optional header: e0
[thread aaa15] Image Base: 400000 / Size: 53000
[thread aaa15] Page size: 1000
[thread aaa15] loadPE: mapping succeeded (base=0x400000, size=339968)
[thread aaa15] Section 0: name=CODE addr=1000 size=2c000 (raw=2bc00) ptr=e00
[thread aaa15] Section 1: name=DATA addr=2d000 size=1c000 (raw=6c00) ptr=2ca00
[thread aaa15] Section 2: name=.tls addr=49000 size=1000 (raw=200) ptr=33600
[thread aaa15] Section 3: name=.rdata addr=4a000 size=1000 (raw=200) ptr=33800
[thread aaa15] Section 4: name=.idata addr=4b000 size=1000 (raw=800) ptr=33a00
[thread aaa15] Section 5: name=.edata addr=4c000 size=1000 (raw=200) ptr=34200
[thread aaa15] Section 6: name=.reloc addr=4d000 size=3000 (raw=2600) ptr=34400
[thread aaa15] Section 7: name=.rsrc addr=50000 size=3000 (raw=2200) ptr=36a00
[thread aaa15] Registered main module tlink32.exe at 0x400000
[thread aaa15] DLL Name: KERNEL32.DLL
[thread aaa15] loadModule(KERNEL32.DLL)
[thread aaa15]   found existing module alias kernel32.dll (builtin=1)
[thread aaa15]   module not found on disk
[thread aaa15]   returning builtin module kernel32
[thread aaa15]   Name: GetCurrentDirectoryA (IAT=0x44b15c)
[thread aaa15]     -> 0x7e100c1b
[thread aaa15]   Name: CreateFileW (IAT=0x44b160)
[thread aaa15]     -> 0x7e0fedf0
[thread aaa15]   Name: GetProcAddress (IAT=0x44b164)
[thread aaa15]     -> 0x7e101f09
[thread aaa15]   Name: EnterCriticalSection (IAT=0x44b168)
[thread aaa15]     -> 0x7e0ff76e
[thread aaa15]   Name: ExitProcess (IAT=0x44b16c)
[thread aaa15]     -> 0x7e0ff85a
[thread aaa15]   Name: FileTimeToDosDateTime (IAT=0x44b170)
[thread aaa15]     -> 0x7e0ff942
[thread aaa15]   Name: CloseHandle (IAT=0x44b174)
[thread aaa15]     -> 0x7e0fe83c
[thread aaa15]   Name: FileTimeToSystemTime (IAT=0x44b178)
[thread aaa15]     -> 0x7e0ffa36
[thread aaa15]   Name: FindClose (IAT=0x44b17c)
[thread aaa15]     -> 0x7e0ffc9e
[thread aaa15]   Name: FindFirstFileA (IAT=0x44b180)
[thread aaa15]     -> 0x7e0ffd15
[thread aaa15]   Name: FindNextFileA (IAT=0x44b184)
[thread aaa15]     -> 0x7e0ffe8d
[thread aaa15]   Name: FreeLibrary (IAT=0x44b188)
[thread aaa15]     -> 0x7e100532
[thread aaa15]   Name: GetACP (IAT=0x44b18c)
[thread aaa15]     -> 0x7e1005a9
[thread aaa15]   Name: GetCPInfo (IAT=0x44b190)
[thread aaa15]     -> 0x7e100715
[thread aaa15]   Name: GetCommandLineA (IAT=0x44b194)
[thread aaa15]     -> 0x7e10078d
[thread aaa15]   Name: CreateFileA (IAT=0x44b198)
[thread aaa15]     -> 0x7e0fec46
[thread aaa15]   Name: GetCurrentThreadId (IAT=0x44b19c)
[thread aaa15]     -> 0x7e100e55
[thread aaa15]   Name: GetDateFormatA (IAT=0x44b1a0)
[thread aaa15] Missing function: kernel32 (GetDateFormatA)
[thread aaa15]     -> 0x7e0d5bc8
[thread aaa15]   Name: GetDriveTypeA (IAT=0x44b1a4)
[thread aaa15]     -> 0x7e1010cb
[thread aaa15]   Name: GetEnvironmentStrings (IAT=0x44b1a8)
[thread aaa15]     -> 0x7e1011b3
[thread aaa15]   Name: GetFileAttributesA (IAT=0x44b1ac)
[thread aaa15]     -> 0x7e1014eb
[thread aaa15]   Name: GetFileAttributesW (IAT=0x44b1b0)
[thread aaa15]     -> 0x7e10155f
[thread aaa15]   Name: GetFileInformationByHandle (IAT=0x44b1b4)
[thread aaa15]     -> 0x7e1015d3
[thread aaa15]   Name: GetFileSize (IAT=0x44b1b8)
[thread aaa15]     -> 0x7e10164e
[thread aaa15]   Name: GetFileTime (IAT=0x44b1bc)
[thread aaa15]     -> 0x7e1016c9
[thread aaa15]   Name: GetFileType (IAT=0x44b1c0)
[thread aaa15]     -> 0x7e10174c
[thread aaa15]   Name: GetFullPathNameA (IAT=0x44b1c4)
[thread aaa15]     -> 0x7e1017c3
[thread aaa15]   Name: GetLastError (IAT=0x44b1c8)
[thread aaa15]     -> 0x7e1018c3
[thread aaa15]   Name: GetLocalTime (IAT=0x44b1cc)
[thread aaa15]     -> 0x7e101931
[thread aaa15]   Name: GetLogicalDrives (IAT=0x44b1d0)
[thread aaa15] Missing function: kernel32 (GetLogicalDrives)
[thread aaa15]     -> 0x7e0d5bd1
[thread aaa15]   Name: GetModuleFileNameA (IAT=0x44b1d4)
[thread aaa15]     -> 0x7e101c26
[thread aaa15]   Name: GetModuleHandleA (IAT=0x44b1d8)
[thread aaa15]     -> 0x7e101d24
[thread aaa15]   Name: FileTimeToLocalFileTime (IAT=0x44b1dc)
[thread aaa15]     -> 0x7e0ff9be
[thread aaa15]   Name: DeleteFileA (IAT=0x44b1e0)
[thread aaa15]     -> 0x7e0ff47f
[thread aaa15]   Name: GetStartupInfoA (IAT=0x44b1e4)
[thread aaa15]     -> 0x7e1021e8
[thread aaa15]   Name: GetStdHandle (IAT=0x44b1e8)
[thread aaa15]     -> 0x7e1022d0
[thread aaa15]   Name: GetStringTypeW (IAT=0x44b1ec)
[thread aaa15]     -> 0x7e1023cb
[thread aaa15]   Name: GetTempFileNameA (IAT=0x44b1f0)
[thread aaa15]     -> 0x7e1028e8
[thread aaa15]   Name: GetVersion (IAT=0x44b1f4)
[thread aaa15]     -> 0x7e102d17
[thread aaa15]   Name: GetVersionExA (IAT=0x44b1f8)
[thread aaa15]     -> 0x7e102d85
[thread aaa15]   Name: GetVolumeInformationA (IAT=0x44b1fc)
[thread aaa15]     -> 0x7e102e6d
[thread aaa15]   Name: GlobalMemoryStatus (IAT=0x44b200)
[thread aaa15]     -> 0x7e103185
[thread aaa15]   Name: InitializeCriticalSection (IAT=0x44b204)
[thread aaa15]     -> 0x7e1036ea
[thread aaa15]   Name: LeaveCriticalSection (IAT=0x44b208)
[thread aaa15]     -> 0x7e103fec
[thread aaa15]   Name: LoadLibraryA (IAT=0x44b20c)
[thread aaa15]     -> 0x7e104060
[thread aaa15]   Name: LocalAlloc (IAT=0x44b210)
[thread aaa15]     -> 0x7e104245
[thread aaa15]   Name: LocalFree (IAT=0x44b214)
[thread aaa15]     -> 0x7e1043ac
[thread aaa15]   Name: MultiByteToWideChar (IAT=0x44b218)
[thread aaa15]     -> 0x7e10496c
[thread aaa15]   Name: RaiseException (IAT=0x44b21c)
[thread aaa15]     -> 0x7e104b65
[thread aaa15]   Name: ReadFile (IAT=0x44b220)
[thread aaa15]     -> 0x7e104c68
[thread aaa15]   Name: RtlUnwind (IAT=0x44b224)
[thread aaa15]     -> 0x7e105032
[thread aaa15]   Name: SetConsoleCtrlHandler (IAT=0x44b228)
[thread aaa15]     -> 0x7e1050b2
[thread aaa15]   Name: SetFileAttributesA (IAT=0x44b22c)
[thread aaa15]     -> 0x7e105556
[thread aaa15]   Name: SetFilePointer (IAT=0x44b230)
[thread aaa15]     -> 0x7e1055ce
[thread aaa15]   Name: SetHandleCount (IAT=0x44b234)
[thread aaa15]     -> 0x7e10575a
[thread aaa15]   Name: TlsAlloc (IAT=0x44b238)
[thread aaa15]     -> 0x7e105df8
[thread aaa15]   Name: TlsFree (IAT=0x44b23c)
[thread aaa15]     -> 0x7e105e66
[thread aaa15]   Name: TlsGetValue (IAT=0x44b240)
[thread aaa15]     -> 0x7e105eda
[thread aaa15]   Name: TlsSetValue (IAT=0x44b244)
[thread aaa15]     -> 0x7e105f4e
[thread aaa15]   Name: UnhandledExceptionFilter (IAT=0x44b248)
[thread aaa15]     -> 0x7e106122
[thread aaa15]   Name: VirtualAlloc (IAT=0x44b24c)
[thread aaa15]     -> 0x7e106281
[thread aaa15]   Name: VirtualFree (IAT=0x44b250)
[thread aaa15]     -> 0x7e106301
[thread aaa15]   Name: VirtualQuery (IAT=0x44b254)
[thread aaa15]     -> 0x7e1063fd
[thread aaa15]   Name: WideCharToMultiByte (IAT=0x44b258)
[thread aaa15]     -> 0x7e1066df
[thread aaa15]   Name: WriteFile (IAT=0x44b25c)
[thread aaa15]     -> 0x7e1068f1
[thread aaa15]   Name: WritePrivateProfileStringA (IAT=0x44b260)
[thread aaa15] Missing function: kernel32 (WritePrivateProfileStringA)
[thread aaa15]     -> 0x7e0d5bda
[thread aaa15]   Name: GetPrivateProfileStringA (IAT=0x44b264)
[thread aaa15] Missing function: kernel32 (GetPrivateProfileStringA)
[thread aaa15]     -> 0x7e0d5be3
[thread aaa15] DLL Name: USER32.DLL
[thread aaa15] loadModule(USER32.DLL)
[thread aaa15]   found existing module alias user32.dll (builtin=1)
[thread aaa15]   module not found on disk
[thread aaa15]   returning builtin module user32
[thread aaa15]   Name: MessageBoxA (IAT=0x44b26c)
[thread aaa15]     -> 0x7e0fddb1
[thread aaa15]   Name: LoadStringA (IAT=0x44b270)
[thread aaa15]     -> 0x7e0fdca5
[thread aaa15]   Name: EnumThreadWindows (IAT=0x44b274)
[thread aaa15]     -> 0x7e0fda4c
zsh: segmentation fault  ./wibo -D Borland/BC5/BIN/tlink32.exe

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions