[PATCH] D85782: [X86][ELF] Prefer lowering MC_GlobalAddress operands to .Lfoo$local only for STV_DEFAULT globals

Kan Shengchen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 25 02:06:37 PDT 2020


skan added a comment.

I think this introduces an old issue when lowering the instruction.

Ref: https://sourceware.org/bugzilla/show_bug.cgi?id=13600

**Reproducer:**

  __attribute__((visibility("protected"))) void * foo (void) { return (void *)foo; }



  clang -c  -O0  -fpic test.c 
  clang -O0  -fpic test.o  -shared

**Error message:**
bfd/bin/ld: test.o: relocation R_X86_64_PC32 against protected symbol `foo' can not be used when making a shared object

**Analysis:**
 Consider visibility in canBenefitFromLocalAlias function limits the MC's ability to use local reference when selecting operand.

Before this patch, the assemble looks like

          .text
          .file   "test.c"
          .protected      foo                     # -- Begin function foo
          .globl  foo
          .p2align        4, 0x90
          .type   foo, at function
  foo:                                    # @foo
  .Lfoo$local:
          .cfi_startproc
  # %bb.0:                                # %entry
          pushq   %rbp
          .cfi_def_cfa_offset 16
          .cfi_offset %rbp, -16
          movq    %rsp, %rbp
          .cfi_def_cfa_register %rbp
          leaq    .Lfoo$local(%rip), %rax
          popq    %rbp
          .cfi_def_cfa %rsp, 8
          retq
  .Lfunc_end0:

`.Lfoo$local(%rip)` can be calculated directly and is not a relocation when emiting object file, so we no need to worry about the visibility of foo.

After this patch

  leaq    .Lfoo$local(%rip), %rax    ->  leaq    foo(%rip), %rax

The visibility of foo conflicts with the relocation type..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85782



More information about the llvm-commits mailing list