ld: record a fragment's output offset separately from its input shdr

This commit is contained in:
Mikael Pettersson 2020-07-06 12:12:19 +02:00
parent 92d5ed6a1a
commit 5adda72e1f
3 changed files with 5 additions and 6 deletions

View File

@ -35,6 +35,7 @@
, shdr :: #elf36_Shdr{}
, shndx :: non_neg_integer()
, relocs :: #elf36_Shdr{} | false
, offset :: non_neg_integer() % within enclosing #section{}
}).
-record(section,

View File

@ -56,9 +56,9 @@ phase1(File, ShTab, StShNdx, OutputsMap) ->
phase1([], _ShNdx, _File, _RelocsMap, OutputsMap) ->
OutputsMap;
phase1([SHdr | ShTab], ShNdx, File, RelocsMap, OutputsMap) ->
phase1([Shdr | ShTab], ShNdx, File, RelocsMap, OutputsMap) ->
NewOutputsMap =
maybe_output_section(SHdr, ShNdx, File, RelocsMap, OutputsMap),
maybe_output_section(Shdr, ShNdx, File, RelocsMap, OutputsMap),
phase1(ShTab, ShNdx + 1, File, RelocsMap, NewOutputsMap).
maybe_output_section(Shdr, ShNdx, File, RelocsMap, OutputsMap) ->
@ -99,8 +99,7 @@ output_append({Nr, OutputShdr, Frags}, File, Shdr, ShNdx, Relocs) ->
NewOutputShdr = OutputShdr#elf36_Shdr{ sh_size = NewSize
, sh_addralign = NewAlignment
},
NewShdr = Shdr#elf36_Shdr{sh_offset = FragOffset},
Frag = #sectfrag{file = File, shdr = NewShdr, shndx = ShNdx, relocs = Relocs},
Frag = #sectfrag{file = File, shdr = Shdr, shndx = ShNdx, relocs = Relocs, offset = FragOffset},
{Nr, NewOutputShdr, [Frag | Frags]}.
section_alignment(Shdr) ->

View File

@ -50,8 +50,7 @@ scan_section(#section{shdr = Shdr, frags = Frags}, FragMap0, SegmentBase) ->
scan_frag(Frag, FragMap, SectionBase)
end, FragMap0, Frags).
scan_frag(#sectfrag{file = File, shdr = Shdr, shndx = ShNdx}, FragMap, SectionBase) ->
#elf36_Shdr{sh_offset = SectionOffset} = Shdr,
scan_frag(#sectfrag{file = File, shndx = ShNdx, offset = SectionOffset}, FragMap, SectionBase) ->
maps:put({File, ShNdx}, SectionBase + SectionOffset, FragMap).
%% Scan all input files, whose segments now have load addresses in FragMap,