From: Lang Hames Date: Mon, 22 Feb 2021 06:16:19 +0000 (+1100) Subject: [JITLink] Don't allow creation of sections with duplicate names. X-Git-Tag: llvmorg-14-init~14357 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=adf2098bd8193e3f9395512143071328e7bd024d;p=platform%2Fupstream%2Fllvm.git [JITLink] Don't allow creation of sections with duplicate names. --- 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,