@@ -46,6 +46,7 @@ pub(crate) struct DebugReloc {
46
46
pub ( crate ) size : u8 ,
47
47
pub ( crate ) name : DebugRelocName ,
48
48
pub ( crate ) addend : i64 ,
49
+ pub ( crate ) kind : object:: RelocationKind ,
49
50
}
50
51
51
52
#[ derive( Clone ) ]
@@ -122,21 +123,21 @@ impl Writer for WriterRelocate {
122
123
size,
123
124
name : DebugRelocName :: Symbol ( symbol) ,
124
125
addend : addend as i64 ,
126
+ kind : object:: RelocationKind :: Absolute ,
125
127
} ) ;
126
128
self . write_udata ( 0 , size)
127
129
}
128
130
}
129
131
}
130
132
131
- // TODO: implement write_eh_pointer
132
-
133
133
fn write_offset ( & mut self , val : usize , section : SectionId , size : u8 ) -> Result < ( ) > {
134
134
let offset = self . len ( ) as u32 ;
135
135
self . relocs . push ( DebugReloc {
136
136
offset,
137
137
size,
138
138
name : DebugRelocName :: Section ( section) ,
139
139
addend : val as i64 ,
140
+ kind : object:: RelocationKind :: Absolute ,
140
141
} ) ;
141
142
self . write_udata ( 0 , size)
142
143
}
@@ -153,7 +154,55 @@ impl Writer for WriterRelocate {
153
154
size,
154
155
name : DebugRelocName :: Section ( section) ,
155
156
addend : val as i64 ,
157
+ kind : object:: RelocationKind :: Absolute ,
156
158
} ) ;
157
159
self . write_udata_at ( offset, 0 , size)
158
160
}
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
+ }
159
208
}
0 commit comments