diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py
index 5122fcb08e..69199c87da 100644
--- a/meta/lib/oe/path.py
+++ b/meta/lib/oe/path.py
@@ -156,7 +156,7 @@ def copyhardlinktree(src, dst):
 
     if testfile is not None:
         try:
-            os.link(testfile, os.path.join(dst, 'testfile'))
+            os.link(testfile, os.path.join(dst, 'testfile'), follow_symlinks=False)
             os.unlink(os.path.join(dst, 'testfile'))
             canhard = True
         except Exception as e:
diff --git a/meta/lib/oeqa/selftest/cases/liboe.py b/meta/lib/oeqa/selftest/cases/liboe.py
index 96969da161..3930a31c6d 100644
--- a/meta/lib/oeqa/selftest/cases/liboe.py
+++ b/meta/lib/oeqa/selftest/cases/liboe.py
@@ -106,6 +106,28 @@ class CopyTreeTests(OESelftestTestCase):
 
         oe.path.remove(testloc)
 
+    def test_copy_hardlink_tree_dangling_symlink(self):
+        """
+        Summary:    oe.path.copyhardlinktree() should still hardlink when the
+                    first entry os.walk() returns is a dangling symlink
+        Expected:   the regular file in dst is a hardlink of the one in src
+        Product:    OE-Core
+        """
+        with tempfile.TemporaryDirectory(prefix="oeqa-copyhardlinktree-") as testloc:
+            src = oe.path.join(testloc, 'src')
+            dst = oe.path.join(testloc, 'dst')
+            bb.utils.mkdirhier(oe.path.join(src, 'sub'))
+            # Like var/lock -> /run/lock in a target rootfs
+            os.symlink('/nonexistent/target', oe.path.join(src, 'dangling'))
+            open(oe.path.join(src, 'sub', 'file'), 'w+b').close()
+
+            oe.path.copyhardlinktree(src, dst)
+
+            self.assertTrue(os.path.samefile(oe.path.join(src, 'sub', 'file'),
+                                             oe.path.join(dst, 'sub', 'file')),
+                            "File in dst was copied instead of hardlinked")
+            self.assertEqual(os.readlink(oe.path.join(dst, 'dangling')), '/nonexistent/target')
+
 class SubprocessTests(OESelftestTestCase):
 
     def test_subprocess_tweak(self):
