[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 02:20:10 PST 2022


dougpuob added a comment.

In D116886#3246619 <https://reviews.llvm.org/D116886#3246619>, @0x59616e wrote:

> 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 this issue may have something to do with the code model ?

Hi @0x59616e:
Thanks for your idea. It works with `-mcmodel=large` option.

  ❯ bin/clang++ hello.cpp --target=m68k-linux-gnu -static -mcmodel=large -o hello.m68k.out
  ❯ qemu-m68k  hello.m68k.out
  Hello M68K!!!

I dumped the sections of the elf, the distance between .text and .rodata is possible greater than 16 bits (0x80047ca8-0x80000168=0x47B40).

  Section Headers:
    [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
    [ 0]                   NULL            00000000 000000 000000 00      0   0  0
    [ 1] .note.ABI-tag     NOTE            80000114 000114 000020 00   A  0   0  4
    [ 2] .init             PROGBITS        80000134 000134 000032 00  AX  0   0  2
    [ 3] .text             PROGBITS        80000168 000168 0471f8 00  AX  0   0  4 <--+ code
    [ 4] __libc_freeres_fn PROGBITS        80047360 047360 00092c 00  AX  0   0  2    |
    [ 5] .fini             PROGBITS        80047c8c 047c8c 00001c 00  AX  0   0  2    |
    [ 6] .rodata           PROGBITS        80047ca8 047ca8 019354 00   A  0   0  2 <--+ .rodata.str1.1
    [ 7] __libc_subfreeres PROGBITS        80060ffc 060ffc 000024 00   A  0   0  2
    [ 8] __libc_IO_vtables PROGBITS        80061020 061020 0002f4 00   A  0   0  2
    [ 9] __libc_atexit     PROGBITS        80061314 061314 000004 00   A  0   0  2


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