After commit  "tccelf: unify SHT_NOTE sections" openbsd and freebsd do not work anymore.

I debugged the problem and found that if I disable the GNU_RELRO section the problem disappears.

If I compile examples/ex2.c with tcc and use "readelf -e -W a.out" on openbsd I get:

Program Headers:
  Type           Offset   VirtAddr           PhysAddr  FileSiz  MemSiz   Flg Align   PHDR           0x000040 0x0000000000400040 0x0000000000400040 0x0001c0 0x0001c0 R   0x4   INTERP         0x000940 0x0000000000400940 0x0000000000400940 0x000013 0x000013 R   0x1
      [Requesting program interpreter: /usr/libexec/ld.so]
  LOAD           0x000000 0x0000000000400000 0x0000000000400000 0x000f21 0x000f21 R   0x1000   LOAD           0x000f30 0x0000000000401f30 0x0000000000401f30 0x000a0c 0x000a0c R E 0x1000   LOAD           0x001940 0x0000000000403940 0x0000000000403940 0x000218 0x00040c RW  0x1000   DYNAMIC        0x001940 0x0000000000403940 0x0000000000403940 0x000140 0x000140 RW  0x8   NOTE           0x000958 0x0000000000400958 0x0000000000400958 0x000078 0x000078 R   0x8   GNU_RELRO      0x001940 0x0000000000403940 0x0000000000403940 0x0001c8 0x0001c8 RW  0x1

 Section to Segment mapping:
  Segment Sections...
   00
   01     .interp
   02     .interp .note.gnu.property .note.openbsd.ident .dynsym .dynstr .hash .gnu.hash .rela.got .rela.plt .eh_frame .data.ro
   03     .init .fini .plt .text
   04     .dynamic .got .openbsd.randomdata.retguard.1205 .jcr .ctors .dtors .openbsd.randomdata .openbsd.randomdata.retguard.2473 .openbsd.randomdata.retguard.1471 .openbsd.randomdata.retguard.1773 .bss
   05     .dynamic
   06     .note.gnu.property .note.openbsd.ident
   07     .dynamic .got

The ".bss" is in the same LOAD section as the " .dynamic .got" section.
The problem is that openbsd and freebsd set the whole LOAD section to RO.
This means that the ".bss" section becomes RO and the first write to ".bss" crashes.

If I revert the commit the ".dynamic .got" sections are in a seperate LOAD section.

    Herman


_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to