This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Add function pointer alignment to DataLayout
ClosedPublic

Authored by daltenty on Mar 27 2023, 6:05 PM.

Details

Summary

The alignment of function pointers was added to the Datalayout by
D57335 but currently is unset for the Power target. This will cause us
to compute a conservative minimum alignment of one if places like
Value::getPointerAlignment.

This patch implements the function pointer alignment in the Datalayout
for the Power backend and Power targets in clang, so we can query the
value for a particular Power target.

We come up with the correct value one of two ways:

  • If the target uses function descriptor objects (i.e. ELFv1 & AIX ABIs), then a function pointer points to the descriptor, so use the alignment we would emit the descriptor with.
  • If the target doesn't use function descriptor objects (i.e. ELFv2), a function pointer points to the global entry point, so use the minimum alignment for code on Power (i.e. 4-bytes).

Diff Detail

Event Timeline

daltenty created this revision.Mar 27 2023, 6:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 27 2023, 6:05 PM
daltenty requested review of this revision.Mar 27 2023, 6:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 27 2023, 6:05 PM
daltenty added a reviewer: Restricted Project.Mar 27 2023, 6:05 PM
nemanjai accepted this revision.Apr 3 2023, 3:03 PM

LGTM. Maybe give others a bit of time to chime in.

This revision is now accepted and ready to land.Apr 3 2023, 3:03 PM
This revision was landed with ongoing or failed builds.Apr 18 2023, 10:02 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 18 2023, 10:02 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

This is causing buildbot failures e.g., https://lab.llvm.org/buildbot/#/builders/5/builds/33084:

******************** TEST 'lld :: ELF/lto/ppc.ll' FAILED ********************
...
ld.lld: /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/CodeGen/MachineFunction.cpp:231: void llvm::MachineFunction::init(): Assertion `Target.isCompatibleDataLayout(getDataLayout()) && "Can't create a MachineFunction using a Module with a " "Target-incompatible DataLayout attached\n"' failed.
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/tools/lld/test/ELF/lto/Output/ppc.ll.script: line 10: 1277639 Aborted                 (core dumped) /b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/ld.lld /b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/tools/lld/test/ELF/lto/Output/ppc.ll.tmp/32le.o -o /b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/tools/lld/test/ELF/lto/Output/ppc.ll.tmp/32le

I reproduced the build error locally for this commit (8d2e9fc8553c91b1f22e82ffc2c00020f40bb0a2), while also verifying that the immediately preceding commit (221350965a891fc4ce33ea311428448939678112) did not have this error.

Could you please take a look at this?

thurston added a comment.EditedApr 18 2023, 1:30 PM

Ah, I just noticed you had a follow-up commit (https://reviews.llvm.org/rG0236564771b432ebf050144eda4ef4b7424db8c3). I'm re-running the tests/build.

edit: it passed