Skip to content

Commit

Permalink
Add dwarf support
Browse files Browse the repository at this point in the history
The new gcc12 release does not support stabs any more.
This was a good reason to add support for dwarf.

The stabs code still works and is used if configure option --dwarf
is not used.

Tested on x86_64, i386, arm, arm64, riscv64 with dwarf-5.
Some debuggers may not support dwarf-5. Try using older dwarf versions
i that case.
The tccmacho.c code probably need some support for dwarf.

arm-gen.c, arm64-gen.c, i386-gen.c, riscv64-gen.c, x86_64-gen.
- fix get_sym_ref symbol size

arm-link.c, arm64-link.c, i386-link.c, riscv64-link.c, x86_64-link.c
- add R_DATA_32U

libtcc.c:
- parse -gdwarf option

tcc.c:
- add dwarf option

tcc.h:
- add dwarf option and sections

tccelf.c:
- init dwarf sections
- avoid adding sh_addr for dwarf sections
- remove dwarf relocs for output dll
- add dwarf sections for tccrun

tccgen.c:
- add dwarf defines + global data
- add dwarf_* functions
- mix dwarf code with stabs code
- a trick is used to emit function name in .debug_line section so
  only this section has to be parsed instead of .debug_info and
  .debug_abbrev.
- fix init debug_modes

tccrun.c:
- add dwarf sections in rt_context
- init them in tcc_run
- add new dwarf code rt_printline_dwarf to find file/function

dwarf.h:
- New file

tcc-doc.texi:
- document dwarf

configure:
- add dwarf option

lib/Makefile
- change -gstabs into -gdwarf

lib/bt-exe.c, tests/tests2/Makefile, tests/tests2/126_bound_global:
- Add __bound_init call
- Add new testcase to test it
  • Loading branch information
hermantb committed May 5, 2022
1 parent d3e940c commit 2f2708a
Show file tree
Hide file tree
Showing 26 changed files with 2,754 additions and 144 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ config*.h
config*.mak
config.texi
conftest*
c2str
tags
TAGS
tcc.1
Expand Down
2 changes: 1 addition & 1 deletion arm-gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ static void gen_bounds_epilog(void)
*bounds_ptr = 0;

sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
func_bound_offset, lbounds_section->data_offset);
func_bound_offset, PTR_SIZE);

/* generate bound local allocation */
if (offset_modified) {
Expand Down
1 change: 1 addition & 0 deletions arm-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/* relocation type for 32 bit data relocation */
#define R_DATA_32 R_ARM_ABS32
#define R_DATA_32U R_ARM_ABS32
#define R_DATA_PTR R_ARM_ABS32
#define R_JMP_SLOT R_ARM_JUMP_SLOT
#define R_GLOB_DAT R_ARM_GLOB_DAT
Expand Down
2 changes: 1 addition & 1 deletion arm64-gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ static void gen_bounds_epilog(void)
*bounds_ptr = 0;

sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
func_bound_offset, lbounds_section->data_offset);
func_bound_offset, PTR_SIZE);

/* generate bound local allocation */
if (offset_modified) {
Expand Down
1 change: 1 addition & 0 deletions arm64-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define EM_TCC_TARGET EM_AARCH64

#define R_DATA_32 R_AARCH64_ABS32
#define R_DATA_32U R_AARCH64_ABS32
#define R_DATA_PTR R_AARCH64_ABS64
#define R_JMP_SLOT R_AARCH64_JUMP_SLOT
#define R_GLOB_DAT R_AARCH64_GLOB_DAT
Expand Down
1 change: 1 addition & 0 deletions c67-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/* relocation type for 32 bit data relocation */
#define R_DATA_32 R_C60_32
#define R_DATA_32U R_C60_32
#define R_DATA_PTR R_C60_32
#define R_JMP_SLOT R_C60_JMP_SLOT
#define R_GLOB_DAT R_C60_GLOB_DAT
Expand Down
5 changes: 5 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ ar_set=
darwin=
cpu=
cpuver=
dwarf=

# OS specific
cpu_sys=`uname -m`
Expand Down Expand Up @@ -136,6 +137,8 @@ for opt do
;;
--cpu=*) cpu=`echo $opt | cut -d '=' -f 2-`
;;
--dwarf=*) dwarf=`echo $opt | cut -d '=' -f 2-`
;;
--enable-cross) confvars="$confvars cross"
;;
--disable-static) confvars="$confvars static=no"
Expand Down Expand Up @@ -328,6 +331,7 @@ Advanced options (experts only):
--config-backtrace=no disable stack backtraces (with -run or -bt)
--config-bcheck=no disable bounds checker (-b)
--config-predefs=no do not compile tccdefs.h, instead just include
--dwarf=x Use dwarf debug info instead of stabs (x=2..5)
EOF
exit 1
fi
Expand Down Expand Up @@ -493,6 +497,7 @@ print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
print_mak CONFIG_LDDIR "$tcc_lddir"
print_mak CONFIG_TRIPLET "$triplet"
print_mak TCC_CPU_VERSION "$cpuver" num
print_mak CONFIG_DWARF "$dwarf"

echo "ARCH=$cpu" >> config.mak
echo "TARGETOS=$targetos" >> config.mak
Expand Down
Loading

0 comments on commit 2f2708a

Please sign in to comment.