[PATCH] D102894: [SystemZ] Emit .gnu_attribute for an externally visible vector abi.

Ulrich Weigand via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 31 06:46:31 PDT 2021


uweigand added a comment.

In D102894#2786239 <https://reviews.llvm.org/D102894#2786239>, @jonpa wrote:

> Patch updated - in progress.
>
>> This is probably not even necessary, since even a pointer to a vector would still trigger the emission of the gnu_attribute...
>> Yes, indeed. The alignment of 128-bit vector types is different between the two ABIs, which means that any use of such types, even via pointers or as struct elements, will trigger ABI differences.
>
> Aha... I removed the function attribute emission from clang and now do all the work in SystemZAsmPrinter instead. Added a check for actually passed arguments to a vararg function.
>
>> For an example of how to handle such things, you might look at emitLocalEntry in the PowerPC target. You'll need a virtual function in TargetStreamer.h that can be called by the AsmPrinter.cpp code. Then there need to be two implementations of the virtual function, one for emitting assembler text, and one when directly emitting object files. Finally, you'll need to handle reading the directive in assembler code in the AsmParser.
>
> I did an attempt at this except for the parser part, which seems to work.

Missing parser support is what caused this error:

  ./bin/clang -o b.o -c -O3 ./b.c -march=z13 -mzvector -save-temps
  b.s:27:2: error: unknown directive 

which you'll only see with `-save-temps` (because then it reads back from the assembler file it just wrote).

> The bytes in SystemZTargetELFStreamer are simply copied from GCC output - I have no idea about the actual layout/meaing of that, except for the last two bytes...

The layout is documented in the ARM ABI I refered to above.   See in particular here:

> The overall syntactic structure of an attributes section is:
>
>   <format-version>
>   [ <section-length> "vendor-name"
>         [ <file-tag> <size> <attribute>*
>         | <section-tag> <size> <section-number>* 0 <attribute>*
>         | <symbol-tag> <size> <symbol-number>* 0 <attribute>*
>         ]+
>   ]*

Looking at your example, the bytes you output match the above format:

  0x41 - format-version
  0x00 0x00 0x00 0x0f - section-length
  0x67 0x6e 0x75 0x00 - vendor-name ("gnu")
  0x01 - file-tag
  0x00 0x00 0x00 0x07 - size
  Value Tag - attribute

Note that in order to properly emit this section, you cannot emit the attributes one by one, but you need to collect them somewhere and emit the whole section at the end of the file, otherwise you e.g. cannot get the section-length correct.

>> This isn't really Z specific, so it should probably be implemented somewhere in common code, if it isn't already ...
>
> Actually not sure what should go into common code... ARM defines ARMTargetStreamer with some attribute emission methods, but none for .gnu_attr that I can see.

The ARM attributes go into a different section, and use a different vendor name (not "gnu"), but otherwise the format is the same as described above.  So maybe the code that generates this format can be even shared between the ARM attribute section and the GNU attribute section.  But in any case, the //GNU attribute section// in itself is common across all (ELF) platforms that use the GNU tool chain, so this part should definitely go to common code.


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

https://reviews.llvm.org/D102894



More information about the llvm-commits mailing list