Skip to content

Commit d7ddbe4

Browse files
committed
Initialize required global variables to avoid compilation failure
In dynamic linking mode, the bootstrapping process will fail, and the root cause is that certain global variables are uninitialized, causing the compiler to retrieve invalid values and trigger a segmentation fault. After further experiments, this commit initializes minimal required variables so that the bootstrapping can complete in both static and dynamic modes.
1 parent 72d1b48 commit d7ddbe4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/elf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "defs.h"
1212
#include "globals.c"
1313

14-
int elf_symbol_index;
14+
int elf_symbol_index = 0;
1515

1616
void elf_write_str(strbuf_t *elf_array, const char *vals)
1717
{

src/globals.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ char *intern_string(char *str);
1818

1919
/* Lexer */
2020
char token_str[MAX_TOKEN_LEN];
21-
token_t next_token;
22-
char next_char;
21+
token_t next_token = 0;
22+
char next_char = 0;
2323
bool skip_newline = true;
2424

2525
/* Token memory management */
@@ -32,7 +32,7 @@ bool preproc_match;
3232
/* Point to the first character after where the macro has been called. It is
3333
* needed when returning from the macro body.
3434
*/
35-
int macro_return_idx;
35+
int macro_return_idx = 0;
3636

3737
/* Global objects */
3838

@@ -1236,6 +1236,10 @@ void strbuf_free(strbuf_t *src)
12361236
*/
12371237
void global_init(void)
12381238
{
1239+
FUNC_LIST.head = NULL;
1240+
FUNC_LIST.tail = NULL;
1241+
memset(REGS, 0, sizeof(regfile_t) * REG_CNT);
1242+
12391243
MACROS_MAP = hashmap_create(MAX_ALIASES);
12401244

12411245
/* Initialize arenas first so we can use them for allocation */

0 commit comments

Comments
 (0)