Skip to content

Commit c4d010b

Browse files
committed
Deduplicate debug section defining and linking
1 parent ddbbb26 commit c4d010b

File tree

1 file changed

+26
-121
lines changed

1 file changed

+26
-121
lines changed

src/debuginfo.rs

Lines changed: 26 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -200,127 +200,37 @@ impl<'a, 'tcx: 'a> DebugContext<'tcx> {
200200
)
201201
.unwrap();
202202

203-
artifact
204-
.declare_with(
205-
SectionId::DebugAbbrev.name(),
206-
Decl::DebugSection,
207-
debug_abbrev.0.writer.into_vec(),
208-
)
209-
.unwrap();
210-
artifact
211-
.declare_with(
212-
SectionId::DebugInfo.name(),
213-
Decl::DebugSection,
214-
debug_info.0.writer.into_vec(),
215-
)
216-
.unwrap();
217-
artifact
218-
.declare_with(
219-
SectionId::DebugStr.name(),
220-
Decl::DebugSection,
221-
debug_str.0.writer.into_vec(),
222-
)
223-
.unwrap();
224-
artifact
225-
.declare_with(
226-
SectionId::DebugLine.name(),
227-
Decl::DebugSection,
228-
debug_line.0.writer.into_vec(),
229-
)
230-
.unwrap();
231-
232-
let debug_ranges_not_empty = !debug_ranges.0.writer.slice().is_empty();
233-
if debug_ranges_not_empty {
203+
macro decl_section($section:ident = $name:ident) {
234204
artifact
235205
.declare_with(
236-
SectionId::DebugRanges.name(),
206+
SectionId::$section.name(),
237207
Decl::DebugSection,
238-
debug_ranges.0.writer.into_vec(),
208+
$name.0.writer.into_vec(),
239209
)
240210
.unwrap();
241211
}
242212

243-
let debug_rnglists_not_empty = !debug_rnglists.0.writer.slice().is_empty();
244-
if debug_rnglists_not_empty {
245-
artifact
246-
.declare_with(
247-
SectionId::DebugRngLists.name(),
248-
Decl::DebugSection,
249-
debug_rnglists.0.writer.into_vec(),
250-
)
251-
.unwrap();
252-
}
253-
254-
for reloc in debug_abbrev.0.relocs {
255-
artifact
256-
.link_with(
257-
faerie::Link {
258-
from: SectionId::DebugAbbrev.name(),
259-
to: &reloc.name,
260-
at: u64::from(reloc.offset),
261-
},
262-
faerie::Reloc::Debug {
263-
size: reloc.size,
264-
addend: reloc.addend as i32,
265-
},
266-
)
267-
.expect("faerie relocation error");
268-
}
269-
270-
for reloc in debug_info.0.relocs {
271-
artifact
272-
.link_with(
273-
faerie::Link {
274-
from: SectionId::DebugInfo.name(),
275-
to: &reloc.name,
276-
at: u64::from(reloc.offset),
277-
},
278-
faerie::Reloc::Debug {
279-
size: reloc.size,
280-
addend: reloc.addend as i32,
281-
},
282-
)
283-
.expect("faerie relocation error");
284-
}
213+
decl_section!(DebugAbbrev = debug_abbrev);
214+
decl_section!(DebugInfo = debug_info);
215+
decl_section!(DebugStr = debug_str);
216+
decl_section!(DebugLine = debug_line);
285217

286-
for reloc in debug_str.0.relocs {
287-
artifact
288-
.link_with(
289-
faerie::Link {
290-
from: SectionId::DebugStr.name(),
291-
to: &reloc.name,
292-
at: u64::from(reloc.offset),
293-
},
294-
faerie::Reloc::Debug {
295-
size: reloc.size,
296-
addend: reloc.addend as i32,
297-
},
298-
)
299-
.expect("faerie relocation error");
218+
let debug_ranges_not_empty = !debug_ranges.0.writer.slice().is_empty();
219+
if debug_ranges_not_empty {
220+
decl_section!(DebugRanges = debug_ranges);
300221
}
301222

302-
for reloc in debug_line.0.relocs {
303-
artifact
304-
.link_with(
305-
faerie::Link {
306-
from: SectionId::DebugLine.name(),
307-
to: &reloc.name,
308-
at: u64::from(reloc.offset),
309-
},
310-
faerie::Reloc::Debug {
311-
size: reloc.size,
312-
addend: reloc.addend as i32,
313-
},
314-
)
315-
.expect("faerie relocation error");
223+
let debug_rnglists_not_empty = !debug_rnglists.0.writer.slice().is_empty();
224+
if debug_rnglists_not_empty {
225+
decl_section!(DebugRngLists = debug_rnglists);
316226
}
317227

318-
if debug_ranges_not_empty {
319-
for reloc in debug_ranges.0.relocs {
228+
macro sect_relocs($section:ident = $name:ident) {
229+
for reloc in $name.0.relocs {
320230
artifact
321231
.link_with(
322232
faerie::Link {
323-
from: SectionId::DebugRanges.name(),
233+
from: SectionId::$section.name(),
324234
to: &reloc.name,
325235
at: u64::from(reloc.offset),
326236
},
@@ -333,22 +243,17 @@ impl<'a, 'tcx: 'a> DebugContext<'tcx> {
333243
}
334244
}
335245

246+
sect_relocs!(DebugAbbrev = debug_abbrev);
247+
sect_relocs!(DebugInfo = debug_info);
248+
sect_relocs!(DebugStr = debug_str);
249+
sect_relocs!(DebugLine = debug_line);
250+
251+
if debug_ranges_not_empty {
252+
sect_relocs!(DebugRanges = debug_ranges);
253+
}
254+
336255
if debug_rnglists_not_empty {
337-
for reloc in debug_rnglists.0.relocs {
338-
artifact
339-
.link_with(
340-
faerie::Link {
341-
from: SectionId::DebugRngLists.name(),
342-
to: &reloc.name,
343-
at: u64::from(reloc.offset),
344-
},
345-
faerie::Reloc::Debug {
346-
size: reloc.size,
347-
addend: reloc.addend as i32,
348-
},
349-
)
350-
.expect("faerie relocation error");
351-
}
256+
sect_relocs!(DebugRngLists = debug_rnglists);
352257
}
353258
}
354259

0 commit comments

Comments
 (0)