浏览代码

fix: support LLVM-generated rodata section names

LLVM's BPF backend creates optimized section names like `.rodata.str1.1`
for merged string constants, instead of just `.rodata`. The linker was
only looking for exact `.rodata` match, causing it to fail with
"Relocations found but no .rodata section" error.

Changed to find any section starting with `.rodata` prefix to handle:
- .rodata (generic read-only data)
- .rodata.str1.1 (merged 1-byte aligned strings)
- .rodata.str8.8 (8-byte aligned strings)
- etc.

This enables programs with string constants and read-only data to link
correctly.
Vitor Py 1 月之前
父节点
当前提交
f308338e37
共有 1 个文件被更改,包括 8 次插入2 次删除
  1. 8 2
      src/byteparser.rs

+ 8 - 2
src/byteparser.rs

@@ -16,8 +16,14 @@ pub fn parse_bytecode(bytes: &[u8]) -> Result<ParseResult, SbpfLinkerError> {
     let mut ast = AST::new();
 
     let obj = File::parse(bytes)?;
+
+    // Find rodata section - could be .rodata, .rodata.str1.1, etc.
+    let ro_section = obj.sections().find(|s| {
+        s.name().map(|name| name.starts_with(".rodata")).unwrap_or(false)
+    });
+
     let mut rodata_table = HashMap::new();
-    if let Some(ro_section) = obj.section_by_name(".rodata") {
+    if let Some(ref ro_section) = ro_section {
         // only handle symbols in the .rodata section for now
         let mut rodata_offset = 0;
         for symbol in obj.symbols() {
@@ -76,7 +82,7 @@ pub fn parse_bytecode(bytes: &[u8]) -> Result<ParseResult, SbpfLinkerError> {
                 offset += node_len;
             }
 
-            if let Some(ro_section) = obj.section_by_name(".rodata") {
+            if let Some(ref ro_section) = ro_section {
                 // handle relocations
                 for rel in section.relocations() {
                     // only handle relocations for symbols in the .rodata section for now