Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed Checking missing-syscalls for O32 #37411

Closed
xiangzhai opened this issue Jul 5, 2018 · 14 comments
Closed

Failed Checking missing-syscalls for O32 #37411

xiangzhai opened this issue Jul 5, 2018 · 14 comments
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category wontfix Issue is real, but we can't or won't fix it. Not invalid

Comments

@xiangzhai
Copy link
Member

Bugzilla Link 38063
Resolution WONTFIX
Resolved on Jan 23, 2019 06:05
Version trunk
OS Linux
CC @zygoloid,@atanasyan

Extended Description

Hi LLVM developers,

I am building Linux Kernel[1] with LLVM toolchain[2] for mips64el.
But it failed Checking missing-syscalls for O32:

error: ABI 'o32' is not supported on CPU 'mips64r2'
Kbuild:98: recipe for target 'missing-syscalls' failed
make[1]: *** [missing-syscalls] Error 1

GCC is able to work:

...
Checking missing-syscalls for O32
CHK include/generated/timeconst.h
CHK include/generated/bounds.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
CHK include/generated/bounds.h
CHK include/generated/timeconst.h
CHK include/generated/asm-offsets.h
...

So ugly workaround patch:

diff --git a/lib/Basic/Targets/Mips.cpp b/lib/Basic/Targets/Mips.cpp
index cbd5a01..59dd34b 100644
--- a/lib/Basic/Targets/Mips.cpp
+++ b/lib/Basic/Targets/Mips.cpp
@@ -207,8 +207,7 @@ bool MipsTargetInfo::validateTarget(DiagnosticsEngine &Diags) const {
// FIXME: It's valid to use O32 on a 64-bit CPU but the backend can't handle
// this yet. It's better to fail here than on the backend assertion.
if (processorSupportsG#64 () && ABI == "o32") {

  • Diags.Report(diag::err_target_unsupported_abi) << ABI << CPU;
  • return false;
  • return true;
    }

// 64-bit ABI's require 64-bit CPU's.

  1. Linux Kernel 4.9 branch https://github.com/loongson-community/linux-stable
  2. Loongson clang version 7.0.0 (git@github.com:llvm-mirror/clang.git ef356db5c03a0f052c09ebd0a964b9eda3852847) (git@github.com:llvm-mirror/llvm.git ab9920d16bc0acaa2a458b49a43b3aaa9bcda8e6) (based on LLVM 7.0.0svn)
    Target: mips64el-redhat-linux
    Thread model: posix
    InstalledDir: /opt/llvm-git/bin
    Found candidate GCC installation: /usr/lib/gcc/mips64el-redhat-linux/4.9.3
    Selected GCC installation: /usr/lib/gcc/mips64el-redhat-linux/4.9.3
    Candidate multilib: .;
    Selected multilib: .;

Regards,
Leslie Zhai

@atanasyan
Copy link
Collaborator

Unfortunately the backend does not support O32 ABI on 64-bit CPU so this fix just suppresses the error and leads to other errors and/or incorrectly generated code.

@xiangzhai
Copy link
Member Author

Hi Simon,

Thanks for your response! and congratulations for new code owner of MIPS backend. My motivation is Compiling Linux kernel with LLVM[1] but our GCC toolchain[2] is able to pass the O32 ABI checking. And I have learned MIPS Software Standards (ABIs) in the Chapter 11 of 'See MIPS Run'[3], MIPS Architecture in the Chapter 6 of 'Digital Design and Computer Architecture'[4]. Please teach me how to fix the issue correctly, not like my monkey patch, thanks a lot!

  1. Compiling Android userspace and Linux kernel with LLVM http://llvm.org/devmtg/2017-10/#talk21
  2. Loongson GCC https://github.com/loongson-community/gcc
  3. See MIPS Run, Second Edition https://www.amazon.com/Second-Morgan-Kaufmann-Computer-Architecture/dp/0120884216
  4. https://www.amazon.com/Digital-Design-Computer-Architecture-Second/dp/0123944244

Regards,
Leslie Zhai https://reviews.llvm.org/p/xiangzhai/

@atanasyan
Copy link
Collaborator

In short, it's a difficult task. If you really need to support O32 ABI on 64-bit CPUs, I would recommend to start from the backend. Take a look at test/MC/Mips test cases with the -target-abi option. For example cpload.s. Add -mcpu=mips64r2 -target-abi o32 case to them, then teach the backend to emit a correct code, etc ...

By the way, a) could you switch to mips32r2 option? b) could you use or build and use a toolchain with N64 ABI support?

@xiangzhai
Copy link
Member Author

In short, it's a difficult task. If you really need to support O32 ABI on
64-bit CPUs, I would recommend to start from the backend. Take a look at
test/MC/Mips test cases with the -target-abi option. For example cpload.s.
Add -mcpu=mips64r2 -target-abi o32 case to them, then teach the backend to
emit a correct code, etc ...

Thanks for your teaching! I will try to implement it and let you to review the patch.

By the way, a) could you switch to mips32r2 option? b) could you use or
build and use a toolchain with N64 ABI support?

Loongson 3A3000[1] is MIPS64r2, so I couldn't switch to mips32r2, correct? My LLVM toolchain[2] support N64 ABI, is there something wrong, please teach me, thanks a lot!

  1. Loongson 3A3000 https://en.wikipedia.org/wiki/Loongson#Loongson_microprocessor_specifications
  2. $ cat hello.c
    #include <stdio.h>

int main(int argc, char *argv[]) {
printf("Hello Loongson\n");
return 0;
}

$ /opt/llvm-git/bin/clang hello.c
$ file a.out
a.out: ELF 64-bit LSB executable, MIPS, MIPS64 rel2 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, not stripped
$ readelf -a a.out
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x1200008e0
Start of program headers: 64 (bytes into file)
Start of section headers: 4944 (bytes into file)
Flags: 0x80a20007, noreorder, pic, cpic, loongson-3a, mips64r2
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 10
Size of section headers: 64 (bytes)
Number of section headers: 31
Section header string table index: 28

Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .MIPS.options MIPS_OPTIONS 0000000120000270 00000270
0000000000000168 0000000000000001 Ao 0 0 8
[ 2] .dynamic DYNAMIC 00000001200003d8 000003d8
00000000000001f0 0000000000000010 A 5 0 8
[ 3] .hash HASH 00000001200005c8 000005c8
0000000000000050 0000000000000004 A 4 0 8
[ 4] .dynsym DYNSYM 0000000120000618 00000618
0000000000000168 0000000000000018 A 5 1 8
[ 5] .dynstr STRTAB 0000000120000780 00000780
00000000000000dd 0000000000000000 A 0 0 1
[ 6] .gnu.version VERSYM 000000012000085e 0000085e
000000000000001e 0000000000000002 A 4 0 2
[ 7] .gnu.version_r VERNEED 0000000120000880 00000880
0000000000000020 0000000000000000 A 5 1 8
[ 8] .init PROGBITS 00000001200008a0 000008a0
0000000000000040 0000000000000000 AX 0 0 4
[ 9] .text PROGBITS 00000001200008e0 000008e0
00000000000002c0 0000000000000000 AX 0 0 16
[10] .MIPS.stubs PROGBITS 0000000120000ba0 00000ba0
0000000000000030 0000000000000000 AX 0 0 8
[11] .fini PROGBITS 0000000120000bd0 00000bd0
0000000000000028 0000000000000000 AX 0 0 4
[12] .rodata PROGBITS 0000000120000bf8 00000bf8
0000000000000014 0000000000000000 A 0 0 4
[13] .interp PROGBITS 0000000120000c0c 00000c0c
000000000000000f 0000000000000000 A 0 0 1
[14] .eh_frame_hdr PROGBITS 0000000120000c1c 00000c1c
000000000000001c 0000000000000000 A 0 0 4
[15] .eh_frame PROGBITS 0000000120000c38 00000c38
0000000000000074 0000000000000000 A 0 0 8
[16] .note.ABI-tag NOTE 0000000120000cac 00000cac
0000000000000020 0000000000000000 A 0 0 4
[17] .init_array INIT_ARRAY 0000000120010fe8 00000fe8
0000000000000008 0000000000000000 WA 0 0 8
[18] .fini_array FINI_ARRAY 0000000120010ff0 00000ff0
0000000000000008 0000000000000000 WA 0 0 8
[19] .jcr PROGBITS 0000000120010ff8 00000ff8
0000000000000008 0000000000000000 WA 0 0 8
[20] .data PROGBITS 0000000120011000 00001000
0000000000000010 0000000000000000 WA 0 0 16
[21] .rld_map PROGBITS 0000000120011010 00001010
0000000000000008 0000000000000000 WA 0 0 8
[22] .got PROGBITS 0000000120011020 00001020
00000000000000a0 0000000000000008 WAp 0 0 16
[23] .sdata PROGBITS 00000001200110c0 000010c0
0000000000000008 0000000000000000 WAp 0 0 8
[24] .bss NOBITS 00000001200110d0 000010c8
0000000000000010 0000000000000000 WA 0 0 16
[25] .comment PROGBITS 0000000000000000 000010c8
0000000000000101 0000000000000001 MS 0 0 1
[26] .pdr PROGBITS 0000000000000000 000011cc
0000000000000060 0000000000000000 0 0 4
[27] .gnu.attributes LOOS+ffffff5 0000000000000000 0000122c
0000000000000010 0000000000000000 0 0 1
[28] .shstrtab STRTAB 0000000000000000 0000123c
0000000000000113 0000000000000000 0 0 1
[29] .symtab SYMTAB 0000000000000000 00001b10
0000000000000708 0000000000000018 30 50 8
[30] .strtab STRTAB 0000000000000000 00002218
00000000000002bc 0000000000000000 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)

There are no section groups in this file.

Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000120000040 0x0000000120000040
0x0000000000000230 0x0000000000000230 R E 8
INTERP 0x0000000000000c0c 0x0000000120000c0c 0x0000000120000c0c
0x000000000000000f 0x000000000000000f R 1
[Requesting program interpreter: /lib64/ld.so.1]
LOAD 0x0000000000000000 0x0000000120000000 0x0000000120000000
0x0000000000000ccc 0x0000000000000ccc R E 10000
LOAD 0x0000000000000fe8 0x0000000120010fe8 0x0000000120010fe8
0x00000000000000e0 0x00000000000000f8 RW 10000
DYNAMIC 0x00000000000003d8 0x00000001200003d8 0x00000001200003d8
0x00000000000001f0 0x00000000000001f0 RWE 8
NOTE 0x0000000000000cac 0x0000000120000cac 0x0000000120000cac
0x0000000000000020 0x0000000000000020 R 4
GNU_EH_FRAME 0x0000000000000c1c 0x0000000120000c1c 0x0000000120000c1c
0x000000000000001c 0x000000000000001c R 4
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RWE 10
GNU_RELRO 0x0000000000000fe8 0x0000000120010fe8 0x0000000120010fe8
0x0000000000000018 0x0000000000000018 R 1
NULL 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 8

Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .MIPS.options .dynamic .hash .dynsym .dynstr .gnu.version .gnu.version_r .init .text .MIPS.stubs .fini .rodata .interp .eh_frame_hdr .eh_frame .note.ABI-tag
03 .init_array .fini_array .jcr .data .rld_map .got .sdata .bss
04 .dynamic
05 .note.ABI-tag
06 .eh_frame_hdr
07
08 .init_array .fini_array .jcr
09

Dynamic section at offset 0x3d8 contains 26 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000c (INIT) 0x1200008a0
0x000000000000000d (FINI) 0x120000bd0
0x0000000000000019 (INIT_ARRAY) 0x120010fe8
0x000000000000001b (INIT_ARRAYSZ) 8 (bytes)
0x000000000000001a (FINI_ARRAY) 0x120010ff0
0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
0x0000000000000004 (HASH) 0x1200005c8
0x0000000000000005 (STRTAB) 0x120000780
0x0000000000000006 (SYMTAB) 0x120000618
0x000000000000000a (STRSZ) 221 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000070000016 (MIPS_RLD_MAP) 0x120011010
0x0000000000000015 (DEBUG) 0x0
0x0000000000000003 (PLTGOT) 0x120011020
0x0000000070000001 (MIPS_RLD_VERSION) 1
0x0000000070000005 (MIPS_FLAGS) NOTPOT
0x0000000070000006 (MIPS_BASE_ADDRESS) 0x120000000
0x000000007000000a (MIPS_LOCAL_GOTNO) 14
0x0000000070000011 (MIPS_SYMTABNO) 15
0x0000000070000012 (MIPS_UNREFEXTNO) 28
0x0000000070000013 (MIPS_GOTSYM) 0x9
0x000000006ffffffe (VERNEED) 0x120000880
0x000000006fffffff (VERNEEDNUM) 1
0x000000006ffffff0 (VERSYM) 0x12000085e
0x0000000000000000 (NULL) 0x0

There are no relocations in this file.

The decoding of unwind sections for machine type MIPS R3000 is not currently supported.

Symbol table '.dynsym' contains 15 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000120000b98 8 FUNC GLOBAL DEFAULT 9 __libc_csu_fini
2: 0000000000000001 0 SECTION GLOBAL DEFAULT ABS _DYNAMIC_LINKING
3: 0000000120000bf8 4 OBJECT GLOBAL DEFAULT 12 _IO_stdin_used
4: 0000000120011010 0 OBJECT GLOBAL DEFAULT 21 __RLD_MAP
5: 0000000120000b00 148 FUNC GLOBAL DEFAULT 9 __libc_csu_init
6: 0000000120000a80 124 FUNC GLOBAL DEFAULT 9 main
7: 0000000120011018 0 OBJECT LOCAL DEFAULT 21 TMC_END
8: 00000001200008a0 0 FUNC GLOBAL DEFAULT 8 _init
9: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
10: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
11: 0000000120000bb0 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2)
12: 0000000000000000 0 FUNC WEAK DEFAULT UND gmon_start
13: 0000000120000ba0 0 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.0 (2)
14: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab

Symbol table '.symtab' contains 75 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000120000270 0 SECTION LOCAL DEFAULT 1
2: 00000001200003d8 0 SECTION LOCAL DEFAULT 2
3: 00000001200005c8 0 SECTION LOCAL DEFAULT 3
4: 0000000120000618 0 SECTION LOCAL DEFAULT 4
5: 0000000120000780 0 SECTION LOCAL DEFAULT 5
6: 000000012000085e 0 SECTION LOCAL DEFAULT 6
7: 0000000120000880 0 SECTION LOCAL DEFAULT 7
8: 00000001200008a0 0 SECTION LOCAL DEFAULT 8
9: 00000001200008e0 0 SECTION LOCAL DEFAULT 9
10: 0000000120000ba0 0 SECTION LOCAL DEFAULT 10
11: 0000000120000bd0 0 SECTION LOCAL DEFAULT 11
12: 0000000120000bf8 0 SECTION LOCAL DEFAULT 12
13: 0000000120000c0c 0 SECTION LOCAL DEFAULT 13
14: 0000000120000c1c 0 SECTION LOCAL DEFAULT 14
15: 0000000120000c38 0 SECTION LOCAL DEFAULT 15
16: 0000000120000cac 0 SECTION LOCAL DEFAULT 16
17: 0000000120010fe8 0 SECTION LOCAL DEFAULT 17
18: 0000000120010ff0 0 SECTION LOCAL DEFAULT 18
19: 0000000120010ff8 0 SECTION LOCAL DEFAULT 19
20: 0000000120011000 0 SECTION LOCAL DEFAULT 20
21: 0000000120011010 0 SECTION LOCAL DEFAULT 21
22: 0000000120011020 0 SECTION LOCAL DEFAULT 22
23: 00000001200110c0 0 SECTION LOCAL DEFAULT 23
24: 00000001200110d0 0 SECTION LOCAL DEFAULT 24
25: 0000000000000000 0 SECTION LOCAL DEFAULT 25
26: 0000000000000000 0 SECTION LOCAL DEFAULT 26
27: 0000000000000000 0 SECTION LOCAL DEFAULT 27
28: 0000000000000000 0 FILE LOCAL DEFAULT ABS /usr/lib/gcc/mips64el-red
29: 0000000120000930 0 NOTYPE LOCAL DEFAULT 9 hlt
30: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
31: 0000000120010ff8 0 OBJECT LOCAL DEFAULT 19 JCR_LIST
32: 0000000120000940 0 FUNC LOCAL DEFAULT 9 deregister_tm_clones
33: 0000000120000988 0 FUNC LOCAL DEFAULT 9 register_tm_clones
34: 00000001200009d8 0 FUNC LOCAL DEFAULT 9 __do_global_dtors_aux
35: 00000001200110d0 1 OBJECT LOCAL DEFAULT 24 completed.6044
36: 0000000120010ff0 0 OBJECT LOCAL DEFAULT 18 __do_global_dtors_aux_fin
37: 0000000120000a28 0 FUNC LOCAL DEFAULT 9 frame_dummy
38: 0000000120010fe8 0 OBJECT LOCAL DEFAULT 17 _frame_dummy_init_array
39: 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.c
40: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
41: 0000000120000ca8 0 OBJECT LOCAL DEFAULT 15 FRAME_END
42: 0000000120010ff8 0 OBJECT LOCAL DEFAULT 19 JCR_END
43: 0000000000000000 0 FILE LOCAL DEFAULT ABS
44: 0000000120000ba0 0 FUNC LOCAL DEFAULT 10 MIPS_STUBS
45: 0000000120010ff0 0 NOTYPE LOCAL DEFAULT 17 __init_array_end
46: 00000001200003d8 0 OBJECT LOCAL DEFAULT 2 _DYNAMIC
47: 0000000120010fe8 0 NOTYPE LOCAL DEFAULT 17 __init_array_start
48: 0000000120011018 0 OBJECT LOCAL DEFAULT 21 TMC_END
49: 0000000120019010 0 NOTYPE LOCAL DEFAULT ABS _gp
50: 0000000120000b98 8 FUNC GLOBAL DEFAULT 9 __libc_csu_fini
51: 0000000000000001 0 SECTION GLOBAL DEFAULT ABS _DYNAMIC_LINKING
52: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab
53: 0000000120011000 0 OBJECT WEAK DEFAULT 20 data_start
54: 0000000120000ba0 0 FUNC GLOBAL DEFAULT UND printf@@GLIBC_2.0
55: 00000001200110c8 0 NOTYPE GLOBAL DEFAULT 23 _edata
56: 0000000120000bd0 0 FUNC GLOBAL DEFAULT 11 _fini
57: 0000000120011000 0 OBJECT GLOBAL DEFAULT 20 __data_start
58: 0000000000000000 0 FUNC WEAK DEFAULT UND gmon_start
59: 00000001200110c0 0 OBJECT GLOBAL HIDDEN 23 __dso_handle
60: 0000000120000bf8 4 OBJECT GLOBAL DEFAULT 12 _IO_stdin_used
61: 0000000120011000 0 NOTYPE GLOBAL DEFAULT 20 _fdata
62: 0000000120000bb0 0 FUNC GLOBAL DEFAULT UND _libc_start_main@@glibc
63: 0000000120011010 0 OBJECT GLOBAL DEFAULT 21 __RLD_MAP
64: 0000000120000b00 148 FUNC GLOBAL DEFAULT 9 __libc_csu_init
65: 00000001200110e0 0 NOTYPE GLOBAL DEFAULT 24 _end
66: 00000001200110c8 0 NOTYPE GLOBAL DEFAULT 24 __bss_start
67: 0000000120000a80 124 FUNC GLOBAL DEFAULT 9 main
68: 00000001200008e0 0 FUNC GLOBAL DEFAULT 9 __start
69: 00000001200008e0 0 NOTYPE GLOBAL DEFAULT 9 _ftext
70: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
71: 0000000120011020 0 OBJECT GLOBAL HIDDEN 22 GLOBAL_OFFSET_TABLE
72: 00000001200110c8 0 NOTYPE GLOBAL DEFAULT 24 _fbss
73: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
74: 00000001200008a0 0 FUNC GLOBAL DEFAULT 8 _init

Histogram for bucket list length (total of 3 buckets):
Length Number % of total Coverage
0 0 ( 0.0%)
1 0 ( 0.0%) 0.0%
2 0 ( 0.0%) 0.0%
3 1 ( 33.3%) 21.4%
4 0 ( 0.0%) 21.4%
5 1 ( 33.3%) 57.1%
6 1 ( 33.3%) 100.0%

Version symbols section '.gnu.version' contains 15 entries:
Addr: 000000012000085e Offset: 0x00085e Link: 4 (.dynsym)
000: 0 (local) 1 (global) 1 (global) 1 (global)
004: 1 (global) 1 (global) 1 (global) 1 (global)
008: 1 (global) 0 (local) 0 (local) 2 (GLIBC_2.0)
00c: 0 (local) 2 (GLIBC_2.0) 0 (local)

Version needs section '.gnu.version_r' contains 1 entries:
Addr: 0x0000000120000880 Offset: 0x000880 Link: 5 (.dynstr)
000000: Version: 1 File: libc.so.6 Cnt: 1
0x0010: Name: GLIBC_2.0 Flags: none Version: 2

Displaying notes found at file offset 0x00000cac with length 0x00000020:
Owner Data size Description
GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)
OS: Linux, ABI: 2.6.32
Attribute Section: gnu
File Attributes
Tag_GNU_MIPS_ABI_FP: Hard float (double precision)

Primary GOT:
Canonical gp value: 0000000120019010

Reserved entries:
Address Access Initial Purpose
0000000120011020 -32752(gp) 0000000000000000 Lazy resolver
0000000120011028 -32744(gp) 8000000000000000 Module pointer (GNU extension)

Local entries:
Address Access Initial
0000000120011030 -32736(gp) 0000000120000a80
0000000120011038 -32728(gp) 0000000120000b00
0000000120011040 -32720(gp) 0000000120000b98
0000000120011048 -32712(gp) 0000000120010000
0000000120011050 -32704(gp) 0000000120011018
0000000120011058 -32696(gp) 0000000120000000
0000000120011060 -32688(gp) 00000001200008a0
0000000120011068 -32680(gp) 0000000120010fe8
0000000120011070 -32672(gp) 0000000120010ff0
0000000120011078 -32664(gp) 0000000000000000
0000000120011080 -32656(gp) 0000000000000000
0000000120011088 -32648(gp) 0000000000000000

Global entries:
Address Access Initial Sym.Val. Type Ndx Name
0000000120011090 -32640(gp) 0000000000000000 0000000000000000 NOTYPE UND _ITM_registerTMCloneTable
0000000120011098 -32632(gp) 0000000000000000 0000000000000000 NOTYPE UND _Jv_RegisterClasses
00000001200110a0 -32624(gp) 0000000120000bb0 0000000120000bb0 FUNC UND __libc_start_main
00000001200110a8 -32616(gp) 0000000000000000 0000000000000000 FUNC UND gmon_start
00000001200110b0 -32608(gp) 0000000120000ba0 0000000120000ba0 FUNC UND printf
00000001200110b8 -32600(gp) 0000000000000000 0000000000000000 NOTYPE UND _ITM_deregisterTMCloneTable

Regards,
Leslie Zhai

@atanasyan
Copy link
Collaborator

  1. You can use mips32r2 to generate code for a MIPS64 CPU. In that case the code will not contain MIPS64 specific instructions, but will work.

  2. If you can build a N64 ABI executable, you have a N64 ABI toolchain. Why can't you use this toolchain to build Linux?

@xiangzhai
Copy link
Member Author

  1. You can use mips32r2 to generate code for a MIPS64 CPU. In that case the
    code will not contain MIPS64 specific instructions, but will work.

Thanks for your teaching!

  1. If you can build a N64 ABI executable, you have a N64 ABI toolchain. Why
    can't you use this toolchain to build Linux?

It also confused me, but GCC is able to work #37411 #c0

Take a look at test/MC/Mips test cases with the -target-abi option. For
example cpload.s

$ llvm-mc cpload.s -arch=mips64el -mcpu=mips64r2 -target-abi o32 -filetype=obj -o cpload-llvm-o32.o
$ llvm-objdump -d -r cpload-llvm-o32.o

cpload-llvm-o32.o: file format ELF64-mips

Disassembly of section .text:
.text:
0: 00 00 1c 3c lui $gp, 0
0000000000000000: R_MIPS_HI16/R_MIPS_NONE/R_MIPS_NONE _gp_disp
4: 00 00 9c 27 addiu $gp, $gp, 0
0000000000000004: R_MIPS_LO16/R_MIPS_NONE/R_MIPS_NONE _gp_disp
8: 21 e0 99 03 addu $gp, $gp, $25

Why there is R_MIPS_NONE?

$ gcc -c cpload.s -mabi=32 -o cpload-gnu-o32.o
$ llvm-objdump -d -r cpload-gnu-o32.o

cpload-gnu-o32.o: file format ELF32-mips

Disassembly of section .text:
.text:
0: 00 00 1c 3c lui $gp, 0
00000000: R_MIPS_HI16 __gnu_local_gp
4: 00 00 9c 27 addiu $gp, $gp, 0
00000004: R_MIPS_LO16 __gnu_local_gp
8: 00 00 00 00 nop
c: 00 00 00 00 nop

Regards,
Leslie Zhai - an apprentice in MIPS world

@xiangzhai
Copy link
Member Author

If you can build a N64 ABI executable, you have a N64 ABI toolchain. Why
can't you use this toolchain to build Linux?

With the ugly monkey patch, LLVM is able to pass the testcase[1] Checking missing-syscalls for O32, and go forward[2]

  1. [Compiler] Failed Checking missing-syscalls for O32 loongson-community/linux-stable#4
  2. [Compiler] unsupported inline asm: input with type 'unsigned long' loongson-community/linux-stable#5

Regards,
Leslie Zhai

@xiangzhai
Copy link
Member Author

The similar issue:

$ make CC=/opt/loong-llvm/bin/clang
clang-7: warning: argument unused during compilation: '-Wa,-msoft-float' [-Wunused-command-line-argument]
clang-7: warning: argument unused during compilation: '-Wa,--trap' [-Wunused-command-line-argument]
clang-7: warning: argument unused during compilation: '-Wa,-mno-fix-loongson3-llsc' [-Wunused-command-line-argument]
clang-7: warning: argument unused during compilation: '-mno-branch-likely' [-Wunused-command-line-argument]
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
Checking missing-syscalls for N32
CHK include/generated/timeconst.h
CHK include/generated/bounds.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
Checking missing-syscalls for O32
CHK include/generated/timeconst.h
CHK include/generated/bounds.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
CHK include/generated/bounds.h
CHK include/generated/timeconst.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
CC arch/mips/kernel/traps.o
LD arch/mips/kernel/built-in.o
CC arch/mips/mm/page.o
CC arch/mips/mm/tlbex.o
AS arch/mips/mm/tlbex-fault.o
AS arch/mips/mm/tlb-funcs.o
CC arch/mips/mm/uasm-mips.o
CC arch/mips/mm/pgtable-64.o
CC arch/mips/mm/hugetlbpage.o
CC arch/mips/mm/c-r4k.o
AS arch/mips/mm/cex-gen.o
CC arch/mips/mm/tlb-r4k.o
LD arch/mips/mm/built-in.o
LD arch/mips/net/built-in.o
arch/mips/vdso/Makefile:31: MIPS VDSO requires binutils >= 2.25
LDS arch/mips/vdso/vdso.lds
AS arch/mips/vdso/elf.o
AS arch/mips/vdso/sigreturn.o
VDSO arch/mips/vdso/vdso.so.dbg.raw
OBJCOPY arch/mips/vdso/vdso.so.raw
HOSTCC arch/mips/vdso/genvdso
GENVDSO arch/mips/vdso/vdso-image.c
CC arch/mips/vdso/vdso-image.o
LDS arch/mips/vdso/vdso-o32.lds
error: ABI 'o32' is not supported for 'mips64el-redhat-linux'
arch/mips/vdso/Makefile:122: recipe for target 'arch/mips/vdso/vdso-o32.lds' failed
make[2]: *** [arch/mips/vdso/vdso-o32.lds] Error 1

Regards,
Leslie Zhai

@atanasyan
Copy link
Collaborator

$ llvm-mc cpload.s -arch=mips64el -mcpu=mips64r2 -target-abi o32
-filetype=obj -o cpload-llvm-o32.o
$ llvm-objdump -d -r cpload-llvm-o32.o

cpload-llvm-o32.o: file format ELF64-mips

Disassembly of section .text:
.text:
0: 00 00 1c 3c lui $gp, 0
0000000000000000: R_MIPS_HI16/R_MIPS_NONE/R_MIPS_NONE _gp_disp
4: 00 00 9c 27 addiu $gp, $gp, 0
0000000000000004: R_MIPS_LO16/R_MIPS_NONE/R_MIPS_NONE _gp_disp
8: 21 e0 99 03 addu $gp, $gp, $25

Why there is R_MIPS_NONE?

llvm-mc generates 64-bit ELF file. For 64-bit MIPS files llvm-objdump prints relocations accordingly to the N64 ABI specification. In that case each relocation record might contain up to three relocations. See p. 40 at [1].

[1] ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/elf64-2.4.pdf

@xiangzhai
Copy link
Member Author

$ llvm-mc cpload.s -arch=mips64el -mcpu=mips64r2 -target-abi o32
-filetype=obj -o cpload-llvm-o32.o
$ llvm-objdump -d -r cpload-llvm-o32.o

cpload-llvm-o32.o: file format ELF64-mips

Disassembly of section .text:
.text:
0: 00 00 1c 3c lui $gp, 0
0000000000000000: R_MIPS_HI16/R_MIPS_NONE/R_MIPS_NONE _gp_disp
4: 00 00 9c 27 addiu $gp, $gp, 0
0000000000000004: R_MIPS_LO16/R_MIPS_NONE/R_MIPS_NONE _gp_disp
8: 21 e0 99 03 addu $gp, $gp, $25

Why there is R_MIPS_NONE?

llvm-mc generates 64-bit ELF file. For 64-bit MIPS files llvm-objdump prints
relocations accordingly to the N64 ABI specification. In that case each
relocation record might contain up to three relocations. See p. 40 at [1].

[1] ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/elf64-2.4.pdf

Sorry for my late response! So is my output correct?

Regards,
Leslie Zhai

@atanasyan
Copy link
Collaborator

$ llvm-mc cpload.s -arch=mips64el -mcpu=mips64r2 -target-abi o32
-filetype=obj -o cpload-llvm-o32.o
$ llvm-objdump -d -r cpload-llvm-o32.o

cpload-llvm-o32.o: file format ELF64-mips

Disassembly of section .text:
.text:
0: 00 00 1c 3c lui $gp, 0
0000000000000000: R_MIPS_HI16/R_MIPS_NONE/R_MIPS_NONE _gp_disp
4: 00 00 9c 27 addiu $gp, $gp, 0
0000000000000004: R_MIPS_LO16/R_MIPS_NONE/R_MIPS_NONE _gp_disp
8: 21 e0 99 03 addu $gp, $gp, $25

Why there is R_MIPS_NONE?

llvm-mc generates 64-bit ELF file. For 64-bit MIPS files llvm-objdump prints
relocations accordingly to the N64 ABI specification. In that case each
relocation record might contain up to three relocations. See p. 40 at [1].

[1] ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/elf64-2.4.pdf

Sorry for my late response! So is my output correct?

It depends on what you want to geе. If you run gcc with "-mabi=32 -mips64" options, you get 32-bit binaries with MIPS64 instructions. You output from the llvm-mc shows that you get 64-bit binaries.

@xiangzhai
Copy link
Member Author

$ llvm-mc cpload.s -arch=mips64el -mcpu=mips64r2 -target-abi o32
-filetype=obj -o cpload-llvm-o32.o
$ llvm-objdump -d -r cpload-llvm-o32.o

cpload-llvm-o32.o: file format ELF64-mips

Disassembly of section .text:
.text:
0: 00 00 1c 3c lui $gp, 0
0000000000000000: R_MIPS_HI16/R_MIPS_NONE/R_MIPS_NONE _gp_disp
4: 00 00 9c 27 addiu $gp, $gp, 0
0000000000000004: R_MIPS_LO16/R_MIPS_NONE/R_MIPS_NONE _gp_disp
8: 21 e0 99 03 addu $gp, $gp, $25

Why there is R_MIPS_NONE?

llvm-mc generates 64-bit ELF file. For 64-bit MIPS files llvm-objdump prints
relocations accordingly to the N64 ABI specification. In that case each
relocation record might contain up to three relocations. See p. 40 at [1].

[1] ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/elf64-2.4.pdf

Sorry for my late response! So is my output correct?

It depends on what you want to geе. If you run gcc with "-mabi=32 -mips64"
options, you get 32-bit binaries with MIPS64 instructions. You output from
the llvm-mc shows that you get 64-bit binaries.

Thanks for your teaching!

then teach the backend to emit a correct code

#37411 #c3

Could you give me some hint about how to support O32 ABI on 64-bit CPUs? thanks a lot!

Regards,
Leslie Zhai

@atanasyan
Copy link
Collaborator

There is no plan on support O32 for MIPS64 due to lack of resources. But I'm ready to accept and review any related patches.

@xiangzhai
Copy link
Member Author

mentioned in issue llvm/llvm-bugzilla-archive#38128

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@Quuxplusone Quuxplusone added the wontfix Issue is real, but we can't or won't fix it. Not invalid label Jan 20, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category wontfix Issue is real, but we can't or won't fix it. Not invalid
Projects
None yet
Development

No branches or pull requests

3 participants