mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-12 09:41:26 +00:00
45b8a741fb
This is a follow-up for D70378 (Cover usage of LLD as a library). While debugging an intermittent failure on a bot, I recalled this scenario which causes the issue: 1.When executing lld/test/ELF/invalid/symtab-sh-info.s L45, we reach lld:🧝:Obj-File::ObjFile() which goes straight into its base ELFFileBase(), then ELFFileBase::init(). 2.At that point fatal() is thrown in lld/ELF/InputFiles.cpp L381, leaving a half-initialized ObjFile instance. 3.We then end up in lld::exitLld() and since we are running with LLD_IN_TEST, we hapily restore the control flow to CrashRecoveryContext::RunSafely() then back in lld::safeLldMain(). 4.Before this patch, we called errorHandler().reset() just after, and this attempted to reset the associated SpecificAlloc<ObjFile<ELF64LE>>. That tried to free the half-initialized ObjFile instance, and more precisely its ObjFile::dwarf member. Sometimes that worked, sometimes it failed and was catched by the CrashRecoveryContext. This scenario was the reason we called errorHandler().reset() through a CrashRecoveryContext. But in some rare cases, the above repro somehow corrupted the heap, creating a stack overflow. When the CrashRecoveryContext's filter (that is, __except (ExceptionFilter(GetExceptionInformation()))) tried to handle the exception, it crashed again since the stack was exhausted -- and that took the whole application down. That is the issue seen on the bot. Locally it happens about 1 times out of 15. Now this situation can happen anywhere in LLD. Since catching stack overflows is not a reliable scenario ATM when using CrashRecoveryContext, we're now preventing further re-entrance when such failures occur, by signaling lld::SafeReturn::canRunAgain=false. When running with LLD_IN_TEST=2 (or above), only one iteration will be executed, instead of two. Differential Revision: https://reviews.llvm.org/D88348
80 lines
3.1 KiB
Plaintext
80 lines
3.1 KiB
Plaintext
# RUN: yaml2obj %s -o %t.obj
|
|
# RUN: lld-link /out:%t.exe /entry:main /subsystem:console /force \
|
|
# RUN: /merge:.foo=.abc /merge:.bar=.def %t.obj /debug
|
|
# RUN: llvm-readobj --sections %t.exe | FileCheck %s
|
|
|
|
# RUN: lld-link /out:%t.exe /entry:main /subsystem:console /force \
|
|
# RUN: /merge:.foo=.bar /merge:.bar=.abc %t.obj /debug
|
|
# RUN: llvm-readobj --sections %t.exe | FileCheck --check-prefix=CHECK2 %s
|
|
|
|
# RUN: env LLD_IN_TEST=1 not lld-link /out:%t.exe /entry:main /subsystem:console /force \
|
|
# RUN: /merge:.rsrc=.foo %t.obj /debug 2>&1 | FileCheck --check-prefix=NO-RSRC %s
|
|
# RUN: env LLD_IN_TEST=1 not lld-link /out:%t.exe /entry:main /subsystem:console /force \
|
|
# RUN: /merge:.foo=.rsrc %t.obj /debug 2>&1 | FileCheck --check-prefix=NO-RSRC %s
|
|
# RUN: env LLD_IN_TEST=1 not lld-link /out:%t.exe /entry:main /subsystem:console /force \
|
|
# RUN: /merge:.reloc=.foo %t.obj /debug 2>&1 | FileCheck --check-prefix=NO-RELOC %s
|
|
# RUN: env LLD_IN_TEST=1 not lld-link /out:%t.exe /entry:main /subsystem:console /force \
|
|
# RUN: /merge:.foo=.reloc %t.obj /debug 2>&1 | FileCheck --check-prefix=NO-RELOC %s
|
|
# RUN: env LLD_IN_TEST=1 not lld-link /out:%t.exe /entry:main /subsystem:console /force \
|
|
# RUN: /merge:.foo=.foo1 /merge:.foo1=.foo %t.obj /debug 2>&1 | FileCheck --check-prefix=NO-CYCLE %s
|
|
# RUN: env LLD_IN_TEST=1 not lld-link /out:%t.exe /entry:main /subsystem:console /force \
|
|
# RUN: /merge:.foo=.foo1 /merge:.foo1=.foo2 /merge:.foo2=.foo1 %t.obj /debug 2>&1 | FileCheck --check-prefix=NO-CYCLE %s
|
|
|
|
# CHECK: Name: .def
|
|
# CHECK: Name: .abc
|
|
|
|
# CHECK2-NOT: Name: .bar
|
|
# CHECK2: Name: .abc
|
|
# CHECK2-NOT: Name: .bar
|
|
|
|
# NO-RSRC: /merge: cannot merge '.rsrc' with any section
|
|
# NO-RELOC: /merge: cannot merge '.reloc' with any section
|
|
|
|
# NO-CYCLE: /merge: cycle found for section '.foo'
|
|
|
|
--- !COFF
|
|
header:
|
|
Machine: IMAGE_FILE_MACHINE_AMD64
|
|
Characteristics: []
|
|
sections:
|
|
- Name: .foo
|
|
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
|
|
Alignment: 4
|
|
SectionData: 000000000000
|
|
- Name: .bar
|
|
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
|
|
Alignment: 4
|
|
SectionData: 000000000000
|
|
symbols:
|
|
- Name: .foo
|
|
Value: 0
|
|
SectionNumber: 1
|
|
SimpleType: IMAGE_SYM_TYPE_NULL
|
|
ComplexType: IMAGE_SYM_DTYPE_NULL
|
|
StorageClass: IMAGE_SYM_CLASS_STATIC
|
|
SectionDefinition:
|
|
Length: 6
|
|
NumberOfRelocations: 0
|
|
NumberOfLinenumbers: 0
|
|
CheckSum: 0
|
|
Number: 0
|
|
- Name: .bar
|
|
Value: 0
|
|
SectionNumber: 2
|
|
SimpleType: IMAGE_SYM_TYPE_NULL
|
|
ComplexType: IMAGE_SYM_DTYPE_NULL
|
|
StorageClass: IMAGE_SYM_CLASS_STATIC
|
|
SectionDefinition:
|
|
Length: 6
|
|
NumberOfRelocations: 0
|
|
NumberOfLinenumbers: 0
|
|
CheckSum: 0
|
|
Number: 0
|
|
- Name: main
|
|
Value: 0
|
|
SectionNumber: 1
|
|
SimpleType: IMAGE_SYM_TYPE_NULL
|
|
ComplexType: IMAGE_SYM_DTYPE_FUNCTION
|
|
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
|
|
...
|