[PATCH] D116886: [M68k] Instruction selection to choose neg x when mul x -1 (Fix issue 48588)

Douglas Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 16 05:22:03 PST 2022


dougpuob added a comment.

Hi @myhsu,

About the error message, "relocation truncated to fit: R_68K_PC16 against '.rodata.str1.1'" when compile with `-static` option. I traced the source code. M68K doesn't support `CodeModel::Large` and `CodeModel::Kernel`. So, to build a static executable binary via clang, adding `-mcmodel=medium` is a suitable choice at this moment.

I try to compare the object files (before linker) generated by gcc and clang, the following is my result:

[1/2] compile with **clang++** (result: default is R_68K_PC16)

  ❯ bin/clang++ -static -c --target=m68k-linux-gnu ./hello.cpp
  ❯ m68k-linux-gnu-readelf -r ./hello.o
  
  Relocation section '.rela.text' at offset 0x180 contains 2 entries:
   Offset     Info    Type            Sym.Value  Sym. Name + Addend
  00000014  00000305 R_68K_PC16        00000000   .rodata.str1.1 + 0
  0000001c  00000501 R_68K_32          00000000   printf + 0
  
  Relocation section '.rela.eh_frame' at offset 0x198 contains 1 entry:
   Offset     Info    Type            Sym.Value  Sym. Name + Addend
  00000024  00000204 R_68K_PC32        00000000   .text + 0

[2/2] compile with **g++** (result: default is R_68K_32)

  ❯ m68k-linux-gnu-g++ -static -c ./hello.cpp
  ❯ m68k-linux-gnu-readelf -r ./hello.o
  
  Relocation section '.rela.text' at offset 0x180 contains 2 entries:
   Offset     Info    Type            Sym.Value  Sym. Name + Addend
  00000006  00000501 R_68K_32          00000000   .rodata + 0
  0000000c  00000a01 R_68K_32          00000000   puts + 0
  
  Relocation section '.rela.eh_frame' at offset 0x198 contains 1 entry:
   Offset     Info    Type            Sym.Value  Sym. Name + Addend
  00000020  00000204 R_68K_PC32        00000000   .text + 0

Summary the result for their default:

- clang: `R_68K_PC16`
- gcc : `R_68K_32`

I am not sure that is it an issue or a limitation requiring to build `-mcmodel=medium` option? Seems you did it for some purpose because of the exclusive getEffectiveCodeModel() function for M68K. If it is not a limitation, I plan to fix it with another patch.

Another doubt about the function. More precisely, its second parameter, `bool JIT` (https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/M68k/M68kTargetMachine.cpp#L83). Could I know more about it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116886



More information about the llvm-commits mailing list