[PATCH] D73999: [MC][ELF] Error for sh_type, sh_flags or sh_entsize change

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 22 13:07:39 PDT 2020


MaskRay added a comment.

In D73999#2232111 <https://reviews.llvm.org/D73999#2232111>, @dim wrote:

> After this change, it turns out that some of the errors that this results in can be very confusing. For example, when building ocaml, it uses a .S file (https://github.com/ocaml/ocaml/blob/trunk/runtime/amd64.S#L729) containing:
>
>   .section .rodata.cst8,"a", at progbits
>
> Note that this is the first time in the file any such section is mentioned! Then clang 11 gives an error which appears to indicate that the flags and entsize have "changed", even though the user has no idea that these sections apparently have built-in defaults:
>
>   amd64.S:1:1: error: changed section flags for .rodata.cst8, expected: 0x12
>   .section .rodata.cst8,"a", at progbits
>   ^
>   amd64.S:1:1: error: changed section entsize for .rodata.cst8, expected: 8
>   .section .rodata.cst8,"a", at progbits
>   ^
>
> Apparently the flags must be `"aM"`` instead, but that is hard to tell from the error message. Also, the directive does not specify an entsize at all, so how can it then complain that changed? That latter error message is not only misleading, but simply incorrect.
>
> If you change the flags to `"aM"`, the complaint about the 'changed' flags goes away, but now you get another error about entsize:
>
>   md64.S:1:37: error: expected the entry size
>   .section .rodata.cst8,"aM", at progbits
>                                       ^
>
> So now it suddenly expects that size, while it previously fetched some internal default from somewhere?
>
> Note that GNU as (I used 2.33.1) has much less trouble with all this:
>
> - If you assemble the first example, e.g. `.section .rodata.cst8,"a", at progbits`, it will not warn at all.
> - If you assemble the second example, e.g. `.section .rodata.cst8,"aM", at progbits`, it will warn: `amd64.S:1: Warning: entity size for SHF_MERGE not specified`. Which is much nicer, and does not break the build.

GNU as knows that `.rodata.*` needs to be non-SHF_WRITE. It warns `ignoring changed section attributes for .rodata.cst8` if the section flag `w` is set.
It does appear to ignore `M`. The rule it uses is quite complex (gas/config/obj-elf.c:obj_elf_change_section).

LLVM MC is less permissive. In this case I think an error is the intended behavior, otherwise the section may collide with a compiler-generated .rodata.cst8 which has the SHF_MERGE flag (you can use the `.section` directive in inline assembly).

I think ocaml needs to be patched in this case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73999/new/

https://reviews.llvm.org/D73999



More information about the llvm-commits mailing list