History

Add option -e for setting ELF file's entry

Ziyao committed 4 years ago

Commit 39ea3401 parent 03669243 files · +12 −2Browse files

Unified · Split

3 files
  1. libtcc.c +2 −0
  2. tcc.h +2 −0
  3. tccelf.c +8 −2
libtcc.c+2−0
@@ -1335,6 +1335,8 @@ static int tcc_set_linker(TCCState *s, const char *option) · 1334 unmodified lines
13351335 s->symbolic = 1;
13361336 } else if (link_option(option, "nostdlib", &p)) {
13371337 s->nostdlib = 1;
1338+ } else if (link_option(option, "e=", &p)) {
1339+ copy_linker_arg(&s->elf_entryname, p, 0);
13381340 } else if (link_option(option, "fini=", &p)) {
13391341 copy_linker_arg(&s->fini_symbol, p, 0);
13401342 ignoring = 1;
tcc.h+2−0
@@ -961,6 +961,8 @@ struct TCCState { · 960 unmodified lines
961961 Section *verneed_section;
962962 #endif
963963
964+ char *elf_entryname;
965+
964966 #ifdef TCC_IS_NATIVE
965967 const char *runtime_main;
966968 void **runtime_mem;
tccelf.c+8−2
@@ -2322,11 +2322,17 @@ static void tcc_output_elf(TCCState *s1, FILE *f, int phnum, ElfW(Phdr) *phdr, · 2321 unmodified lines
23222322 default:
23232323 case TCC_OUTPUT_EXE:
23242324 ehdr.e_type = ET_EXEC;
2325− ehdr.e_entry = get_sym_addr(s1, "_start", 1, 0);
2325+ ehdr.e_entry = get_sym_addr(s1,
2326+ s1->elf_entryname ?
2327+ s1->elf_entryname : "_start",
2328+ 1, 0);
23262329 break;
23272330 case TCC_OUTPUT_DLL:
23282331 ehdr.e_type = ET_DYN;
2329− ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */
2332+ ehdr.e_entry = s1->elf_entryname ?
2333+ get_sym_addr(s1,s1->elf_entryname,1,0) :
2334+ text_section->sh_addr;
2335+ /* XXX: is it correct ? */
23302336 break;
23312337 case TCC_OUTPUT_OBJ:
23322338 ehdr.e_type = ET_REL;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t