ld_state.as_needed = false;
else if (strcmp (arg, "systemlibrary") == 0)
ld_state.is_system_library = true;
+ else if (strcmp (arg, "execstack") == 0)
+ ld_state.execstack = execstack_true;
+ else if (strcmp (arg, "noexecstack") == 0)
+ ld_state.execstack = execstack_false_force;
else if (strcmp (arg, "allextract") != 0
&& strcmp (arg, "defaultextract") != 0
&& strcmp (arg, "weakextract") != 0
size_t nsymbols = 0;
size_t nlocalsymbols = 0;
bool has_merge_sections = false;
+ /* Unless we have different information we assume the code needs
+ an executable stack. */
+ enum execstack execstack = execstack_true;
/* Prerequisites. */
assert (fileinfo->elf != NULL);
|| shdr->sh_type == SHT_INIT_ARRAY
|| shdr->sh_type == SHT_FINI_ARRAY
|| shdr->sh_type == SHT_PREINIT_ARRAY))
- add_section (fileinfo, &fileinfo->scninfo[cnt]);
+ {
+ /* Check whether the check needs to be executable. */
+ if (shdr->sh_type == SHT_PROGBITS
+ && strcmp (elf_strptr (fileinfo->elf, fileinfo->shstrndx,
+ shdr->sh_name),
+ ".note.GNU-stack") == 0
+ && (shdr->sh_flags & SHF_EXECINSTR) == 0)
+ execstack = execstack_false;
+ printf("%s %d\n", elf_strptr (fileinfo->elf, fileinfo->shstrndx,
+ shdr->sh_name),(int)execstack);
+
+ add_section (fileinfo, &fileinfo->scninfo[cnt]);
+ }
}
+ /* Now we know more about the requirements for an executable stack
+ of the result. */
+ if (fileinfo->file_type == relocatable_file_type
+ && execstack == execstack_true
+ && ld_state.execstack != execstack_false_force)
+ ld_state.execstack = execstack_true;
+ printf("%s: state = %d\n", fileinfo->fname,(int)ld_state.execstack);
+
/* Handle the symbols. Record defined and undefined symbols in the
hash table. In theory there can be a file without any symbol
table. */
XXX Determine whether the segment is non-empty. */
nphdr = 0;
+
+ /* We always add a PT_GNU_stack entry. */
+ ++nphdr;
+
segment = ld_state.output_segments;
while (segment != NULL)
{
xelf_getehdr (ld_state.outelf, ehdr);
assert (ehdr != NULL);
- xelf_getphdr_ptr (ld_state.outelf, 1, phdr);
+ xelf_getphdr_ptr (ld_state.outelf, 0, phdr);
phdr->p_type = PT_PHDR;
phdr->p_offset = ehdr->e_phoff;
phdr->p_vaddr = ld_state.output_segments->addr + phdr->p_offset;
(void) xelf_update_phdr (ld_state.outelf, 0, phdr);
+ /* Add the stack information. */
+ xelf_getphdr_ptr (ld_state.outelf, nphdr, phdr);
+ phdr->p_type = PT_GNU_STACK;
+ phdr->p_offset = 0;
+ phdr->p_vaddr = 0;
+ phdr->p_paddr = 0;
+ phdr->p_filesz = 0;
+ phdr->p_memsz = 0;
+ phdr->p_flags = ld_state.execstack == execstack_true ? PF_X : 0;
+ phdr->p_align = 0;
+
+ (void) xelf_update_phdr (ld_state.outelf, nphdr, phdr);
+ ++nphdr;
+
+
/* Adjust the addresses in the address fields of the symbol
records according to the load addresses of the sections. */
if (ld_state.need_symtab)