If there are more than 65534 relocation entries in a single section, we should generate an overflow section.
Since we don't support overflow section for now, we should generate an error.
Details
Diff Detail
Event Timeline
why the file llvm/test/CodeGen/PowerPC/aix-xcoff-reloc-overflow.ll so large ,it can not be loaded?
I was able to load it by clicking Show File Contents.
I'm open to any ideas that could greatly reduce the file size and still trigger the error I put in.
llvm/test/CodeGen/PowerPC/aix-xcoff-reloc-overflow.ll | ||
---|---|---|
6 | We're able to sed and friends in tests, so I think we can do an expansion based on @hubert.reinterpretcast original preprocessor example. Replacing the repeated line with 'A' and using something like this seems like it would do the trick: sed "s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;s/A/ABA/g;" %s| tr B "\n" | sed "s/A/call\ void\ bitcast\ \(void (...)*\ @foo\ to\ void\ ()*)()/g"|llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -mcpu=pwr4 -mattr=-altivec -filetype=obj -o %t.o |
llvm/test/CodeGen/PowerPC/aix-xcoff-reloc-overflow.ll | ||
---|---|---|
6 | Thanks for the suggestion. |
llvm/test/CodeGen/PowerPC/aix-xcoff-reloc-overflow.ll | ||
---|---|---|
6 | Would grep -v have helped there? |
llvm/test/CodeGen/PowerPC/aix-xcoff-reloc-overflow.ll | ||
---|---|---|
6 | Hmm... I'm not sure how grep -v would help. ;; 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: sed "s/call void bitcast (void (...)* @foo to void ()*)() call void bitcast (void (...)* @foo to void ()*)() call void bitcast (void (...)* @foo to void ()*)() call void bitcast (void (...)* @foo to void ()*)() .... /g;" \ ; RUN: %p/Inputs/reloc-sed.ll | tr B "\n" | \ .... |
llvm/lib/MC/XCOFFObjectWriter.cpp | ||
---|---|---|
744 | Semantically, this is not UINT16_MAX but an XCOFF-defined constant. Otherwise, the maximum representable value would be UINT16_MAX itself and not one less. RelocOverflow is currently defined in lib/Object/XCOFFObjectFile.cpp, but it should probably be defined in include/llvm/BinaryFormat/XCOFF.h. | |
750 | Move the check to before the addition; use: Section->RelocationCount >= UINT16_MAX - Csect.Relocations.size(). After said move, the two if statements can be merged. |
llvm/test/CodeGen/PowerPC/aix-xcoff-reloc-overflow.ll | ||
---|---|---|
8 | I suggest testing exactly 65535: ; RUN: grep -v RUN: %s | \ ; RUN: sed >%t.overflow.ll 's/SIZE/65535/;s/MACRO/#/;s/#/################/g;s/#/################/g;s/#/################/g;s/#/################/g;s/#/#_/g;s/_#_\([^#]\)/\1/;s/_/, /g;s/#/i8* @c/g;' ; RUN: not --crash llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff \ ; RUN: -mcpu=pwr4 -mattr=-altivec -filetype=obj -o %t.o %t.overflow.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.overflow.ll 2>&1 | \ ; RUN: FileCheck --check-prefix=XCOFF64 %s ; XCOFF64: LLVM ERROR: 64-bit XCOFF object files are not supported yet. @c = external global i8, align 1 @arr = global [SIZE x i8*] [MACRO], align 8 Also, I think we should test for 65534. |
llvm/test/CodeGen/PowerPC/aix-xcoff-reloc-overflow.ll | ||
---|---|---|
8 | Thanks. I was pleasantly surprised that the suggested test(4 llc invocation) finished within 30 seconds. |
llvm/lib/MC/XCOFFObjectWriter.cpp | ||
---|---|---|
754 | https://llvm.org/docs/CodingStandards.html#error-and-warning-messages |
LGTM with minor comments.
llvm/test/CodeGen/PowerPC/aix-xcoff-huge-relocs.ll | ||
---|---|---|
8 ↗ | (On Diff #268823) | Minor nit: Not sure if we want to align -mcpu with the llc options? |
21 ↗ | (On Diff #268823) | Same comment. |
24 ↗ | (On Diff #268823) | Same comment. |
31 ↗ | (On Diff #268823) | I think we'd need the NOT lines after the other lines as well. |
Semantically, this is not UINT16_MAX but an XCOFF-defined constant. Otherwise, the maximum representable value would be UINT16_MAX itself and not one less. RelocOverflow is currently defined in lib/Object/XCOFFObjectFile.cpp, but it should probably be defined in include/llvm/BinaryFormat/XCOFF.h.