Skip to content

Commit 8680849

Browse files
committed
Merge branch 'feature/add_esp_common_component' into 'master'
esp_common: add stack check function for gcc See merge request sdk/ESP8266_RTOS_SDK!1059
2 parents bf053f8 + c326ec6 commit 8680849

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

components/esp_common/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
if(BOOTLOADER_BUILD)
2+
# For bootloader, all we need from esp_common is headers
3+
idf_component_register(INCLUDE_DIRS include)
4+
set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-Wl,--gc-sections")
5+
else()
6+
# Regular app build
7+
idf_component_register(SRCS "src/stack_check.c"
8+
INCLUDE_DIRS include)
9+
10+
set_source_files_properties(
11+
"src/stack_check.c"
12+
PROPERTIES COMPILE_FLAGS
13+
-fno-stack-protector)
14+
set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY LINK_LIBRARIES "-Wl,--gc-sections")
15+
set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-Wl,--gc-sections")
16+
endif()

components/esp_common/component.mk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Component Makefile
3+
#
4+
5+
COMPONENT_ADD_INCLUDEDIRS := include
6+
COMPONENT_SRCDIRS := src
7+
8+
# disable stack protection in files which are involved in initialization of that feature
9+
src/stack_check.o: CFLAGS := $(filter-out -fstack-protector%, $(CFLAGS))
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2010-2019 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
//Register Bits{{
18+
#define BIT31 0x80000000
19+
#define BIT30 0x40000000
20+
#define BIT29 0x20000000
21+
#define BIT28 0x10000000
22+
#define BIT27 0x08000000
23+
#define BIT26 0x04000000
24+
#define BIT25 0x02000000
25+
#define BIT24 0x01000000
26+
#define BIT23 0x00800000
27+
#define BIT22 0x00400000
28+
#define BIT21 0x00200000
29+
#define BIT20 0x00100000
30+
#define BIT19 0x00080000
31+
#define BIT18 0x00040000
32+
#define BIT17 0x00020000
33+
#define BIT16 0x00010000
34+
#define BIT15 0x00008000
35+
#define BIT14 0x00004000
36+
#define BIT13 0x00002000
37+
#define BIT12 0x00001000
38+
#define BIT11 0x00000800
39+
#define BIT10 0x00000400
40+
#define BIT9 0x00000200
41+
#define BIT8 0x00000100
42+
#define BIT7 0x00000080
43+
#define BIT6 0x00000040
44+
#define BIT5 0x00000020
45+
#define BIT4 0x00000010
46+
#define BIT3 0x00000008
47+
#define BIT2 0x00000004
48+
#define BIT1 0x00000002
49+
#define BIT0 0x00000001
50+
//}}
51+
52+
#ifndef __ASSEMBLER__
53+
#define BIT(nr) (1UL << (nr))
54+
#define BIT64(nr) (1ULL << (nr))
55+
#else
56+
#define BIT(nr) (1 << (nr))
57+
#endif
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2017 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <stdlib.h>
16+
#include "sdkconfig.h"
17+
#include "esp_system.h"
18+
19+
#if CONFIG_COMPILER_STACK_CHECK
20+
21+
#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL
22+
#include "esp_log.h"
23+
const static char *TAG = "stack_chk";
24+
25+
void *__stack_chk_guard = NULL;
26+
27+
static void __attribute__ ((constructor))
28+
__esp_stack_guard_setup (void)
29+
{
30+
ESP_LOGD(TAG, "Intialize random stack guard");
31+
__stack_chk_guard = (void *)esp_random();
32+
}
33+
34+
void __stack_chk_fail (void)
35+
{
36+
ets_printf("\r\nStack smashing protect failure!\r\n\r\n");
37+
abort();
38+
}
39+
40+
#endif

0 commit comments

Comments
 (0)