[PATCH] ld: Align the PDB DBI source-info substream
Oleg Tolmatcev
oleg.tolmatcev@gmail.com
Sun Sep 13 17:56:10 GMT 2026
Round the source-info substream size up to four bytes and zero the
padding. Extend the test to exercise this case.
ld/
* pdb.c (create_source_info_substream): Align the substream size and
zero the padding.
* testsuite/ld-pe/pdb3b.s: Make the source-info substream require
padding.
* testsuite/ld-pe/pdb3-source-info.d: Expect the padding.
---
ld/pdb.c | 5 +++++
ld/testsuite/ld-pe/pdb3-source-info.d | 2 +-
ld/testsuite/ld-pe/pdb3b.s | 3 ++-
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/ld/pdb.c b/ld/pdb.c
index 673d041ce2e..d069549153e 100644
--- a/ld/pdb.c
+++ b/ld/pdb.c
@@ -4391,6 +4391,10 @@ create_source_info_substream (void **data, uint32_t *size,
*size += sizeof (uint32_t) * source_files_count;
*size += strings_len;
+ /* Subsequent DBI substreams must be 4-byte aligned. */
+
+ *size = (*size + 3) & ~3u;
+
*data = xmalloc (*size);
ptr = (uint8_t *) *data;
@@ -4456,6 +4460,7 @@ create_source_info_substream (void **data, uint32_t *size,
}
}
}
+ memset (ptr, 0, (uint8_t *) *data + *size - ptr);
}
/* Used as parameter to qsort, to sort globals by hash. */
diff --git a/ld/testsuite/ld-pe/pdb3-source-info.d b/ld/testsuite/ld-pe/pdb3-source-info.d
index 4239c1cb9cf..753a0583b53 100644
--- a/ld/testsuite/ld-pe/pdb3-source-info.d
+++ b/ld/testsuite/ld-pe/pdb3-source-info.d
@@ -4,4 +4,4 @@
Contents of section .data:
0000 03000300 00000100 02000200 02000000 ................
0010 00000000 04000000 04000000 08000000 ................
- 0020 666f6f00 62617200 62617a00 foo.bar.baz.
+ 0020 666f6f00 62617200 62617a7a 00000000 foo.bar.bazz....
diff --git a/ld/testsuite/ld-pe/pdb3b.s b/ld/testsuite/ld-pe/pdb3b.s
index aa23821648b..f7f70fbad14 100644
--- a/ld/testsuite/ld-pe/pdb3b.s
+++ b/ld/testsuite/ld-pe/pdb3b.s
@@ -17,8 +17,9 @@
.src1:
.asciz "bar"
+/* Make the unpadded DBI source-info substream size non-aligned. */
.src2:
-.asciz "baz"
+.asciz "bazz"
.strings_end:
--
2.55.0.windows.5
More information about the Binutils
mailing list