[PATCH] D48792: [ARM] Set execute-only flags in .text.

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 3 09:38:01 PDT 2018


peter.smith added a comment.

As an example for LTO, or just using a single bitcode file I'm thinking of something like

  __attribute__((noinline)) int func1(void) {
      return 123456789;
  }
  
  __attribute__((noinline)) int func2(void) {
      return 987654321;
  }
  
  int main(void) {
      return func2() + func1();
  }

When I compile this with

  clang --target=thumb-linux-gnueabihf -emit-llvm -O1 -mexecute-only -o t.bc t.c -mcpu=cortex-m3 -c

Then the bitcode file will have the execute-only target feature embedded in the per function attributes. For example:

  ; Function Attrs: noinline norecurse nounwind readnone
  define dso_local i32 @func1() local_unnamed_addr #0 {
  entry:
    ret i32 123456789
  }
  ...
  attributes #0 = { noinline, ..., "target-features"="+armv7-m,+execute-only,+hwdiv,+thumb-mode,-crc,-dotprod,-dsp,-hwdiv-arm,-ras" "unsafe-fp-math"="false" "use-soft-float"="false" }

We can then generate code for the bitcode file without passing in -mexecute-only. This is similar to the final "link-step" in a LTO build where the compilation options might not be given by the build system:

  clang t.bc -c --target=thumb-linux-gnueabihf -mcpu=cortex-m3

We can see that purecode has still been generated for the .text section:

  [ 2] .text             PROGBITS        00000000 000034 000000 00  AX  0   0  4
  [ 3] .text             PROGBITS        00000000 000034 00001e 00 AXp  0   0  2

This is with an unpatched clang so my initial 0 sized section doesn't have purecode. If I'm right I'm expecting that the target feature of the initial MCSubtarget won't have execute-only as I didn't pass it on the command line so I'd expect to see the zero sized text section to not have SHF_ARM_PURECODE even when the above patch is applied. I've not got any great ideas of how to solve that right now, perhaps do the change of the TextSection at a later stage when we know if there is at least one function with the execute-only target-feature.


Repository:
  rL LLVM

https://reviews.llvm.org/D48792





More information about the llvm-commits mailing list