8000 Compile error on Apple M1 Chip running as Rosetta2 x86 · Issue #1997 · jemalloc/jemalloc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Compile error on Apple M1 Chip running as Rosetta2 x86 #1997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kushtrimjunuzi opened this issue Dec 10, 2020 · 8 comments
Open

Compile error on Apple M1 Chip running as Rosetta2 x86 #1997

kushtrimjunuzi opened this issue Dec 10, 2020 · 8 comments

Comments

@kushtrimjunuzi
Copy link
kushtrimjunuzi commented Dec 10, 2020

Sorry, I'm totally newbie to this repo and probably I event don't know what I'm talking about, but just wanted to put this log here so if anyone encounter this issue its not the only one. I tried to search about this error and nothing specific.
The device I'm using is Apple MacBook Air M1 chip, I know lots of errors on this device just it happens to be me on this specific one error.

Trying to install jemalloc package with homebrew and cause a compile error.
This log is from homebrew, you probably can reproduce the issue by running this cmd $arch -x86_64 brew install jemalloc

patching file include/jemalloc/jemalloc_macros.h.in
Hunk #1 succeeded at 127 (offset -7 lines).
patching file include/jemalloc/jemalloc_protos.h.in
==> ./configure --prefix=/usr/local/homebrew/Cellar/jemalloc/5.2.1_1 --with-jemalloc-prefix=
==> make
Last 15 lines from /Users/kushtrim/Library/Logs/Homebrew/jemalloc/02.make:
#define RTREE_NSB (LG_VADDR - RTREE_NLIB)
                  ^~~~~~~~~~~~~~~~~~~~~~~
include/jemalloc/internal/rtree.h:98:3: note: insert an explicit cast to silence this issue
        {RTREE_NSB, RTREE_NHIB + RTREE_NSB}
         ^~~~~~~~~
         static_cast<unsigned int>( )
include/jemalloc/internal/rtree.h:22:19: note: expanded from macro 'RTREE_NSB'
#define RTREE_NSB (LG_VADDR - RTREE_NLIB)
                  ^~~~~~~~~~~~~~~~~~~~~~~
clang -std=gnu11 -Wall -Wextra -Wshorten-64-to-32 -Wsign-compare -Wundef -Wno-format-zero-length -pipe -g3 -O3 -funroll-loops -c -D_REENTRANT -Iinclude -Iinclude -o src/base.o src/base.c
clang -std=gnu11 -Wall -Wextra -Wshorten-64-to-32 -Wsign-compare -Wundef -Wno-format-zero-length -pipe -g3 -O3 -funroll-loops -c -D_REENTRANT -Iinclude -Iinclude -o src/bin.o src/bin.c
clang -std=gnu11 -Wall -Wextra -Wshorten-64-to-32 -Wsign-compare -Wundef -Wno-format-zero-length -pipe -g3 -O3 -funroll-loops -c -D_REENTRANT -Iinclude -Iinclude -o src/bitmap.o src/bitmap.c
1 error generated.
make: *** [src/jemalloc_cpp.pic.o] Error 1
make: *** Waiting for unfinished jobs....
@codeyash
Copy link

Facing the exact same problem.

@atn34
Copy link
atn34 commented Feb 15, 2021

I'm facing a similar issue, also running Mac m1 with rosetta2. It seems that --with-lg-vaddr=48 seems to fix it.

$ git clone https://github.com/jemalloc/jemalloc && cd jemalloc
$ git rev-parse HEAD
a11be50332c5cdae7ce74d8e0551e7f3143630b8
$ ./autogen.sh
$ make all tests check #fails
...
lots of warnings, e.g.
gcc -std=gnu11 -Wall -Wshorten-64-to-32 -Wsign-compare -Wundef -Wno-format-zero-length -pipe -g3 -O3 -funroll-loops -fno-omit-frame-pointer -c -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_STRESS_TEST -Itest/include -Itest/include -o test/stress/microbench.o test/stress/microbench.c
In file included from test/stress/microbench.c:1:
In file included from test/include/test/jemalloc_test.h:98:
In file included from include/jemalloc/internal/jemalloc_internal_includes.h:66:
In file included from include/jemalloc/internal/extent_externs.h:7:
include/jemalloc/internal/rtree.h:193:50: warning: shift count >= width of type [-Wshift-count-overflow]
        return (extent_t *)((uintptr_t)((intptr_t)(bits << RTREE_NHIB) >>
                                                        ^  ~~~~~~~~~~
include/jemalloc/internal/rtree.h:193:65: warning: shift count >= width of type [-Wshift-count-overflow]
        return (extent_t *)((uintptr_t)((intptr_t)(bits << RTREE_NHIB) >>
                                                                       ^
2 warnings generated.
$ ./autogen.sh --with-lg-vaddr=48
$ make all tests check # passes

@brokenjacobs
Copy link
brokenjacobs commented Nov 3, 2021

this fails for compiles running on x86_64 as well on osx under lima. --with-lg-vaddr=48 works there as well.

@brokenjacobs
Copy link
brokenjacobs commented Nov 3, 2021

Some testing shows that LG_VADDR is being set to 0 on this platform by autogen.sh
checking number of significant virtual address bits... 0

@interwq
Copy link
Member
interwq commented Nov 3, 2021

Thanks for sharing the info!

@brokenjacobs : can you please help to try if the tests all pass with --with-lg-vaddr=48;, using make all tests check?

< 8000 p class="text-center mt-3" data-hide-on-error>

@brokenjacobs
Copy link
brokenjacobs commented Nov 3, 2021

I think I found the source of the issue:
https://gitlab.com/qemu-project/qemu/-/issues/664

I've been playing around with the check and pulled the test out like this:

#include <stdio.h>
#include <stdint.h>

int
main ()
{
        uint32_t r[4];
        uint32_t eax_in = 0x80000008U;
        asm volatile ("cpuid"
            : "=a" (r[0]), "=b" (r[1]), "=c" (r[2]), "=d" (r[3])
            : "a" (eax_in), "c" (0)
        );
        uint32_t eax_out = r[0];
        uint32_t vaddr = ((eax_out & 0x0000ff00U) >> 8);
        if (vaddr > (sizeof(void *) << 3)) {
                vaddr = sizeof(void *) << 3;
        }
        printf("VADDR Result: %u\n", vaddr);
        printf("EAX OUT: %08x\n", eax_out);
        return 0;

  ;
  return 0;
}

Inside lima, this returns incorrectly, which lead me to the QEMU bug.

NOT IN VM:
VADDR Result: 48
EAX OUT: 00003027

Inside VM:
VADDR Result: 0
EAX OUT: 00000007

@brokenjacobs
Copy link

Thanks for sharing the info!

@brokenjacobs : can you please help to try if the tests all pass with --with-lg-vaddr=48;, using make all tests check?

It does, but this is actually a QEMU bug.

@jrwren
Copy link
jrwren commented Feb 16, 2022

For folks that need an immediate work around like I needed in my build environment, apply this patch before running configure:

--- configure	2022-02-16 01:43:33.470553518 +0000
+++ configure.new	2022-02-16 01:43:24.149733186 +0000
@@ -7175,6 +7175,7 @@
 fi

 fi
+if test "x${je_cv_lg_vaddr}" = "x0" ; then je_cv_lg_vaddr=48 ;fi # For podman/docker/qemu on macos dev build.
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $je_cv_lg_vaddr" >&5
 $as_echo "$je_cv_lg_vaddr" >&6; }
       if test "x${je_cv_lg_vaddr}" != "x" ; then

kivikakk added a commit to radiopaedia/sorbet that referenced this issue Jan 1, 2023
jez added a commit to sorbet/sorbet that referenced this issue Apr 3, 2023
Further discussion here:
<jemalloc/jemalloc#1997>

    include/jemalloc/internal/rtree.h:118:3: error: constant expression evaluates to -12 which cannot be narrowed to type 'unsigned int' [-Wc++11-narrowing]
            {RTREE_NSB, RTREE_NHIB + RTREE_NSB}
             ^~~~~~~~~
    include/jemalloc/internal/rtree.h:22:19: note: expanded from macro 'RTREE_NSB'
    #define RTREE_NSB (LG_VADDR - RTREE_NLIB)
                      ^~~~~~~~~~~~~~~~~~~~~~~
    include/jemalloc/internal/rtree.h:118:3: note: insert an explicit cast to silence this issue
            {RTREE_NSB, RTREE_NHIB + RTREE_NSB}
             ^~~~~~~~~
             static_cast<unsigned int>( )
    include/jemalloc/internal/rtree.h:22:19: note: expanded from macro 'RTREE_NSB'
    #define RTREE_NSB (LG_VADDR - RTREE_NLIB)
                      ^~~~~~~~~~~~~~~~~~~~~~~
jez added a commit to sorbet/sorbet that referenced this issue Apr 3, 2023
Further discussion here:
<jemalloc/jemalloc#1997>

    include/jemalloc/internal/rtree.h:118:3: error: constant expression evaluates to -12 which cannot be narrowed to type 'unsigned int' [-Wc++11-narrowing]
            {RTREE_NSB, RTREE_NHIB + RTREE_NSB}
             ^~~~~~~~~
    include/jemalloc/internal/rtree.h:22:19: note: expanded from macro 'RTREE_NSB'
    #define RTREE_NSB (LG_VADDR - RTREE_NLIB)
                      ^~~~~~~~~~~~~~~~~~~~~~~
    include/jemalloc/internal/rtree.h:118:3: note: insert an explicit cast to silence this issue
            {RTREE_NSB, RTREE_NHIB + RTREE_NSB}
             ^~~~~~~~~
             static_cast<unsigned int>( )
    include/jemalloc/internal/rtree.h:22:19: note: expanded from macro 'RTREE_NSB'
    #define RTREE_NSB (LG_VADDR - RTREE_NLIB)
                      ^~~~~~~~~~~~~~~~~~~~~~~
raboof added a commit to raboof/nixpkgs that referenced this issue Apr 2, 2025
Working towards making the build deterministic regardless of the build host

Page size:

jemalloc/jemalloc#467
https://sources.debian.org/src/jemalloc/5.3.0-3/debian/rules/
NixOS#380852

Darwin:

Similar to NixOS#394620

LG_VADDR:

jemalloc/jemalloc#1997
raboof added a commit to raboof/nixpkgs that referenced this issue Apr 3, 2025
Working towards making the build deterministic regardless of the build host

Page size:

jemalloc/jemalloc#467
https://sources.debian.org/src/jemalloc/5.3.0-3/debian/rules/
NixOS#380852

Darwin:

Similar to NixOS#394620

LG_VADDR:

jemalloc/jemalloc#1997
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

No branches or pull requests

6 participants
0