[llvm] c92ddf4 - [ORC] Add a unit test to verify that bound weak symbols can't be overridden.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 9 11:22:45 PST 2022


Author: Lang Hames
Date: 2022-11-09T11:22:31-08:00
New Revision: c92ddf4e235932ee6d03d5ea878a084b73a07974

URL: https://github.com/llvm/llvm-project/commit/c92ddf4e235932ee6d03d5ea878a084b73a07974
DIFF: https://github.com/llvm/llvm-project/commit/c92ddf4e235932ee6d03d5ea878a084b73a07974.diff

LOG: [ORC] Add a unit test to verify that bound weak symbols can't be overridden.

Weak symbols can be overridden while they're in the NeverSearched state, but
should not be able to be overridden once they've been bound by some lookup.
Historically we guaranteed this by stripping the weak flag once a symbol as
bound, causing it to appear as if it were strong. In ffe2dda29f3 we changed
that behavior to retain weak flags on symbols (to facilitate tracking for
dynamic re-binding during dlopen). This test checks that we still fail as
required after ffe2dda29f3.

Added: 
    

Modified: 
    llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
index 8022f03172326..3cd0504bb3b2e 100644
--- a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
@@ -1039,6 +1039,21 @@ TEST_F(CoreAPIsStandardTest, TestBasicWeakSymbolMaterialization) {
       << "Duplicate bar definition not discarded";
 }
 
+TEST_F(CoreAPIsStandardTest, RedefineBoundWeakSymbol) {
+  // Check that redefinition of a bound weak symbol fails.
+
+  JITSymbolFlags WeakExported(JITSymbolFlags::Exported);
+  WeakExported |= JITSymbolFlags::Weak;
+
+  // Define "Foo" as weak, force materialization.
+  cantFail(JD.define(absoluteSymbols({{Foo, {FooAddr, WeakExported}}})));
+  cantFail(ES.lookup({&JD}, Foo));
+
+  // Attempt to redefine "Foo". Expect failure, despite "Foo" being weak,
+  // since it has already been bound.
+  EXPECT_THAT_ERROR(JD.define(absoluteSymbols({{Foo, FooSym}})), Failed());
+}
+
 TEST_F(CoreAPIsStandardTest, DefineMaterializingSymbol) {
   bool ExpectNoMoreMaterialization = false;
   ES.setDispatchTask([&](std::unique_ptr<Task> T) {


        


More information about the llvm-commits mailing list