Use architecture pointer size for AddConstructor (#1094)

* Use architecture pointer size for AddConstructor

* Update src/backend.rs

Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
This commit is contained in:
Kitsu 2020-10-16 17:19:22 +03:00 committed by GitHub
parent 0416f122aa
commit 04091772bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -132,10 +132,16 @@ impl AddConstructor for ObjectProduct {
let init_array_section =
self.object
.add_section(segment.to_vec(), b".init_array".to_vec(), SectionKind::Data);
let address_size = self
.object
.architecture()
.address_size()
.expect("address_size must be known")
.bytes();
self.object.append_section_data(
init_array_section,
&std::iter::repeat(0)
.take(8 /*FIXME pointer size*/)
.take(address_size.into())
.collect::<Vec<u8>>(),
8,
);
@ -144,7 +150,7 @@ impl AddConstructor for ObjectProduct {
init_array_section,
object::write::Relocation {
offset: 0,
size: 64, // FIXME pointer size
size: address_size * 8,
kind: RelocationKind::Absolute,
encoding: RelocationEncoding::Generic,
symbol,