From adf2098bd8193e3f9395512143071328e7bd024d Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 22 Feb 2021 17:16:19 +1100 Subject: [PATCH] [JITLink] Don't allow creation of sections with duplicate names. --- llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h | 5 +++++ llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h index e8c0e28..016285e 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h @@ -830,6 +830,11 @@ public: /// Create a section with the given name, protection flags, and alignment. Section &createSection(StringRef Name, sys::Memory::ProtectionFlags Prot) { + assert(llvm::find_if(Sections, + [&](std::unique_ptr
&Sec) { + return Sec->getName() == Name; + }) == Sections.end() && + "Duplicate section name"); std::unique_ptr
Sec(new Section(Name, Prot, Sections.size())); Sections.push_back(std::move(Sec)); return *Sections.back(); diff --git a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp index 360bc88..9c890b55 100644 --- a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp +++ b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp @@ -48,7 +48,7 @@ TEST(LinkGraphTest, BlockAndSymbolIteration) { auto &S2 = G.addDefinedSymbol(B2, 4, "S2", 4, Linkage::Strong, Scope::Default, false, false); - auto &Sec2 = G.createSection("__data.1", RWFlags); + auto &Sec2 = G.createSection("__data.2", RWFlags); auto &B3 = G.createContentBlock(Sec2, BlockContent, 0x3000, 8, 0); auto &B4 = G.createContentBlock(Sec2, BlockContent, 0x4000, 8, 0); auto &S3 = G.addDefinedSymbol(B3, 0, "S3", 4, Linkage::Strong, Scope::Default, -- 2.7.4