Prechádzať zdrojové kódy

Merge pull request #7 from vitorpy/master

fix: support LLVM-generated rodata section names
Claire Fan 1 mesiac pred
rodič
commit
90b34ee630
1 zmenil súbory, kde vykonal 14 pridanie a 2 odobranie
  1. 14 2
      src/byteparser.rs

+ 14 - 2
src/byteparser.rs

@@ -16,8 +16,20 @@ 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)
+    });
+
+    // Ensure there's only one .rodata section
+    let rodata_count = obj.sections().filter(|s| {
+        s.name().map(|name| name.starts_with(".rodata")).unwrap_or(false)
+    }).count();
+    assert!(rodata_count <= 1, "Multiple .rodata sections found");
+
     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 +88,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