This is an archive of the discontinued LLVM Phabricator instance.

MIPS: fix build from IR files, nan2008 and FpAbi
ClosedPublic

Authored by wzssyqa on Nov 16 2022, 9:23 PM.

Details

Summary

When we use llc or lld to compiler IR files, the features +nan2008 and +fpxx/+fp64 are not used.
Thus wrong format files are produced.

In IR files, the attributes are only set for function while not the whole compile units.
So we output .nan 2008 and .module fp=xx/64 before every function.

isFPXXDefault: for o32, the FPXX should always be the default, no matter about the vendors.
Of course some distributions with FP64 default enabled should be listed explicit.
Let's add them in future if we know about one.

Diff Detail

Event Timeline

wzssyqa created this revision.Nov 16 2022, 9:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 16 2022, 9:23 PM
wzssyqa requested review of this revision.Nov 16 2022, 9:23 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 16 2022, 9:23 PM
wzssyqa updated this revision to Diff 476033.Nov 17 2022, 12:24 AM
wzssyqa updated this revision to Diff 476039.Nov 17 2022, 1:04 AM

Add llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll

wzssyqa edited the summary of this revision. (Show Details)Nov 17 2022, 1:52 AM
MaskRay accepted this revision.Nov 17 2022, 10:32 AM

Rubber stamp. I try to find some mips folks who can verify, so maybe wait a day or so.

When we use llc or lld to compiler IR files, the features +nan2008 and +fpxx/+fp64 are not used. Thus wrong format files are produced.

Not sure lld is related. It just consumes the bitcode input when using LTO. Did you mean Clang?

llvm/lib/Target/Mips/MipsAsmPrinter.cpp
402–412

Seems that you can group TS/MTM declaration together, and then place TS. calls together?

llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll
2
12

Delete unrelated attributes from the list.

This revision is now accepted and ready to land.Nov 17 2022, 10:32 AM

Rubber stamp. I try to find some mips folks who can verify, so maybe wait a day or so.

When we use llc or lld to compiler IR files, the features +nan2008 and +fpxx/+fp64 are not used. Thus wrong format files are produced.

Not sure lld is related. It just consumes the bitcode input when using LTO. Did you mean Clang?

Any program call libllvm to convert IR to asm file or object is effected.
the example is like this:

example 1:

clang -flto -mnan=2008 -O3 -target mipsel-linux-gnu -c test.c   # the nan2008 attribute does set
llc test.o  # the nan2008 is not set in the output test.o.s

example 2

clang -flto -mnan=2008 -O3 -target mipsel-linux-gnu -o a.out test.c
# the output is not nan2008 object
#due to clang doesn't pass -mllvm=-mattr=+nan2008 to lld.

For example2:
We can:

  1. pass -mllvm=-mattr=+nan2008 to lld, while ld.bfd doesn't support it.
  2. make lld/llvm can recognize the attributes #0 = in IR files.
wzssyqa updated this revision to Diff 476302.Nov 17 2022, 6:13 PM
wzssyqa updated this revision to Diff 476303.Nov 17 2022, 6:17 PM
wzssyqa marked 2 inline comments as done.
MaskRay accepted this revision.Nov 19 2022, 3:32 PM
MaskRay added inline comments.
llvm/lib/Target/Mips/MipsAsmPrinter.cpp
402

delete blank line

404

If ABI only used once, avoid the variable

wzssyqa updated this revision to Diff 476716.Nov 19 2022, 6:58 PM
wzssyqa marked 3 inline comments as done.

ahhh, ping.

MaskRay added a comment.EditedDec 15 2022, 1:02 AM

(On a trip so I may be slow.)

I know very little about mips. I wish that some mips experts like @atanasyan can some proper checks but this patch seems fine.
Landing in one minute after testing finishes.

This revision was landed with ongoing or failed builds.Dec 15 2022, 1:04 AM
This revision was automatically updated to reflect the committed changes.

For what it's worth, this breaks building the Linux kernel's ARCH=mips 32r1_defconfig with clang and GNU as, with thousands of messages along the line of:

/tmp/mmc_ops-d329c3.s: Assembler messages:
/tmp/mmc_ops-d329c3.s:310: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:473: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:594: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:687: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:781: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:946: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:1023: Error: .module is not permitted after generating code
...

A simplified reproducer:

void rcu_normal_store() {}
void __attribute__ksysfs_init() {}
$ clang --version | head -1
ClangBuiltLinux clang version 16.0.0 (https://github.com/llvm/llvm-project 9739bb81aed490bfcbcbbac6970da8fb7232fd34)

$ clang --target=mips-linux-gnu -fno-integrated-as -c -o /dev/null ksysfs.i
/tmp/ksysfs-9b0c50.s: Assembler messages:
/tmp/ksysfs-9b0c50.s:44: Error: .module is not permitted after generating code
clang-16: error: assembler command failed with exit code 1 (use -v to see invocation)
$ clang --version | head -1
ClangBuiltLinux clang version 16.0.0 (https://github.com/llvm/llvm-project 92619956eb27ef08dd24045307593fc3d7f78db0)

$ clang --target=mips-linux-gnu -fno-integrated-as -c -o /dev/null ksysfs.i

For what it's worth, this breaks building the Linux kernel's ARCH=mips 32r1_defconfig with clang and GNU as, with thousands of messages along the line of:

/tmp/mmc_ops-d329c3.s: Assembler messages:
/tmp/mmc_ops-d329c3.s:310: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:473: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:594: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:687: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:781: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:946: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:1023: Error: .module is not permitted after generating code
...

A simplified reproducer:

void rcu_normal_store() {}
void __attribute__ksysfs_init() {}

Thanks for your test. I will work it just now.

$ clang --version | head -1
ClangBuiltLinux clang version 16.0.0 (https://github.com/llvm/llvm-project 9739bb81aed490bfcbcbbac6970da8fb7232fd34)

$ clang --target=mips-linux-gnu -fno-integrated-as -c -o /dev/null ksysfs.i
/tmp/ksysfs-9b0c50.s: Assembler messages:
/tmp/ksysfs-9b0c50.s:44: Error: .module is not permitted after generating code
clang-16: error: assembler command failed with exit code 1 (use -v to see invocation)
$ clang --version | head -1
ClangBuiltLinux clang version 16.0.0 (https://github.com/llvm/llvm-project 92619956eb27ef08dd24045307593fc3d7f78db0)

$ clang --target=mips-linux-gnu -fno-integrated-as -c -o /dev/null ksysfs.i

For what it's worth, this breaks building the Linux kernel's ARCH=mips 32r1_defconfig with clang and GNU as, with thousands of messages along the line of:

/tmp/mmc_ops-d329c3.s: Assembler messages:
/tmp/mmc_ops-d329c3.s:310: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:473: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:594: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:687: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:781: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:946: Error: .module is not permitted after generating code
/tmp/mmc_ops-d329c3.s:1023: Error: .module is not permitted after generating code
...

A simplified reproducer:

void rcu_normal_store() {}
void __attribute__ksysfs_init() {}
$ clang --version | head -1
ClangBuiltLinux clang version 16.0.0 (https://github.com/llvm/llvm-project 9739bb81aed490bfcbcbbac6970da8fb7232fd34)

$ clang --target=mips-linux-gnu -fno-integrated-as -c -o /dev/null ksysfs.i
/tmp/ksysfs-9b0c50.s: Assembler messages:
/tmp/ksysfs-9b0c50.s:44: Error: .module is not permitted after generating code
clang-16: error: assembler command failed with exit code 1 (use -v to see invocation)
$ clang --version | head -1
ClangBuiltLinux clang version 16.0.0 (https://github.com/llvm/llvm-project 92619956eb27ef08dd24045307593fc3d7f78db0)

$ clang --target=mips-linux-gnu -fno-integrated-as -c -o /dev/null ksysfs.i