int32_t index;
struct Reloc *head, **tail;
uint32_t flags; /* section flags */
- char name[9];
+ char *name;
+ int32_t namepos; /* Offset of name into the strings table */
int32_t pos, relpos;
};
static void coff_gen_init(void);
static void coff_sect_write(struct Section *, const uint8_t *, uint32_t);
static void coff_write(void);
-static void coff_section_header(char *, int32_t, int32_t, int32_t, int32_t, int, int32_t);
+static void coff_section_header(char *, int32_t, int32_t, int32_t, int32_t, int32_t, int, int32_t);
static void coff_write_relocs(struct Section *);
static void coff_write_symbols(void);
sects[i]->head = sects[i]->head->next;
nasm_free(r);
}
+ nasm_free(sects[i]->name);
nasm_free(sects[i]);
}
nasm_free(sects);
static int coff_make_section(char *name, uint32_t flags)
{
struct Section *s;
+ size_t namelen;
s = nasm_zalloc(sizeof(*s));
s->index = def_seg;
else
s->index = seg_alloc();
- strncpy(s->name, name, 8);
- s->name[8] = '\0';
+ s->namepos = -1;
+ namelen = strlen(name);
+ if (namelen > 8) {
+ if (win32 || win64) {
+ s->namepos = strslen + 4;
+ saa_wbytes(strs, name, namelen + 1);
+ strslen += namelen + 1;
+ } else {
+ namelen = 8;
+ }
+ }
+ s->name = nasm_malloc(namelen + 1);
+ strncpy(s->name, name, namelen);
+ s->name[namelen] = '\0';
s->flags = flags;
if (nsects >= sectlen) {
if (*p)
*p++ = '\0';
if (strlen(name) > 8) {
- nasm_error(ERR_WARNING, "COFF section names limited to 8 characters:"
- " truncating");
- name[8] = '\0';
+ if (!win32 && !win64) {
+ nasm_error(ERR_WARNING,
+ "COFF section names limited to 8 characters: truncating");
+ name[8] = '\0';
+ }
}
flags = 0;
*/
vsize = 0L;
for (i = 0; i < nsects; i++) {
- coff_section_header(sects[i]->name, vsize, sects[i]->len,
+ coff_section_header(sects[i]->name, sects[i]->namepos, vsize, sects[i]->len,
sects[i]->pos, sects[i]->relpos,
sects[i]->nrelocs, sects[i]->flags);
vsize += sects[i]->len;
saa_fpwrite(strs, ofile);
}
-static void coff_section_header(char *name, int32_t vsize,
+static void coff_section_header(char *name, int32_t namepos, int32_t vsize,
int32_t datalen, int32_t datapos,
int32_t relpos, int nrelocs, int32_t flags)
{
(void)vsize;
- strncpy(padname, name, 8);
- fwrite(padname, 8, 1, ofile);
+ if (namepos == -1) {
+ strncpy(padname, name, 8);
+ fwrite(padname, 8, 1, ofile);
+ } else {
+ /*
+ * If name is longer than 8 bytes, write '/' followed
+ * by offset into the strings table represented as
+ * decimal number.
+ */
+ namepos = namepos % 100000000;
+ padname[0] = '/';
+ padname[1] = '0' + (namepos / 1000000);
+ namepos = namepos % 1000000;
+ padname[2] = '0' + (namepos / 100000);
+ namepos = namepos % 100000;
+ padname[3] = '0' + (namepos / 10000);
+ namepos = namepos % 10000;
+ padname[4] = '0' + (namepos / 1000);
+ namepos = namepos % 1000;
+ padname[5] = '0' + (namepos / 100);
+ namepos = namepos % 100;
+ padname[6] = '0' + (namepos / 10);
+ namepos = namepos % 10;
+ padname[7] = '0' + (namepos);
+ fwrite(padname, 8, 1, ofile);
+ }
fwriteint32_t(0, ofile); /* Virtual size field - set to 0 or vsize */
fwriteint32_t(0L, ofile); /* RVA/offset - we ignore */
uint32_t v = 0, vmin = 0;
while (len--) {
- c = *str++;
-
- if (expect) {
- if ((c & 0xc0) != 0x80) {
- expect = 0;
- return -1;
- } else {
- v = (v << 6) | (c & 0x3f);
- if (!--expect) {
- if (v < vmin || v > 0x10ffff ||
- (v >= 0xd800 && v <= 0xdfff)) {
- return -1;
- } else if (v > 0xffff) {
- v -= 0x10000;
- EMIT(0xd800 | (v >> 10));
- EMIT(0xdc00 | (v & 0x3ff));
- } else {
- EMIT(v);
- }
- }
- continue;
- }
- }
-
- if (c < 0x80) {
- EMIT(c);
- } else if (c < 0xc0 || c >= 0xfe) {
- /* Invalid UTF-8 */
- return -1;
- } else if (c < 0xe0) {
- v = c & 0x1f;
- expect = 1;
- vmin = 0x80;
- } else if (c < 0xf0) {
- v = c & 0x0f;
- expect = 2;
- vmin = 0x800;
- } else if (c < 0xf8) {
- v = c & 0x07;
- expect = 3;
- vmin = 0x10000;
- } else if (c < 0xfc) {
- v = c & 0x03;
- expect = 4;
- vmin = 0x200000;
- } else {
- v = c & 0x01;
- expect = 5;
- vmin = 0x4000000;
- }
+ c = *str++;
+
+ if (expect) {
+ if ((c & 0xc0) != 0x80) {
+ expect = 0;
+ return -1;
+ } else {
+ v = (v << 6) | (c & 0x3f);
+ if (!--expect) {
+ if (v < vmin || v > 0x10ffff ||
+ (v >= 0xd800 && v <= 0xdfff)) {
+ return -1;
+ } else if (v > 0xffff) {
+ v -= 0x10000;
+ EMIT(0xd800 | (v >> 10));
+ EMIT(0xdc00 | (v & 0x3ff));
+ } else {
+ EMIT(v);
+ }
+ }
+ continue;
+ }
+ }
+
+ if (c < 0x80) {
+ EMIT(c);
+ } else if (c < 0xc0 || c >= 0xfe) {
+ /* Invalid UTF-8 */
+ return -1;
+ } else if (c < 0xe0) {
+ v = c & 0x1f;
+ expect = 1;
+ vmin = 0x80;
+ } else if (c < 0xf0) {
+ v = c & 0x0f;
+ expect = 2;
+ vmin = 0x800;
+ } else if (c < 0xf8) {
+ v = c & 0x07;
+ expect = 3;
+ vmin = 0x10000;
+ } else if (c < 0xfc) {
+ v = c & 0x03;
+ expect = 4;
+ vmin = 0x200000;
+ } else {
+ v = c & 0x01;
+ expect = 5;
+ vmin = 0x4000000;
+ }
}
return expect ? (size_t)-1 : outlen << 1;
uint32_t v = 0, vmin = 0;
while (len--) {
- c = *str++;
-
- if (expect) {
- if ((c & 0xc0) != 0x80) {
- expect = 0;
- return -1;
- } else {
- v = (v << 6) | (c & 0x3f);
- if (!--expect) {
- if (v < vmin || v > 0x10ffff ||
- (v >= 0xd800 && v <= 0xdfff)) {
- return -1;
- } else if (v > 0xffff) {
- v -= 0x10000;
- EMIT(0xdc00 | (v & 0x3ff));
- EMIT(0xd800 | (v >> 10));
- } else {
- EMIT(v);
- }
- }
- continue;
- }
- }
-
- if (c < 0x80) {
- EMIT(c);
- } else if (c < 0xc0 || c >= 0xfe) {
- /* Invalid UTF-8 */
- return -1;
- } else if (c < 0xe0) {
- v = c & 0x1f;
- expect = 1;
- vmin = 0x80;
- } else if (c < 0xf0) {
- v = c & 0x0f;
- expect = 2;
- vmin = 0x800;
- } else if (c < 0xf8) {
- v = c & 0x07;
- expect = 3;
- vmin = 0x10000;
- } else if (c < 0xfc) {
- v = c & 0x03;
- expect = 4;
- vmin = 0x200000;
- } else {
- v = c & 0x01;
- expect = 5;
- vmin = 0x4000000;
- }
+ c = *str++;
+
+ if (expect) {
+ if ((c & 0xc0) != 0x80) {
+ expect = 0;
+ return -1;
+ } else {
+ v = (v << 6) | (c & 0x3f);
+ if (!--expect) {
+ if (v < vmin || v > 0x10ffff ||
+ (v >= 0xd800 && v <= 0xdfff)) {
+ return -1;
+ } else if (v > 0xffff) {
+ v -= 0x10000;
+ EMIT(0xdc00 | (v & 0x3ff));
+ EMIT(0xd800 | (v >> 10));
+ } else {
+ EMIT(v);
+ }
+ }
+ continue;
+ }
+ }
+
+ if (c < 0x80) {
+ EMIT(c);
+ } else if (c < 0xc0 || c >= 0xfe) {
+ /* Invalid UTF-8 */
+ return -1;
+ } else if (c < 0xe0) {
+ v = c & 0x1f;
+ expect = 1;
+ vmin = 0x80;
+ } else if (c < 0xf0) {
+ v = c & 0x0f;
+ expect = 2;
+ vmin = 0x800;
+ } else if (c < 0xf8) {
+ v = c & 0x07;
+ expect = 3;
+ vmin = 0x10000;
+ } else if (c < 0xfc) {
+ v = c & 0x03;
+ expect = 4;
+ vmin = 0x200000;
+ } else {
+ v = c & 0x01;
+ expect = 5;
+ vmin = 0x4000000;
+ }
}
return expect ? (size_t)-1 : outlen << 1;
uint32_t v = 0, vmin = 0;
while (len--) {
- c = *str++;
-
- if (expect) {
- if ((c & 0xc0) != 0x80) {
- return -1;
- } else {
- v = (v << 6) | (c & 0x3f);
- if (!--expect) {
- if (v < vmin || (v >= 0xd800 && v <= 0xdfff)) {
- return -1;
- } else {
- EMIT(v);
- }
- }
- continue;
- }
- }
-
- if (c < 0x80) {
- EMIT(c);
- } else if (c < 0xc0 || c >= 0xfe) {
- /* Invalid UTF-8 */
- return -1;
- } else if (c < 0xe0) {
- v = c & 0x1f;
- expect = 1;
- vmin = 0x80;
- } else if (c < 0xf0) {
- v = c & 0x0f;
- expect = 2;
- vmin = 0x800;
- } else if (c < 0xf8) {
- v = c & 0x07;
- expect = 3;
- vmin = 0x10000;
- } else if (c < 0xfc) {
- v = c & 0x03;
- expect = 4;
- vmin = 0x200000;
- } else {
- v = c & 0x01;
- expect = 5;
- vmin = 0x4000000;
- }
+ c = *str++;
+
+ if (expect) {
+ if ((c & 0xc0) != 0x80) {
+ return -1;
+ } else {
+ v = (v << 6) | (c & 0x3f);
+ if (!--expect) {
+ if (v < vmin || (v >= 0xd800 && v <= 0xdfff)) {
+ return -1;
+ } else {
+ EMIT(v);
+ }
+ }
+ continue;
+ }
+ }
+
+ if (c < 0x80) {
+ EMIT(c);
+ } else if (c < 0xc0 || c >= 0xfe) {
+ /* Invalid UTF-8 */
+ return -1;
+ } else if (c < 0xe0) {
+ v = c & 0x1f;
+ expect = 1;
+ vmin = 0x80;
+ } else if (c < 0xf0) {
+ v = c & 0x0f;
+ expect = 2;
+ vmin = 0x800;
+ } else if (c < 0xf8) {
+ v = c & 0x07;
+ expect = 3;
+ vmin = 0x10000;
+ } else if (c < 0xfc) {
+ v = c & 0x03;
+ expect = 4;
+ vmin = 0x200000;
+ } else {
+ v = c & 0x01;
+ expect = 5;
+ vmin = 0x4000000;
+ }
}
return expect ? (size_t)-1 : outlen << 2;
uint32_t v = 0, vmin = 0;
while (len--) {
- c = *str++;
-
- if (expect) {
- if ((c & 0xc0) != 0x80) {
- return -1;
- } else {
- v = (v << 6) | (c & 0x3f);
- if (!--expect) {
- if (v < vmin || (v >= 0xd800 && v <= 0xdfff)) {
- return -1;
- } else {
- EMIT(v);
- }
- }
- continue;
- }
- }
-
- if (c < 0x80) {
- EMIT(c);
- } else if (c < 0xc0 || c >= 0xfe) {
- /* Invalid UTF-8 */
- return -1;
- } else if (c < 0xe0) {
- v = c & 0x1f;
- expect = 1;
- vmin = 0x80;
- } else if (c < 0xf0) {
- v = c & 0x0f;
- expect = 2;
- vmin = 0x800;
- } else if (c < 0xf8) {
- v = c & 0x07;
- expect = 3;
- vmin = 0x10000;
- } else if (c < 0xfc) {
- v = c & 0x03;
- expect = 4;
- vmin = 0x200000;
- } else {
- v = c & 0x01;
- expect = 5;
- vmin = 0x4000000;
- }
+ c = *str++;
+
+ if (expect) {
+ if ((c & 0xc0) != 0x80) {
+ return -1;
+ } else {
+ v = (v << 6) | (c & 0x3f);
+ if (!--expect) {
+ if (v < vmin || (v >= 0xd800 && v <= 0xdfff)) {
+ return -1;
+ } else {
+ EMIT(v);
+ }
+ }
+ continue;
+ }
+ }
+
+ if (c < 0x80) {
+ EMIT(c);
+ } else if (c < 0xc0 || c >= 0xfe) {
+ /* Invalid UTF-8 */
+ return -1;
+ } else if (c < 0xe0) {
+ v = c & 0x1f;
+ expect = 1;
+ vmin = 0x80;
+ } else if (c < 0xf0) {
+ v = c & 0x0f;
+ expect = 2;
+ vmin = 0x800;
+ } else if (c < 0xf8) {
+ v = c & 0x07;
+ expect = 3;
+ vmin = 0x10000;
+ } else if (c < 0xfc) {
+ v = c & 0x03;
+ expect = 4;
+ vmin = 0x200000;
+ } else {
+ v = c & 0x01;
+ expect = 5;
+ vmin = 0x4000000;
+ }
}
return expect ? (size_t)-1 : outlen << 2;
{
/* This should match enum strfunc in nasm.h */
static const transform_func str_transforms[] = {
- utf8_to_16le,
- utf8_to_16le,
- utf8_to_16be,
- utf8_to_32le,
- utf8_to_32le,
- utf8_to_32be,
+ utf8_to_16le,
+ utf8_to_16le,
+ utf8_to_16be,
+ utf8_to_32le,
+ utf8_to_32le,
+ utf8_to_32be,
};
transform_func transform = str_transforms[func];
size_t outlen;
outlen = transform(s, len, NULL);
if (outlen == (size_t)-1)
- return -1;
+ return -1;
*out = buf = nasm_malloc(outlen+1);
- buf[outlen] = '\0'; /* Forcibly null-terminate the buffer */
+ buf[outlen] = '\0'; /* Forcibly null-terminate the buffer */
return transform(s, len, buf);
}