Skip to content
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

build: fixed cygwin build with malloc wrap #27473

Merged
merged 3 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Tools/ardupilotwaf/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,10 @@ def configure_env(self, cfg, env):
]

# wrap malloc to ensure memory is zeroed
# don't do this on MacOS as ld doesn't support --wrap
if platform.system() != 'Darwin':
if cfg.env.DEST_OS == 'cygwin':
# on cygwin we need to wrap _malloc_r instead
env.LINKFLAGS += ['-Wl,--wrap,_malloc_r']
elif platform.system() != 'Darwin':
env.LINKFLAGS += ['-Wl,--wrap,malloc']

if cfg.options.enable_sfml:
Expand Down Expand Up @@ -1019,8 +1021,7 @@ def expand_path(p):
'-fno-inline-functions',
'-mlongcalls',
'-fsingle-precision-constant', # force const vals to be float , not double. so 100.0 means 100.0f
'-fno-threadsafe-statics',
'-DCYGWIN_BUILD']
'-fno-threadsafe-statics']
env.CXXFLAGS.remove('-Werror=undef')
env.CXXFLAGS.remove('-Werror=shadow')

Expand Down
29 changes: 28 additions & 1 deletion libraries/AP_Common/c++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,35 @@ void operator delete[](void * ptr)
if (ptr) free(ptr);
}

#ifdef CYGWIN_BUILD
/*
wrapper around malloc to ensure all memory is initialised as zero
cygwin needs to wrap _malloc_r
*/
#undef _malloc_r
extern "C" {
void *__wrap__malloc_r(_reent *r, size_t size);
void *__real__malloc_r(_reent *r, size_t size);
void *_malloc_r(_reent *r, size_t size);
}
void *__wrap__malloc_r(_reent *r, size_t size)
{
void *ret = __real__malloc_r(r, size);
if (ret != nullptr) {
memset(ret, 0, size);
}
return ret;
}
void *_malloc_r(_reent *x, size_t size)
{
void *ret = __real__malloc_r(x, size);
if (ret != nullptr) {
memset(ret, 0, size);
}
return ret;
}

#if CONFIG_HAL_BOARD != HAL_BOARD_CHIBIOS
#elif CONFIG_HAL_BOARD != HAL_BOARD_CHIBIOS
/*
wrapper around malloc to ensure all memory is initialised as zero
ChibiOS has its own wrapper
Expand Down
Loading