llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.96k stars 11.54k forks source link

Clang crash with -fsanitize=hwaddress -flto=thin -ffat-lto-objects #105569

Open pirama-arumuga-nainar opened 3 weeks ago

pirama-arumuga-nainar commented 3 weeks ago

The crash is caused when using -ffat-lto-objects together with -fsanitize=hwaddress.

$ cat test.c
int main(int argc, char* argv[])
{ (void)argv; return argc-1;}
$ clang  -c test.c -fsanitize=hwaddress -flto=thin
// no crash

$ clang -c test.c -fsanitize=hwaddress -flto=thin -ffat-lto-objects
clang: /usr/local/google/work/llvm-monorepo/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:897: void clang::BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &): Assertion `CurLinkModule && "CurLinkM
odule must be set for linker diagnostics"' failed.                                                                                                                                                                 
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.                            
Stack dump:                                                                                                                                                                                                        
0.      Program arguments: ../release/bin/clang -c test.c -fsanitize=hwaddress -flto=thin -ffat-lto-objects                                                              
1.      <eof> parser at end of file                                                                                                                                                                                
2.      Optimizer                                                                                                                                                                                                  3.      Running pass "hwasan<>" on module "test.c" 
pirama-arumuga-nainar commented 3 weeks ago

(cc: @ZijunZhaoCCK )

llvmbot commented 3 weeks ago

@llvm/issue-subscribers-clang-codegen

Author: None (pirama-arumuga-nainar)

``` $ cat test.c int main(int argc, char* argv[]) { (void)argv; return argc-1;} $ clang -c test.c -fsanitize=hwaddress -flto=thin // no crash $ clang -c test.c -fsanitize=hwaddress -flto=thin -ffat-lto-objects clang: /usr/local/google/work/llvm-monorepo/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:897: void clang::BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &): Assertion `CurLinkModule && "CurLinkM odule must be set for linker diagnostics"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: ../release/bin/clang -c test.c -fsanitize=hwaddress -flto=thin -ffat-lto-objects 1. <eof> parser at end of file 2. Optimizer 3. Running pass "hwasan<>" on module "test.c" ```
pirama-arumuga-nainar commented 3 weeks ago

(cc: @fmayer )

ZijunZhaoCCK commented 3 weeks ago

On my end, this error can be reproduced by cherrypicking this change https://github.com/llvm/llvm-project/pull/99439/files

pirama-arumuga-nainar commented 2 weeks ago

cc: @skc7 @vitalybuka

skc7 commented 2 weeks ago

Raised PR #106356 which should fix the issue.