This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [gold] creating linker generated output section and segment
- From: Cary Coutant <ccoutant at gmail dot com>
- To: Henry Cheang <hcheang at gmail dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Wed, 26 Aug 2015 00:44:17 -0700
- Subject: Re: [gold] creating linker generated output section and segment
- Authentication-results: sourceware.org; auth=none
- References: <CAEZ6=7xm1gk8GQhpQvsNewvTdt3jH1VLUgRTJZsiD0SkoWt-WA at mail dot gmail dot com>
> Hi, I'm working on add a new target to gold linker where the abi
> requires the linker to generate a custom section (a custom strtab) and
> mapped to a output segment for simulator use. i.e. This section does
> not need data from input objects.
>
> I'm current doing this in the target's do_finialize_sections() like this:
>
> // create custom output section and segment
> Stringpool *mystrtab = new Stringpool();
> mystrtab->add("mystr1", false, NULL);
> mystrtab->add("mystr2", false, NULL);
> mystrtab->set_string_offsets();
This looks fine.
> // using target's do_make_output_section here which simply does new
> Output_section
> // as layout's make_output_section is private
> Output_section* mystrtab_os = this->make_output_section(".mystrtab",
> elfcpp::SHT_STRTAB,
> elfcpp::SHF_ALLOC);
>
> Output_data_strtab* mystrtab_data = new Output_data_strtab(mystrtab);
> mystrtab_os->add_output_section_data(mystrtab_data);
>
> //do I need to add the section to section_list and how? Below does not work.
> //layout->section_list().push_back(mystrtab_os);
>
> Output_segment* mystrtab_seg =
> layout->make_output_segment(elfcpp::PT_LOPROC+0x1234, 0);
> mystrtab_seg->add_output_section_to_nonload(mystrtab_os, elfcpp::PF_R);
>
> This is currently not working yet with an runtime assert of Output
> section address not valid.
> But I want to make sure I'm on the right track first so I want to ask
> if this the right way to add linker generated sections and segment?
Use Layout::add_output_section_data() to allocate your
Output_data_strtab to an output section. There are several examples of
this in some of the existing targets. For example, in arm.cc:
Output_attributes_section_data* attributes_section =
new Output_attributes_section_data(*this->attributes_section_data_);
layout->add_output_section_data(".ARM.attributes",
elfcpp::SHT_ARM_ATTRIBUTES, 0,
attributes_section, ORDER_INVALID,
false);
-cary