Linux: libdxcompiler replaces the host's signal handlers (SA_RESETHAND) on in-process DXIL compile and -P
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- cpp
- Domain
- compilers, operating-systems
Research direction
Start with CompilerInstance.cpp around createDefaultOutputFile and compare its RemoveFileOnSignal path with the library-exposed handling in FrontendActions.cpp. Trace the call into lib/Support/Unix/Signals.inc, then run the provided repro for DXIL and -spirv, including -P. Done means in-process DXIL compilation and preprocessing leave the host's signal dispositions unchanged while existing output behavior remains intact.
Written by the indexing model from the issue text.
Description
This issue was written and submitted by an AI assistant (Claude) on behalf of the repository owner (@kaltinril), after the owner reviewed and agreed to its creation. The owner is accountable for it and will answer questions.
Description
On Linux, an in-process DXIL compile (or -P preprocess) through IDxcCompiler3::Compile installs LLVM's signal handler over 16 process-wide signals (SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2, SIGILL, SIGTRAP, SIGABRT, SIGFPE, SIGBUS, SIGSEGV, SIGQUIT, SIGSYS, SIGXCPU, SIGXFSZ) with SA_NODEFER|SA_RESETHAND, replacing the host application's handlers. A -spirv compile of the same shader does not.
Path: CompilerInstance::createDefaultOutputFile passes RemoveFileOnSignal=true (CompilerInstance.cpp#L603-L609), reached from EmitBCAction and PrintPreprocessedAction, then llvm::sys::RemoveFileOnSignal -> RegisterHandlers() (Signals.inc#L67-L122). In dxcompiler the output goes to an in-memory stream, so there seems to be no on-disk file to protect. FrontendActions.cpp already avoids RemoveFileOnSignal for library-exposed paths (#L120-L125).
Impact: with SA_RESETHAND, a host that delivers one of these signals to several threads can be killed by the default action. Related: #5271 / #5272 made the registration thread-safe; this report is about the registration happening at all in library use.
Steps to Reproduce
From the root of the extracted linux_dxc_2026_09_28.x86_x64.tar.gz:
g++ -std=c++17 -I include repro.cpp -o repro -L lib -ldxcompiler -lpthread -ldl
LD_LIBRARY_PATH=lib ./repro # DXIL
LD_LIBRARY_PATH=lib ./repro -spirv # same shader, SPIR-V
#include <dlfcn.h>
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include <atomic>
#include <cstdio>
#include <cstring>
#include <thread>
#include <vector>
#include "dxc/dxcapi.h"
static std::atomic<int> g_handled{0};
static std::atomic<bool> g_stop{false};
static void hostHandler(int) { g_handled++; }
int main(int argc, char **argv) {
struct sigaction sa; // the host owns SIGUSR1 before DXC is called
memset(&sa, 0, sizeof sa);
sa.sa_handler = hostHandler;
sigaction(SIGUSR1, &sa, nullptr);
const int kThreads = 8;
std::vector<std::thread> threads;
std::vector<pthread_t> ids(kThreads);
std::atomic<int> ready{0};
for (int i = 0; i < kThreads; i++)
threads.emplace_back([&, i] { ids[i] = pthread_self(); ready++; while (!g_stop) {} });
while (ready != kThreads) usleep(1000);
static const char src[] = "float4 main() : SV_Target { return 0; }";
std::vector<LPCWSTR> args = {L"-T", L"ps_6_0", L"-E", L"main"};
if (argc > 1 && !strcmp(argv[1], "-spirv")) args.push_back(L"-spirv");
IDxcCompiler3 *compiler = nullptr;
DxcCreateInstance(CLSID_DxcCompiler, __uuidof(IDxcCompiler3), (void **)&compiler);
DxcBuffer buf = {src, sizeof(src) - 1, 65001};
IDxcResult *result = nullptr;
HRESULT hr = compiler->Compile(&buf, args.data(), (UINT32)args.size(), nullptr,
__uuidof(IDxcResult), (void **)&result);
HRESULT status = -1;
if (result) result->GetStatus(&status);
printf("Compile hr=0x%x status=0x%x\n", (unsigned)hr, (unsigned)status);
struct sigaction now;
sigaction(SIGUSR1, nullptr, &now);
Dl_info info;
const char *image = "?";
if (dladdr((void *)now.sa_handler, &info) && info.dli_fname) image = info.dli_fname;
printf("SIGUSR1 handler after Compile: %s, in %s%s\n",
now.sa_handler == hostHandler ? "still the host's" : "REPLACED", image,
(now.sa_flags & SA_RESETHAND) ? ", SA_RESETHAND" : "");
fflush(stdout);
for (int i = 0; i < kThreads; i++) pthread_kill(ids[i], SIGUSR1);
usleep(200 * 1000);
g_stop = true;
for (auto &t : threads) t.join();
printf("survived; host handler ran %d times\n", g_handled.load());
return 0;
}
Actual Behavior
DXIL (killed in 50 of 50 runs):
Compile hr=0x0 status=0x0
SIGUSR1 handler after Compile: REPLACED, in lib/libdxcompiler.so, SA_RESETHAND
User defined signal 1 (exit 138)
-spirv (survives 50 of 50 runs):
Compile hr=0x0 status=0x0
SIGUSR1 handler after Compile: still the host's, in ./repro
survived; host handler ran 8 times
Expected: an in-process compile leaves the host's signal dispositions alone.
Environment
- DXC version:
libdxcompiler.so: 1.9(5512-01b62ad4)(1.9.2609.5)(official v1.9.2609 release). Also present in v1.7.2212.1. - Host Operating System: Ubuntu 24.04 (WSL2), glibc 2.39, g++ 13.3.0, x86_64
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 926
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 45
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/DirectXShaderCompiler
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/DirectXShaderCompiler#9173 ·
Maintainers usually reply within 2 days
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
microsoft/DirectXShaderCompiler#9155 · 4 comments ·
Maintainers usually reply within 2 days
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/DirectXShaderCompiler#9135 ·
Maintainers usually reply within 2 days
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSLPossibly taken @rj123-nv claimed this 18 days ago. Openbug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
microsoft/DirectXShaderCompiler#9087 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
microsoft/DirectXShaderCompiler#9086 ·
Maintainers usually reply within 2 days
All issues in microsoft/DirectXShaderCompiler
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
telefonicaid/fiware-orion#4836 ·
Maintainers usually reply within 1 day
-
refactor topic-ui topic-weather
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Command-Install Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
microsoft/winget-cli#6718 ·
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
leanprover/lean4#16810 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day