diff mbox series

[FFmpeg-devel] aarch64: Implement support for elf_aux_info(3) on FreeBSD and OpenBSD

Message ID Zt7TJnzEW3qPLOPP@humpty.home.comstyle.com
State New
Headers show
Series [FFmpeg-devel] aarch64: Implement support for elf_aux_info(3) on FreeBSD and OpenBSD | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Brad Smith Sept. 9, 2024, 10:51 a.m. UTC
aarch64: Implement support for elf_aux_info(3) on FreeBSD and OpenBSD

FreeBSD 12.0+, OpenBSD -current and what will be OpenBSD 7.6 support
elf_aux_info(3).

Signed-off-by: Brad Smith <brad@comstyle.com>
---
 configure               | 2 ++
 libavutil/aarch64/cpu.c | 2 +-
 libavutil/cpu.c         | 9 ++++++++-
 3 files changed, 11 insertions(+), 2 deletions(-)

Comments

Martin Storsjö Sept. 9, 2024, 11 a.m. UTC | #1
On Mon, 9 Sep 2024, Brad Smith wrote:

> aarch64: Implement support for elf_aux_info(3) on FreeBSD and OpenBSD
>
> FreeBSD 12.0+, OpenBSD -current and what will be OpenBSD 7.6 support
> elf_aux_info(3).
>
> Signed-off-by: Brad Smith <brad@comstyle.com>
> ---
> configure               | 2 ++
> libavutil/aarch64/cpu.c | 2 +-
> libavutil/cpu.c         | 9 ++++++++-
> 3 files changed, 11 insertions(+), 2 deletions(-)

LGTM, thanks. (I guess the same change as in aarch64/cpu.c also could be 
done in other architectures' cpu.c?)

// Martin
Brad Smith Sept. 9, 2024, 11:05 a.m. UTC | #2
On 2024-09-09 7:00 a.m., Martin Storsjö wrote:
> On Mon, 9 Sep 2024, Brad Smith wrote:
>
>> aarch64: Implement support for elf_aux_info(3) on FreeBSD and OpenBSD
>>
>> FreeBSD 12.0+, OpenBSD -current and what will be OpenBSD 7.6 support
>> elf_aux_info(3).
>>
>> Signed-off-by: Brad Smith <brad@comstyle.com>
>> ---
>> configure               | 2 ++
>> libavutil/aarch64/cpu.c | 2 +-
>> libavutil/cpu.c         | 9 ++++++++-
>> 3 files changed, 11 insertions(+), 2 deletions(-)
>
> LGTM, thanks. (I guess the same change as in aarch64/cpu.c also could 
> be done in other architectures' cpu.c?)
>
> // Martin

I was looking at ppc for ppc64. Adding some sort of /proc/self/auxv 
fallback to ff_getauxval() and then
re-writting all that to use ff_getauxval() and have support for 
FreeBSD/powerpc64 and OpenBSD/powerpc64.
FFmpeg is the only project I have come across so far that does not use 
getauxval() on ppc64.
Ramiro Polla Sept. 9, 2024, 11:09 a.m. UTC | #3
On Mon, Sep 9, 2024 at 1:01 PM Martin Storsjö <martin@martin.st> wrote:
> On Mon, 9 Sep 2024, Brad Smith wrote:
>
> > aarch64: Implement support for elf_aux_info(3) on FreeBSD and OpenBSD
> >
> > FreeBSD 12.0+, OpenBSD -current and what will be OpenBSD 7.6 support
> > elf_aux_info(3).
> >
> > Signed-off-by: Brad Smith <brad@comstyle.com>
> > ---
> > configure               | 2 ++
> > libavutil/aarch64/cpu.c | 2 +-
> > libavutil/cpu.c         | 9 ++++++++-
> > 3 files changed, 11 insertions(+), 2 deletions(-)
>
> LGTM, thanks. (I guess the same change as in aarch64/cpu.c also could be
> done in other architectures' cpu.c?)

I agree. These are the cases I still see in the codebase:
libavutil/mips/cpu.c:
libavutil/arm/cpu.c:
#if defined __linux__ || defined __ANDROID__
libavutil/loongarch/cpu.c:
#if defined __linux__

In general we should avoid using system #ifdefs, relying instead on
features that can be properly detected by configure.
(This comment in unrelated to the patch)
Ramiro Polla Sept. 9, 2024, 11:11 a.m. UTC | #4
On Mon, Sep 9, 2024 at 1:06 PM Brad Smith
<brad-at-comstyle.com@ffmpeg.org> wrote:
> On 2024-09-09 7:00 a.m., Martin Storsjö wrote:
> > On Mon, 9 Sep 2024, Brad Smith wrote:
> >
> >> aarch64: Implement support for elf_aux_info(3) on FreeBSD and OpenBSD
> >>
> >> FreeBSD 12.0+, OpenBSD -current and what will be OpenBSD 7.6 support
> >> elf_aux_info(3).
> >>
> >> Signed-off-by: Brad Smith <brad@comstyle.com>
> >> ---
> >> configure               | 2 ++
> >> libavutil/aarch64/cpu.c | 2 +-
> >> libavutil/cpu.c         | 9 ++++++++-
> >> 3 files changed, 11 insertions(+), 2 deletions(-)
> >
> > LGTM, thanks. (I guess the same change as in aarch64/cpu.c also could
> > be done in other architectures' cpu.c?)
>
> I was looking at ppc for ppc64. Adding some sort of /proc/self/auxv
> fallback to ff_getauxval() and then
> re-writting all that to use ff_getauxval() and have support for
> FreeBSD/powerpc64 and OpenBSD/powerpc64.
> FFmpeg is the only project I have come across so far that does not use
> getauxval() on ppc64.

Patches welcome :). Do you have such a system for testing?
Brad Smith Sept. 9, 2024, 11:16 a.m. UTC | #5
On 2024-09-09 7:11 a.m., Ramiro Polla wrote:
> On Mon, Sep 9, 2024 at 1:06 PM Brad Smith
> <brad-at-comstyle.com@ffmpeg.org> wrote:
>> On 2024-09-09 7:00 a.m., Martin Storsjö wrote:
>>> On Mon, 9 Sep 2024, Brad Smith wrote:
>>>
>>>> aarch64: Implement support for elf_aux_info(3) on FreeBSD and OpenBSD
>>>>
>>>> FreeBSD 12.0+, OpenBSD -current and what will be OpenBSD 7.6 support
>>>> elf_aux_info(3).
>>>>
>>>> Signed-off-by: Brad Smith<brad@comstyle.com>
>>>> ---
>>>> configure               | 2 ++
>>>> libavutil/aarch64/cpu.c | 2 +-
>>>> libavutil/cpu.c         | 9 ++++++++-
>>>> 3 files changed, 11 insertions(+), 2 deletions(-)
>>> LGTM, thanks. (I guess the same change as in aarch64/cpu.c also could
>>> be done in other architectures' cpu.c?)
>> I was looking at ppc for ppc64. Adding some sort of /proc/self/auxv
>> fallback to ff_getauxval() and then
>> re-writting all that to use ff_getauxval() and have support for
>> FreeBSD/powerpc64 and OpenBSD/powerpc64.
>> FFmpeg is the only project I have come across so far that does not use
>> getauxval() on ppc64.
> Patches welcome :). Do you have such a system for testing?


I have a Linux ppc64 VM so I can test that part.
diff mbox series

Patch

diff --git a/configure b/configure
index a8e67d230c..d3bd46f382 100755
--- a/configure
+++ b/configure
@@ -2367,6 +2367,7 @@  SYSTEM_FUNCS="
     clock_gettime
     closesocket
     CommandLineToArgvW
+    elf_aux_info
     fcntl
     getaddrinfo
     getauxval
@@ -6579,6 +6580,7 @@  check_func_headers mach/mach_time.h mach_absolute_time
 check_func_headers stdlib.h getenv
 check_func_headers sys/stat.h lstat
 check_func_headers sys/auxv.h getauxval
+check_func_headers sys/auxv.h elf_aux_info
 check_func_headers sys/sysctl.h sysctlbyname
 
 check_func_headers windows.h GetModuleHandle
diff --git a/libavutil/aarch64/cpu.c b/libavutil/aarch64/cpu.c
index 084c81e999..7631d13de0 100644
--- a/libavutil/aarch64/cpu.c
+++ b/libavutil/aarch64/cpu.c
@@ -20,7 +20,7 @@ 
 #include "libavutil/cpu_internal.h"
 #include "config.h"
 
-#if (defined(__linux__) || defined(__ANDROID__)) && HAVE_GETAUXVAL
+#if HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO
 #include <stdint.h>
 #include <sys/auxv.h>
 
diff --git a/libavutil/cpu.c b/libavutil/cpu.c
index 61c1cf3faf..df00bd541f 100644
--- a/libavutil/cpu.c
+++ b/libavutil/cpu.c
@@ -49,7 +49,7 @@ 
 #include <unistd.h>
 #endif
 
-#if HAVE_GETAUXVAL
+#if HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO
 #include <sys/auxv.h>
 #endif
 
@@ -292,6 +292,13 @@  unsigned long ff_getauxval(unsigned long type)
 {
 #if HAVE_GETAUXVAL
     return getauxval(type);
+#elif HAVE_ELF_AUX_INFO
+    unsigned long aux = 0;
+    int ret = elf_aux_info(type, &aux, sizeof(aux));
+    if (ret != 0) {
+        errno = ret;
+    }
+    return aux;
 #else
     errno = ENOSYS;
     return 0;