Skip to content

Commit

Permalink
Merge branch 'mob'
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Nov 10, 2024
2 parents f6e86d9 + f0cd0fb commit 46c0c2e
Show file tree
Hide file tree
Showing 9 changed files with 398 additions and 61 deletions.
2 changes: 1 addition & 1 deletion arm64-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
break;
}
}
write32le(ptr, val - addr);
add32le(ptr, val - addr);
return;
case R_AARCH64_MOVW_UABS_G0_NC:
write32le(ptr, ((read32le(ptr) & 0xffe0001f) |
Expand Down
16 changes: 9 additions & 7 deletions lib/bcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,9 @@ void * __bound_ptr_add(void *p, size_t offset)
if (tree->is_invalid || addr + offset > tree->size) {
POST_SEM ();
if (print_warn_ptr_add)
bound_warning("%p is outside of the region", p + offset);
bound_warning("%p is outside of the region (0x%lx..0x%lx)",
p + offset, (long)tree->start,
(long)(tree->start + tree->size - 1));
if (never_fatal <= 0)
return INVALID_POINTER; /* return an invalid pointer */
return p + offset;
Expand Down Expand Up @@ -605,7 +607,9 @@ void * __bound_ptr_indir ## dsize (void *p, size_t offset) \
if (addr <= tree->size) { \
if (tree->is_invalid || addr + offset + dsize > tree->size) { \
POST_SEM (); \
bound_warning("%p is outside of the region", p + offset); \
bound_warning("%p is outside of the region (0x%lx..0x%lx)", \
p + offset, (long)tree->start, \
(long)(tree->start + tree->size - 1)); \
if (never_fatal <= 0) \
return INVALID_POINTER; /* return an invalid pointer */ \
return p + offset; \
Expand Down Expand Up @@ -1105,11 +1109,9 @@ void __bound_init(size_t *p, int mode)
while (p[0] != 0) {
tree = splay_insert(p[0], p[1], tree);
#if BOUND_DEBUG
if (print_calls) {
dprintf(stderr, "%s, %s(): static var %p 0x%lx\n",
__FILE__, __FUNCTION__,
(void *) p[0], (unsigned long) p[1]);
}
dprintf(stderr, "%s, %s(): static var %p 0x%lx\n",
__FILE__, __FUNCTION__,
(void *) p[0], (unsigned long) p[1]);
#endif
p += 2;
}
Expand Down
15 changes: 14 additions & 1 deletion riscv64-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,21 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
case R_RISCV_SUB6:
*ptr = (*ptr & ~0x3f) | ((*ptr - val) & 0x3f);
return;

case R_RISCV_32_PCREL:
if (s1->output_type & TCC_OUTPUT_DYN) {
/* DLL relocation */
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
if (esym_index) {
qrel->r_offset = rel->r_offset;
qrel->r_info = ELFW(R_INFO)(esym_index, R_RISCV_32_PCREL);
/* Use sign extension! */
qrel->r_addend = (int)read32le(ptr) + rel->r_addend;
qrel++;
break;
}
}
add32le(ptr, val - addr);
return;
case R_RISCV_COPY:
/* XXX */
return;
Expand Down
57 changes: 57 additions & 0 deletions tcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,10 @@ struct TCCState {
Section *dynsym;
/* got & plt handling */
Section *got, *plt;
/* exception handling */
Section *eh_frame_section;
Section *eh_frame_hdr_section;
unsigned long eh_start;
/* debug sections */
Section *stab_section;
Section *dwarf_info_section;
Expand Down Expand Up @@ -1673,6 +1677,53 @@ static inline void write64le(unsigned char *p, uint64_t x) {
static inline void add64le(unsigned char *p, int64_t x) {
write64le(p, read64le(p) + x);
}
#define DWARF_MAX_128 ((8 * sizeof (int64_t) + 6) / 7)
#define dwarf_read_1(ln,end) \
((ln) < (end) ? *(ln)++ : 0)
#define dwarf_read_2(ln,end) \
((ln) + 1 < (end) ? (ln) += 2, read16le((ln) - 2) : 0)
#define dwarf_read_4(ln,end) \
((ln) + 3 < (end) ? (ln) += 4, read32le((ln) - 4) : 0)
#define dwarf_read_8(ln,end) \
((ln) + 7 < (end) ? (ln) += 8, read64le((ln) - 8) : 0)
static inline uint64_t
dwarf_read_uleb128(unsigned char **ln, unsigned char *end)
{
unsigned char *cp = *ln;
uint64_t retval = 0;
int i;

for (i = 0; i < DWARF_MAX_128; i++) {
uint64_t byte = dwarf_read_1(cp, end);

retval |= (byte & 0x7f) << (i * 7);
if ((byte & 0x80) == 0)
break;
}
*ln = cp;
return retval;
}
static inline int64_t
dwarf_read_sleb128(unsigned char **ln, unsigned char *end)
{
unsigned char *cp = *ln;
int64_t retval = 0;
int i;

for (i = 0; i < DWARF_MAX_128; i++) {
uint64_t byte = dwarf_read_1(cp, end);

retval |= (byte & 0x7f) << (i * 7);
if ((byte & 0x80) == 0) {
if ((byte & 0x40) && (i + 1) * 7 < 64)
retval |= -1LL << ((i + 1) * 7);
break;
}
}
*ln = cp;
return retval;
}


/* ------------ i386-gen.c ------------ */
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM
Expand Down Expand Up @@ -1818,6 +1869,10 @@ ST_FUNC int gen_makedeps(TCCState *s, const char *target, const char *filename);

/* ------------ tccdbg.c ------------ */

ST_FUNC void tcc_eh_frame_start(TCCState *s1);
ST_FUNC void tcc_eh_frame_end(TCCState *s1);
ST_FUNC void tcc_eh_frame_hdr(TCCState *s1, int final);

ST_FUNC void tcc_debug_new(TCCState *s);

ST_FUNC void tcc_debug_start(TCCState *s1);
Expand Down Expand Up @@ -1846,6 +1901,8 @@ ST_FUNC void tcc_tcov_reset_ind(TCCState *s1);
#define stab_section s1->stab_section
#define stabstr_section stab_section->link
#define tcov_section s1->tcov_section
#define eh_frame_section s1->eh_frame_section
#define eh_frame_hdr_section s1->eh_frame_hdr_section
#define dwarf_info_section s1->dwarf_info_section
#define dwarf_abbrev_section s1->dwarf_abbrev_section
#define dwarf_line_section s1->dwarf_line_section
Expand Down
Loading

0 comments on commit 46c0c2e

Please sign in to comment.