llvm-project/llvm/test/MC/ELF
Fangrui Song 2bfee35cb8 [MC][ELF] Emit a relocation if target is defined in the same section and is non-local
For a target symbol defined in the same section, currently we don't emit
a relocation if VariantKind is VK_None (with few exceptions like RISC-V
relaxation), while GNU as emits one. This causes program behavior
differences with and without -ffunction-sections, and can break intended
symbol interposition in a -shared link.

```
.globl foo
foo:
  call foo      # no relocation. On other targets, may be written as b foo, etc
  call bar      # a relocation if bar is in another section (e.g. -ffunction-sections)
  call foo@plt  # a relocation
```

Unify these cases by always emitting a relocation. If we ever want to
optimize `call foo` in -shared links, we should emit a STB_LOCAL alias
and call via the alias.

ARM/thumb2-beq-fixup.s: we now emit a relocation to global_thumb_fn as GNU as does.
X86/Inputs/align-branch-64-2.s: we now emit R_X86_64_PLT32 to foo as GNU does.

ELF/relax.s: rewrite the test as target-in-same-section.s .
We omitted relocations to `global` and now emit R_X86_64_PLT32.
Note, GNU as does not emit a relocation for `jmp global` (maybe its own
bug). Our new behavior is compatible except `jmp global`.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D72197
2020-01-12 13:46:24 -08:00
..
ARM
abs.s
addrsig-error.s
addrsig.s
alias-reloc.s
alias-to-local.s
alias.s
align-bss.s
align-nops.s
align-size.s
align-text.s
align-zero.s
align.s
bad-expr.s
bad-expr2.s
bad-expr3.s
bad-relocation.s
bad-section.s
basic-elf-32.s
basic-elf-64.s
bracket-exprs.s
bracket.s
bss-large.ll
bss.ll
call-abs.s
cfi-adjust-cfa-offset.s
cfi-advance-loc2.s
cfi-b-key-frame.s
cfi-def-cfa-offset.s
cfi-def-cfa-register.s
cfi-def-cfa.s
cfi-escape.s
cfi-large-model.s
cfi-offset.s
cfi-reg.s
cfi-register.s
cfi-rel-offset.s
cfi-rel-offset2.s
cfi-remember.s
cfi-restore-extended.s
cfi-restore.s
cfi-same-value.s
cfi-sections.s
cfi-signal-frame.s
cfi-undefined.s
cfi-version.ll Migrate function attribute "no-frame-pointer-elim" to "frame-pointer"="all" as cleanups after D56351 2019-12-24 15:57:33 -08:00
cfi-window-save.s
cfi-zero-addr-delta.s
cfi.s
cgprofile-error.s
cgprofile.ll
cgprofile.s
comdat-declaration-errors.s
comdat-dup-group-name.s
comdat-name-number.s
comdat-reloc.s
comdat.s
common-error1.s
common-error2.s
common-error3.s
common-redeclare.s
common.s
common2.s
comp-dir.s Remove some unnecessary REQUIRES: shell lines 2019-09-10 00:06:52 +00:00
compression.s
debug-file-options.s
debug-hash-file.s
debug-line.s
debug-line2.s
debug-loc.s
debug-main-file.s
debug-md5-err.s
debug-md5.s
debug-mixed-md5.ll
debug-prefix-map.s
debug-source.s
diff.s
diff2.s
discriminator.s
div-by-zero.s
dot-symbol-assignment.s
dwarf-file0.s
dwarf-loc0.s
dwo-restrict-relocs.s
dwo-sections.s
elf_directive_previous.s
elf_directive_section.s
empty-dwarf-lines.s
empty-twice.ll
empty.s
entsize.ll
entsize.s
exclude-debug-dwo.s [llvm-readobj] - Fix letters used for dumping section types in GNU style. 2019-12-13 11:31:24 +03:00
fde.s
file-double.s
file.s
gen-dwarf.s
global-offset.s
gnu-type-diagnostics.s
gnu-type.s
got-relaxed-i386.s
got-relaxed-no-relax.s
got-relaxed-rex.s
got-relaxed.s
got.s
ident.s
ifunc-alias.s [ELF][MC] Set types of aliases of IFunc to STT_GNU_IFUNC 2019-09-07 14:58:47 +00:00
ifunc-reloc.s
invalid-symver.s
lcomm.s
leb128.s
lit.local.cfg
local-reloc.s
many-sections-2.s
many-sections-3.s
many-sections.s
merge.s
metadata-declaration-errors.s
multiple-different-symver.s Revert r369233. 2019-08-23 18:01:13 +00:00
multiple-equiv-symver.s
n_bytes.s
no-fixup.s
no-reloc.s
nocompression.s
noexec.s
norelocation.s
offset.s
org.s
pic-diff.s
plt.s
popsection.s
pr9292.s
pr19430.s
pr19582.s
relax-all-flag.s
relax-arith.s
relax-arith2.s
relax-arith3.s
relax-arith4.s
relax-crash.s
reloc-same-name-section.s
relocation-386.s
relocation-pc.s
relocation.s
rename.s
section-metadata-err1.s
section-metadata-err2.s
section-metadata-err3.s
section-metadata-err4.s
section-numeric-flag.s
section-numeric-invalid-type.s
section-numeric-type.s
section-quoting.s
section-relro.ll Added support for "#pragma clang section relro=<name>" 2019-10-15 18:31:10 +00:00
section-sym-err.s
section-sym-err2.s
section-sym.s
section-sym2.s
section-unique-err1.s
section-unique-err2.s
section-unique-err3.s
section-unique-err4.s
section-unique.s
section.s
set.s
size.s
sleb.s
strtab-suffix-opt.s
subsection.s
subtraction-error.s
symbol-names.s
symver-msvc.s
symver-pr23914.s
symver.s Revert r369233. 2019-08-23 18:01:13 +00:00
target-in-same-section.s [MC][ELF] Emit a relocation if target is defined in the same section and is non-local 2020-01-12 13:46:24 -08:00
tls-i386.s
tls.s
type-propagate.s
type.s
uleb-ehtable.s
uleb.s
undef-temp.s
undef.s [MC] Emit unused undefined symbol even if its binding is not set 2019-11-08 14:47:48 -08:00
undefined-debug.s
undefined-directional.s
version.s
weak-diff.s
weak-relocation.s
weak.s
weakref-plt.s
weakref-reloc.s
weakref.s [MC] Emit unused undefined symbol even if its binding is not set 2019-11-08 14:47:48 -08:00
x86_64-reloc-sizetest.s
zero.s