Bug 27565 - ld: Support input section description keyword: REVERSE
Summary: ld: Support input section description keyword: REVERSE
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-11 21:25 UTC by Fangrui Song
Modified: 2021-03-11 21:25 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2021-03-11 21:25:07 UTC
REVERSE complements SORT, e.g.

  SECTIONS { .aaa : { *(REVERSE(SORT_BY_NAME(.aaa.*))) } }

If the user wants to detect some static initialization order fiasco issues, they can specify:

  # If https://sourceware.org/bugzilla/show_bug.cgi?id=26404 is supported,
  # the user can provide a fragment instead of a full linker script

  .init_array : {
     *(SORT_BY_INIT_PRIORITY(REVERSE(.init_array.* .ctors.*)))
     *(REVERSE(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
   }

which runs static constructors in a reversed order.