/* Add name a file offset of a symbol. */ void arlib_add_symref (const char *symname, off_t symoff) { /* For all supported platforms the following is true. */ assert (sizeof (uint32_t) == sizeof (int)); obstack_int_grow (&symtab.symsoffob, (int) le_bswap_32 (symoff)); size_t symname_len = strlen (symname) + 1; obstack_grow (&symtab.symsnameob, symname, symname_len); }
void testValues() { f = 2; struct obstack o; obstack_init(&o); obstack_int_grow(&o, anyint()); //@ assert f == 2; //@ assert vacuous: \false; }
/* Initialize ARLIB_SYMTAB structure. */ void arlib_init (void) { #define obstack_chunk_alloc xmalloc #define obstack_chunk_free free obstack_init (&symtab.symsoffob); obstack_init (&symtab.symsnameob); obstack_init (&symtab.longnamesob); /* We add the archive header here as well, that avoids allocating another memory block. */ struct ar_hdr ar_hdr; memcpy (ar_hdr.ar_name, "/ ", sizeof (ar_hdr.ar_name)); /* Using snprintf here has a problem: the call always wants to add a NUL byte. We could use a trick whereby we specify the target buffer size longer than it is and this would not actually fail, since all the fields are consecutive and we fill them in sequence (i.e., the NUL byte gets overwritten). But _FORTIFY_SOURCE=2 would not let us play these games. Therefore we play it safe. */ char tmpbuf[sizeof (ar_hdr.ar_date) + 1]; int s = snprintf (tmpbuf, sizeof (tmpbuf), "%-*lld", (int) sizeof (ar_hdr.ar_date), (arlib_deterministic_output ? 0 : (long long int) time (NULL))); memcpy (ar_hdr.ar_date, tmpbuf, s); assert ((sizeof (struct ar_hdr) % sizeof (uint32_t)) == 0); /* Note the string for the ar_uid and ar_gid cases is longer than necessary. This does not matter since we copy only as much as necessary but it helps the compiler to use the same string for the ar_mode case. */ memcpy (ar_hdr.ar_uid, "0 ", sizeof (ar_hdr.ar_uid)); memcpy (ar_hdr.ar_gid, "0 ", sizeof (ar_hdr.ar_gid)); memcpy (ar_hdr.ar_mode, "0 ", sizeof (ar_hdr.ar_mode)); memcpy (ar_hdr.ar_fmag, ARFMAG, sizeof (ar_hdr.ar_fmag)); /* Add the archive header to the file content. */ obstack_grow (&symtab.symsoffob, &ar_hdr, sizeof (ar_hdr)); /* The first word in the offset table specifies the size. Create such an entry now. The real value will be filled-in later. For all supported platforms the following is true. */ assert (sizeof (uint32_t) == sizeof (int)); obstack_int_grow (&symtab.symsoffob, 0); /* The long name obstack also gets its archive header. As above, some of the input strings are longer than required but we only copy the necessary part. */ memcpy (ar_hdr.ar_name, "// ", sizeof (ar_hdr.ar_name)); memcpy (ar_hdr.ar_date, " ", sizeof (ar_hdr.ar_date)); memcpy (ar_hdr.ar_uid, " ", sizeof (ar_hdr.ar_uid)); memcpy (ar_hdr.ar_gid, " ", sizeof (ar_hdr.ar_gid)); memcpy (ar_hdr.ar_mode, " ", sizeof (ar_hdr.ar_mode)); /* The ar_size field will be filled in later and ar_fmag is already OK. */ obstack_grow (&symtab.longnamesob, &ar_hdr, sizeof (ar_hdr)); /* All other members are zero. */ symtab.symsofflen = 0; symtab.symsoff = NULL; symtab.symsnamelen = 0; symtab.symsname = NULL; }
void runSuccess() { struct obstack o; obstack_init(&o); obstack_int_grow(&o, anyint()); }
void runFailure() { obstack_int_grow(NULL, anyint()); }