History

tccasm: Implement .pushsection and .popsection

Michael Matz committed 10 years ago

Commit c82e52d1 parent 6763b024 files · +40 −3Browse files

Unified · Split

4 files
  1. tcc.h +2 −2
  2. tccasm.c +26 −1
  3. tcctok.h +2 −0
  4. tests/asmtest.S +10 −0
tcc.h+2−2
@@ -448,8 +448,8 @@ typedef struct Section { · 447 unmodified lines
448 int nb_hashed_syms; /* used to resize the hash table */448 int nb_hashed_syms; /* used to resize the hash table */
449 struct Section *link; /* link to another section */449 struct Section *link; /* link to another section */
450 struct Section *reloc; /* corresponding section for relocation, if any */450 struct Section *reloc; /* corresponding section for relocation, if any */
451 struct Section *hash; /* hash table for symbols */451 struct Section *hash; /* hash table for symbols */
452 struct Section *next;452 struct Section *prev; /* previous section on section stack */
453 char name[1]; /* section name */453 char name[1]; /* section name */
454} Section;454} Section;
455 455
tccasm.c+26−1
@@ -335,6 +335,22 @@ static void use_section(TCCState *s1, const char *name) · 334 unmodified lines
335 use_section1(s1, sec);335 use_section1(s1, sec);
336}336}
337 337
338static void push_section(TCCState *s1, const char *name)
339{
340 Section *sec = find_section(s1, name);
341 sec->prev = cur_text_section;
342 use_section1(s1, sec);
343}
344
345static void pop_section(TCCState *s1)
346{
347 Section *prev = cur_text_section->prev;
348 if (!prev)
349 tcc_error(".popsection without .pushsection");
350 cur_text_section->prev = NULL;
351 use_section1(s1, prev);
352}
353
338static void asm_parse_directive(TCCState *s1)354static void asm_parse_directive(TCCState *s1)
339{355{
340 int n, offset, v, size, tok1;356 int n, offset, v, size, tok1;
@@ -683,10 +699,12 @@ static void asm_parse_directive(TCCState *s1) · 342 unmodified lines
683 next();699 next();
684 }700 }
685 break;701 break;
702 case TOK_ASMDIR_pushsection:
686 case TOK_ASMDIR_section:703 case TOK_ASMDIR_section:
687 {704 {
688 char sname[256];705 char sname[256];
689 706
707 tok1 = tok;
690 /* XXX: support more options */708 /* XXX: support more options */
691 next();709 next();
692 sname[0] = '\0';710 sname[0] = '\0';
@@ -711,7 +729,10 @@ static void asm_parse_directive(TCCState *s1) · 18 unmodified lines
711 }729 }
712 }730 }
713 last_text_section = cur_text_section;731 last_text_section = cur_text_section;
714 use_section(s1, sname);732 if (tok1 == TOK_ASMDIR_section)
733 use_section(s1, sname);
734 else
735 push_section(s1, sname);
715 }736 }
716 break;737 break;
717 case TOK_ASMDIR_previous:738 case TOK_ASMDIR_previous:
@@ -725,6 +746,10 @@ static void asm_parse_directive(TCCState *s1) · 7 unmodified lines
725 last_text_section = sec;746 last_text_section = sec;
726 }747 }
727 break;748 break;
749 case TOK_ASMDIR_popsection:
750 next();
751 pop_section(s1);
752 break;
728#ifdef TCC_TARGET_I386753#ifdef TCC_TARGET_I386
729 case TOK_ASMDIR_code16:754 case TOK_ASMDIR_code16:
730 {755 {
tcctok.h+2−0
@@ -323,6 +323,8 @@ · 322 unmodified lines
323 DEF_ASMDIR(data)323 DEF_ASMDIR(data)
324 DEF_ASMDIR(bss)324 DEF_ASMDIR(bss)
325 DEF_ASMDIR(previous)325 DEF_ASMDIR(previous)
326 DEF_ASMDIR(pushsection)
327 DEF_ASMDIR(popsection)
326 DEF_ASMDIR(fill)328 DEF_ASMDIR(fill)
327 DEF_ASMDIR(rept)329 DEF_ASMDIR(rept)
328 DEF_ASMDIR(endr)330 DEF_ASMDIR(endr)
tests/asmtest.S+10−0
@@ -717,6 +717,16 @@ ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9: · 716 unmodified lines
717.endr717.endr
718.fill 4,1,0x90718.fill 4,1,0x90
719 719
720.section .text.one,"ax"
721nop
722.previous
723.pushsection .text.one,"ax"
724nop
725.pushsection .text.two,"ax"
726nop
727.popsection
728.popsection
729
720 movd %esi, %mm1730 movd %esi, %mm1
721 movd %edi, %xmm2731 movd %edi, %xmm2
722 movd (%ebx), %mm3732 movd (%ebx), %mm3

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