Skip to content

Commit c497e0a

Browse files
Connor-GHConnor
and
Connor
authored
Fix glibc assert: __assert -> __assert_fail (#4667)
Previously, glibc would use __assert, which causes a segmentation fault due to strange internal behavior between D and C compilers. It is better practice to use __assert_fail. See #16515 of dlang/dmd. Do not use isOSGlibc(); instead use isGNUEnvironment() --------- Co-authored-by: Connor <[email protected]>
1 parent c91e199 commit c497e0a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

gen/llvmhelpers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ void DtoCAssert(Module *M, const Loc &loc, LLValue *msg) {
291291
args.push_back(line);
292292
args.push_back(msg);
293293
} else if (triple.isOSSolaris() || triple.isMusl() ||
294-
global.params.isUClibcEnvironment) {
294+
global.params.isUClibcEnvironment ||
295+
triple.isGNUEnvironment()) {
295296
const auto irFunc = gIR->func();
296297
const auto funcName =
297298
(irFunc && irFunc->decl) ? irFunc->decl->toPrettyChars() : "";

gen/runtime.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ llvm::Function *getRuntimeFunction(const Loc &loc, llvm::Module &target,
355355
// const char *funcname);
356356
// Musl: void __assert_fail(const char *assertion, const char *filename, int line_num,
357357
// const char *funcname);
358+
// Glibc: void __assert_fail(const char *assertion, const char *filename, int line_num,
359+
// const char *funcname);
358360
// uClibc: void __assert(const char *assertion, const char *filename, int linenumber,
359361
// const char *function);
360362
// newlib: void __assert_func(const char *file, int line, const char *func,
@@ -369,7 +371,7 @@ static const char *getCAssertFunctionName() {
369371
return "_assert";
370372
} else if (triple.isOSSolaris()) {
371373
return "__assert_c99";
372-
} else if (triple.isMusl()) {
374+
} else if (triple.isMusl() || triple.isGNUEnvironment()) {
373375
return "__assert_fail";
374376
} else if (global.params.isNewlibEnvironment) {
375377
return "__assert_func";
@@ -383,7 +385,7 @@ static std::vector<PotentiallyLazyType> getCAssertFunctionParamTypes() {
383385
const auto uint = Type::tuns32;
384386

385387
if (triple.isOSDarwin() || triple.isOSSolaris() || triple.isMusl() ||
386-
global.params.isUClibcEnvironment) {
388+
global.params.isUClibcEnvironment || (triple.isOSGlibc() && triple.isGNUEnvironment())) {
387389
return {voidPtr, voidPtr, uint, voidPtr};
388390
}
389391
if (triple.getEnvironment() == llvm::Triple::Android) {

0 commit comments

Comments
 (0)