This is an archive of the discontinued LLVM Phabricator instance.

[MC] Handle discardable COFF sections in assembly
ClosedPublic

Authored by rnk on Sep 14 2016, 2:01 PM.

Details

Summary

This fixes a dumpbin warning on objects produced by the MC assembler
when starting from text. All .debug$S sections are supposed to be marked
IMAGE_SCN_MEM_DISCARDABLE. The main, non-COMDAT .debug$S section had
this set, but any comdat ones were not being marked discardable because
there was no .section flag for it.

This change does two things:

  • If the section name starts with .debug, implicitly mark the section as discardable. This means we do the same thing as gas on .s files with DWARF from GCC, which is important.
  • Adds the 'D' flag to the .section directive on COFF to explicitly say a section is discardable. We only emit this flag if the section name does not start with .debug. This allows the user to explicitly tweak their section flags without worrying about magic section names.

The only thing you can't do in this scheme is to create a
non-discardable section with a name starting with ".debug", but
hopefully users don't need that.

Diff Detail

Event Timeline

rnk updated this revision to Diff 71427.Sep 14 2016, 2:01 PM
rnk retitled this revision from to [MC] Add section flag 'D' for disardable COFF sections.
rnk updated this object.
rnk added reviewers: majnemer, rafael.
rnk added a subscriber: llvm-commits.
rnk updated this revision to Diff 71428.Sep 14 2016, 2:06 PM
  • Update CV tests
majnemer edited edge metadata.Sep 14 2016, 2:17 PM

I wonder if we should just adopt the section name hack for improved compatibility with mingw. We'd give any section which starts with .debug IMAGE_SCN_MEM_DISCARDABLE

rnk added a comment.Sep 14 2016, 2:21 PM

I wonder if we should just adopt the section name hack for improved compatibility with mingw. We'd give any section which starts with .debug IMAGE_SCN_MEM_DISCARDABLE

Maybe we should do both? I don't want to leave MCSectionCOFF with an incomplete .section serialization.

In D24582#543082, @rnk wrote:

I wonder if we should just adopt the section name hack for improved compatibility with mingw. We'd give any section which starts with .debug IMAGE_SCN_MEM_DISCARDABLE

Maybe we should do both? I don't want to leave MCSectionCOFF with an incomplete .section serialization.

It won't work when we try to take our .s output to mingw though. Seeing as how this won't work in the general case, I'd suggest the following:

  • Infer IMAGE_SCN_MEM_DISCARDABLE if the section starts with .debug
  • Raise an error if we have a section with IMAGE_SCN_MEM_DISCARDABLE which does not start with .debug
rnk added a comment.Sep 14 2016, 2:57 PM
In D24582#543082, @rnk wrote:

I wonder if we should just adopt the section name hack for improved compatibility with mingw. We'd give any section which starts with .debug IMAGE_SCN_MEM_DISCARDABLE

Maybe we should do both? I don't want to leave MCSectionCOFF with an incomplete .section serialization.

It won't work when we try to take our .s output to mingw though. Seeing as how this won't work in the general case, I'd suggest the following:

  • Infer IMAGE_SCN_MEM_DISCARDABLE if the section starts with .debug
  • Raise an error if we have a section with IMAGE_SCN_MEM_DISCARDABLE which does not start with .debug

How about I do all that, and instead of raising an error if there is a discardable section that doesn't start with .debug, I emit the 'D' flag?

In D24582#543165, @rnk wrote:
In D24582#543082, @rnk wrote:

I wonder if we should just adopt the section name hack for improved compatibility with mingw. We'd give any section which starts with .debug IMAGE_SCN_MEM_DISCARDABLE

Maybe we should do both? I don't want to leave MCSectionCOFF with an incomplete .section serialization.

It won't work when we try to take our .s output to mingw though. Seeing as how this won't work in the general case, I'd suggest the following:

  • Infer IMAGE_SCN_MEM_DISCARDABLE if the section starts with .debug
  • Raise an error if we have a section with IMAGE_SCN_MEM_DISCARDABLE which does not start with .debug

How about I do all that, and instead of raising an error if there is a discardable section that doesn't start with .debug, I emit the 'D' flag?

SGTM

rnk updated this revision to Diff 71451.Sep 14 2016, 3:26 PM
rnk edited edge metadata.
  • Implicitly make .debug sections discardable.
rnk retitled this revision from [MC] Add section flag 'D' for disardable COFF sections to [MC] Handle discardable COFF sections in assembly.Sep 14 2016, 3:27 PM
rnk updated this object.
majnemer accepted this revision.Sep 14 2016, 3:38 PM
majnemer edited edge metadata.

LGTM

This revision is now accepted and ready to land.Sep 14 2016, 3:38 PM
majnemer added inline comments.Sep 14 2016, 3:39 PM
lib/MC/MCSectionCOFF.cpp
67

Maybe parens because of the bitwise operator?

rnk added a comment.Sep 14 2016, 3:41 PM

Thanks!

lib/MC/MCSectionCOFF.cpp
67

Yeah, man, I can never remember the bitwise operator precedence. Parens++

This revision was automatically updated to reflect the committed changes.