Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
bfd: prune COFF/PE section flags setting
Browse files Browse the repository at this point in the history
It is my understanding that IMAGE_SCN_LNK_* are supposed to communicate
information to the (static) linker, and become at best meaningless in PE
images. I wouldn't call loaders wrong which would refuse to process
sections with any of these bits set. While there's no replacement for
IMAGE_SCN_LNK_COMDAT, use IMAGE_SCN_MEM_DISCARDABLE in place of
IMAGE_SCN_LNK_REMOVE in this case.
  • Loading branch information
jbeulich committed Mar 4, 2021
1 parent 6fa7408 commit 6b5465b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions bfd/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2021-03-04 Jan Beulich <[email protected]>

* coffcode.h (sec_to_styp_flags): Don't set IMAGE_SCN_LNK_* in
final PE images.

2021-03-04 Alan Modra <[email protected]>

* rs6000-core.c (rs6000coff_core_p): Correct prototype.
Expand Down
15 changes: 12 additions & 3 deletions bfd/coffcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,22 +672,31 @@ sec_to_styp_flags (const char *sec_name, flagword sec_flags)
/* skip ROM */
/* skip constRUCTOR */
/* skip CONTENTS */
#ifndef COFF_IMAGE_WITH_PE
/* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
when the output is PE. Only object files should have them, for the linker
to consume. */
if ((sec_flags & SEC_IS_COMMON) != 0)
styp_flags |= IMAGE_SCN_LNK_COMDAT;
#endif
if ((sec_flags & SEC_DEBUGGING) != 0)
styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
if ((sec_flags & SEC_EXCLUDE) != 0 && !is_dbg)
styp_flags |= IMAGE_SCN_LNK_REMOVE;
if ((sec_flags & SEC_NEVER_LOAD) != 0 && !is_dbg)
if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
#ifdef COFF_IMAGE_WITH_PE
styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
#else
styp_flags |= IMAGE_SCN_LNK_REMOVE;
#endif
/* skip IN_MEMORY */
/* skip SORT */
#ifndef COFF_IMAGE_WITH_PE
if (sec_flags & SEC_LINK_ONCE)
styp_flags |= IMAGE_SCN_LNK_COMDAT;
if ((sec_flags
& (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
| SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
styp_flags |= IMAGE_SCN_LNK_COMDAT;
#endif

/* skip LINKER_CREATED */

Expand Down

0 comments on commit 6b5465b

Please sign in to comment.