This is an archive of the discontinued LLVM Phabricator instance.

Be explicit about Windows coff name trailing character policy
ClosedPublic

Authored by serge-sans-paille on Aug 19 2019, 8:47 AM.

Details

Summary

It's okay to *not* copy the trailing zero of a windows section/symbol name.
This is compatible with strncpy behavior but gcc doesn't know that and
throws an invalid warning. Encode this behavior in a proper function.

Ref: https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#section-table-section-headers
and https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#symbol-name-representation

Diff Detail

Event Timeline

rnk added a comment.Aug 20 2019, 11:28 AM

Why does this suppress the warning? Just the templatization?

llvm/lib/Object/WindowsResource.cpp
520–521

Can we drop the template parameter and make Dest char (&Dest)[COFF::NameSize]? Then all we need is the assert for Src.size() <= COFF::NameSize.

serge-sans-paille marked an inline comment as done.Aug 20 2019, 1:15 PM

The gcc analysis is not interprocedural.

llvm/lib/Object/WindowsResource.cpp
520–521

Sure.

Take into account @rnk's review.

serge-sans-paille marked an inline comment as done.Aug 20 2019, 2:13 PM
rnk accepted this revision.Aug 20 2019, 2:42 PM

lgtm

I guess we're suppressing the warning by rinsing the string literals through StringRef, so GCC can't see the source string size.

This revision is now accepted and ready to land.Aug 20 2019, 2:42 PM

I guess we're suppressing the warning by rinsing the string literals through StringRef, so GCC can't see the source string size.

Indeed. Thanks for the review!

This revision was automatically updated to reflect the committed changes.