/* Return the directory name portion of a PATH as a new string */ char *nasm_dirname(const char *path) { const char *p = first_filename_char(path); const char *p0 = p; (void)p0; /* Don't warn if unused */ if (p == path) return nasm_strdup(curdir); #ifdef cleandirend while (p > path+leaveonclean) { if (ismatch(cleandirend, p[-1])) break; p--; } #endif #ifdef leave_leading /* If the directory contained ONLY separators, leave as-is */ if (p == path+leaveonclean) p = p0; #endif return nasm_strndup(path, p-path); }
static void dbgls_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { struct ieeeSection *seg; /* Keep compiler from warning about special */ (void)special; /* * If it's a special-retry from pass two, discard it. */ if (is_global == 3) return; /* * First check for the double-period, signifying something * unusual. */ if (name[0] == '.' && name[1] == '.' && name[2] != '@') { return; } /* * Case (i): */ if (ieee_seg_needs_update) return; if (segment < SEG_ABS && segment != NO_SEG && segment % 2) return; if (segment >= SEG_ABS || segment == NO_SEG) { return; } /* * If `any_segs' is still false, we might need to define a * default segment, if they're trying to declare a label in * `first_seg'. But the label should exist due to a prior * call to ieee_deflabel so we can skip that. */ for (seg = seghead; seg; seg = seg->next) if (seg->index == segment) { struct ieeePublic *loc; /* * Case (ii). Maybe MODPUB someday? */ if (!is_global) { last_defined = loc = nasm_malloc(sizeof(*loc)); *seg->loctail = loc; seg->loctail = &loc->next; loc->next = NULL; loc->name = nasm_strdup(name); loc->offset = offset; loc->segment = -1; loc->index = seg->ieee_index; } } }
int rdl_open(struct librarynode *lib, const char *name) { int i = rdl_verify(name); if (i) return i; lib->fp = NULL; lib->name = nasm_strdup(name); lib->referenced = 0; lib->next = NULL; return 0; }
static void nop_reset(char *file, int pass, ListGen *listgen, StrList **deplist) { src_set_fname(nasm_strdup(file)); src_set_linnum(0); nop_lineinc = 1; nop_fp = fopen(file, "r"); if (!nop_fp) nasm_error(ERR_FATAL | ERR_NOFILE, "unable to open input file `%s'", file); nop_list = listgen; (void)pass; /* placate compilers */ if (deplist) { StrList *sl = nasm_malloc(strlen(file)+1+sizeof sl->next); sl->next = NULL; strcpy(sl->str, file); *deplist = sl; } }
static void elf_deflabel(char *name, long segment, long offset, int is_global, char *special) { int pos = strslen; struct Symbol *sym; int special_used = FALSE; #if defined(DEBUG) && DEBUG>2 fprintf(stderr, " elf_deflabel: %s, seg=%ld, off=%ld, is_global=%d, %s\n", name, segment, offset, is_global, special); #endif if (name[0] == '.' && name[1] == '.' && name[2] != '@') { /* * This is a NASM special symbol. We never allow it into * the ELF symbol table, even if it's a valid one. If it * _isn't_ a valid one, we should barf immediately. */ if (strcmp(name, "..gotpc") && strcmp(name, "..gotoff") && strcmp(name, "..got") && strcmp(name, "..plt") && strcmp(name, "..sym")) error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); return; } if (is_global == 3) { struct Symbol **s; /* * Fix up a forward-reference symbol size from the first * pass. */ for (s = &fwds; *s; s = &(*s)->nextfwd) if (!strcmp((*s)->name, name)) { struct tokenval tokval; expr *e; char *p = special; while (*p && !isspace(*p)) p++; while (*p && isspace(*p)) p++; stdscan_reset(); stdscan_bufptr = p; tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL); if (e) { if (!is_simple(e)) error(ERR_NONFATAL, "cannot use relocatable" " expression as symbol size"); else (*s)->size = reloc_value(e); } /* * Remove it from the list of unresolved sizes. */ nasm_free((*s)->name); *s = (*s)->nextfwd; return; } return; /* it wasn't an important one */ } saa_wbytes(strs, name, (long)(1 + strlen(name))); strslen += 1 + strlen(name); sym = saa_wstruct(syms); sym->strpos = pos; sym->type = is_global ? SYM_GLOBAL : 0; sym->size = 0; if (segment == NO_SEG) sym->section = SHN_ABS; else { int i; sym->section = SHN_UNDEF; if (nsects == 0 && segment == def_seg) { int tempint; if (segment != elf_section_names(".text", 2, &tempint)) 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; } } } if (is_global == 2) { sym->size = offset; sym->value = 0; sym->section = SHN_COMMON; /* * We have a common variable. Check the special text to see * if it's a valid number and power of two; if so, store it * as the alignment for the common variable. */ if (special) { int err; sym->value = readnum(special, &err); if (err) error(ERR_NONFATAL, "alignment constraint `%s' is not a" " valid number", special); else if ((sym->value | (sym->value - 1)) != 2 * sym->value - 1) error(ERR_NONFATAL, "alignment constraint `%s' is not a" " power of two", special); } special_used = TRUE; } else sym->value = (sym->section == SHN_UNDEF ? 0 : offset); if (sym->type == SYM_GLOBAL) { /* * There's a problem here that needs fixing. * If sym->section == SHN_ABS, then the first line of the * else section causes a core dump, because its a reference * beyond the end of the section array. * This behaviour is exhibited by this code: * GLOBAL crash_nasm * crash_nasm equ 0 * * I'm not sure how to procede, because I haven't got the * first clue about how ELF works, so I don't know what to * do with it. Furthermore, I'm not sure what the rest of this * section of code does. Help? * * For now, I'll see if doing absolutely nothing with it will * work... */ if (sym->section == SHN_UNDEF || sym->section == SHN_COMMON) { bsym = raa_write(bsym, segment, nglobs); } else if (sym->section != SHN_ABS) { /* * This is a global symbol; so we must add it to the linked * list of global symbols in its section. We'll push it on * the beginning of the list, because it doesn't matter * much which end we put it on and it's easier like this. * * In addition, we check the special text for symbol * type and size information. */ sym->next = sects[sym->section - 1]->gsyms; sects[sym->section - 1]->gsyms = sym; if (special) { int n = strcspn(special, " "); if (!nasm_strnicmp(special, "function", n)) sym->type |= SYM_FUNCTION; else if (!nasm_strnicmp(special, "data", n) || !nasm_strnicmp(special, "object", n)) sym->type |= SYM_DATA; else error(ERR_NONFATAL, "unrecognised symbol type `%.*s'", n, special); if (special[n]) { struct tokenval tokval; expr *e; int fwd = FALSE; char *saveme = stdscan_bufptr; /* bugfix? fbk 8/10/00 */ while (special[n] && isspace(special[n])) n++; /* * We have a size expression; attempt to * evaluate it. */ stdscan_reset(); stdscan_bufptr = special + n; tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, &fwd, 0, error, NULL); if (fwd) { sym->nextfwd = fwds; fwds = sym; sym->name = nasm_strdup(name); } else if (e) { if (!is_simple(e)) error(ERR_NONFATAL, "cannot use relocatable" " expression as symbol size"); else sym->size = reloc_value(e); } stdscan_bufptr = saveme; /* bugfix? fbk 8/10/00 */ } special_used = TRUE; } } sym->globnum = nglobs; nglobs++; } else nlocals++; if (special && !special_used) error(ERR_NONFATAL, "no special symbol features supported here"); }
static void aout_deflabel (char *name, long segment, long offset, int is_global, char *special) { int pos = strslen+4; struct Symbol *sym; int special_used = FALSE; if (name[0] == '.' && name[1] == '.' && name[2] != '@') { /* * This is a NASM special symbol. We never allow it into * the a.out symbol table, even if it's a valid one. If it * _isn't_ a valid one, we should barf immediately. */ if (strcmp(name, "..gotpc") && strcmp(name, "..gotoff") && strcmp(name, "..got") && strcmp(name, "..plt") && strcmp(name, "..sym")) error (ERR_NONFATAL, "unrecognised special symbol `%s'", name); return; } if (is_global == 3) { struct Symbol **s; /* * Fix up a forward-reference symbol size from the first * pass. */ for (s = &fwds; *s; s = &(*s)->nextfwd) if (!strcmp((*s)->name, name)) { struct tokenval tokval; expr *e; char *p = special; while (*p && !isspace(*p)) p++; while (*p && isspace(*p)) p++; stdscan_reset(); stdscan_bufptr = p; tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL); if (e) { if (!is_simple(e)) error (ERR_NONFATAL, "cannot use relocatable" " expression as symbol size"); else (*s)->size = reloc_value(e); } /* * Remove it from the list of unresolved sizes. */ nasm_free ((*s)->name); *s = (*s)->nextfwd; return; } return; /* it wasn't an important one */ } saa_wbytes (strs, name, (long)(1+strlen(name))); strslen += 1+strlen(name); sym = saa_wstruct (syms); sym->strpos = pos; sym->type = is_global ? SYM_GLOBAL : 0; sym->segment = segment; if (segment == NO_SEG) sym->type |= SECT_ABS; else if (segment == stext.index) { sym->type |= SECT_TEXT; if (is_global) { sym->next = stext.gsyms; stext.gsyms = sym; } else if (!stext.asym) stext.asym = sym; } else if (segment == sdata.index) { sym->type |= SECT_DATA; if (is_global) { sym->next = sdata.gsyms; sdata.gsyms = sym; } else if (!sdata.asym) sdata.asym = sym; } else if (segment == sbss.index) { sym->type |= SECT_BSS; if (is_global) { sym->next = sbss.gsyms; sbss.gsyms = sym; } else if (!sbss.asym) sbss.asym = sym; } else sym->type = SYM_GLOBAL; if (is_global == 2) sym->value = offset; else sym->value = (sym->type == SYM_GLOBAL ? 0 : offset); if (is_global && sym->type != SYM_GLOBAL) { /* * Global symbol exported _from_ this module. We must check * the special text for type information. */ if (special) { int n = strcspn(special, " "); if (!nasm_strnicmp(special, "function", n)) sym->type |= SYM_FUNCTION; else if (!nasm_strnicmp(special, "data", n) || !nasm_strnicmp(special, "object", n)) sym->type |= SYM_DATA; else error(ERR_NONFATAL, "unrecognised symbol type `%.*s'", n, special); if (special[n]) { struct tokenval tokval; expr *e; int fwd = FALSE; char *saveme=stdscan_bufptr; /* bugfix? fbk 8/10/00 */ if (!bsd) { error(ERR_NONFATAL, "Linux a.out does not support" " symbol size information"); } else { while (special[n] && isspace(special[n])) n++; /* * We have a size expression; attempt to * evaluate it. */ sym->type |= SYM_WITH_SIZE; stdscan_reset(); stdscan_bufptr = special+n; tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, &fwd, 0, error, NULL); if (fwd) { sym->nextfwd = fwds; fwds = sym; sym->name = nasm_strdup(name); } else if (e) { if (!is_simple(e)) error (ERR_NONFATAL, "cannot use relocatable" " expression as symbol size"); else sym->size = reloc_value(e); } } stdscan_bufptr=saveme; /* bugfix? fbk 8/10/00 */ } special_used = TRUE; } } /* * define the references from external-symbol segment numbers * to these symbol records. */ if (segment != NO_SEG && segment != stext.index && segment != sdata.index && segment != sbss.index) bsym = raa_write (bsym, segment, nsyms); sym->symnum = nsyms; nsyms++; if (sym->type & SYM_WITH_SIZE) nsyms++; /* and another for the size */ if (special && !special_used) error(ERR_NONFATAL, "no special symbol features supported here"); }
/* Return the filename portion of a PATH as a new string */ char *nasm_basename(const char *path) { return nasm_strdup(first_filename_char(path)); }