Skip to content

Commit

Permalink
Fix issue with uintptr_t size
Browse files Browse the repository at this point in the history
  • Loading branch information
branpk committed Oct 8, 2023
1 parent 09b4ab7 commit 1f6aa50
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
22 changes: 22 additions & 0 deletions wafel_data_type/src/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ impl IntType {
Self::S64 => 8,
}
}

/// Returns an unsigned int type with the given size in bytes.
pub fn unsigned_with_size(size: usize) -> Self {
match size {
1 => Self::U8,
2 => Self::U16,
4 => Self::U32,
8 => Self::U64,
_ => unimplemented!("unsigned int with size {}", size),
}
}

/// Returns a signed int type with the given size in bytes.
pub fn signed_with_size(size: usize) -> Self {
match size {
1 => Self::S8,
2 => Self::S16,
4 => Self::S32,
8 => Self::S64,
_ => unimplemented!("signed int with size {}", size),
}
}
}

impl FloatType {
Expand Down
27 changes: 14 additions & 13 deletions wafel_layout/src/dll_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,22 +428,23 @@ where
) -> Result<(), DllLayoutErrorKind> {
let entry = node.entry();
let name = self.req_attr_string(entry, gimli::DW_AT_name)?;
let size = self.req_attr_usize(entry, gimli::DW_AT_byte_size)?;
let shallow_type = match name.as_ref() {
"char" => ShallowDataType::Int(IntType::S8),
"long long unsigned int" => ShallowDataType::Int(IntType::U64),
"long long int" => ShallowDataType::Int(IntType::S64),
"short unsigned int" => ShallowDataType::Int(IntType::U16),
"int" => ShallowDataType::Int(IntType::S32),
"long int" => ShallowDataType::Int(IntType::S32),
"unsigned int" => ShallowDataType::Int(IntType::U32),
"long unsigned int" => ShallowDataType::Int(IntType::U32),
"unsigned char" => ShallowDataType::Int(IntType::U8),
"char" => ShallowDataType::Int(IntType::signed_with_size(size)),
"long long unsigned int" => ShallowDataType::Int(IntType::unsigned_with_size(size)),
"long long int" => ShallowDataType::Int(IntType::signed_with_size(size)),
"short unsigned int" => ShallowDataType::Int(IntType::unsigned_with_size(size)),
"int" => ShallowDataType::Int(IntType::signed_with_size(size)),
"long int" => ShallowDataType::Int(IntType::signed_with_size(size)),
"unsigned int" => ShallowDataType::Int(IntType::unsigned_with_size(size)),
"long unsigned int" => ShallowDataType::Int(IntType::unsigned_with_size(size)),
"unsigned char" => ShallowDataType::Int(IntType::unsigned_with_size(size)),
"double" => ShallowDataType::Float(FloatType::F64),
"float" => ShallowDataType::Float(FloatType::F32),
"long double" => ShallowDataType::Void, // f128 is not currently supported
"signed char" => ShallowDataType::Int(IntType::S8),
"short int" => ShallowDataType::Int(IntType::S16),
"_Bool" => ShallowDataType::Int(IntType::S32),
"signed char" => ShallowDataType::Int(IntType::signed_with_size(size)),
"short int" => ShallowDataType::Int(IntType::signed_with_size(size)),
"_Bool" => ShallowDataType::Int(IntType::signed_with_size(size)),
"__int128 unsigned" => ShallowDataType::Array {
base: TypeId::U64,
length: Some(2),
Expand All @@ -459,7 +460,7 @@ where
TypeId::Offset(entry.offset().0),
PreDataType {
shallow_type,
size: PreDataTypeSize::Known(self.req_attr_usize(entry, gimli::DW_AT_byte_size)?),
size: PreDataTypeSize::Known(size),
},
);
Ok(())
Expand Down

0 comments on commit 1f6aa50

Please sign in to comment.