Index: llvm/lib/MC/XCOFFObjectWriter.cpp =================================================================== --- llvm/lib/MC/XCOFFObjectWriter.cpp +++ llvm/lib/MC/XCOFFObjectWriter.cpp @@ -740,8 +740,18 @@ if (Group->empty()) continue; - for (auto &Csect : *Group) + for (auto &Csect : *Group) { + if (Csect.Relocations.size() >= UINT16_MAX) + report_fatal_error( + "relocation entries overflowed; overflow section is " + "not implemented yet"); + Section->RelocationCount += Csect.Relocations.size(); + if (Section->RelocationCount >= UINT16_MAX) + report_fatal_error( + "relocation entries overflowed; overflow section is " + "not implemented yet"); + } } } Index: llvm/test/CodeGen/PowerPC/aix-xcoff-reloc-overflow.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/PowerPC/aix-xcoff-reloc-overflow.ll @@ -0,0 +1,27 @@ +;; This test generates more than 65535 relocation entries in a single section, +;; which would trigger an overflow section to be generated in 32-bit mode. +;; Since overflow section is not supported yet, we will emit an error instead of +;; generating an invalid binary for now. + +; RUN: grep -v sed %s | \ +; RUN: sed "s/A/ABABA/g;s/A/ABABA/g;s/A/ABABA/g;s/A/ABABA/g;s/A/ABABA/g;s/A/ABABA/g;s/A/ABABA/g;s/A/ABABA/g;s/A/ABABA/g;s/A/ABA/g;s/A/ABA/g;" | tr B "\n" | \ +; RUN: sed "s/A/call\ void\ bitcast\ \(void (...)*\ @foo\ to\ void\ ()*)()/g" > %t.ll + +; RUN: not --crash llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff \ +; RUN: -mcpu=pwr4 -mattr=-altivec -filetype=obj -o %t.o %t.ll 2>&1 | \ +; RUN: FileCheck --check-prefix=XCOFF32 %s +; XCOFF32: LLVM ERROR: relocation entries overflowed; overflow section is not implemented yet + +; RUN: not --crash llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff \ +; RUN: -mcpu=pwr4 -mattr=-altivec -filetype=obj -o %t.o %t.ll 2>&1 | \ +; RUN: FileCheck --check-prefix=XCOFF64 %s +; XCOFF64: LLVM ERROR: 64-bit XCOFF object files are not supported yet. + +define void @bar() { +entry: +;; The line below will get transformed. + A + ret void +} + +declare void @foo(...)