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

Sheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 16 00:22:58 PST 2022


0x59616e added a comment.

In D116886#3246562 <https://reviews.llvm.org/D116886#3246562>, @dougpuob wrote:

> In D116886#3242633 <https://reviews.llvm.org/D116886#3242633>, @0x59616e wrote:
>
>> In D116886#3242621 <https://reviews.llvm.org/D116886#3242621>, @myhsu wrote:
>>
>>> In D116886#3240566 <https://reviews.llvm.org/D116886#3240566>, @0x59616e wrote:
>>>
>>>> In D116886#3229948 <https://reviews.llvm.org/D116886#3229948>, @dougpuob wrote:
>>>>
>>>>> Hi @myhsu
>>>>> Even though the instruction selection is focused on `sub 0 x` only, I still want to build a simple function with clang and run it with QEMU user emulator (qemu-m68k). But I have no idea how to cross-compile it with GCC runtime, do you have any document for it or could you show me a brief instruction.
>>>>
>>>> FYI, You can build it with 
>>>> `clang --target=m68k $(SOURCE_FILE) -c -o` 
>>>> and then
>>>> `m68k-linux-gnu-gcc $(SOURCE_OBJECT) -o $(FILE_NAME)`
>>>>
>>>> or
>>>> `clang --target=m68k $(SOURCE_FILE) -o $(FILE_NAME) -ccc-gcc-name linux-gnu-gcc`
>>>>
>>>> Currently lld doesn't have M68k support, but I'm trying on it.
>>>> In the future, you may use lld to link m68k object with:
>>>> `clang --target=m68k $(SOURCE_FILE) -o $(FILE_NAME) -fuse-ld=lld
>>>
>>> LLD is not required, you can use `m68k-linux-gnu-ld` to link. The key is using the correct target triple: m68k-linux-gnu rather than just m68k. Such that the compiler driver can find the right tools (in this case m68k-linux-gnu-ld) and libraries to use.
>>> Actually, I just put up a document regarding m68k cross-compiling: https://m680x0.github.io/doc/cross-compile-how-to
>>
>> That makes sense. Thanks
>
> Hi @0x59616e and @myhsu,
> Thank your reply. Now I can compile a hello program as an elf executable binary for m68k and execute it in Debian (qemu-system-m68k).
>
> But I still cannot build the hello program with `-static`. My sample program just call print("Hello M68K!!!  \n") in main(). Is it an issue?
>
>   ❯ bin/clang++ --target=m68k-linux-gnu -static hello.cpp -o hello.m68k.out
>   /tmp/hello-a7168e.o: in function `main':
>   hello.cpp:(.text+0x14): relocation truncated to fit: R_68K_PC16 against `.rodata.str1.1'
>   clang-14: error: linker command failed with exit code 1 (use -v to see invocation)

Hi,

I haven't dived into the problem, so this just my guess.

It seems that the address of the string (.rodata.str.1, I guess it's the string in your printf) is too far from the instruction itself, PC16 addressing mode is not enough, it needs (maybe ?) PC32.

I guess it's an issue in instruction selector.


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