Compiler

RSS for tag

Discuss the various compiler and toolchain technologies used in development.

Posts under Compiler tag

104 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Problem with variadic C functions
I am the author of the open-source Dynace. This is an OO extension to C. It has been in production use for around 20 years. It has been used on DOS, all Windows, Linux, macOS/Intel, VMS, PLAN9, COSMIC, SUNOS, etc. all without a problem. However it does not run on Apple M1, M2 machines. I traced the problem to variadic function calls. I am creating a va_list in a ... function. I then pass the va_list to a second function. I wrote something to copy the the va_list (via va_copy) to see what I am getting. The first function works okay. But the second function does not. (I know you can't re-use a va_list.) I have spend a couple of days on this and can't find a problem with my code. I tried creating a simple example but it worked. Apparently the problem is situational. Anyway, I have no idea what is wrong or what to do next. I'd sure appreciate any help! Thanks!
2
0
782
Nov ’23
Illegal instruction in std::remainder (libsystem_m.dylib) when floating point exceptions enabled on M1 mac
Call to std::remainder(double(411.0), int(365)); results in a crash due to a nan in libsystem_m.dylib. MCVE program is provided + lldb backtrace and system report. $ clang++ -g -arch arm64 -std=c++20 main.cpp -o test $ ./test ori_fpcr=0, new_fpcr=1792 std::fmod(simTimeInDays, numDays) = 46 Illegal instruction: 4 main.cpp #include <cassert> #include <cfenv> #include <cmath> #include <iostream> #if !defined(__arm64__) || !defined(__APPLE__) # error "Meant to be run on arm64 apple" #endif inline int feenableexcept(unsigned int excepts) { static fenv_t fenv; if (std::fegetenv(&fenv) != 0) { return -1; } const unsigned long long old_fpcr = fenv.__fpcr; const unsigned int old_excepts = (old_fpcr >> 8u) & unsigned(FE_ALL_EXCEPT); // Check the bits passed are valid, and bit shift them const unsigned int new_excepts = excepts & unsigned(FE_ALL_EXCEPT); const unsigned long long new_fpcr = new_excepts << 8u; // Set the new bits fenv.__fpcr = fenv.__fpcr | new_fpcr; return (std::fesetenv(&fenv) != 0) ? -1 : static_cast<int>(old_excepts); } int main([[maybe_unused]] int argc, [[maybe_unused]] const char** argv) { constexpr unsigned int flags = FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW; static_assert(flags == 7); constexpr uint32_t fpcr_flags_shifted = flags << 8; constexpr uint32_t fpcr_flags = (__fpcr_trap_divbyzero | __fpcr_trap_invalid | __fpcr_trap_overflow); static_assert(fpcr_flags_shifted == fpcr_flags); static_assert(fpcr_flags_shifted == 1792); uint32_t ori_fpcr = __builtin_arm_rsr("fpcr"); feenableexcept(flags); uint32_t new_fpcr = __builtin_arm_rsr("fpcr"); // std::cout << "(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW) = " << flags << '\n'; // std::cout << "((FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW) << 8) = " << fpcr_flags_shifted << '\n'; // std::cout << "(__fpcr_trap_divbyzero | __fpcr_trap_invalid | __fpcr_trap_overflow) = " << fpcr_flags << '\n'; std::cout << "ori_fpcr=" << ori_fpcr << ", new_fpcr=" << new_fpcr << '\n'; const double simTimeInDays = 411.0; const int numDays = 365; // This is fine std::cout << "std::fmod(simTimeInDays, numDays) = " << std::fmod(simTimeInDays, numDays) << '\n'; // This isn't std::cout << "std::fmod(simTimeInDays, numDays) = " << std::remainder(simTimeInDays, numDays) << '\n'; return 0; } backtrace: see attachment lldb_backtrace.txt $ system_profiler SPSoftwareDataType SPHardwareDataType Software: System Software Overview: System Version: macOS 13.2 (22D49) Kernel Version: Darwin 22.3.0 Boot Volume: Macintosh HD Boot Mode: Normal Secure Virtual Memory: Enabled System Integrity Protection: Enabled Time since boot: 7 hours, 58 minutes Hardware: Hardware Overview: Model Name: MacBook Pro Model Identifier: MacBookPro18,2 Model Number: Z14V000NBFN/A Chip: Apple M1 Max Total Number of Cores: 10 (8 performance and 2 efficiency) Memory: 64 GB System Firmware Version: 8419.80.7 OS Loader Version: 8419.80.7 Activation Lock Status: Enabled $ otool -L test test: /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.36.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0 $ clang++ --version Apple clang version 14.0.0 (clang-1400.0.29.202) Target: arm64-apple-darwin22.3.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin
1
0
929
Sep ’24
Xcode does not respect '__builtin_available' availability API
I'm writing a simple Command line application on macOS with code using C++, using a API called 'std::to_chars' from charconv void foo(void) {   if (__builtin_available(macOS 10.15, *))   {     char buffer[10];     std::to_chars_result tcr = std::to_chars( buffer, buffer+5, 5 ); #pragma unused (tcr)   }else{     return;   }     } Since Xcode complains main.cpp:19:41: error build: 'to_chars<int, 0>' is unavailable: introduced in macOS 10.15 I wrapped the code with an availability check API in C++, __builtin_available(macOS 10.15, *)) But even with this availability check API, Xcode still failed to compile. Anyone knows why?
1
0
1.6k
Jul ’24
LLVM and Terminal Support on Mac Apple Silicon
My question set is fairly broad, but I can't seem to find any answers anywhere. As a fairly low-level developer, the vast majority of my work is done with Sublime Text, terminal-based compilers, IDEs like Coq's (coq.inria.fr), and code that has to be compiled by terminal. These projects are at the very fabric of what I do, and I fear that Rosetta 2 will be inadequate until LLVM and other systems are updated to run natively on Apple Silicon. Honestly, I can't really afford complex virtualization systems like Parallels or VMWare (not that they help much) and I'd rather not give up MacOS for my Ubuntu desktop. I was raised on MacOS and I can't imagine losing features like scenes or seamless integration with the rest of my electronics. I want to keep my initial post fairly simple and broad, but if anyone has any questions on what I need supported, feel free to ask. I am sure I'm not alone here.
8
1
6.8k
Oct ’24