Repository: Homebrew/homebrew-core

Issue #69786: AddressSanitizer fails to work on llvm on M1 machines
Created: 2021-01-26T17:54:29Z
Bug report
Please note we will close your issue without comment if you delete, do not read or do not fill out the issue checklist below and provide ALL the requested information. If you repeatedly fail to use the issue template, we will block you from ever submitting issues to Homebrew again.

[Y ] ran brew update and can still reproduce the problem?
[Y] ran brew doctor, fixed all issues and can still reproduce the problem?
[Y] ran brew gist-logs <formula> (where <formula> is the name of the formula that failed) and included the output link? [This did not work]
[Y] if brew gist-logs didn't work: ran brew config and brew doctor and included their output with your issue?


What you were trying to do (and why)
Run a simple hello world c++ executable compiled with brew clang and AddressSanitizer enabled and on M1 hardware. Was running this to create a minimum repro to show that AddressSanitizer does not work under brew clang on M1 hardware.
What happened (include command output)
foobar % cat main.cpp
#include 
#include 
int main(int argc, char** argv) {
std::cout << "hello world!" << std::endl;
return 0;
}
foobar % /opt/homebrew/opt/llvm/bin/clang++ -fsanitize=address main.cpp -o main
foobar % ./main
==5007==ERROR: AddressSanitizer failed to allocate 0x200004000 (8589950976) bytes at address fffffc000 (errno: 12)
==5007==ReserveShadowMemoryRange failed while trying to map 0x200004000 bytes. Perhaps you're using ulimit -v
zsh: abort      ./main
What you expected to happen
Expected the simple hello world c++ program to work correctly.
Step-by-step reproduction instructions (by running brew install commands)
Assuming you have a Mac machine with M1 chips

brew install llvm
Create file called main.cpp with following content
#include 

int main(int argc, char** argv) {
std::cout << "hello world!" << std::endl;
return 0;
}
3. Compile file using -/opt/homebrew/opt/llvm/bin/clang++ -fsanitize=address main.cpp -o main
4. Run compiled executable using ./main
5.  You will get the following error==5007==ERROR: AddressSanitizer failed to allocate 0x200004000 (8589950976) bytes at address fffffc000 (errno: 12)
==5007==ReserveShadowMemoryRange failed while trying to map 0x200004000 bytes. Perhaps you're using ulimit -v
zsh: abort      ./main
Brew Config is
foobar % brew config
HOMEBREW_VERSION: 2.7.5
ORIGIN: https://github.com/Homebrew/brew
HEAD: bca4804
Last commit: 11 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: f2487ee
Core tap last commit: 78 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 12.0 build 1200
Git: 2.24.3 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 11.1-arm64
CLT: 12.3.0.0.1.1607026830
Xcode: 12.3
Rosetta 2: false
foobar % brew doctor
Your system is ready to brew.

Duplicate issue #74262:  AddressSanitizer failed to allocate on Apple M1
Created: 2021-03-31T13:25:39Z
brew gist-logs <formula> link OR brew config AND brew doctor output
% brew config
HOMEBREW_VERSION: 3.0.10
ORIGIN: https://github.com/Homebrew/brew
HEAD: 0ad2564c5f1ddf6f16f707f2861556b80546713c
Last commit: 2 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 72894f32b1fcb5d2063b378a3f2a15cb08234e90
Core tap last commit: 75 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_EDITOR: vim
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 12.0 build 1200
Git: 2.24.3 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 11.2.3-arm64
CLT: 12.4.0.0.1.1610135815
Xcode: 12.4
Rosetta 2: false

% brew doctor
Your system is ready to brew.


 The brew doctor above contains no "Warning" lines.

What were you trying to do (and why)?
Address sanitise a C program.
What happened (include all command output)?
==4036==ERROR: AddressSanitizer failed to allocate 0x200004000 (8589950976) bytes at address fffffc000 (errno: 12)
==4036==ReserveShadowMemoryRange failed while trying to map 0x200004000 bytes. Perhaps you're using ulimit -v
zsh: abort      ./main
What did you expect to happen?
No output.
Step-by-step reproduction instructions (by running brew commands)
% cat main.c
int main(void)
{
    return 0;
}
% /opt/homebrew/opt/llvm/bin/clang main.c -fsanitize=address -o main
% ./main

Closing comment (2021-03-31T13:26:13Z): With verbosity=3:
% ASAN_OPTIONS=verbosity=3 ./main                                                                                                                                                                           ~/tmp/addr
==4071==AddressSanitizer: libc interceptors initialized
|| `[0x101000000000, 0x7fffffffffff]` || HighMem    ||
|| `[0x021200000000, 0x100fffffffff]` || HighShadow ||
|| `[0x001200000000, 0x0211ffffffff]` || ShadowGap  ||
|| `[0x001000000000, 0x0011ffffffff]` || LowShadow  ||
|| `[0x000000000000, 0x000fffffffff]` || LowMem     ||
MemToShadow(shadow): 0x001200000000 0x00123fffffff 0x005240000000 0x0211ffffffff
redzone=16
max_redzone=2048
quarantine_size_mb=256M
thread_local_quarantine_size_kb=1024K
malloc_context_size=30
SHADOW_SCALE: 3
SHADOW_GRANULARITY: 8
SHADOW_OFFSET: 0x1000000000
==4071==ERROR: AddressSanitizer failed to allocate 0x200004000 (8589950976) bytes at address fffffc000 (errno: 12)
==4071==ReserveShadowMemoryRange failed while trying to map 0x200004000 bytes. Perhaps you're using ulimit -v
zsh: abort      ASAN_OPTIONS=verbosity=3 ./main

It is related to #69786.