I discovered this due to an error in my Makefile. I was using "-Wl,-Map=$(@:.dll=.map) -o $@" on the command line but the target was foo.pyd (not foo.dll). Therefore I inadvertantly specified the same filename for the map file and the output file. This caused the linker to fail silently (no warnings or errors) and generate a corrupt output file. The section headers pointed to areas in the file that did not contain the expected sections. When doing the same thing using lld it succeeds with a valid output file but no map file is generated. It would be better for ld to detect the duplicate filename and fail with a helpful error message or to mimic the behavior of lld.
I guess you could do something like we do for gas, where we check that the output st_ino is different from any input.