Skip to content

Attempt to fix PPC/PPC64 ABI issues#1905

Merged
dnadlinger merged 4 commits intoldc-developers:masterfrom
kinke:ppc
Dec 1, 2016
Merged

Attempt to fix PPC/PPC64 ABI issues#1905
dnadlinger merged 4 commits intoldc-developers:masterfrom
kinke:ppc

Conversation

@kinke
Copy link
Member

@kinke kinke commented Nov 29, 2016

Continuation of #1683.

redstar and others added 2 commits November 29, 2016 20:13
Issue ldc-developers#1652 seems to be caused by ABI errors in the bootstrap compiler.
This PR updates the PPC/PPC64 ABI to conform to clang/gcc output.
@kinke
Copy link
Member Author

kinke commented Nov 29, 2016

Kai mentioned that LDC was able to compile itself back then, but that one test still failed. I assume it's the one wrt. reversed sorting, which was also a problem for ARM as long as the arguments order wasn't reversed for extern(D).

@kinke
Copy link
Member Author

kinke commented Nov 29, 2016

Note that #1680 was merged, i.e., Kai's fixes are in ltsmaster, but not in master.

void rewriteFunctionType(TypeFunction *tf, IrFuncTy &fty) override {
if (!fty.ret->byref) {
rewriteArgument(fty, *fty.ret);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that MIPS64TargetABI::rewriteArgument() is empty and needs to be implemented, so this ABI has probably never been properly tested. Almost all ABIs rewrite a non-sret return value just like a regular argument of the same type.

if (!arg->byref)
rewriteArgument(fty, *arg);
else if (passByVal(arg->type))
arg->attrs.remove(LLAttribute::ByVal);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should never happen; IIRC, LLVM's byval attribute is never considered for args passed by ref.

Copy link
Member Author

@kinke kinke Nov 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh not so sure anymore, I think IrFuncTyArg::byref is set if the arg is to be passed with LLVM's byval attribute (passByVal(arg->type) == true), which means that that decision is overridden here, clearing the byval attribute but leaving IrFuncTyArg::byref intact, so that a D argument passed by value for which passByVal(arg->type) == true is actually passed by reference!

Most importantly, make sure sret is enforced for all non-POD structs as
done for all other ABIs, and don't treat extern(D) any different from the
C ABI wrt. return values anymore.

Also reduce code duplication via common TargetABI patterns.
@kinke
Copy link
Member Author

kinke commented Nov 29, 2016

@joakim-noah, @smolt: It would be nice if you could verify everything still works.

@joakim-noah
Copy link
Contributor

Compiling ltsmaster natively on Android/ARM with the ARM portion of this PR, then will try the full PR with master. That'll cover ARM soft-float, somebody with an armhf board will have to test that separately.

@kalev
Copy link
Contributor

kalev commented Nov 30, 2016

I tested the pull request and it fixes the ppc64 issue, #1904 for me. Thanks!

I ran it through Fedora's armv7hl, x86_64, ppc64le, ppc64, i686 builders and ldc can successfully build itself on all of these now.

@kinke
Copy link
Member Author

kinke commented Nov 30, 2016

Excellent, thank you very much!

@joakim-noah
Copy link
Contributor

joakim-noah commented Dec 1, 2016

Full stdlib and dmd testsuite passes with this PR on Android/ARM with ltsmaster and master.

@dnadlinger dnadlinger merged commit 38be953 into ldc-developers:master Dec 1, 2016
@dnadlinger
Copy link
Member

dnadlinger commented Dec 1, 2016

I assume it's the one wrt. reversed sorting, which was also a problem for ARM as long as the arguments order wasn't reversed for extern(D).

Why would that be, though?

@kinke
Copy link
Member Author

kinke commented Dec 1, 2016

See #865 and dlang/dmd#5232 as to why druntime and the compiler itself currently depend on the reversed order.
Thanks @joakim-noah.
I'll cherry-pick these fixes into ltsmaster too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants