--- src/ld/parsers/macho_relocatable_file.cpp
+++ src/ld/parsers/macho_relocatable_file.cpp
@@ -1757,11 +1757,14 @@ typename A::P::uint_t Parser<A>::realAddr(typename A::P::uint_t addr)
 #define STACK_ALLOC_IF_SMALL(_type, _name, _actual_count, _maxCount) \
 	_type*  _name = NULL;   \
 	uint32_t _name##_count = 1; \
-	if ( _actual_count > _maxCount ) \
+	uint32_t _name##_stack_count = _actual_count; \
+	if ( _actual_count > _maxCount ) { \
 		_name = (_type*)malloc(sizeof(_type) * _actual_count); \
+		_name##_stack_count = 1; \
+	} \
 	else \
 		_name##_count = _actual_count; \
-	_type  _name##_buffer[_name##_count]; \
+	_type _name##_buffer[_name##_stack_count]; \
 	if ( _name == NULL ) \
 		_name = _name##_buffer;
 
@@ -1812,7 +1815,7 @@ ld::relocatable::File* Parser<A>::parse(const ParserOptions& opts)
 
 	// create lists of address that already have compact unwind and thus don't need the dwarf parsed
 	unsigned cuLsdaCount = 0;
-	pint_t cuStarts[countOfCUs];
+	STACK_ALLOC_IF_SMALL(pint_t, cuStarts, countOfCUs, 1024);
 	for (uint32_t i=0; i < countOfCUs; ++i) {
 		if ( CUSection<A>::encodingMeansUseDwarf(cuInfoArray[i].compactUnwindInfo) )
 			cuStarts[i] = -1;
