diff --git a/cddl/contrib/opensolaris/tools/ctf/cvt/output.c b/cddl/contrib/opensolaris/tools/ctf/cvt/output.c index ae8c594..9c97ce6 100644 --- a/cddl/contrib/opensolaris/tools/ctf/cvt/output.c +++ b/cddl/contrib/opensolaris/tools/ctf/cvt/output.c @@ -583,20 +583,16 @@ write_file(Elf *src, const char *srcname, Elf *dst, const char *dstname, elfterminate(srcname, "Cannot get sect %s data", sname); if ((ddata = elf_newdata(dscn)) == NULL) elfterminate(dstname, "Can't make sect %s data", sname); -#if defined(sun) bcopy(sdata, ddata, sizeof (Elf_Data)); -#else +#if !defined(sun) /* - * FreeBSD's Elf_Data has private fields which the + * FreeBSD's Elf_Data has private malloced buffer that * elf_* routines manage. Simply copying the - * entire structure corrupts the data. So we need - * to copy the public fields explictly. + * entire structure corrupts the data by double-freeing + * it. Work around this problem by cleaning 'malloced' + * flag in our copy. */ - ddata->d_align = sdata->d_align; - ddata->d_off = sdata->d_off; - ddata->d_size = sdata->d_size; - ddata->d_type = sdata->d_type; - ddata->d_version = sdata->d_version; + ddata->d_flags = 0; #endif if (srcidx == sehdr.e_shstrndx) { @@ -643,13 +639,6 @@ write_file(Elf *src, const char *srcname, Elf *dst, const char *dstname, } } -#if !defined(sun) - if (ddata->d_buf == NULL) { - ddata->d_buf = xmalloc(shdr.sh_size); - bcopy(sdata->d_buf, ddata->d_buf, shdr.sh_size); - } -#endif - if (gelf_update_shdr(dscn, &shdr) == 0) elfterminate(dstname, "Cannot update sect %s", sname); diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp index c9bcb1b..51fcf18 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp @@ -758,22 +758,30 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, // its members. Finally, we create a descriptor for the complete type (which // may refer to the forward decl if the struct is recursive) and replace all // uses of the forward declaration with the final definition. + llvm::DIDescriptor FDContext = + getContextDescriptor(dyn_cast(RD->getDeclContext()), Unit); + + // If this is just a forward declaration, construct an appropriately + // marked node and just return it. + if (!RD->getDefinition()) { + llvm::DICompositeType FwdDecl = + DebugFactory.CreateCompositeType(Tag, FDContext, RD->getName(), + DefUnit, Line, 0, 0, 0, + llvm::DIType::FlagFwdDecl, + llvm::DIType(), llvm::DIArray()); + + return FwdDecl; + } // A RD->getName() is not unique. However, the debug info descriptors // are uniqued so use type name to ensure uniquness. llvm::SmallString<128> FwdDeclName; llvm::raw_svector_ostream(FwdDeclName) << "fwd.type." << FwdDeclCount++; - llvm::DIDescriptor FDContext = - getContextDescriptor(dyn_cast(RD->getDeclContext()), Unit); llvm::DICompositeType FwdDecl = DebugFactory.CreateCompositeType(Tag, FDContext, FwdDeclName, DefUnit, Line, 0, 0, 0, 0, llvm::DIType(), llvm::DIArray()); - // If this is just a forward declaration, return it. - if (!RD->getDefinition()) - return FwdDecl; - llvm::MDNode *MN = FwdDecl; llvm::TrackingVH FwdDeclNode = MN; // Otherwise, insert it into the TypeCache so that recursive uses will find diff --git a/lib/libelf/elf_data.c b/lib/libelf/elf_data.c index 4613358..a10a4a3 100644 --- a/lib/libelf/elf_data.c +++ b/lib/libelf/elf_data.c @@ -92,7 +92,6 @@ elf_getdata(Elf_Scn *s, Elf_Data *d) return (NULL); } - if (sh_size % fsz) { LIBELF_SET_ERROR(SECTION, 0); return (NULL); @@ -104,10 +103,13 @@ elf_getdata(Elf_Scn *s, Elf_Data *d) assert(msz > 0); - if ((dst = malloc(msz*count)) == NULL) { - LIBELF_SET_ERROR(RESOURCE, 0); - return (NULL); - } + if (count > 0) { + if ((dst = malloc(msz * count)) == NULL) { + LIBELF_SET_ERROR(RESOURCE, 0); + return (NULL); + } + } else + dst = NULL; if ((d = _libelf_allocate_data(s)) == NULL) return (NULL); diff --git a/lib/libelf/elf_update.c b/lib/libelf/elf_update.c index 988609b..80afd39 100644 --- a/lib/libelf/elf_update.c +++ b/lib/libelf/elf_update.c @@ -608,7 +608,7 @@ _libelf_write_scn(Elf *e, char *nf, Elf_Scn *s, off_t rc) rc = sh_off + d->d_off; - assert(d->d_buf != NULL); + assert(d->d_size == 0 || d->d_buf != NULL); assert(d->d_type == (Elf_Type) elftype); assert(d->d_version == e->e_version); assert(d->d_size % msz == 0); diff --git a/lib/libelf/libelf_xlate.c b/lib/libelf/libelf_xlate.c index 362e82d..79949f8 100644 --- a/lib/libelf/libelf_xlate.c +++ b/lib/libelf/libelf_xlate.c @@ -68,11 +68,6 @@ _libelf_xlate(Elf_Data *dst, const Elf_Data *src, unsigned int encoding, return (NULL); } - if (src->d_buf == NULL || dst->d_buf == NULL) { - LIBELF_SET_ERROR(DATA, 0); - return (NULL); - } - if ((int) src->d_type < 0 || src->d_type >= ELF_T_NUM) { LIBELF_SET_ERROR(DATA, 0); return (NULL); @@ -123,10 +118,22 @@ _libelf_xlate(Elf_Data *dst, const Elf_Data *src, unsigned int encoding, return (NULL); } - if ((direction == ELF_TOMEMORY ? db : sb) % - _libelf_malign(src->d_type, elfclass)) { - LIBELF_SET_ERROR(DATA, 0); - return (NULL); + /* + * Enforce the data alignment for section data while in memory, + * but only if there is actual data in the buffer. + */ + if (direction == ELF_TOMEMORY) { + if (db != de && + (db % _libelf_malign(src->d_type, elfclass))) { + LIBELF_SET_ERROR(DATA, 0); + return (NULL); + } + } else { + if (sb != se && + (sb % _libelf_malign(src->d_type, elfclass))) { + LIBELF_SET_ERROR(DATA, 0); + return (NULL); + } } dst->d_type = src->d_type;