[PATCH] bfd/pdb: fix bitmap generation in pdb_write_bitmap

Mark Wielaard mark@klomp.org
Wed Sep 4 10:27:08 GMT 2024


Hi,

On Sun, Sep 01, 2024 at 05:47:15PM +0100, Mark Harmstone wrote:
> MSVC 2022 is more pedantic than MSVC 2019 when it comes to loading PDB
> files, and was rejecting PDB files generated by binutils because of
> their invalid free-space bitmaps. This patch fixes pdb_write_bitmap so
> we generate files that MSVC will accept.
> 
> Specifically there were three things we were doing wrong:
> 
> - We weren't including the superblock (block 0)
> 
> - We were setting bits in bytes backwards (MSB to LSB, rather than LSB to MSB)
> 
> - We should have been marking the contents of stream 0 as free. This is
>   because, as the comment says, it's intended to be used for the
>   directory for the previous write, to allow atomic updates.
> ---
>  bfd/pdb.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 48 insertions(+), 9 deletions(-)

This seems to have broken the gdb build on some builders with older gcc:
https://builder.sourceware.org/buildbot/#/changes/61630
gdb-debian-armhf, gdb-ubuntu-riscv, gdb-alma-x86_64 and gdb-ibm-power9

In function ‘pdb_write_bitmap’,
    inlined from ‘pdb_write_contents’ at ../../binutils-gdb/bfd/pdb.c:780:8:
../../binutils-gdb/bfd/pdb.c:675:29: error: ‘stream0_start’ may be used uninitialized [-Werror=maybe-uninitialized]
  675 |           if (stream0_start % 8)
      |               ~~~~~~~~~~~~~~^~~
../../binutils-gdb/bfd/pdb.c: In function ‘pdb_write_contents’:
../../binutils-gdb/bfd/pdb.c:721:12: note: ‘stream0_start’ was declared here
  721 |   uint32_t stream0_start;
      |            ^~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[3]: *** [Makefile:1768: pdb.lo] Error 1
make[3]: *** Waiting for unfinished jobs....

Maybe just initialize to zero to make the compiler happy?

Thanks,

Mark


More information about the Binutils mailing list