[PATCH] D96914: [ELF] Don't let __start_/__stop_ retain C identifier name sections

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 22 03:00:32 PST 2021


peter.smith added a comment.

These types of reference can be difficult as it is difficult to know what the users intention with respect to gc_root is. I think that the majority of programs don't depend on all sections being marked live but there are definitely programs out there that do. It may not be easy to migrate all these programs to use alternative means such as SHF_RETAIN. Would it be useful to make this a selectable option for users with lots of existing code that depends on these sections being marked live?

As an aside, in Arm's proprietary linker we have had some experience with trying to come up with a more complex way of handling these types of reference as 
we found that keeping everything was too restrictive for the use case we had for .ARM.exidx sections. We wanted to always generate unwind tables (.ARM.exidx), but to be able to remove all the .ARM.exidx sections and all the exception handling code from the library that process them if no call to throw was found in the program; in effect a semi-automatic -fno-exceptions. A key part of that was only referencing the .ARM.exidx sections via the equivalent of _start and _stop sections. Rather than special case this we wanted to come up with a general mechansim.

I wish I could say we came up with a good automatic solution but we couldn't find anything particularly justifiable. Our thought was to mark sections that were reachable only via a chain of dependencies (relocations or link-order) from _start and _stop symbols as weakly used. Sections reachable from a GC root were strongly used. A weakly used section could be turned into strongly used if one of the weakly used sections had a dependency on a strongly used section defined in the same object file as the weakly used section (the last bit was in effect a hack as we found the gc ineffective without it). This worked reasonably well for .ARM.exidx sections. However while it was intended to generalise to other use cases, such as throwing away unused C++ static constructors, we found this broke too many programs so the whole mechanism only got used for exceptions.



================
Comment at: lld/test/ELF/startstop-gccollect.s:8
 
 ## Check that foo and bar sections are not garbage collected,
 ## we do not want to reclaim sections if they are referred
----------------
Presumably you'd need to update the comment if the change went through.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96914/new/

https://reviews.llvm.org/D96914



More information about the llvm-commits mailing list