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
448448 int nb_hashed_syms; /* used to resize the hash table */
449449 struct Section *link; /* link to another section */
450450 struct Section *reloc; /* corresponding section for relocation, if any */
451− struct Section *hash; /* hash table for symbols */
452− struct Section *next;
451+ struct Section *hash; /* hash table for symbols */
452+ struct Section *prev; /* previous section on section stack */
453453 char name[1]; /* section name */
454454 } Section;
455455
tccasm.c+26−1
@@ -335,6 +335,22 @@ static void use_section(TCCState *s1, const char *name) · 334 unmodified lines
335335 use_section1(s1, sec);
336336 }
337337
338+static 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+
345+static 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+
338354 static void asm_parse_directive(TCCState *s1)
339355 {
340356 int n, offset, v, size, tok1;
@@ -683,10 +699,12 @@ static void asm_parse_directive(TCCState *s1) · 342 unmodified lines
683699 next();
684700 }
685701 break;
702+ case TOK_ASMDIR_pushsection:
686703 case TOK_ASMDIR_section:
687704 {
688705 char sname[256];
689706
707+ tok1 = tok;
690708 /* XXX: support more options */
691709 next();
692710 sname[0] = '\0';
@@ -711,7 +729,10 @@ static void asm_parse_directive(TCCState *s1) · 18 unmodified lines
711729 }
712730 }
713731 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);
715736 }
716737 break;
717738 case TOK_ASMDIR_previous:
@@ -725,6 +746,10 @@ static void asm_parse_directive(TCCState *s1) · 7 unmodified lines
725746 last_text_section = sec;
726747 }
727748 break;
749+ case TOK_ASMDIR_popsection:
750+ next();
751+ pop_section(s1);
752+ break;
728753 #ifdef TCC_TARGET_I386
729754 case TOK_ASMDIR_code16:
730755 {
tcctok.h+2−0
@@ -323,6 +323,8 @@ · 322 unmodified lines
323323 DEF_ASMDIR(data)
324324 DEF_ASMDIR(bss)
325325 DEF_ASMDIR(previous)
326+ DEF_ASMDIR(pushsection)
327+ DEF_ASMDIR(popsection)
326328 DEF_ASMDIR(fill)
327329 DEF_ASMDIR(rept)
328330 DEF_ASMDIR(endr)
tests/asmtest.S+10−0
@@ -717,6 +717,16 @@ ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9: · 716 unmodified lines
717717 .endr
718718 .fill 4,1,0x90
719719
720+.section .text.one,"ax"
721+nop
722+.previous
723+.pushsection .text.one,"ax"
724+nop
725+.pushsection .text.two,"ax"
726+nop
727+.popsection
728+.popsection
729+
720730 movd %esi, %mm1
721731 movd %edi, %xmm2
722732 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