This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Fix sanitizers build on FreeBSD
ClosedPublic

Authored by pkubaj on Jan 8 2022, 12:40 PM.

Details

Reviewers
adalava
dim
nemanjai
Group Reviewers
Restricted Project
Summary
  1. Add correct pc, sp and bp for FreeBSD.
  2. Since there's no personality.h header on FreeBSD, move SANITIZER_PPC64V2 case below FREEBSD case.
  3. __ppc_get_timebase_freq() is glibc-specific. Add a shim for FreeBSD that does the same.

Diff Detail

Event Timeline

pkubaj created this revision.Jan 8 2022, 12:40 PM
pkubaj requested review of this revision.Jan 8 2022, 12:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 8 2022, 12:40 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
pkubaj edited the summary of this revision. (Show Details)Jan 8 2022, 12:41 PM

Note that __ppc_get_timebase is pretty much copied from glibc (writing it here to make sure that there are no licensing issues).
That said, I don't think there's any other way to read TBR.

pkubaj updated this revision to Diff 398373.Jan 8 2022, 1:46 PM

I followed lint suggestions for SANITIZER_FREEBSD.
As for SANITIZER_PPC64V2 and below, lint seems to be mistaken.

lkail added a subscriber: lkail.Jan 9 2022, 5:57 PM
pkubaj added a reviewer: kcc.Jan 10 2022, 4:00 AM
pkubaj updated this revision to Diff 406884.Feb 8 2022, 10:09 AM

Bring the diff to the current state of sanitizer_linux.cpp and adjust indents to the convention used in the file.

Also drop 32-bit path from xray_powerpc64.inc since the file is for 64-bits.

Note that __ppc_get_timebase is pretty much copied from glibc (writing it here to make sure that there are no licensing issues).
That said, I don't think there's any other way to read TBR.

Not that there's anything wrong with this implementation (in 64-bit mode), but there is also __builtin_ppc_get_timebase()/__builtin_readcyclecounter().

pkubaj added a comment.Feb 9 2022, 1:24 PM

While it probably wouldn't hurt to use compiler builtins, isn't it better to use system-specific functions? They are probably best tailored for specific systems.
Using builtins IMO would be fine as a fallback (for platforms other than Linux with glibc or FreeBSD).

pkubaj added a comment.Feb 9 2022, 5:51 PM

I meant this for __ppc_get_timebase_freq, which uses sysctlbyname. __ppc_get_timebase could actually use a builtin.

pkubaj updated this revision to Diff 408144.Feb 11 2022, 8:28 PM

Make __ppc_get_timebase use __builtin_ppc_get_timebase since it's an assembly function anyway.

Is there anything I'm doing wrong here?
If not, would it be possible to get this merged? It would be awesome to have this patch merged to 14.0, if possible, as well.

dim accepted this revision.Feb 21 2022, 5:57 AM

I can't vouch for any of the PowerPC specific stuff, but I would like to get it into FreeBSD if at all possible. :)

qiucf edited reviewers, added: Restricted Project; removed: power-llvm-team.Mar 1 2022, 6:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2022, 6:01 PM
adalava added inline comments.Mar 18 2022, 5:09 AM
compiler-rt/lib/xray/xray_powerpc64.inc
23

Looking at https://man7.org/linux/man-pages/man3/__ppc_get_timebase.3.html, this function should return a uint64_t, could you please double check?

pkubaj updated this revision to Diff 416996.Mar 21 2022, 9:51 AM

Change type of __ppc_get_timebase_freq() to uint64_t.

pkubaj updated this revision to Diff 416997.Mar 21 2022, 9:52 AM

Also change the type of tb_freq.

pkubaj updated this revision to Diff 416998.Mar 21 2022, 9:55 AM

Set origin/HEAD as base.

pkubaj added inline comments.Mar 21 2022, 10:00 AM
compiler-rt/lib/xray/xray_powerpc64.inc
23

Fixed.

pkubaj edited the summary of this revision. (Show Details)Mar 21 2022, 10:01 AM
adalava accepted this revision.Apr 5 2022, 2:54 PM

It's not actually a problem but tb_freq should be initialized as integer. Otherwise looks good to me!

I validated the code snippet on FreeBSD13/powerpc64 and it's consistent with linux/glibc output on same machine.

compiler-rt/lib/xray/xray_powerpc64.inc
25

uint64_t tb_freq = 0;

pkubaj updated this revision to Diff 420646.Apr 5 2022, 3:07 PM

Actually initialize tb_freq as integer.

adalava accepted this revision.Apr 5 2022, 8:55 PM
pkubaj removed a reviewer: kcc.Apr 6 2022, 5:12 AM
This revision is now accepted and ready to land.Apr 6 2022, 5:12 AM
pkubaj added a comment.Apr 6 2022, 5:13 AM

Removing kcc from reviewers since he seems inactive for the part half a year.
@adalava
As this is now accepted, can you commit it and if possible (since this is a build fix) merge for 14.0.1?

pkubaj updated this revision to Diff 420927.Apr 6 2022, 9:41 AM

Fix clang-format issues.

nemanjai accepted this revision.Apr 6 2022, 11:25 AM

I am not familiar with the FreeBSD-specific stuff, but there is nothing I see any issues with here.
LGTM.

adalava accepted this revision.Apr 6 2022, 11:32 AM

Removing kcc from reviewers since he seems inactive for the part half a year.
@adalava
As this is now accepted, can you commit it and if possible (since this is a build fix) merge for 14.0.1?

I'm not a commiter on LLVM side, but @nemanjai or someone else may commit :)

@nemanjai
As mentioned by adalava, can you commit this patch?

@nemanjai
As mentioned by adalava, can you commit this patch?

I will commit this for you tomorrow. Sorry about the delay.

nemanjai closed this revision.Apr 18 2022, 5:18 AM

Committed in https://reviews.llvm.org/rG315d79213025

I forgot to add the review in the commit message.