PING [PATCH] gold: Support SHF_GNU_RETAIN
Cary Coutant
ccoutant@gmail.com
Mon Dec 14 23:45:04 GMT 2020
+ elfcpp::Elf_Xword ignored_flags;
+ elfcpp::ELFOSABI osabi = object->osabi();
+ if (osabi == elfcpp::ELFOSABI_GNU
+ || osabi == elfcpp::ELFOSABI_FREEBSD)
+ ignored_flags = elfcpp::SHF_GNU_RETAIN;
+ else
+ ignored_flags = 0;
Rather than scatter OS ABI logic all over the place, I'd rather create
a class Osabi that can abstract this logic into one place, and use it
like this:
+ // Get the section flags and mask out any flags that do not
+ // take part in section matching.
+ elfcpp::Elf_Xword sh_flags
+ = (this->get_output_section_flags(shdr.get_sh_flags())
+ & ~object->osabi().ignored_sh_flags());
I've promoted this to the top of the if...else chain so that it gets
done only once in Layout::layout().
In Sized_relobj_file::do_layout(), we can do this:
if (is_pass_one && parameters->options().gc_sections())
{
+ elfcpp::ELFOSABI osabi = this->osabi();
if (this->is_section_name_included(name)
|| layout->keep_input_section (this, name)
|| sh_type == elfcpp::SHT_INIT_ARRAY
- || sh_type == elfcpp::SHT_FINI_ARRAY)
+ || sh_type == elfcpp::SHT_FINI_ARRAY
+ || ((osabi == elfcpp::ELFOSABI_GNU
+ || osabi == elfcpp::ELFOSABI_FREEBSD)
+ && shdr.get_sh_flags() & elfcpp::SHF_GNU_RETAIN) != 0)
{
symtab->gc()->worklist().push_back(Section_id(this, i));
}
The parentheses are messed up here. Using the new Osabi class, I've
simplified this to:
+ || this->osabi().has_shf_retain(shdr.get_sh_flags()))
Updated patch is attached. Will commit shortly.
Thanks for working on this!
-cary
-------------- next part --------------
A non-text attachment was scrubbed...
Name: retain.patch
Type: application/octet-stream
Size: 12697 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20201214/567fef89/attachment-0001.obj>
More information about the Binutils
mailing list