This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [COFF] Don't write long section names for sections that will be mapped at runtime
ClosedPublic

Authored by mstorsjo on Nov 14 2017, 6:20 AM.

Details

Summary

Sections that will be mapped at runtime will only have the short section name available, since the string table it points into isn't mapped. Therefore prefer truncating those names over writing a long name that is unavailable at runtime.

This allows libunwind to find the .eh_frame section at runtime even if the module was built with debug info enabled.

This relates to the issue discussed in D39918.

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Nov 14 2017, 6:20 AM
rnk edited edge metadata.Nov 14 2017, 9:31 AM

I wonder if we should limit the long section name extension to sections that aren't mapped at runtime. This makes sense because if some tool cares about unmapped section contents, they're going to need to look at the file on disk, not the image in memory, and that will have a full symbol table.

Does that make sense, or should we just go with this?

In D40025#924844, @rnk wrote:

I wonder if we should limit the long section name extension to sections that aren't mapped at runtime. This makes sense because if some tool cares about unmapped section contents, they're going to need to look at the file on disk, not the image in memory, and that will have a full symbol table.

Does that make sense, or should we just go with this?

I'd be in favor of that. It'd be more consistent with link's behavior as well (I believe it always truncates).

8 characters ought to be enough for anybody :)

ruiu added inline comments.Nov 14 2017, 11:34 PM
COFF/Writer.cpp
544 ↗(On Diff #122832)

I'd prefer doing this at the very early stage instead of this late. Can you modify InputFiles.cpp so that a section with name ".eh_frame" is read as if ".eh_fram"?

I also wonder if there's a problem if we do not limit it to MinGW. Generally I'd try reducing "if (MinGW)" code, so if we can do this unconditionally, we should do that unconditionally.

mstorsjo added inline comments.Nov 14 2017, 11:45 PM
COFF/Writer.cpp
544 ↗(On Diff #122832)

I guess that's doable as well.

What do you think about @rnk 's suggestion about always truncating it for any section that will be mapped at runtime (only write long names for sections with the flag IMAGE_SCN_MEM_DISCARDABLE, or what's the right way to find out about that)?

I don't mind removing the "if (MinGW)" if what the patch does is considered favourable in general and not just a tradeoff/workaround for this case.

ruiu edited edge metadata.Nov 15 2017, 12:05 AM

What do you think about @rnk 's suggestion about always truncating it for any section that will be mapped at runtime (only write long names for sections with the flag IMAGE_SCN_MEM_DISCARDABLE, or what's the right way to find out about that)?

I think that is a great idea.

mstorsjo updated this revision to Diff 122985.Nov 15 2017, 12:44 AM
mstorsjo retitled this revision from [LLD] [COFF] Always truncate the .eh_frame section name to [LLD] [COFF] Don't write long section names for sections that will be mapped at runtime.
mstorsjo edited the summary of this revision. (Show Details)

Always truncate the names of sections that will be mapped at runtime, as suggested by @rnk.

@ruiu Any comments on this version of the patch?

ruiu accepted this revision.Nov 16 2017, 4:01 AM

LGTM

COFF/Writer.cpp
548 ↗(On Diff #122985)

Please also mention that this is different from MSVC link.exe but we found it is useful to have a section name like ".eh_fram" instead of something like "/4".

This revision is now accepted and ready to land.Nov 16 2017, 4:01 AM
ruiu added a comment.Nov 16 2017, 4:01 AM

With that change, LGTM.

This revision was automatically updated to reflect the committed changes.