File tree 2 files changed +38
-2
lines changed
2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -130,9 +130,11 @@ impl Section {
130
130
}
131
131
}
132
132
133
- pub fn get_contents ( & self ) -> & CStr {
133
+ pub fn get_contents ( & self ) -> & [ u8 ] {
134
134
unsafe {
135
- CStr :: from_ptr ( LLVMGetSectionContents ( self . section ) )
135
+ std:: slice:: from_raw_parts (
136
+ LLVMGetSectionContents ( self . section ) as * const u8 ,
137
+ self . size ( ) as usize )
136
138
}
137
139
}
138
140
Original file line number Diff line number Diff line change @@ -210,3 +210,37 @@ fn test_reloc_iterator() {
210
210
}
211
211
assert ! ( found_relocation) ;
212
212
}
213
+
214
+ #[ test]
215
+ fn test_section_contains_nul ( ) {
216
+ let target_machine = get_native_target_machine ( ) ;
217
+
218
+ let context = Context :: create ( ) ;
219
+ let mut module = context. create_module ( "test_section_iterator" ) ;
220
+
221
+ let gv = module. add_global ( context. i32_type ( ) , None , "gv" ) ;
222
+ gv. set_initializer (
223
+ & context
224
+ . i32_type ( )
225
+ . const_int ( 0xff0000ff , false )
226
+ . as_basic_value_enum ( ) ,
227
+ ) ;
228
+ gv. set_section ( "test" ) ;
229
+
230
+ apply_target_to_module ( & target_machine, & module) ;
231
+
232
+ let memory_buffer = target_machine
233
+ . write_to_memory_buffer ( & mut module, FileType :: Object )
234
+ . unwrap ( ) ;
235
+ let object_file = memory_buffer. create_object_file ( ) . unwrap ( ) ;
236
+
237
+ let mut has_section_test = false ;
238
+ for section in object_file. get_sections ( ) {
239
+ if section. get_name ( ) . and_then ( |name| name. to_str ( ) . ok ( ) ) == Some ( "test" ) {
240
+ assert_eq ! ( section. get_contents( ) , 0xff0000ffu32 . to_ne_bytes( ) ) ;
241
+ has_section_test = true ;
242
+ break ;
243
+ }
244
+ }
245
+ assert ! ( has_section_test) ;
246
+ }
You can’t perform that action at this time.
0 commit comments