llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Clang 15 LTO assertion failure with ifunc referenced by global

Open nikic opened this issue 2 years ago • 5 comments

Building https://github.com/ColinIanKing/stress-ng with clang and -flto results in an assertion failure during the LTO step:

ld.gold: /home/npopov/repos/llvm-project/llvm/lib/Bitcode/Reader/BitcodeReader.cpp:6597: std::pair<llvm::ValueInfo, long unsigned int> {anonymous}::ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(unsigned int): Assertion `VGI.first' failed.

The problematic input appears to be stress-cpu.o, which results in the same assertion when run through llvm-dis.

At a guess, this has something to do with ifuncs.

nikic avatar Sep 21 '22 12:09 nikic

Problematic IR file (marginally reduced): https://gist.github.com/nikic/982993b057bd9362b0055a90926e5437

Tested with build/bin/opt -module-summary < $1 | build/bin/llvm-dis.

Unfortunately none of our reduction tooling works with this, probably because something in bitcode reading or writing itself is broken.

nikic avatar Sep 21 '22 12:09 nikic

Reduced:

@gv = constant ptr @ifunc

@ifunc = ifunc void (ptr), ptr @resolver

define ptr @resolver() {
  ret ptr null
}

nikic avatar Sep 21 '22 14:09 nikic

cc @teresajohnson, who is hopefully familiar with ModuleSummaryAnalysis.

nikic avatar Sep 21 '22 14:09 nikic

Also cc @SchrodingerZhu who did recent work on LTO + ifuncs.

nikic avatar Sep 22 '22 08:09 nikic

This seems to be related to the linker behavior. So ifunc will not appear in the summary; guess this is causing the issue. Maybe someone has insights of gold linker could take a look at the problem?

SchrodingerZhu avatar Oct 14 '22 21:10 SchrodingerZhu

This https://reviews.llvm.org/D144982 solves the crash with the above reproducers.

DanielKristofKiss avatar Mar 01 '23 15:03 DanielKristofKiss