Skip to content

Conversation

da-viper
Copy link
Contributor

@da-viper da-viper commented Sep 8, 2025

INSERT BEFORE keyword is not supported in current versions gold and mold linkers. Since we cannot confirm accurately what linker and version is available on the system and when it will be supported. We test it with a sample program using the script keywords.

@llvmbot
Copy link
Member

llvmbot commented Sep 8, 2025

@llvm/pr-subscribers-lldb

Author: Ebuka Ezike (da-viper)

Changes

INSERT BEFORE keyword is not supported in current versions gold and mold linkers. Since we cannot confirm accurately what linker and version is available on the system and when it will be supported. We test it with a sample program using the script keywords.


Full diff: https://github.com/llvm/llvm-project/pull/157474.diff

2 Files Affected:

  • (modified) lldb/test/API/functionalities/thread/step_until/TestStepUntil.py (+40)
  • (modified) lldb/test/API/functionalities/thread/step_until/TestStepUntilAPI.py (+43)
diff --git a/lldb/test/API/functionalities/thread/step_until/TestStepUntil.py b/lldb/test/API/functionalities/thread/step_until/TestStepUntil.py
index 965da02ed0f98..90f207b5d4660 100644
--- a/lldb/test/API/functionalities/thread/step_until/TestStepUntil.py
+++ b/lldb/test/API/functionalities/thread/step_until/TestStepUntil.py
@@ -1,11 +1,50 @@
 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
 
+from typing import Optional
 
 import lldb
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
+import tempfile
+
+
+def linker_script_syntax_unsupported() -> Optional[str]:
+    """Current versions of mold and gold linker does not support some syntax of
+    linker scripts, this maybe supported in future versions. check if it compiles,
+    if not it is not supported.
+    """
+    with tempfile.TemporaryDirectory() as tmpdir:
+        output_path = os.path.join(tmpdir, "linker_support.out")
+        linker_script_path = os.path.join(tmpdir, "test.ld")
+
+        with open(linker_script_path, "w") as linker_script:
+            linker_script.write(
+                "SECTIONS {.text.ordered : { *(.text.ordered) *(.text.foo) } } INSERT BEFORE .text;"
+            )
+
+        compiler_cmd = subprocess.Popen(
+            [
+                lldbplatformutil.getCompiler(),
+                f"-o {output_path}",
+                "-ffunction-sections",
+                f"-Wl,--script={linker_script_path}",
+                "-xc",
+                "-",
+            ],
+            shell=True,
+            universal_newlines=True,
+            stdin=subprocess.PIPE,
+            stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE,
+        )
+        _, comp_err = compiler_cmd.communicate(
+            "int foo() { return 1; } int main() { return 0; }"
+        )
 
+        if len(comp_err) != 0:
+            return str(tmpdir) + " " + comp_err
+        return None
 
 class StepUntilTestCase(TestBase):
     def setUp(self):
@@ -112,6 +151,7 @@ def test_bad_line(self):
     @no_debug_info_test
     @skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"])
     @skipIf(archs=no_match(["x86_64", "aarch64"]))
+    @skipTestIfFn(linker_script_syntax_unsupported)
     def test_bad_line_discontinuous(self):
         """Test that we get an error if attempting to step outside the current
         function -- and the function is discontinuous"""
diff --git a/lldb/test/API/functionalities/thread/step_until/TestStepUntilAPI.py b/lldb/test/API/functionalities/thread/step_until/TestStepUntilAPI.py
index 59e028acf014c..44e764c43cd20 100644
--- a/lldb/test/API/functionalities/thread/step_until/TestStepUntilAPI.py
+++ b/lldb/test/API/functionalities/thread/step_until/TestStepUntilAPI.py
@@ -1,8 +1,48 @@
+from typing import Optional
+
 import lldb
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
+import tempfile
+
+
+def linker_script_syntax_unsupported() -> Optional[str]:
+    """Current versions of mold and gold linker does not support some syntax of
+    linker scripts, this maybe supported in future versions. check if it compiles,
+    if not it is not supported.
+    """
+    with tempfile.TemporaryDirectory() as tmpdir:
+        output_path = os.path.join(tmpdir, "linker_support.out")
+        linker_script_path = os.path.join(tmpdir, "test.ld")
+
+        with open(linker_script_path, "w") as linker_script:
+            linker_script.write(
+                "SECTIONS {.text.ordered : { *(.text.ordered) *(.text.foo) } } INSERT BEFORE .text;"
+            )
+
+        compiler_cmd = subprocess.Popen(
+            [
+                lldbplatformutil.getCompiler(),
+                f"-o {output_path}",
+                "-ffunction-sections",
+                f"-Wl,--script={linker_script_path}",
+                "-xc",
+                "-",
+            ],
+            shell=True,
+            universal_newlines=True,
+            stdin=subprocess.PIPE,
+            stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE,
+        )
+        _, comp_err = compiler_cmd.communicate(
+            "int foo() { return 1; } int main() { return 0; }"
+        )
 
+        if len(comp_err) != 0:
+            return comp_err
+        return None
 
 class TestStepUntilAPI(TestBase):
     NO_DEBUG_INFO_TESTCASE = True
@@ -74,6 +114,7 @@ def test_hitting(self):
 
     @skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"])
     @skipIf(archs=no_match(["x86_64", "aarch64"]))
+    @skipTestIfFn(linker_script_syntax_unsupported)
     def test_hitting_discontinuous(self):
         """Test SBThread.StepOverUntil - targeting a line and hitting it -- with
         discontinuous functions"""
@@ -93,6 +134,7 @@ def test_missing(self):
 
     @skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"])
     @skipIf(archs=no_match(["x86_64", "aarch64"]))
+    @skipTestIfFn(linker_script_syntax_unsupported)
     def test_missing_discontinuous(self):
         """Test SBThread.StepOverUntil - targeting a line and missing it by
         stepping out to call site -- with discontinuous functions"""
@@ -120,6 +162,7 @@ def test_bad_line(self):
 
     @skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"])
     @skipIf(archs=no_match(["x86_64", "aarch64"]))
+    @skipTestIfFn(linker_script_syntax_unsupported)
     def test_bad_line_discontinuous(self):
         """Test that we get an error if attempting to step outside the current
         function -- and the function is discontinuous"""

Copy link

github-actions bot commented Sep 9, 2025

✅ With the latest revision this PR passed the Python code formatter.

`INSERT BEFORE` keyword is not supported in current versions gold and mold linkers. Since we cannot confirm accurately what linker and version is available on the system and when it will be supported.
Copy link
Member

@Michael137 Michael137 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if this works for your use-case, thanks! I'd give @JDevlieghere some time to look at this before merging

@da-viper da-viper merged commit a65aca6 into llvm:main Sep 10, 2025
9 checks passed
@da-viper da-viper deleted the fix-test-step-until branch September 30, 2025 14:57
da-viper added a commit to da-viper/llvm-project that referenced this pull request Sep 30, 2025
…7474)

`INSERT BEFORE` keyword is not supported in current versions gold and
mold linkers. Since we cannot confirm accurately what linker and version
is available on the system and when it will be supported. We test it
with a sample program using the script keywords.

(cherry picked from commit a65aca6)
da-viper added a commit to swiftlang/llvm-project that referenced this pull request Oct 1, 2025
…7474) (#11528)

`INSERT BEFORE` keyword is not supported in current versions gold and
mold linkers. Since we cannot confirm accurately what linker and version
is available on the system and when it will be supported. We test it
with a sample program using the script keywords.

(cherry picked from commit a65aca6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants