From 2ddcd03900d134772e98acf8cab17a12cc0c3f2a Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Sun, 29 Nov 2009 23:21:16 +0300 Subject: [PATCH] Elf: bind labels to text section by default In case if SECTION directive is omitted but the real code exist we form .text section by default and put compiled code here. In turn labels are not handled in a same manner. So lets bind them to text section by default as well. [ BR: 2835192 ] Signed-off-by: Cyrill Gorcunov --- output/outelf32.c | 23 ++++++++++++----------- output/outelf64.c | 23 ++++++++++++----------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/output/outelf32.c b/output/outelf32.c index de318056..1625fb7d 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -523,19 +523,20 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, else { int i; sym->section = SHN_UNDEF; - if (nsects == 0 && segment == def_seg) { + if (segment == def_seg) { + /* we have to be sure at least text section is there */ int tempint; - if (segment != elf_section_names(".text", 2, &tempint)) - nasm_error(ERR_PANIC, - "strange segment conditions in ELF driver"); - sym->section = nsects; - } else { - for (i = 0; i < nsects; i++) - if (segment == sects[i]->index) { - sym->section = i + 1; - break; - } + elf_section_names(".text", 2, &tempint); } + sym->section = nsects; + for (i = 0; i < nsects; i++) { + if (segment == sects[i]->index) { + sym->section = i + 1; + break; + } + } + if (nsects && i == nsects) + nasm_error(ERR_PANIC, "strange segment conditions in ELF driver"); } if (is_global == 2) { diff --git a/output/outelf64.c b/output/outelf64.c index ba049b1c..18508fb3 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -527,19 +527,20 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, else { int i; sym->section = SHN_UNDEF; - if (nsects == 0 && segment == def_seg) { + if (segment == def_seg) { + /* we have to be sure at least text section is there */ int tempint; - if (segment != elf_section_names(".text", 2, &tempint)) - nasm_error(ERR_PANIC, - "strange segment conditions in ELF driver"); - sym->section = nsects; - } else { - for (i = 0; i < nsects; i++) - if (segment == sects[i]->index) { - sym->section = i + 1; - break; - } + elf_section_names(".text", 2, &tempint); } + sym->section = nsects; + for (i = 0; i < nsects; i++) { + if (segment == sects[i]->index) { + sym->section = i + 1; + break; + } + } + if (nsects && i == nsects) + nasm_error(ERR_PANIC, "strange segment conditions in ELF driver"); } if (is_global == 2) { -- 2.11.4.GIT