[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `lld-x86_64-win` running on `as-worker-93` while building `clang,llvm` at step 7 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/146/builds/1856 Here is the relevant piece of the build log for the reference ``` Step 7 (test-build-unified-tree-check-all) failure: test (failure) TEST 'LLVM-Unit :: Support/./SupportTests.exe/38/87' FAILED Script(shard): -- GTEST_OUTPUT=json:C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe-LLVM-Unit-17584-38-87.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=87 GTEST_SHARD_INDEX=38 C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe -- Script: -- C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe --gtest_filter=ProgramEnvTest.CreateProcessLongPath -- C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(160): error: Expected equality of these values: 0 RC Which is: -2 C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(163): error: fs::remove(Twine(LongPath)): did not return errc::success. error number: 13 error message: permission denied C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:160 Expected equality of these values: 0 RC Which is: -2 C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:163 fs::remove(Twine(LongPath)): did not return errc::success. error number: 13 error message: permission denied ``` https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
fmayer wrote: > > I had to do something very similar for CHERI downstream: We have to ensure > > that all globals are precisely representable (which may require rounding up > > the size+alignment) so you don't end up creating bounds that include > > adjacent ones. The original patch from 2019 is here: > > [CTSRD-CHERI/llvm-project@fd224dd](https://github.com/CTSRD-CHERI/llvm-project/commit/fd224dddafefbed3b068a0afc1a242bf8eb65d20) > > I wonder if it would be possible have a hook that CHERI can reuse > > downstream: something like: `getRequiredGlobalAlignment()` and > > `getRequiredGlobalSize()`. For MTE this could return 16 for alignment and > > round the size up to a multiple of 16 and after the next merge the CHERI > > downstream could reuse those hooks. > > Adding @jrtc27 for visibility. > > As far as I can tell this feedback was completely ignored?.. Yes, I will look at that in a follow up after Christmas, forgot to leave the comment. I don't think there's a reason to block this. https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
jrtc27 wrote: > I had to do something very similar for CHERI downstream: We have to ensure > that all globals are precisely representable (which may require rounding up > the size+alignment) so you don't end up creating bounds that include adjacent > ones. The original patch from 2019 is here: > [CTSRD-CHERI/llvm-project@fd224dd](https://github.com/CTSRD-CHERI/llvm-project/commit/fd224dddafefbed3b068a0afc1a242bf8eb65d20) > > I wonder if it would be possible have a hook that CHERI can reuse downstream: > something like: `getRequiredGlobalAlignment()` and `getRequiredGlobalSize()`. > For MTE this could return 16 for alignment and round the size up to a > multiple of 16 and after the next merge the CHERI downstream could reuse > those hooks. > > Adding @jrtc27 for visibility. As far as I can tell this feedback was completely ignored?.. https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
uweigand wrote: The s390x failures are unrelated. https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-s390x-linux-lnt` running on `systemz-1` while building `clang,llvm` at step 7 "ninja check 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/136/builds/2026 Here is the relevant piece of the build log for the reference ``` Step 7 (ninja check 1) failure: stage 1 checked (failure) TEST 'libFuzzer-s390x-default-Linux :: fuzzer-timeout.test' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest + /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest RUN: at line 2: /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest + /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest RUN: at line 3: not /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 2>&1 | FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=TimeoutTest + not /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 + FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=TimeoutTest RUN: at line 12: not /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/hi.txt 2>&1 | FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=SingleInputTimeoutTest + not /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/hi.txt + FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=SingleInputTimeoutTest RUN: at line 16: /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 -timeout_exitcode=0 + /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 -timeout_exitcode=0 INFO: Running with entropic power schedule (0xFF, 100). INFO: Seed: 171
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-s390x-linux` running on `systemz-1` while building `clang,llvm` at step 5 "ninja check 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/42/builds/2376 Here is the relevant piece of the build log for the reference ``` Step 5 (ninja check 1) failure: stage 1 checked (failure) TEST 'libFuzzer-s390x-default-Linux :: fuzzer-timeout.test' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest + /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest RUN: at line 2: /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest + /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest RUN: at line 3: not /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 2>&1 | FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=TimeoutTest + not /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 + FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=TimeoutTest /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test:7:14: error: TimeoutTest: expected string not found in input TimeoutTest: #0 ^ :19:44: note: scanning from here ==1607170== ERROR: libFuzzer: timeout after 1 seconds ^ :24:104: note: possible intended match here AddressSanitizer: CHECK failed: asan_report.cpp:199 "((current_error_.kind)) == ((kErrorKindInvalid))" (0x1, 0x0) (tid=1607170) ^ Input file: Check file: /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test -dump-input=help explains the following input dump. Input was: << . . . 14: MS: 1 InsertByte-; base unit: 94dd9e08c129c785f7f256e82fbe0a30e6d1ae40 15: 0x48,0x69,0x21, 16: Hi! 17: artifact_prefix='./'; Test unit written to ./timeout-c0a0ad26a634840c67a210fefdda76577b03a111 18: Base64: SGkh 19: ==1607170== ERROR: libFuzzer: timeout after 1 seconds check:7'0X~~ error: no match found 20: AddressSanitizer:DEADLYSIGNAL check:7'0 ~~ 21: = check:7'0 ~~
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `cross-project-tests-sie-ubuntu` running on `doug-worker-1a` while building `clang,llvm` at step 2 "checkout". Full details are available at: https://lab.llvm.org/buildbot/#/builders/181/builds/10481 Here is the relevant piece of the build log for the reference ``` Step 2 (checkout) failure: update (failure) git version 2.25.1 fatal: unable to access 'https://github.com/llvm/llvm-project.git/': HTTP/2 stream 0 was not closed cleanly: CANCEL (err 8) fatal: the remote end hung up upon initial contact ``` https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
https://github.com/fmayer closed https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/111918 error: too big or took too long to generate ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
@@ -2406,12 +2406,55 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) { OutStreamer->emitBinaryData(Buf); } +static void tagGlobalDefinition(Module &M, GlobalVariable *G) { + Constant *Initializer = G->getInitializer(); + uint64_t SizeInBytes = + M.getDataLayout().getTypeAllocSize(Initializer->getType()); + + uint64_t NewSize = alignTo(SizeInBytes, 16); + if (SizeInBytes != NewSize) { +// Pad the initializer out to the next multiple of 16 bytes. +llvm::SmallVector Init(NewSize - SizeInBytes, 0); +Constant *Padding = ConstantDataArray::get(M.getContext(), Init); +Initializer = ConstantStruct::getAnon({Initializer, Padding}); +auto *NewGV = new GlobalVariable( +M, Initializer->getType(), G->isConstant(), G->getLinkage(), +Initializer, "", G, G->getThreadLocalMode(), G->getAddressSpace()); +NewGV->copyAttributesFrom(G); +NewGV->setComdat(G->getComdat()); +NewGV->copyMetadata(G, 0); + +NewGV->takeName(G); +G->replaceAllUsesWith(NewGV); +G->eraseFromParent(); +G = NewGV; + } + + if (G->getAlign().valueOrOne() < 16) +G->setAlignment(Align(16)); + + // Ensure that tagged globals don't get merged by ICF - as they should have + // different tags at runtime. + G->setUnnamedAddr(GlobalValue::UnnamedAddr::None); +} + bool AsmPrinter::doFinalization(Module &M) { // Set the MachineFunction to nullptr so that we can catch attempted // accesses to MF specific features at the module level and so that // we can conditionalize accesses based on whether or not it is nullptr. MF = nullptr; + SmallVector GlobalsToTag; + for (GlobalVariable &G : M.globals()) { fmayer wrote: note that I had to spend some time to convince myself this is okay (because new variables get assigned to the end, and `end` for the range based loop gets assigned before that), so IMO this does add extra complexity to the code. https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
https://github.com/pcc approved this pull request. https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
@@ -808,6 +808,10 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) { "visibility must be dso_local!", &GV); + if (GV.isTagged()) { pcc wrote: Ah okay, if it's a limitation in the existing codegen code that's fine and we can relax it later if needed. @arichardson yes, we're aware of the reason for this restriction, the question was whether it should be enforced here as well as in the frontend. https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
@@ -2406,12 +2406,55 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) { OutStreamer->emitBinaryData(Buf); } +static void tagGlobalDefinition(Module &M, GlobalVariable *G) { + Constant *Initializer = G->getInitializer(); + uint64_t SizeInBytes = + M.getDataLayout().getTypeAllocSize(Initializer->getType()); + + uint64_t NewSize = alignTo(SizeInBytes, 16); + if (SizeInBytes != NewSize) { +// Pad the initializer out to the next multiple of 16 bytes. +llvm::SmallVector Init(NewSize - SizeInBytes, 0); +Constant *Padding = ConstantDataArray::get(M.getContext(), Init); +Initializer = ConstantStruct::getAnon({Initializer, Padding}); +auto *NewGV = new GlobalVariable( +M, Initializer->getType(), G->isConstant(), G->getLinkage(), +Initializer, "", G, G->getThreadLocalMode(), G->getAddressSpace()); +NewGV->copyAttributesFrom(G); +NewGV->setComdat(G->getComdat()); +NewGV->copyMetadata(G, 0); + +NewGV->takeName(G); +G->replaceAllUsesWith(NewGV); +G->eraseFromParent(); +G = NewGV; + } + + if (G->getAlign().valueOrOne() < 16) +G->setAlignment(Align(16)); + + // Ensure that tagged globals don't get merged by ICF - as they should have + // different tags at runtime. + G->setUnnamedAddr(GlobalValue::UnnamedAddr::None); +} + bool AsmPrinter::doFinalization(Module &M) { // Set the MachineFunction to nullptr so that we can catch attempted // accesses to MF specific features at the module level and so that // we can conditionalize accesses based on whether or not it is nullptr. MF = nullptr; + SmallVector GlobalsToTag; + for (GlobalVariable &G : M.globals()) { fmayer wrote: good point https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/111918 error: too big or took too long to generate ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
@@ -808,6 +808,10 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) { "visibility must be dso_local!", &GV); + if (GV.isTagged()) { arichardson wrote: Back in 2019 or so we had very similar issues in the CHERI downstream due to kernel linker sets. The FreeBSD Kernel extensively usess custom section with C identifiers (so you automatically get __start_ and __stop_ symbols and then iterates over those sections. Adding padding later in the pipeline means the existing loop increments could be wrong and you get incorrect initialization results or crashes. https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
@@ -808,6 +808,10 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) { "visibility must be dso_local!", &GV); + if (GV.isTagged()) { fmayer wrote: The codegen has "is section == precisely honor alignment" ``` Align DataLayout::getPreferredAlign(const GlobalVariable *GV) const { [...] // If a section is specified, always precisely honor explicit alignment, // so we don't insert padding into a section we don't control. if (GVAlignment && GV->hasSection()) return *GVAlignment; ``` https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
https://github.com/arichardson commented: I had to do something very similar for CHERI downstream: We have to ensure that all globals are precisely representable (which may require rounding up the size+alignment) so you don't end up creating bounds that include adjacent ones. The original patch from 2019 is here: https://github.com/CTSRD-CHERI/llvm-project/commit/fd224dddafefbed3b068a0afc1a242bf8eb65d20 I wonder if it would be possible have a hook that CHERI can reuse downstream: something like: `getRequiredGlobalAlignment()` and `getRequiredGlobalSize()`. For MTE this could return 16 for alignment and round the size up to a multiple of 16 and after the next merge the CHERI downstream could reuse those hooks. Adding @jrtc27 for visibility. https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
@@ -808,6 +808,10 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) { "visibility must be dso_local!", &GV); + if (GV.isTagged()) { pcc wrote: Is this really a verifier issue? If the frontend wants to tag a global in a section (e.g. because it is known to be safe), shouldn't it be able to? https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
@@ -2406,12 +2406,55 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) { OutStreamer->emitBinaryData(Buf); } +static void tagGlobalDefinition(Module &M, GlobalVariable *G) { + Constant *Initializer = G->getInitializer(); + uint64_t SizeInBytes = + M.getDataLayout().getTypeAllocSize(Initializer->getType()); + + uint64_t NewSize = alignTo(SizeInBytes, 16); + if (SizeInBytes != NewSize) { +// Pad the initializer out to the next multiple of 16 bytes. +llvm::SmallVector Init(NewSize - SizeInBytes, 0); +Constant *Padding = ConstantDataArray::get(M.getContext(), Init); +Initializer = ConstantStruct::getAnon({Initializer, Padding}); +auto *NewGV = new GlobalVariable( +M, Initializer->getType(), G->isConstant(), G->getLinkage(), +Initializer, "", G, G->getThreadLocalMode(), G->getAddressSpace()); +NewGV->copyAttributesFrom(G); +NewGV->setComdat(G->getComdat()); +NewGV->copyMetadata(G, 0); + +NewGV->takeName(G); +G->replaceAllUsesWith(NewGV); +G->eraseFromParent(); +G = NewGV; + } + + if (G->getAlign().valueOrOne() < 16) +G->setAlignment(Align(16)); + + // Ensure that tagged globals don't get merged by ICF - as they should have + // different tags at runtime. + G->setUnnamedAddr(GlobalValue::UnnamedAddr::None); +} + bool AsmPrinter::doFinalization(Module &M) { // Set the MachineFunction to nullptr so that we can catch attempted // accesses to MF specific features at the module level and so that // we can conditionalize accesses based on whether or not it is nullptr. MF = nullptr; + SmallVector GlobalsToTag; + for (GlobalVariable &G : M.globals()) { pcc wrote: This could use `make_early_inc_range` to avoid needing to save the list of globals. https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/111918 error: too big or took too long to generate ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits