This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix ld to match .data.rel.ro sections more carefully


Both GNU ld and gold share a problem where a variable whose name
begins with "ro" might accidentally end up in a RELRO segment. Compile
the following test program with -fpic -fdata-sections:

#include <stdio.h>

char p[] = "Paris";
char r[] = "Rome";
char l[] = "London";

const char * const paris = p;
const char * rome = r;
const char * london = l;

int main()
{
  printf("%s\n", paris);
  printf("%s\n", london);
  london = "England";
  printf("%s\n", london);
  printf("%s\n", rome);
  rome = "Italy";
  printf("%s\n", rome);
  return 0;
}

The variable "rome" is placed in a data section named
".data.rel.rome", and that matches the pattern that ld uses to place
input sections into .data.rel.ro, which then gets placed in the RELRO
segment, and the program segfaults when trying to assign to "rome".

The attached patch fixes this by matching ".data.rel.ro" and
".data.rel.ro.*" separately (a pattern used for most other similar
cases, but not for the relro sections), and likewise for the
corresponding relocation sections.

Along the way, I found a typo in armbpabi.sc and mep.sc where the
pattern for .rela.data.rel.ro had ".rel.data.rel.ro" ("rel" instead of
"rela").

Tested on x86_64. OK to install?

-cary


2012-05-23  Cary Coutant  <ccoutant@google.com>

ld/
	* scripttempl/armbpabi.sc: Match .data.rel.ro.* sections more
	carefully.  Fix typo where .rela.data.rel.ro matches
	.rel.data.rel.ro.
	* scripttempl/mep.sc: Likewise.
	* scripttempl/elf.sc: Match .data.rel.ro.* sections more carefully.
	* scripttempl/elf64hppa.sc: Likewise.
	* scripttempl/elfxtensa.sc: Likewise.

Attachment: gnuld-data-rel-ro-patch.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]