Jump to content
    

avr-gcc + debian11 + "stack smashing detected"

Добрый день.

После перерыва в программировании минимум в полгода потребовалось пересобрать гарантированно рабочий makefile-based проект avr, вылезает ошибка 

*** stack smashing detected ***: terminated

При этом при сборке пустого проекта ошибка ровно та же самая:

$ cat ./main.c
int main (void)
{
        return 0;
}
$ make

-------- begin --------
avr-gcc (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Compiling: main.c
avr-gcc -c -mmcu=atmega64 -I. -gstabs -DF_CPU=SYSTEM_CLOCK  -Os -Wall -Wstrict-prototypes -Wa,-adhlns=main.lst  -std=gnu99  main.c -o main.o

Linking: atmega64.elf
avr-gcc -mmcu=atmega64 -I. -gstabs -DF_CPU=SYSTEM_CLOCK  -Os -Wall -Wstrict-prototypes -Wa,-adhlns=main.o  -std=gnu99  main.o  --output atmega64.elf -Wl,-Map=atmega64.map,--cref    -lm
collect2: fatal error: ld terminated with signal 6 [Аварийный останов]
compilation terminated.
*** stack smashing detected ***: terminated
make: *** [makefile:391: atmega64.elf] Ошибка 1

 

В августе обновился деб10->деб11.

Подскажите, кто может, что изменилось и куда копать?

 

PS проекты под STM32 пересобираются нормально.

Edited by hw_engineer
дополнение

Share this post


Link to post
Share on other sites

После долгих раздумий выяснилось, что линковщик перестал адекватно реагировать на 

-Wl,-Map=atmega64.map,--cref

что, вообще-то, неожиданно...

Проблема, как я понимаю. не в проекте, а в системе, питоновских скриптах, что ли.

Если "карта" не требуется, то elf/hex собираются нормально.

Share this post


Link to post
Share on other sites

Вроде бы пара опций после -Wl это штатный режим (до сих пор работало, по кр.мере), но на всякий случай попробовал и отдельно: 

avr-gcc -c -mmcu=atmega64 -I. -gstabs   -Os -Wall -Wstrict-prototypes -std=gnu99  main.c -o main.o
avr-gcc -mmcu=atmega64 -I. -gstabs   -Os -Wall -Wstrict-prototypes -std=gnu99  main.o  --output main.elf  -Wl,-Map=main.map -Wl,--cref   -lm
collect2: fatal error: ld terminated with signal 6 [Аварийный останов]
compilation terminated.
*** stack smashing detected ***: terminated
make: *** [makefile_new:221: main.elf] Ошибка 1

 

Share this post


Link to post
Share on other sites

@hw_engineer, я как раз сегодня столкнулся с такой же проблемой после обновления на Debian 11. Дубовое решение - использовать запуск с LANG=""

Т.е. запускать

LANG="" avr-gcc -mmcu=atmega64 -I. -gstabs   .... 


или сделать export LANG="" перед запуском процесса сборки. Но это криво, нужно патчить ld в binutils, в котором есть кривой код:

	if (! header_printed)
	{
	  char buf[100];

	  sprintf (buf, _("Archive member included "
			  "to satisfy reference by file (symbol)\n\n"));
	  minfo ("%s", buf);
	  header_printed = TRUE;
	}

вызывающий в русской локали переполнение буфера.

Share this post


Link to post
Share on other sites

3 часа назад, hw_engineer сказал:

о, спасибо, буду знать!

т.е. 100 мало?

Русский текст в utf-8 может занимать довольно много. В общем случае нужно либо выделать по необходимости, либо использовать snprintf, а не писать строку неизвестного размера в буфер без контроля его переполнения.

PS: Залил пересобранный пакет для Debian 11 - https://dropmefiles.com/0Ujlp

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...