<div dir="ltr"><div dir="ltr">On Wed, Dec 19, 2018 at 12:16 PM Fāng-ruì Sòng <<a href="mailto:maskray@google.com">maskray@google.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
On 2018-12-19, Joerg Sonnenberger wrote:<br>
>On Wed, Dec 19, 2018 at 09:48:06AM -0800, Fāng-ruì Sòng via llvm-commits wrote:<br>
>> Can you give an example of writable SHT_NOTE section?<br>
><br>
>You can create it in assembler by hand? I'm not sure if there are<br>
>documented case of (intentionally) writable SHT_NOTE sections><br>
>Joerg<br>
<br>
% cat n.s<br>
.section .note.a, "aw", @note<br>
.quad 0<br>
<br>
.text<br>
nop<br>
<br>
.data<br>
.quad 0<br>
<br>
% as n.s -o n.o<br>
n.s: Assembler messages:<br>
n.s:1: Warning: setting incorrect section attributes for .note.a<br>
<br>
The warning suggests this may not be a reasonable construct. After this<br>
revision, lld does something similar to ld.bfd (there are two RW PT_LOAD<br>
segments, which is only one in gold) The output is still valid.<br>
Considering the construct itself (writable SHT_NOTE) may be<br>
questionable, I don't think we have to complicate the code a bit to<br>
handle the case.<br></blockquote><div><br></div><div>I agree with Fang-rui. I cannot immediately come up with a valid use case of writable .note sections. You can indeed create a writable .note section by hand, but you can probably create a writable .interp section by creating an writable .interp section by hand, so that's I think OK.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
% ld.bfd n.o -o n; readelf -WS n<br>
ld.bfd: warning: cannot find entry symbol _start; defaulting to 00000000004000b8<br>
There are 7 section headers, starting at offset 0x200200:<br>
<br>
Section Headers:<br>
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al<br>
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0<br>
  [ 1] .note.a           NOTE            00000000004000b0 0000b0 000008 00  WA  0   0  1<br>
  [ 2] .text             PROGBITS        00000000004000b8 0000b8 000001 00  AX  0   0  4<br>
  [ 3] .data             PROGBITS        00000000006000b9 2000b9 000008 00  WA  0   0  1<br>
  [ 4] .symtab           SYMTAB          0000000000000000 2000c8 0000d8 18      5   5  8<br>
  [ 5] .strtab           STRTAB          0000000000000000 2001a0 00002f 00      0   0  1<br>
  [ 6] .shstrtab         STRTAB          0000000000000000 2001cf 00002f 00      0   0  1<br>
<br>
% gold n.o -o n; readelf -WS n<br>
There are 8 section headers, starting at offset 0x1d8:<br>
<br>
Section Headers:<br>
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al<br>
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0<br>
  [ 1] .text             PROGBITS        00000000004000e8 0000e8 000001 00  AX  0   0  4<br>
  [ 2] .data             PROGBITS        00000000004010e9 0000e9 000008 00  WA  0   0  1<br>
  [ 3] .note.a           NOTE            00000000004010f1 0000f1 000008 00  WA  0   0  1<br>
  [ 4] .note.gnu.gold-version NOTE            0000000000000000 0000fc 00001c 00      0   0  4<br>
  [ 5] .symtab           SYMTAB          0000000000000000 000118 000060 18      6   1  8<br>
  [ 6] .strtab           STRTAB          0000000000000000 000178 000019 00      0   0  1<br>
  [ 7] .shstrtab         STRTAB          0000000000000000 000191 000046 00      0   0  1<br>
<br>
% ld.lld n.o -o n; readelf -WS n<br>
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x202000<br>
There are 8 section headers, starting at offset 0x3088:<br>
<br>
Section Headers:<br>
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al<br>
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0<br>
  [ 1] .note.a           NOTE            0000000000201000 001000 000008 00  WA  0   0  1<br>
  [ 2] .text             PROGBITS        0000000000202000 002000 000001 00  AX  0   0  4<br>
  [ 3] .data             PROGBITS        0000000000203000 003000 000008 00  WA  0   0  1<br>
  [ 4] .comment          PROGBITS        0000000000000000 003008 000021 01  MS  0   0  1<br>
  [ 5] .symtab           SYMTAB          0000000000000000 003030 000018 18      7   1  8<br>
  [ 6] .shstrtab         STRTAB          0000000000000000 003048 000038 00      0   0  1<br>
  [ 7] .strtab           STRTAB          0000000000000000 003080 000001 00      0   0  1<br>
<br>
> but the gold comment you quotet earlier certainly considered it.<br>
<br>
The binutils-gdb commit 22f0da72ea2fc99e409548ce883b751aa822c2c3 added<br>
the code (ORDER_RO_NOTE), but I cannot find explanation for this choice.<br>
<br>
<br>
-- <br>
宋方睿<br>
</blockquote></div></div>