@@ -46,6 +46,7 @@ pub(crate) struct DebugReloc {
4646 pub ( crate ) size : u8 ,
4747 pub ( crate ) name : DebugRelocName ,
4848 pub ( crate ) addend : i64 ,
49+ pub ( crate ) kind : object:: RelocationKind ,
4950}
5051
5152#[ derive( Clone ) ]
@@ -122,21 +123,21 @@ impl Writer for WriterRelocate {
122123 size,
123124 name : DebugRelocName :: Symbol ( symbol) ,
124125 addend : addend as i64 ,
126+ kind : object:: RelocationKind :: Absolute ,
125127 } ) ;
126128 self . write_udata ( 0 , size)
127129 }
128130 }
129131 }
130132
131- // TODO: implement write_eh_pointer
132-
133133 fn write_offset ( & mut self , val : usize , section : SectionId , size : u8 ) -> Result < ( ) > {
134134 let offset = self . len ( ) as u32 ;
135135 self . relocs . push ( DebugReloc {
136136 offset,
137137 size,
138138 name : DebugRelocName :: Section ( section) ,
139139 addend : val as i64 ,
140+ kind : object:: RelocationKind :: Absolute ,
140141 } ) ;
141142 self . write_udata ( 0 , size)
142143 }
@@ -153,7 +154,55 @@ impl Writer for WriterRelocate {
153154 size,
154155 name : DebugRelocName :: Section ( section) ,
155156 addend : val as i64 ,
157+ kind : object:: RelocationKind :: Absolute ,
156158 } ) ;
157159 self . write_udata_at ( offset, 0 , size)
158160 }
161+
162+ fn write_eh_pointer (
163+ & mut self ,
164+ address : Address ,
165+ eh_pe : gimli:: DwEhPe ,
166+ size : u8 ,
167+ ) -> Result < ( ) > {
168+ match address {
169+ // Address::Constant arm copied from gimli
170+ Address :: Constant ( val) => {
171+ // Indirect doesn't matter here.
172+ let val = match eh_pe. application ( ) {
173+ gimli:: DW_EH_PE_absptr => val,
174+ gimli:: DW_EH_PE_pcrel => {
175+ // TODO: better handling of sign
176+ let offset = self . len ( ) as u64 ;
177+ offset. wrapping_sub ( val)
178+ }
179+ _ => {
180+ return Err ( gimli:: write:: Error :: UnsupportedPointerEncoding ( eh_pe) ) ;
181+ }
182+ } ;
183+ self . write_eh_pointer_data ( val, eh_pe. format ( ) , size)
184+ }
185+ Address :: Symbol { symbol, addend } => {
186+ match eh_pe. application ( ) {
187+ gimli:: DW_EH_PE_pcrel => {
188+ let size = match eh_pe. format ( ) {
189+ gimli:: DW_EH_PE_sdata4 => 4 ,
190+ _ => return Err ( gimli:: write:: Error :: UnsupportedPointerEncoding ( eh_pe) ) ,
191+ } ;
192+ self . relocs . push ( DebugReloc {
193+ offset : self . len ( ) as u32 ,
194+ size,
195+ name : DebugRelocName :: Symbol ( symbol) ,
196+ addend,
197+ kind : object:: RelocationKind :: Relative ,
198+ } ) ;
199+ self . write_udata ( 0 , size)
200+ }
201+ _ => {
202+ return Err ( gimli:: write:: Error :: UnsupportedPointerEncoding ( eh_pe) ) ;
203+ }
204+ }
205+ }
206+ }
207+ }
159208}
0 commit comments