[PATCH] linux-user: Add missing includes

Peter Foley posted 1 patch 1 day, 21 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250904-includes-v1-1-a04a0ea14fd1@google.com
Maintainers: Laurent Vivier <laurent@vivier.eu>
linux-user/elfload.c | 1 +
linux-user/mmap.c    | 1 +
linux-user/syscall.c | 1 +
3 files changed, 3 insertions(+)
[PATCH] linux-user: Add missing includes
Posted by Peter Foley 1 day, 21 hours ago
We're getting errors about this:
linux-user/elfload.c:2770:36: error: use of undeclared identifier 'MAP_FIXED_NOREPLACE'

Signed-off-by: Peter Foley <pefoley@google.com>
---
 linux-user/elfload.c | 1 +
 linux-user/mmap.c    | 1 +
 linux-user/syscall.c | 1 +
 3 files changed, 3 insertions(+)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 26c090c95d3e90ad4a23a927267e4106f68975b0..edbacf041f25d88472c95efb4eb9bdccd81e9902 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -5,6 +5,7 @@
 #include <sys/prctl.h>
 #include <sys/resource.h>
 #include <sys/shm.h>
+#include <linux/mman.h>
 
 #include "qemu.h"
 #include "user/tswap-target.h"
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 002e1e668e631130526053599e1d18ffb4b4141a..9e92117ca3e8e4f45cb333366ecf3668b8986200 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -18,6 +18,7 @@
  */
 #include "qemu/osdep.h"
 #include <sys/shm.h>
+#include <linux/mman.h>
 #include "trace.h"
 #include "exec/log.h"
 #include "exec/page-protection.h"
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 91360a072c7f478085ac1c7cc8bb2026f8b32038..4101b0e4e7812740afe7a4246a902a5364d7c331 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -101,6 +101,7 @@
 #include <linux/soundcard.h>
 #include <linux/kd.h>
 #include <linux/mtio.h>
+#include <linux/mman.h>
 #include <linux/fs.h>
 #include <linux/fd.h>
 #if defined(CONFIG_FIEMAP)

---
base-commit: baa79455fa92984ff0f4b9ae94bed66823177a27
change-id: 20250904-includes-19d9afaed67a

Best regards,
-- 
Peter Foley <pefoley@google.com>
Re: [PATCH] linux-user: Add missing includes
Posted by Paolo Bonzini 1 day, 4 hours ago
On 9/4/25 17:21, Peter Foley wrote:
> We're getting errors about this:
> linux-user/elfload.c:2770:36: error: use of undeclared identifier 'MAP_FIXED_NOREPLACE'

Queued, thanks.

Paolo

> 
> Signed-off-by: Peter Foley <pefoley@google.com>
> ---
>   linux-user/elfload.c | 1 +
>   linux-user/mmap.c    | 1 +
>   linux-user/syscall.c | 1 +
>   3 files changed, 3 insertions(+)
> 
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index 26c090c95d3e90ad4a23a927267e4106f68975b0..edbacf041f25d88472c95efb4eb9bdccd81e9902 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -5,6 +5,7 @@
>   #include <sys/prctl.h>
>   #include <sys/resource.h>
>   #include <sys/shm.h>
> +#include <linux/mman.h>
>   
>   #include "qemu.h"
>   #include "user/tswap-target.h"
> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> index 002e1e668e631130526053599e1d18ffb4b4141a..9e92117ca3e8e4f45cb333366ecf3668b8986200 100644
> --- a/linux-user/mmap.c
> +++ b/linux-user/mmap.c
> @@ -18,6 +18,7 @@
>    */
>   #include "qemu/osdep.h"
>   #include <sys/shm.h>
> +#include <linux/mman.h>
>   #include "trace.h"
>   #include "exec/log.h"
>   #include "exec/page-protection.h"
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 91360a072c7f478085ac1c7cc8bb2026f8b32038..4101b0e4e7812740afe7a4246a902a5364d7c331 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -101,6 +101,7 @@
>   #include <linux/soundcard.h>
>   #include <linux/kd.h>
>   #include <linux/mtio.h>
> +#include <linux/mman.h>
>   #include <linux/fs.h>
>   #include <linux/fd.h>
>   #if defined(CONFIG_FIEMAP)
> 
> ---
> base-commit: baa79455fa92984ff0f4b9ae94bed66823177a27
> change-id: 20250904-includes-19d9afaed67a
> 
> Best regards,
Re: [PATCH] linux-user: Add missing includes
Posted by Richard Henderson 1 day, 3 hours ago
On 9/5/25 09:31, Paolo Bonzini wrote:
> On 9/4/25 17:21, Peter Foley wrote:
>> We're getting errors about this:
>> linux-user/elfload.c:2770:36: error: use of undeclared identifier 'MAP_FIXED_NOREPLACE'
> 
> Queued, thanks.
> 
> Paolo
> 
>>
>> Signed-off-by: Peter Foley <pefoley@google.com>
>> ---
>>   linux-user/elfload.c | 1 +
>>   linux-user/mmap.c    | 1 +
>>   linux-user/syscall.c | 1 +
>>   3 files changed, 3 insertions(+)
>>
>> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
>> index 26c090c95d3e90ad4a23a927267e4106f68975b0..edbacf041f25d88472c95efb4eb9bdccd81e9902 
>> 100644
>> --- a/linux-user/elfload.c
>> +++ b/linux-user/elfload.c
>> @@ -5,6 +5,7 @@
>>   #include <sys/prctl.h>
>>   #include <sys/resource.h>
>>   #include <sys/shm.h>
>> +#include <linux/mman.h>

There's no reason to include <linux/mman.h>.

This value is provided by <sys/mman.h> directly for musl and by <sys/mman.h> via 
<bits/mman-map-flags*> for glibc.

Are you using some other libc?  You're solidly in non-standard territory there.
Perhaps that other libc needs updating.


r~

Re: [PATCH] linux-user: Add missing includes
Posted by Peter Foley 20 hours ago
On Fri, Sep 5, 2025 at 4:48 AM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 9/5/25 09:31, Paolo Bonzini wrote:
> > On 9/4/25 17:21, Peter Foley wrote:
> >> We're getting errors about this:
> >> linux-user/elfload.c:2770:36: error: use of undeclared identifier
> 'MAP_FIXED_NOREPLACE'
> >
> > Queued, thanks.
> >
> > Paolo
> >
> >>
> >> Signed-off-by: Peter Foley <pefoley@google.com>
> >> ---
> >>   linux-user/elfload.c | 1 +
> >>   linux-user/mmap.c    | 1 +
> >>   linux-user/syscall.c | 1 +
> >>   3 files changed, 3 insertions(+)
> >>
> >> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> >> index
> 26c090c95d3e90ad4a23a927267e4106f68975b0..edbacf041f25d88472c95efb4eb9bdccd81e9902
>
> >> 100644
> >> --- a/linux-user/elfload.c
> >> +++ b/linux-user/elfload.c
> >> @@ -5,6 +5,7 @@
> >>   #include <sys/prctl.h>
> >>   #include <sys/resource.h>
> >>   #include <sys/shm.h>
> >> +#include <linux/mman.h>
>
> There's no reason to include <linux/mman.h>.
>
> This value is provided by <sys/mman.h> directly for musl and by
> <sys/mman.h> via
> <bits/mman-map-flags*> for glibc.
>
> Are you using some other libc?  You're solidly in non-standard territory
> there.
> Perhaps that other libc needs updating.
>

We're using glibc 2.27.
I definitely saw build failures earlier without this patch, but I'm now
unable to reproduce them at head.
So maybe there was an issue with our headers at an earlier point that has
since been fixed?
I'll revert this patch from our local fork and you should probably drop it
upstream as well.


>
> r~
>
Re: [PATCH] linux-user: Add missing includes
Posted by Richard Henderson 19 hours ago
On 9/5/25 18:00, Peter Foley wrote:
> We're using glibc 2.27.

That's just too old.

commit c42e77a90d9244c8caf76fe0e54f84200430a4e1
Author: Richard Henderson <richard.henderson@linaro.org>
Date:   Tue Aug 8 09:44:18 2023 -0700

     qemu/osdep: Remove fallback for MAP_FIXED_NOREPLACE

     In order for our emulation of MAP_FIXED_NOREPLACE to succeed within
     linux-user target_mmap, we require a non-zero value.  This does not
     require host kernel support, merely the bit being defined.

     MAP_FIXED_NOREPLACE was added with glibc 2.28.  From repology.org:

                       Fedora 36: 2.35
               CentOS 8 (RHEL-8): 2.28
                       Debian 11: 2.31
              OpenSUSE Leap 15.4: 2.31
                Ubuntu LTS 20.04: 2.31

     Reported-by: Akihiko Odaki <akihiko.odaki@daynix.com>
     Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
     Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
     Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
     Message-Id: <20230808164418.69989-1-richard.henderson@linaro.org>


r~


Re: [PATCH] linux-user: Add missing includes
Posted by Peter Foley 19 hours ago
On Fri, Sep 5, 2025 at 12:26 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 9/5/25 18:00, Peter Foley wrote:
> > We're using glibc 2.27.
>
> That's just too old.
>

Yeah, I'm picking up on that.
So it looks like short of back-porting support for MAP_FIXED_NOREPLACE to
our "grte" fork of glibc, we should just keep carrying a local patch.
Sorry for the noise.

>
> commit c42e77a90d9244c8caf76fe0e54f84200430a4e1
> Author: Richard Henderson <richard.henderson@linaro.org>
> Date:   Tue Aug 8 09:44:18 2023 -0700
>
>      qemu/osdep: Remove fallback for MAP_FIXED_NOREPLACE
>
>      In order for our emulation of MAP_FIXED_NOREPLACE to succeed within
>      linux-user target_mmap, we require a non-zero value.  This does not
>      require host kernel support, merely the bit being defined.
>
>      MAP_FIXED_NOREPLACE was added with glibc 2.28.  From repology.org:
>
>                        Fedora 36: 2.35
>                CentOS 8 (RHEL-8): 2.28
>                        Debian 11: 2.31
>               OpenSUSE Leap 15.4: 2.31
>                 Ubuntu LTS 20.04: 2.31
>
>      Reported-by: Akihiko Odaki <akihiko.odaki@daynix.com>
>      Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
>      Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>      Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>      Message-Id: <20230808164418.69989-1-richard.henderson@linaro.org>
>
>
> r~
>
>
Re: [PATCH] linux-user: Add missing includes
Posted by Peter Foley 20 hours ago
On Fri, Sep 5, 2025 at 12:00 PM Peter Foley <pefoley@google.com> wrote:

>
>
> On Fri, Sep 5, 2025 at 4:48 AM Richard Henderson <
> richard.henderson@linaro.org> wrote:
>
>> On 9/5/25 09:31, Paolo Bonzini wrote:
>> > On 9/4/25 17:21, Peter Foley wrote:
>> >> We're getting errors about this:
>> >> linux-user/elfload.c:2770:36: error: use of undeclared identifier
>> 'MAP_FIXED_NOREPLACE'
>> >
>> > Queued, thanks.
>> >
>> > Paolo
>> >
>> >>
>> >> Signed-off-by: Peter Foley <pefoley@google.com>
>> >> ---
>> >>   linux-user/elfload.c | 1 +
>> >>   linux-user/mmap.c    | 1 +
>> >>   linux-user/syscall.c | 1 +
>> >>   3 files changed, 3 insertions(+)
>> >>
>> >> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
>> >> index
>> 26c090c95d3e90ad4a23a927267e4106f68975b0..edbacf041f25d88472c95efb4eb9bdccd81e9902
>>
>> >> 100644
>> >> --- a/linux-user/elfload.c
>> >> +++ b/linux-user/elfload.c
>> >> @@ -5,6 +5,7 @@
>> >>   #include <sys/prctl.h>
>> >>   #include <sys/resource.h>
>> >>   #include <sys/shm.h>
>> >> +#include <linux/mman.h>
>>
>> There's no reason to include <linux/mman.h>.
>>
>> This value is provided by <sys/mman.h> directly for musl and by
>> <sys/mman.h> via
>> <bits/mman-map-flags*> for glibc.
>>
>> Are you using some other libc?  You're solidly in non-standard territory
>> there.
>> Perhaps that other libc needs updating.
>>
>
> We're using glibc 2.27.
> I definitely saw build failures earlier without this patch, but I'm now
> unable to reproduce them at head.
> So maybe there was an issue with our headers at an earlier point that has
> since been fixed?
> I'll revert this patch from our local fork and you should probably drop it
> upstream as well.
>
>
Oh, I figured out why I couldn't reproduce the issue.
We had a separate patch we were carrying that added linux/mman.h
to linux-user/user-mmap.h.
If I revert both patches, I see this:
third_party/qemu/linux-user/mmap.c:602:40: error: use of undeclared
identifier 'MAP_FIXED_NOREPLACE'
  602 |     if (start || (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {



>
>>
>> r~
>>
>