Linux: libdxcompiler replaces the host's signal handlers (SA_RESETHAND) on in-process DXIL compile and -P
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- cpp
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- C++
- 星标
- 3.7k
- 派生
- 926
- 平均合并
- 3 天 22 小时
- 30 天内合并 PR
- 45
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/DirectXShaderCompiler 的其他 Issue
-
bug needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/DirectXShaderCompiler#9173 ·
维护者通常 2 天内回复
-
bug needs-triage
难度 2/5 1-3 小时 新手友好度 65/100
microsoft/DirectXShaderCompiler#9155 · 4 条评论 ·
维护者通常 2 天内回复
-
bug needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/DirectXShaderCompiler#9135 ·
维护者通常 2 天内回复
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSL可能已有人在做 @rj123-nv 于 18 天前认领。 未关闭bug needs-triage
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/DirectXShaderCompiler#9087 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/DirectXShaderCompiler#9086 ·
维护者通常 2 天内回复
查看 microsoft/DirectXShaderCompiler 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
feature:config kind:docs os:windows toolchain:cmake triaged
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
arch-based bug niri
难度 2/5 1-3 小时 新手友好度 68/100
noctalia-dev/noctalia#5552 ·
维护者通常 1 天内回复