Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DebugInfo alignment and offset for aggregate types #1329

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ attributes #2 = { argmemonly nofree nounwind willreturn }
!9 = !DILocation(line: 3, column: 12, scope: !4)
!10 = !DILocalVariable(name: "myFunc", scope: !4, file: !5, line: 2, type: !11)
!11 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "__ref_to_STRING", baseType: !12, size: 64, align: 64, dwarfAddressSpace: 1)
!12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !13, size: 80, align: 64, elements: !14)
!12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !13, size: 648, align: 8, elements: !14)
!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_UTF, flags: DIFlagPublic)
!14 = !{!15}
!15 = !DISubrange(count: 81, lowerBound: 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ attributes #1 = { argmemonly nofree nounwind willreturn writeonly }
!7 = !{null}
!8 = !{}
!9 = !DILocation(line: 6, column: 8, scope: !4)
!10 = !DILocalVariable(name: "a", scope: !4, file: !5, line: 4, type: !11, align: 64)
!11 = !DICompositeType(tag: DW_TAG_array_type, baseType: !12, size: 2048, align: 64, elements: !13)
!10 = !DILocalVariable(name: "a", scope: !4, file: !5, line: 4, type: !11, align: 32)
!11 = !DICompositeType(tag: DW_TAG_array_type, baseType: !12, size: 2048, align: 32, elements: !13)
!12 = !DIBasicType(name: "DINT", size: 32, encoding: DW_ATE_signed, flags: DIFlagPublic)
!13 = !{!14}
!14 = !DISubrange(count: 64, lowerBound: 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ source_filename = "<internal>"
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !2, line: 3, type: !3, isLocal: false, isDefinition: true)
!2 = !DIFile(filename: "<internal>", directory: "")
!3 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 64, align: 64, elements: !5)
!3 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 520, align: 8, elements: !5)
!4 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_UTF, flags: DIFlagPublic)
!5 = !{!6}
!6 = !DISubrange(count: 65, lowerBound: 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ source_filename = "<internal>"
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !2, line: 3, type: !3, isLocal: false, isDefinition: true)
!2 = !DIFile(filename: "<internal>", directory: "")
!3 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 352, align: 64, elements: !5)
!3 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 352, align: 32, elements: !5)
!4 = !DIBasicType(name: "DINT", size: 32, encoding: DW_ATE_signed, flags: DIFlagPublic)
!5 = !{!6}
!6 = !DISubrange(count: 11, lowerBound: 0)
!7 = !DIGlobalVariableExpression(var: !8, expr: !DIExpression())
!8 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !2, line: 4, type: !9, isLocal: false, isDefinition: true)
!9 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 3520, align: 64, elements: !10)
!9 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 3520, align: 32, elements: !10)
!10 = !{!6, !11}
!11 = !DISubrange(count: 10, lowerBound: 11)
!12 = !DIGlobalVariableExpression(var: !13, expr: !DIExpression())
!13 = distinct !DIGlobalVariable(name: "c", scope: !2, file: !2, line: 5, type: !14, isLocal: false, isDefinition: true)
!14 = !DICompositeType(tag: DW_TAG_array_type, baseType: !15, size: 3520, align: 64, elements: !5)
!15 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 320, align: 64, elements: !16)
!14 = !DICompositeType(tag: DW_TAG_array_type, baseType: !15, size: 3520, align: 32, elements: !5)
!15 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 320, align: 32, elements: !16)
!16 = !{!11}
!17 = !{i32 2, !"Dwarf Version", i32 5}
!18 = !{i32 2, !"Debug Info Version", i32 3}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ source_filename = "<internal>"
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !2, line: 3, type: !3, isLocal: false, isDefinition: true)
!2 = !DIFile(filename: "<internal>", directory: "")
!3 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 80, align: 64, elements: !5)
!3 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 648, align: 8, elements: !5)
!4 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_UTF, flags: DIFlagPublic)
!5 = !{!6}
!6 = !DISubrange(count: 81, lowerBound: 0)
!7 = !DIGlobalVariableExpression(var: !8, expr: !DIExpression())
!8 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !2, line: 4, type: !9, isLocal: false, isDefinition: true)
!9 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, size: 160, align: 64, elements: !5)
!9 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, size: 1296, align: 16, elements: !5)
!10 = !DIBasicType(name: "wchar", size: 16, encoding: DW_ATE_UTF, flags: DIFlagPublic)
!11 = !{i32 2, !"Dwarf Version", i32 5}
!12 = !{i32 2, !"Debug Info Version", i32 3}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ source_filename = "<internal>"
!6 = !DIBasicType(name: "DINT", size: 32, encoding: DW_ATE_signed, flags: DIFlagPublic)
!7 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !2, file: !2, line: 4, baseType: !8, size: 64, align: 64, offset: 64, flags: DIFlagPublic)
!8 = !DIBasicType(name: "LREAL", size: 64, encoding: DW_ATE_float, flags: DIFlagPublic)
!9 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !2, file: !2, line: 5, baseType: !10, size: 352, align: 64, offset: 128, flags: DIFlagPublic)
!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 352, align: 64, elements: !11)
!9 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !2, file: !2, line: 5, baseType: !10, size: 352, align: 32, offset: 128, flags: DIFlagPublic)
!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 352, align: 32, elements: !11)
!11 = !{!12}
!12 = !DISubrange(count: 11, lowerBound: 0)
!13 = !DIGlobalVariableExpression(var: !14, expr: !DIExpression())
Expand Down Expand Up @@ -69,8 +69,8 @@ attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
!6 = !DIBasicType(name: "DINT", size: 32, encoding: DW_ATE_signed, flags: DIFlagPublic)
!7 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !2, file: !2, line: 4, baseType: !8, size: 64, align: 64, offset: 64, flags: DIFlagPublic)
!8 = !DIBasicType(name: "LREAL", size: 64, encoding: DW_ATE_float, flags: DIFlagPublic)
!9 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !2, file: !2, line: 5, baseType: !10, size: 352, align: 64, offset: 128, flags: DIFlagPublic)
!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 352, align: 64, elements: !11)
!9 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !2, file: !2, line: 5, baseType: !10, size: 352, align: 32, offset: 128, flags: DIFlagPublic)
!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 352, align: 32, elements: !11)
!11 = !{!12}
!12 = !DISubrange(count: 11, lowerBound: 0)
!13 = !{i32 2, !"Dwarf Version", i32 5}
Expand Down Expand Up @@ -114,8 +114,8 @@ declare !dbg !25 void @__init_mystruct(%myStruct*)
!6 = !DIBasicType(name: "DINT", size: 32, encoding: DW_ATE_signed, flags: DIFlagPublic)
!7 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !2, file: !2, line: 4, baseType: !8, size: 64, align: 64, offset: 64, flags: DIFlagPublic)
!8 = !DIBasicType(name: "LREAL", size: 64, encoding: DW_ATE_float, flags: DIFlagPublic)
!9 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !2, file: !2, line: 5, baseType: !10, size: 352, align: 64, offset: 128, flags: DIFlagPublic)
!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 352, align: 64, elements: !11)
!9 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !2, file: !2, line: 5, baseType: !10, size: 352, align: 32, offset: 128, flags: DIFlagPublic)
!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 352, align: 32, elements: !11)
!11 = !{!12}
!12 = !DISubrange(count: 11, lowerBound: 0)
!13 = !DIGlobalVariableExpression(var: !14, expr: !DIExpression())
Expand Down
1 change: 1 addition & 0 deletions src/datalayout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl MemoryLocation {
MemoryLocation(Bytes(value))
}

// see https://en.wikipedia.org/wiki/Data_structure_alignment#Computing_padding
pub fn align_to(self, align: Bytes) -> Self {
let align = align.value() - 1;
MemoryLocation::new((self.value() + align) & !align)
Expand Down
14 changes: 6 additions & 8 deletions src/typesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ impl DataTypeInformation {
DataTypeInformation::String { size, encoding } => size
.as_int_value(index)
.map(|size| encoding.get_bytes_per_char() * size as u32)
.map(Bytes::from_bits)
.map(Bytes::new)
.unwrap(),
DataTypeInformation::Struct { members, .. } => members
.iter()
Expand Down Expand Up @@ -669,15 +669,13 @@ impl DataTypeInformation {
let type_layout = index.get_type_layout();
match self {
DataTypeInformation::Array { inner_type_name, .. } => {
let inner_type = index.get_type_information_or_void(inner_type_name);
if inner_type.get_alignment(index) > type_layout.i64 {
type_layout.v128
} else {
type_layout.v64
}
index.get_type_information_or_void(inner_type_name).get_alignment(index)
}
DataTypeInformation::Struct { .. } => type_layout.aggregate,
DataTypeInformation::String { .. } => type_layout.v64, //Strings are arrays
DataTypeInformation::String { encoding, .. } => match encoding {
StringEncoding::Utf8 => Bytes::new(1),
StringEncoding::Utf16 => Bytes::new(2),
},
DataTypeInformation::Pointer { .. } => type_layout.p64,
DataTypeInformation::Integer { size, semantic_size, .. } => {
if let Some(1) = semantic_size {
Expand Down
Loading