fortrangoingonforty/afs-ld / a3512fb

Browse files

Align leftover linker helpers

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
a3512fba6bbf38e76eb3b8089ef2a0192315d6dc
Parents
4919d68
Tree
853369f

8 changed files

StatusFile+-
M src/atom.rs 3 1
M src/layout.rs 4 1
M src/link_map.rs 1 1
M src/macho/writer.rs 3 2
M src/reloc/arm64.rs 4 1
M src/string_table.rs 2 3
M src/why_live.rs 2 10
M tests/common/harness.rs 6 3
src/atom.rsmodified
@@ -861,7 +861,9 @@ fn resolve_function_parent(
861
                             .map(|section| section.addr)
861
                             .map(|section| section.addr)
862
                             .unwrap_or(0),
862
                             .unwrap_or(0),
863
                     ) as u32;
863
                     ) as u32;
864
-                    atom_index.get(&(input_sym.sect_idx(), target_offset)).copied()
864
+                    atom_index
865
+                        .get(&(input_sym.sect_idx(), target_offset))
866
+                        .copied()
865
                 })
867
                 })
866
                 .flatten()
868
                 .flatten()
867
         }
869
         }
src/layout.rsmodified
@@ -528,7 +528,10 @@ fn insert_extra_sections(sections: &mut Vec<OutputSection>, extra_sections: &[Ex
528
                 })
528
                 })
529
                 .map(|idx| idx + 1)
529
                 .map(|idx| idx + 1)
530
                 .unwrap_or_else(|| {
530
                 .unwrap_or_else(|| {
531
-                    panic!("missing anchor {:?} for synthetic section {},{}", anchor, section.segment, section.name)
531
+                    panic!(
532
+                        "missing anchor {:?} for synthetic section {},{}",
533
+                        anchor, section.segment, section.name
534
+                    )
532
                 });
535
                 });
533
             sections.insert(insert_at, section);
536
             sections.insert(insert_at, section);
534
         } else {
537
         } else {
src/macho/writer.rsmodified
@@ -2894,12 +2894,13 @@ mod tests {
2894
         });
2894
         });
2895
 
2895
 
2896
         let by_input_section = atoms.by_input_section();
2896
         let by_input_section = atoms.by_input_section();
2897
+        let atom_ranges = build_atom_range_index(&atoms, &by_input_section, None);
2897
         assert_eq!(
2898
         assert_eq!(
2898
-            find_containing_atom(&atoms, &by_input_section, InputId(7), 3, 4, None),
2899
+            find_containing_atom(&atom_ranges, InputId(7), 3, 4),
2899
             Some((first, 4))
2900
             Some((first, 4))
2900
         );
2901
         );
2901
         assert_eq!(
2902
         assert_eq!(
2902
-            find_containing_atom_range(&atoms, &by_input_section, InputId(7), 3, 10, 2, None),
2903
+            find_containing_atom_range(&atom_ranges, InputId(7), 3, 10, 2),
2903
             Some((second, 2))
2904
             Some((second, 2))
2904
         );
2905
         );
2905
     }
2906
     }
src/reloc/arm64.rsmodified
@@ -123,7 +123,10 @@ pub struct ThunkPlan {
123
 
123
 
124
 impl ThunkPlan {
124
 impl ThunkPlan {
125
     pub fn split_after_atoms(&self) -> Vec<crate::resolve::AtomId> {
125
     pub fn split_after_atoms(&self) -> Vec<crate::resolve::AtomId> {
126
-        self.islands.iter().map(|island| island.after_atom).collect()
126
+        self.islands
127
+            .iter()
128
+            .map(|island| island.after_atom)
129
+            .collect()
127
     }
130
     }
128
 
131
 
129
     pub fn output_sections(&self) -> Vec<ExtraOutputSection> {
132
     pub fn output_sections(&self) -> Vec<ExtraOutputSection> {
src/string_table.rsmodified
@@ -159,9 +159,8 @@ impl StringTableBuilder {
159
             .iter()
159
             .iter()
160
             .find_map(|&idx| {
160
             .find_map(|&idx| {
161
                 let existing = &self.roots[idx];
161
                 let existing = &self.roots[idx];
162
-                (existing.name.len() >= name.len() && existing.name.ends_with(name)).then(|| {
162
+                (existing.name.len() >= name.len() && existing.name.ends_with(name))
163
-                    existing.offset + (existing.name.len() - name.len()) as u32
163
+                    .then(|| existing.offset + (existing.name.len() - name.len()) as u32)
164
-                })
165
             })
164
             })
166
     }
165
     }
167
 }
166
 }
src/why_live.rsmodified
@@ -268,11 +268,7 @@ pub fn format_explanations(
268
                 out.push('\n');
268
                 out.push('\n');
269
             }
269
             }
270
             if winner != requested {
270
             if winner != requested {
271
-                writeln!(
271
+                writeln!(&mut out, "{requested} was folded to {winner} by -icf=safe").unwrap();
272
-                    &mut out,
273
-                    "{requested} was folded to {winner} by -icf=safe"
274
-                )
275
-                .unwrap();
276
             }
272
             }
277
             out.push_str(&dead_strip.format_symbol_explanation(sym_table, target));
273
             out.push_str(&dead_strip.format_symbol_explanation(sym_table, target));
278
         }
274
         }
@@ -293,11 +289,7 @@ pub fn format_explanations(
293
             out.push('\n');
289
             out.push('\n');
294
         }
290
         }
295
         if winner != requested {
291
         if winner != requested {
296
-            writeln!(
292
+            writeln!(&mut out, "{requested} was folded to {winner} by -icf=safe").unwrap();
297
-                &mut out,
298
-                "{requested} was folded to {winner} by -icf=safe"
299
-            )
300
-            .unwrap();
301
         }
293
         }
302
         let target_name = graph.symbol_name(target);
294
         let target_name = graph.symbol_name(target);
303
         writeln!(&mut out, "{target_name} is live because:").unwrap();
295
         writeln!(&mut out, "{target_name} is live because:").unwrap();
tests/common/harness.rsmodified
@@ -374,10 +374,13 @@ pub fn load_corpus(root: &Path) -> Result<Vec<LinkCase>, String> {
374
         let page_ref_checks = read_page_refs(&path.join("page_refs.txt"))?;
374
         let page_ref_checks = read_page_refs(&path.join("page_refs.txt"))?;
375
         let command_checks = read_command_checks(&path.join("command_checks.txt"))?;
375
         let command_checks = read_command_checks(&path.join("command_checks.txt"))?;
376
         let artifacts = read_artifacts(&path.join("artifacts.txt"))?;
376
         let artifacts = read_artifacts(&path.join("artifacts.txt"))?;
377
-        let artifact_srcs: HashSet<&str> =
377
+        let artifact_srcs: HashSet<&str> = artifacts
378
-            artifacts.iter().map(|artifact| artifact.src_name.as_str()).collect();
378
+            .iter()
379
+            .map(|artifact| artifact.src_name.as_str())
380
+            .collect();
379
         inputs.retain(|input| {
381
         inputs.retain(|input| {
380
-            input.file_name()
382
+            input
383
+                .file_name()
381
                 .and_then(|s| s.to_str())
384
                 .and_then(|s| s.to_str())
382
                 .map(|name| !artifact_srcs.contains(name))
385
                 .map(|name| !artifact_srcs.contains(name))
383
                 .unwrap_or(true)
386
                 .unwrap_or(true)