#include "insns.h"
#include "tables.h"
-/* Initialized to zero by the C standard */
-static const uint8_t const_zero_buf[256];
-
typedef struct {
int sib_present; /* is a SIB byte necessary? */
int bytes; /* # of bytes of offset needed */
if (align) {
align = wsize - align;
- out(offset, segment, const_zero_buf,
+ out(offset, segment, zero_buffer,
OUT_RAWDATA, align, NO_SEG, NO_SEG);
}
offset += e->stringlen + align;
static FILE *logfp;
#endif
+/* Uninitialized -> all zero by C spec */
+const uint8_t zero_buffer[ZERO_BUF_SIZE];
+
/*
* Prepare a table of tolower() results. This avoids function calls
* on some platforms.
#endif
+size_t fwritezero(size_t bytes, FILE *fp)
+{
+ size_t count = 0;
+ size_t blksize;
+ size_t rv;
+
+ while (bytes) {
+ blksize = (bytes < ZERO_BUF_SIZE) ? bytes : ZERO_BUF_SIZE;
+
+ rv = fwrite(zero_buffer, 1, blksize, fp);
+ if (!rv)
+ break;
+
+ count += rv;
+ bytes -= rv;
+ }
+
+ return count;
+}
+
void standard_extension(char *inname, char *outname, char *extension,
efunc error)
{
const char *prefix_name(int);
+#define ZERO_BUF_SIZE 4096
+extern const uint8_t zero_buffer[ZERO_BUF_SIZE];
+size_t fwritezero(size_t bytes, FILE *fp);
+
#endif
fwrite("\177ELF\1\1\1", 7, 1, elffp);
fputc(elf_osabi, elffp);
fputc(elf_abiver, elffp);
- fwrite("\0\0\0\0\0\0\0", 7, 1, elffp);
+ fwritezero(7, elffp);
fwriteint16_t(1, elffp); /* ET_REL relocatable file */
fwriteint16_t(3, elffp); /* EM_386 processor ID */
fwriteint32_t(1L, elffp); /* EV_CURRENT file format version */
fwrite("\177ELF\2\1\1", 7, 1, elffp);
fputc(elf_osabi, elffp);
fputc(elf_abiver, elffp);
- fwrite("\0\0\0\0\0\0\0", 7, 1, elffp);
+ fwritezero(7, elffp);
fwriteint16_t(ET_REL, elffp); /* relocatable file */
fwriteint16_t(EM_X86_64, elffp); /* processor ID */
fwriteint32_t(1L, elffp); /* EV_CURRENT file format version */
/* in an MH_OBJECT file all sections are in one unnamed (name
** all zeros) segment */
- fwrite("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16, 1, machofp);
+ fwritezero(16, machofp);
fwriteint32_t(0, machofp); /* in-memory offset */
fwriteint32_t(seg_vmsize, machofp); /* in-memory size */
fwriteint32_t(offset, machofp); /* in-file offset to data */
{
struct section *s, *s2;
struct reloc *r;
- char *rel_paddata = "\0\0\0";
uint8_t *p, *q, blk[4];
int32_t l;
}
/* pad last section up to reloc entries on int32_t boundary */
- fwrite(rel_paddata, rel_padcnt, 1, machofp);
+ fwritezero(rel_padcnt, machofp);
/* emit relocation entries */
for (s = sects; s != NULL; s = s->next)
#include "collectn.h"
#include "rdlib.h"
#include "segtab.h"
+#include "nasmlib.h"
#define LDRDF_VERSION "1.07"
fwrite(outputseg[i].data, outputseg[i].length, 1, f);
}
- fwrite("\0\0\0\0\0\0\0\0\0\0", 10, 1, f);
+ fwritezero(10, f);
}
/* =========================================================================