diff options
| author | Simon J. Gerraty <sjg@FreeBSD.org> | 2014-04-28 07:50:45 +0000 |
|---|---|---|
| committer | Simon J. Gerraty <sjg@FreeBSD.org> | 2014-04-28 07:50:45 +0000 |
| commit | 3b8f08459569bf0faa21473e5cec2491e95c9349 (patch) | |
| tree | 80f45dd81ca716bcd7ca9674581e1fc40b93cd34 /lib | |
| parent | 9d2ab4a62d6733c45958627ac113bdbd818d1e2a (diff) | |
| parent | b2ba55951383498f252746f618d513139da06e8e (diff) | |
Notes
Diffstat (limited to 'lib')
122 files changed, 3344 insertions, 4548 deletions
diff --git a/lib/clang/Makefile b/lib/clang/Makefile index 3f30c963e21c2..d335d80fbee28 100644 --- a/lib/clang/Makefile +++ b/lib/clang/Makefile @@ -37,7 +37,6 @@ SUBDIR= libclanganalysis \ ${_libclangstaticanalyzer} \ \ libllvmanalysis \ - libllvmarchive \ libllvmasmparser \ libllvmasmprinter \ libllvmbitreader \ @@ -54,6 +53,7 @@ SUBDIR= libclanganalysis \ libllvmmcparser \ libllvmobjcarcopts \ libllvmobject \ + libllvmoption \ libllvmscalaropts \ libllvmselectiondag \ libllvmsupport \ @@ -74,10 +74,17 @@ SUBDIR= libclanganalysis \ libllvmmipsdisassembler \ libllvmmipsinfo \ libllvmmipsinstprinter \ + libllvmpowerpcasmparser \ libllvmpowerpccodegen \ libllvmpowerpcdesc \ libllvmpowerpcinfo \ libllvmpowerpcinstprinter \ + libllvmsparcasmparser \ + libllvmsparccodegen \ + libllvmsparcdesc \ + libllvmsparcdisassembler \ + libllvmsparcinfo \ + libllvmsparcinstprinter \ libllvmx86asmparser \ libllvmx86codegen \ libllvmx86desc \ @@ -140,4 +147,6 @@ SUBDIR+=liblldb \ SUBDIR+= include +SUBDIR_PARALLEL= + .include <bsd.subdir.mk> diff --git a/lib/clang/clang.build.mk b/lib/clang/clang.build.mk index 7202a44441b74..0ba18f060fcbb 100644 --- a/lib/clang/clang.build.mk +++ b/lib/clang/clang.build.mk @@ -23,12 +23,14 @@ BUILD_ARCH?= ${MACHINE_ARCH} .if (${TARGET_ARCH} == "arm" || ${TARGET_ARCH} == "armv6") && \ ${MK_ARM_EABI} != "no" TARGET_ABI= gnueabi +.elif ${TARGET_ARCH} == "armv6hf" +TARGET_ABI= gnueabihf .else TARGET_ABI= unknown .endif -TARGET_TRIPLE?= ${TARGET_ARCH:C/amd64/x86_64/}-${TARGET_ABI}-freebsd11.0 -BUILD_TRIPLE?= ${BUILD_ARCH:C/amd64/x86_64/}-unknown-freebsd11.0 +TARGET_TRIPLE?= ${TARGET_ARCH:C/amd64/x86_64/:C/armv6hf/armv6/}-${TARGET_ABI}-freebsd11.0 +BUILD_TRIPLE?= ${BUILD_ARCH:C/amd64/x86_64/:C/armv6hf/armv6/}-unknown-freebsd11.0 CFLAGS+= -DLLVM_DEFAULT_TARGET_TRIPLE=\"${TARGET_TRIPLE}\" \ -DLLVM_HOST_TRIPLE=\"${BUILD_TRIPLE}\" \ -DDEFAULT_SYSROOT=\"${TOOLS_PREFIX}\" @@ -56,7 +58,7 @@ Intrinsics.inc.h: ${LLVM_SRCS}/include/llvm/IR/Intrinsics.td \ -gen-intrinsic -o ${.TARGET} \ ${LLVM_SRCS}/include/llvm/IR/Intrinsics.td .for arch in \ - ARM/ARM Mips/Mips PowerPC/PPC X86/X86 + ARM/ARM Mips/Mips PowerPC/PPC Sparc/Sparc X86/X86 . for hdr in \ AsmMatcher/-gen-asm-matcher \ AsmWriter1/-gen-asm-writer,-asmwriternum=1 \ @@ -86,13 +88,14 @@ AttrDump.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include \ -gen-clang-attr-dump -o ${.TARGET} ${.ALLSRC} -AttrExprArgs.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td +AttrIdentifierArg.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include \ - -gen-clang-attr-expr-args-list -o ${.TARGET} ${.ALLSRC} + -gen-clang-attr-identifier-arg-list -o ${.TARGET} ${.ALLSRC} AttrImpl.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include \ -gen-clang-attr-impl -o ${.TARGET} ${.ALLSRC} + AttrLateParsed.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include \ -gen-clang-attr-late-parsed-list -o ${.TARGET} ${.ALLSRC} @@ -101,6 +104,10 @@ AttrList.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include \ -gen-clang-attr-list -o ${.TARGET} ${.ALLSRC} +AttrParsedAttrImpl.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td + ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include \ + -gen-clang-attr-parsed-attr-impl -o ${.TARGET} ${.ALLSRC} + AttrParsedAttrKinds.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include \ -gen-clang-attr-parsed-attr-kinds -o ${.TARGET} ${.ALLSRC} @@ -129,6 +136,10 @@ AttrTemplateInstantiate.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include \ -gen-clang-attr-template-instantiate -o ${.TARGET} ${.ALLSRC} +AttrTypeArg.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td + ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include \ + -gen-clang-attr-type-arg-list -o ${.TARGET} ${.ALLSRC} + CommentCommandInfo.inc.h: ${CLANG_SRCS}/include/clang/AST/CommentCommands.td ${CLANG_TBLGEN} \ -gen-clang-comment-command-info -o ${.TARGET} ${.ALLSRC} @@ -164,6 +175,10 @@ StmtNodes.inc.h: ${CLANG_SRCS}/include/clang/Basic/StmtNodes.td ${CLANG_TBLGEN} \ -gen-clang-stmt-nodes -o ${.TARGET} ${.ALLSRC} +arm_neon.h: ${CLANG_SRCS}/include/clang/Basic/arm_neon.td + ${CLANG_TBLGEN} \ + -gen-arm-neon -o ${.TARGET} ${.ALLSRC} + arm_neon.inc.h: ${CLANG_SRCS}/include/clang/Basic/arm_neon.td ${CLANG_TBLGEN} \ -gen-arm-neon-sema -o ${.TARGET} ${.ALLSRC} @@ -184,11 +199,11 @@ Diagnostic${hdr}Kinds.inc.h: ${CLANG_SRCS}/include/clang/Basic/Diagnostic.td .endfor Options.inc.h: ${CLANG_SRCS}/include/clang/Driver/Options.td - ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include/clang/Driver \ + ${TBLGEN} -I ${LLVM_SRCS}/include -I ${CLANG_SRCS}/include/clang/Driver \ -gen-opt-parser-defs -o ${.TARGET} ${.ALLSRC} CC1AsOptions.inc.h: ${CLANG_SRCS}/include/clang/Driver/CC1AsOptions.td - ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include/clang/Driver \ + ${TBLGEN} -I ${LLVM_SRCS}/include -I ${CLANG_SRCS}/include/clang/Driver \ -gen-opt-parser-defs -o ${.TARGET} ${.ALLSRC} Checkers.inc.h: ${CLANG_SRCS}/lib/StaticAnalyzer/Checkers/Checkers.td \ diff --git a/lib/clang/include/Makefile b/lib/clang/include/Makefile index 1c6bd5c0ed0f6..2b5a976788ce1 100644 --- a/lib/clang/include/Makefile +++ b/lib/clang/include/Makefile @@ -1,8 +1,14 @@ # $FreeBSD$ -.PATH: ${.CURDIR}/../../../contrib/llvm/tools/clang/lib/Headers +.include <bsd.own.mk> -INCSDIR=${INCLUDEDIR}/clang/3.3 +LLVM_SRCS= ${.CURDIR}/../../../contrib/llvm + +.include "../clang.build.mk" + +.PATH: ${LLVM_SRCS}/tools/clang/lib/Headers + +INCSDIR=${INCLUDEDIR}/clang/3.4 INCS= __wmmintrin_aes.h \ __wmmintrin_pclmul.h \ @@ -29,11 +35,16 @@ INCS= __wmmintrin_aes.h \ prfchwintrin.h \ rdseedintrin.h \ rtmintrin.h \ + shaintrin.h \ smmintrin.h \ + tbmintrin.h \ tmmintrin.h \ wmmintrin.h \ x86intrin.h \ xmmintrin.h \ - xopintrin.h + xopintrin.h \ + ${GENINCS} +GENINCS= arm_neon.h +CLEANFILES= ${GENINCS} .include <bsd.prog.mk> diff --git a/lib/clang/include/PPCGenAsmMatcher.inc b/lib/clang/include/PPCGenAsmMatcher.inc new file mode 100644 index 0000000000000..0538126d27730 --- /dev/null +++ b/lib/clang/include/PPCGenAsmMatcher.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "PPCGenAsmMatcher.inc.h" diff --git a/lib/clang/include/PPCGenFastISel.inc b/lib/clang/include/PPCGenFastISel.inc new file mode 100644 index 0000000000000..fec1988571aee --- /dev/null +++ b/lib/clang/include/PPCGenFastISel.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "PPCGenFastISel.inc.h" diff --git a/lib/clang/include/SparcGenAsmMatcher.inc b/lib/clang/include/SparcGenAsmMatcher.inc new file mode 100644 index 0000000000000..3522c591563d9 --- /dev/null +++ b/lib/clang/include/SparcGenAsmMatcher.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "SparcGenAsmMatcher.inc.h" diff --git a/lib/clang/include/SparcGenAsmWriter.inc b/lib/clang/include/SparcGenAsmWriter.inc new file mode 100644 index 0000000000000..c5ae5dca39c99 --- /dev/null +++ b/lib/clang/include/SparcGenAsmWriter.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "SparcGenAsmWriter.inc.h" diff --git a/lib/clang/include/SparcGenCallingConv.inc b/lib/clang/include/SparcGenCallingConv.inc new file mode 100644 index 0000000000000..dde4d8f1fc479 --- /dev/null +++ b/lib/clang/include/SparcGenCallingConv.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "SparcGenCallingConv.inc.h" diff --git a/lib/clang/include/SparcGenCodeEmitter.inc b/lib/clang/include/SparcGenCodeEmitter.inc new file mode 100644 index 0000000000000..0cd2fee44ebc7 --- /dev/null +++ b/lib/clang/include/SparcGenCodeEmitter.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "SparcGenCodeEmitter.inc.h" diff --git a/lib/clang/include/SparcGenDAGISel.inc b/lib/clang/include/SparcGenDAGISel.inc new file mode 100644 index 0000000000000..d85ed6cf55675 --- /dev/null +++ b/lib/clang/include/SparcGenDAGISel.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "SparcGenDAGISel.inc.h" diff --git a/lib/clang/include/SparcGenDisassemblerTables.inc b/lib/clang/include/SparcGenDisassemblerTables.inc new file mode 100644 index 0000000000000..0749ef28fcb41 --- /dev/null +++ b/lib/clang/include/SparcGenDisassemblerTables.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "SparcGenDisassemblerTables.inc.h" diff --git a/lib/clang/include/SparcGenInstrInfo.inc b/lib/clang/include/SparcGenInstrInfo.inc new file mode 100644 index 0000000000000..81c8e0b39d146 --- /dev/null +++ b/lib/clang/include/SparcGenInstrInfo.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "SparcGenInstrInfo.inc.h" diff --git a/lib/clang/include/SparcGenMCCodeEmitter.inc b/lib/clang/include/SparcGenMCCodeEmitter.inc new file mode 100644 index 0000000000000..1e6d6ef2aefa3 --- /dev/null +++ b/lib/clang/include/SparcGenMCCodeEmitter.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "SparcGenMCCodeEmitter.inc.h" diff --git a/lib/clang/include/SparcGenRegisterInfo.inc b/lib/clang/include/SparcGenRegisterInfo.inc new file mode 100644 index 0000000000000..0c3a91c0052c7 --- /dev/null +++ b/lib/clang/include/SparcGenRegisterInfo.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "SparcGenRegisterInfo.inc.h" diff --git a/lib/clang/include/SparcGenSubtargetInfo.inc b/lib/clang/include/SparcGenSubtargetInfo.inc new file mode 100644 index 0000000000000..ac63a7256ab4b --- /dev/null +++ b/lib/clang/include/SparcGenSubtargetInfo.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "SparcGenSubtargetInfo.inc.h" diff --git a/lib/clang/include/clang/Basic/Version.inc b/lib/clang/include/clang/Basic/Version.inc index 1b62e7f0b7ce4..d63713e823f72 100644 --- a/lib/clang/include/clang/Basic/Version.inc +++ b/lib/clang/include/clang/Basic/Version.inc @@ -1,10 +1,10 @@ /* $FreeBSD$ */ -#define CLANG_VERSION 3.3 +#define CLANG_VERSION 3.4 #define CLANG_VERSION_MAJOR 3 -#define CLANG_VERSION_MINOR 3 +#define CLANG_VERSION_MINOR 4 #define CLANG_VENDOR "FreeBSD " -#define CLANG_VENDOR_SUFFIX " 20130610" +#define CLANG_VENDOR_SUFFIX " 20140216" -#define SVN_REVISION "183502" +#define SVN_REVISION "197956" diff --git a/lib/clang/include/clang/Parse/AttrExprArgs.inc b/lib/clang/include/clang/Parse/AttrExprArgs.inc deleted file mode 100644 index 043e034c26478..0000000000000 --- a/lib/clang/include/clang/Parse/AttrExprArgs.inc +++ /dev/null @@ -1,2 +0,0 @@ -/* $FreeBSD$ */ -#include "AttrExprArgs.inc.h" diff --git a/lib/clang/include/clang/Parse/AttrIdentifierArg.inc b/lib/clang/include/clang/Parse/AttrIdentifierArg.inc new file mode 100644 index 0000000000000..2969a5057b945 --- /dev/null +++ b/lib/clang/include/clang/Parse/AttrIdentifierArg.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "AttrIdentifierArg.inc.h" diff --git a/lib/clang/include/clang/Parse/AttrTypeArg.inc b/lib/clang/include/clang/Parse/AttrTypeArg.inc new file mode 100644 index 0000000000000..8eb4699431086 --- /dev/null +++ b/lib/clang/include/clang/Parse/AttrTypeArg.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "AttrTypeArg.inc.h" diff --git a/lib/clang/include/clang/Sema/AttrParsedAttrImpl.inc b/lib/clang/include/clang/Sema/AttrParsedAttrImpl.inc new file mode 100644 index 0000000000000..9577856dae155 --- /dev/null +++ b/lib/clang/include/clang/Sema/AttrParsedAttrImpl.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "AttrParsedAttrImpl.inc.h" diff --git a/lib/clang/include/llvm/Config/AsmParsers.def b/lib/clang/include/llvm/Config/AsmParsers.def index 024462efbd1f3..e0165f0c28e63 100644 --- a/lib/clang/include/llvm/Config/AsmParsers.def +++ b/lib/clang/include/llvm/Config/AsmParsers.def @@ -2,6 +2,8 @@ LLVM_ASM_PARSER(ARM) LLVM_ASM_PARSER(Mips) +LLVM_ASM_PARSER(PowerPC) +LLVM_ASM_PARSER(Sparc) LLVM_ASM_PARSER(X86) #undef LLVM_ASM_PARSER diff --git a/lib/clang/include/llvm/Config/AsmPrinters.def b/lib/clang/include/llvm/Config/AsmPrinters.def index ca335df5fdddf..97ca9521aa02e 100644 --- a/lib/clang/include/llvm/Config/AsmPrinters.def +++ b/lib/clang/include/llvm/Config/AsmPrinters.def @@ -3,6 +3,7 @@ LLVM_ASM_PRINTER(ARM) LLVM_ASM_PRINTER(Mips) LLVM_ASM_PRINTER(PowerPC) +LLVM_ASM_PRINTER(Sparc) LLVM_ASM_PRINTER(X86) #undef LLVM_ASM_PRINTER diff --git a/lib/clang/include/llvm/Config/Disassemblers.def b/lib/clang/include/llvm/Config/Disassemblers.def index 1b26531ce3eff..25406a4ce0074 100644 --- a/lib/clang/include/llvm/Config/Disassemblers.def +++ b/lib/clang/include/llvm/Config/Disassemblers.def @@ -2,6 +2,7 @@ LLVM_DISASSEMBLER(ARM) LLVM_DISASSEMBLER(Mips) +LLVM_DISASSEMBLER(Sparc) LLVM_DISASSEMBLER(X86) #undef LLVM_DISASSEMBLER diff --git a/lib/clang/include/llvm/Config/Targets.def b/lib/clang/include/llvm/Config/Targets.def index 85c3ffe713c2c..e51e06a0de2ba 100644 --- a/lib/clang/include/llvm/Config/Targets.def +++ b/lib/clang/include/llvm/Config/Targets.def @@ -3,6 +3,7 @@ LLVM_TARGET(ARM) LLVM_TARGET(Mips) LLVM_TARGET(PowerPC) +LLVM_TARGET(Sparc) LLVM_TARGET(X86) #undef LLVM_TARGET diff --git a/lib/clang/include/llvm/Config/config.h b/lib/clang/include/llvm/Config/config.h index d72aba857b8da..985d259dfbb0b 100644 --- a/lib/clang/include/llvm/Config/config.h +++ b/lib/clang/include/llvm/Config/config.h @@ -8,6 +8,9 @@ /* Get __FreeBSD_version. */ #include <osreldate.h> +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + /* Bug report URL. */ #define BUG_REPORT_URL "http://llvm.org/bugs/" @@ -26,6 +29,9 @@ /* Define if you want backtraces on crash */ #define ENABLE_BACKTRACES 1 +/* Define to enable crash handling overrides */ +#define ENABLE_CRASH_OVERRIDES 1 + /* Define if position independent code is enabled */ #define ENABLE_PIC 0 @@ -56,15 +62,9 @@ /* Define to 1 if you have the `argz_stringify' function. */ /* #undef HAVE_ARGZ_STRINGIFY */ -/* Define to 1 if you have the <assert.h> header file. */ -#define HAVE_ASSERT_H 1 - /* Define to 1 if you have the `backtrace' function. */ /* #undef HAVE_BACKTRACE */ -/* Define to 1 if you have the `bcopy' function. */ -/* #undef HAVE_BCOPY */ - /* Define to 1 if you have the `ceilf' function. */ #define HAVE_CEILF 1 @@ -80,9 +80,6 @@ /* can use __crashreporter_info__ */ #define HAVE_CRASHREPORTER_INFO 0 -/* Define to 1 if you have the <ctype.h> header file. */ -#define HAVE_CTYPE_H 1 - /* Define to 1 if you have the <cxxabi.h> header file. */ #define HAVE_CXXABI_H 1 @@ -105,9 +102,6 @@ /* Define if you have the GNU dld library. */ /* #undef HAVE_DLD */ -/* Define to 1 if you have the <dld.h> header file. */ -/* #undef HAVE_DLD_H */ - /* Define to 1 if you have the `dlerror' function. */ #define HAVE_DLERROR 1 @@ -117,9 +111,6 @@ /* Define if dlopen() is available on this platform. */ #define HAVE_DLOPEN 1 -/* Define to 1 if you have the <dl.h> header file. */ -/* #undef HAVE_DL_H */ - /* Define if the dot program is available */ /* #undef HAVE_DOT */ @@ -171,6 +162,12 @@ /* Define to 1 if you have the `fmodf' function. */ #define HAVE_FMODF 1 +/* Define to 1 if you have the `futimens' function. */ +/* #undef HAVE_FUTIMENS */ + +/* Define to 1 if you have the `futimes' function. */ +#define HAVE_FUTIMES 1 + /* Define to 1 if you have the `getcwd' function. */ #define HAVE_GETCWD 1 @@ -192,9 +189,6 @@ /* Define if the gv program is available */ /* #undef HAVE_GV */ -/* Define to 1 if you have the `index' function. */ -/* #undef HAVE_INDEX */ - /* Define to 1 if the system has the type `int64_t'. */ #define HAVE_INT64_T 1 @@ -231,16 +225,16 @@ /* Define to 1 if you have the `pthread' library (-lpthread). */ /* #undef HAVE_LIBPTHREAD */ +/* Define to 1 if you have the `shell32' library (-lshell32). */ +/* #undef HAVE_LIBSHELL32 */ + /* Define to 1 if you have the `udis86' library (-ludis86). */ /* #undef HAVE_LIBUDIS86 */ /* Define to 1 if you have the `z' library (-lz). */ #define HAVE_LIBZ 1 -/* Define to 1 if you have the <limits.h> header file. */ -#define HAVE_LIMITS_H 1 - -/* Define if you can use -Wl,-export-dynamic. */ +/* Define if you can use -rdynamic. */ #define HAVE_LINK_EXPORT_DYNAMIC 1 /* Define to 1 if you have the <link.h> header file. */ @@ -282,12 +276,6 @@ /* Define to 1 if you have the `malloc_zone_statistics' function. */ /* #undef HAVE_MALLOC_ZONE_STATISTICS */ -/* Define to 1 if you have the `memcpy' function. */ -#define HAVE_MEMCPY 1 - -/* Define to 1 if you have the `memmove' function. */ -#define HAVE_MEMMOVE 1 - /* Define to 1 if you have the <memory.h> header file. */ #define HAVE_MEMORY_H 1 @@ -358,9 +346,6 @@ /* Define to 1 if you have the `realpath' function. */ #define HAVE_REALPATH 1 -/* Define to 1 if you have the `rindex' function. */ -/* #undef HAVE_RINDEX */ - /* Define to 1 if you have the `rintf' function. */ #define HAVE_RINTF 1 @@ -400,9 +385,6 @@ /* Define to 1 if you have the <stdint.h> header file. */ #define HAVE_STDINT_H 1 -/* Define to 1 if you have the <stdio.h> header file. */ -#define HAVE_STDIO_H 1 - /* Define to 1 if you have the <stdlib.h> header file. */ #define HAVE_STDLIB_H 1 @@ -412,15 +394,6 @@ /* Set to 1 if the std::isnan function is found in <cmath> */ #define HAVE_STD_ISNAN_IN_CMATH 1 -/* Define to 1 if you have the `strchr' function. */ -#define HAVE_STRCHR 1 - -/* Define to 1 if you have the `strcmp' function. */ -#define HAVE_STRCMP 1 - -/* Define to 1 if you have the `strdup' function. */ -#define HAVE_STRDUP 1 - /* Define to 1 if you have the `strerror' function. */ #define HAVE_STRERROR 1 @@ -433,9 +406,6 @@ /* Define to 1 if you have the <string.h> header file. */ #define HAVE_STRING_H 1 -/* Define to 1 if you have the `strrchr' function. */ -#define HAVE_STRRCHR 1 - /* Define to 1 if you have the `strtof' function. */ #define HAVE_STRTOF 1 @@ -452,9 +422,6 @@ */ /* #undef HAVE_SYS_DIR_H */ -/* Define to 1 if you have the <sys/dl.h> header file. */ -/* #undef HAVE_SYS_DL_H */ - /* Define to 1 if you have the <sys/ioctl.h> header file. */ #define HAVE_SYS_IOCTL_H 1 @@ -486,6 +453,9 @@ /* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */ #define HAVE_SYS_WAIT_H 1 +/* Define if the setupterm() function is supported this platform. */ +#define HAVE_TERMINFO 1 + /* Define to 1 if you have the <termios.h> header file. */ #define HAVE_TERMIOS_H 1 @@ -507,14 +477,11 @@ /* Define to 1 if you have the <valgrind/valgrind.h> header file. */ /* #undef HAVE_VALGRIND_VALGRIND_H */ -/* Define to 1 if you have the <windows.h> header file. */ -/* #undef HAVE_WINDOWS_H */ - /* Define to 1 if you have the `writev' function. */ #define HAVE_WRITEV 1 -/* Define if the xdot.py program is available */ -/* #undef HAVE_XDOT_PY */ +/* Define if the xdot program is available */ +/* #undef HAVE_XDOT */ /* Define to 1 if you have the <zlib.h> header file. */ #define HAVE_ZLIB_H 1 @@ -609,9 +576,6 @@ /* Installation directory for .info files */ /* #undef LLVM_INFODIR */ -/* Installation directory for libraries */ -/* #undef LLVM_LIBDIR */ - /* Installation directory for man pages */ /* #undef LLVM_MANDIR */ @@ -666,8 +630,8 @@ /* Define to path to twopi program if found or 'echo twopi' otherwise */ /* #undef LLVM_PATH_TWOPI */ -/* Define to path to xdot.py program if found or 'echo xdot.py' otherwise */ -/* #undef LLVM_PATH_XDOT_PY */ +/* Define to path to xdot program if found or 'echo xdot' otherwise */ +/* #undef LLVM_PATH_XDOT */ /* Installation prefix directory */ #define LLVM_PREFIX "" @@ -682,7 +646,7 @@ #define LLVM_VERSION_MAJOR 3 /* Minor version of the LLVM API */ -#define LLVM_VERSION_MINOR 3 +#define LLVM_VERSION_MINOR 4 /* Define if the OS needs help to load dependent libraries for dlopen(). */ #define LTDL_DLOPEN_DEPLIBS 1 @@ -691,10 +655,6 @@ */ #define LTDL_OBJDIR ".libs/" -/* Define to the name of the environment variable that determines the dynamic - library search path. */ -#define LTDL_SHLIBPATH_VAR "LD_LIBRARY_PATH" - /* Define to the extension used for shared libraries, say, ".so". */ #define LTDL_SHLIB_EXT ".so" @@ -715,13 +675,16 @@ #define PACKAGE_NAME "LLVM" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "LLVM 3.3" +#define PACKAGE_STRING "LLVM 3.4" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "llvm" +/* Define to the home page for this package. */ +/* #undef PACKAGE_URL */ + /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.3" +#define PACKAGE_VERSION "3.4" /* Define as the return type of signal handlers (`int' or `void'). */ #define RETSIGTYPE void @@ -744,6 +707,18 @@ /* Type of 1st arg on ELM Callback */ /* #undef WIN32_ELMCB_PCSTR */ +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ diff --git a/lib/clang/include/llvm/Config/llvm-config.h b/lib/clang/include/llvm/Config/llvm-config.h index 86e0e491c1f1c..c7466874ff11c 100644 --- a/lib/clang/include/llvm/Config/llvm-config.h +++ b/lib/clang/include/llvm/Config/llvm-config.h @@ -51,9 +51,6 @@ /* Installation directory for .info files */ /* #undef LLVM_INFODIR */ -/* Installation directory for libraries */ -/* #undef LLVM_LIBDIR */ - /* Installation directory for man pages */ /* #undef LLVM_MANDIR */ @@ -124,6 +121,6 @@ #define LLVM_VERSION_MAJOR 3 /* Minor version of the LLVM API */ -#define LLVM_VERSION_MINOR 3 +#define LLVM_VERSION_MINOR 4 #endif diff --git a/lib/clang/libclanganalysis/Makefile b/lib/clang/libclanganalysis/Makefile index 40deb80ddff7b..f71b689f117ae 100644 --- a/lib/clang/libclanganalysis/Makefile +++ b/lib/clang/libclanganalysis/Makefile @@ -12,6 +12,7 @@ SRCS= AnalysisDeclContext.cpp \ CFGStmtMap.cpp \ CallGraph.cpp \ CocoaConventions.cpp \ + Consumed.cpp \ Dominators.cpp \ FormatString.cpp \ LiveVariables.cpp \ diff --git a/lib/clang/libclangast/Makefile b/lib/clang/libclangast/Makefile index a867725598ce4..71cd684b007a0 100644 --- a/lib/clang/libclangast/Makefile +++ b/lib/clang/libclangast/Makefile @@ -11,6 +11,7 @@ SRCS= APValue.cpp \ ASTDiagnostic.cpp \ ASTDumper.cpp \ ASTImporter.cpp \ + ASTTypeTraits.cpp \ AttrImpl.cpp \ CXXInheritance.cpp \ Comment.cpp \ @@ -29,7 +30,6 @@ SRCS= APValue.cpp \ DeclPrinter.cpp \ DeclTemplate.cpp \ DeclarationName.cpp \ - DumpXML.cpp \ Expr.cpp \ ExprCXX.cpp \ ExprClassification.cpp \ @@ -38,8 +38,8 @@ SRCS= APValue.cpp \ InheritViz.cpp \ ItaniumCXXABI.cpp \ ItaniumMangle.cpp \ - LambdaMangleContext.cpp \ Mangle.cpp \ + MangleNumberingContext.cpp \ MicrosoftCXXABI.cpp \ MicrosoftMangle.cpp \ NSAPI.cpp \ diff --git a/lib/clang/libclangcodegen/Makefile b/lib/clang/libclangcodegen/Makefile index cf58049472cb8..3b45f6bd52cdb 100644 --- a/lib/clang/libclangcodegen/Makefile +++ b/lib/clang/libclangcodegen/Makefile @@ -36,6 +36,7 @@ SRCS= BackendUtil.cpp \ CGStmt.cpp \ CGVTT.cpp \ CGVTables.cpp \ + CodeGenABITypes.cpp \ CodeGenAction.cpp \ CodeGenFunction.cpp \ CodeGenModule.cpp \ @@ -43,6 +44,7 @@ SRCS= BackendUtil.cpp \ CodeGenTypes.cpp \ ItaniumCXXABI.cpp \ MicrosoftCXXABI.cpp \ + MicrosoftVBTables.cpp \ ModuleBuilder.cpp \ TargetInfo.cpp @@ -53,6 +55,7 @@ TGHDRS= AttrList \ DeclNodes \ DiagnosticCommonKinds \ DiagnosticFrontendKinds \ + DiagnosticSemaKinds \ Intrinsics \ StmtNodes \ arm_neon diff --git a/lib/clang/libclangdriver/Makefile b/lib/clang/libclangdriver/Makefile index aae2a057f589d..91a8f61567055 100644 --- a/lib/clang/libclangdriver/Makefile +++ b/lib/clang/libclangdriver/Makefile @@ -6,16 +6,13 @@ LIB= clangdriver SRCDIR= tools/clang/lib/Driver SRCS= Action.cpp \ - Arg.cpp \ - ArgList.cpp \ CC1AsOptions.cpp \ Compilation.cpp \ Driver.cpp \ DriverOptions.cpp \ Job.cpp \ - OptTable.cpp \ - Option.cpp \ Phases.cpp \ + SanitizerArgs.cpp \ Tool.cpp \ ToolChain.cpp \ ToolChains.cpp \ @@ -26,6 +23,7 @@ SRCS= Action.cpp \ TGHDRS= CC1AsOptions \ DiagnosticCommonKinds \ DiagnosticDriverKinds \ + DiagnosticSemaKinds \ Options .include "../clang.lib.mk" diff --git a/lib/clang/libclangparse/Makefile b/lib/clang/libclangparse/Makefile index 279d003eed5d3..b204d87370af6 100644 --- a/lib/clang/libclangparse/Makefile +++ b/lib/clang/libclangparse/Makefile @@ -20,10 +20,11 @@ SRCS= ParseAST.cpp \ ParseTentative.cpp \ Parser.cpp -TGHDRS= AttrLateParsed \ +TGHDRS= AttrIdentifierArg \ + AttrLateParsed \ AttrList \ AttrParsedAttrList \ - AttrExprArgs \ + AttrTypeArg \ Attrs \ CommentCommandList \ CommentNodes \ diff --git a/lib/clang/libclangsema/Makefile b/lib/clang/libclangsema/Makefile index c9f56d4d5a757..9157b4666abaa 100644 --- a/lib/clang/libclangsema/Makefile +++ b/lib/clang/libclangsema/Makefile @@ -49,9 +49,11 @@ SRCS= AnalysisBasedWarnings.cpp \ SemaTemplateInstantiateDecl.cpp \ SemaTemplateVariadic.cpp \ SemaType.cpp \ - TargetAttributesSema.cpp + TargetAttributesSema.cpp \ + TypeLocBuilder.cpp TGHDRS= AttrList \ + AttrParsedAttrImpl \ AttrParsedAttrKinds \ AttrParsedAttrList \ AttrSpellingListIndex \ diff --git a/lib/clang/libclangstaticanalyzercheckers/Makefile b/lib/clang/libclangstaticanalyzercheckers/Makefile index 10968d27dd5d2..db27182a7f419 100644 --- a/lib/clang/libclangstaticanalyzercheckers/Makefile +++ b/lib/clang/libclangstaticanalyzercheckers/Makefile @@ -24,7 +24,6 @@ SRCS= AllocationDiagnostics.cpp \ CheckerDocumentation.cpp \ ChrootChecker.cpp \ ClangCheckers.cpp \ - CommonBugCategories.cpp \ DeadStoresChecker.cpp \ DebugCheckers.cpp \ DereferenceChecker.cpp \ @@ -35,6 +34,7 @@ SRCS= AllocationDiagnostics.cpp \ FixedAddressChecker.cpp \ GenericTaintChecker.cpp \ IdempotentOperationChecker.cpp \ + IdenticalExprChecker.cpp \ IvarInvalidationChecker.cpp \ LLVMConventionsChecker.cpp \ MacOSKeychainAPIChecker.cpp \ @@ -44,8 +44,8 @@ SRCS= AllocationDiagnostics.cpp \ MallocSizeofChecker.cpp \ NSAutoreleasePoolChecker.cpp \ NSErrorChecker.cpp \ - NonNullParamChecker.cpp \ NoReturnFunctionChecker.cpp \ + NonNullParamChecker.cpp \ ObjCAtSyncChecker.cpp \ ObjCContainersASTChecker.cpp \ ObjCContainersChecker.cpp \ diff --git a/lib/clang/libclangstaticanalyzercore/Makefile b/lib/clang/libclangstaticanalyzercore/Makefile index eda991e314c24..74f49bfce1c97 100644 --- a/lib/clang/libclangstaticanalyzercore/Makefile +++ b/lib/clang/libclangstaticanalyzercore/Makefile @@ -18,6 +18,7 @@ SRCS= APSIntType.cpp \ CheckerHelpers.cpp \ CheckerManager.cpp \ CheckerRegistry.cpp \ + CommonBugCategories.cpp \ ConstraintManager.cpp \ CoreEngine.cpp \ Environment.cpp \ @@ -41,8 +42,7 @@ SRCS= APSIntType.cpp \ SimpleSValBuilder.cpp \ Store.cpp \ SubEngine.cpp \ - SymbolManager.cpp \ - TextPathDiagnostics.cpp + SymbolManager.cpp TGHDRS= AttrList \ Attrs \ diff --git a/lib/clang/liblldbAPI/Makefile b/lib/clang/liblldbAPI/Makefile index 275b26fa945e6..d041d092182b5 100644 --- a/lib/clang/liblldbAPI/Makefile +++ b/lib/clang/liblldbAPI/Makefile @@ -25,14 +25,16 @@ SRCS= SBAddress.cpp \ SBFrame.cpp \ SBFunction.cpp \ SBHostOS.cpp \ - SBInputReader.cpp \ SBInstruction.cpp \ SBInstructionList.cpp \ SBLineEntry.cpp \ SBListener.cpp \ SBModule.cpp \ SBModuleSpec.cpp \ + SBPlatform.cpp \ SBProcess.cpp \ + SBQueue.cpp \ + SBQueueItem.cpp \ SBSection.cpp \ SBSourceManager.cpp \ SBStream.cpp \ diff --git a/lib/clang/liblldbCommands/Makefile b/lib/clang/liblldbCommands/Makefile index 6709017bb4b57..f7baf8397a28e 100644 --- a/lib/clang/liblldbCommands/Makefile +++ b/lib/clang/liblldbCommands/Makefile @@ -14,6 +14,7 @@ SRCS= CommandCompletions.cpp \ CommandObjectDisassemble.cpp \ CommandObjectExpression.cpp \ CommandObjectFrame.cpp \ + CommandObjectGUI.cpp \ CommandObjectHelp.cpp \ CommandObjectLog.cpp \ CommandObjectMemory.cpp \ diff --git a/lib/clang/liblldbCore/Makefile b/lib/clang/liblldbCore/Makefile index 44575313a3e55..e0335f4e3a9af 100644 --- a/lib/clang/liblldbCore/Makefile +++ b/lib/clang/liblldbCore/Makefile @@ -32,9 +32,7 @@ SRCS= Address.cpp \ FileLineResolver.cpp \ FileSpecList.cpp \ History.cpp \ - InputReader.cpp \ - InputReaderEZ.cpp \ - InputReaderStack.cpp \ + IOHandler.cpp \ Language.cpp \ Listener.cpp \ Log.cpp \ @@ -55,6 +53,7 @@ SRCS= Address.cpp \ StreamAsynchronousIO.cpp \ StreamCallback.cpp \ StreamFile.cpp \ + StreamGDBRemote.cpp \ StreamString.cpp \ StringList.cpp \ Timer.cpp \ diff --git a/lib/clang/liblldbDataFormatters/Makefile b/lib/clang/liblldbDataFormatters/Makefile index ca8a6c89155a2..b224215ba90ad 100644 --- a/lib/clang/liblldbDataFormatters/Makefile +++ b/lib/clang/liblldbDataFormatters/Makefile @@ -15,6 +15,7 @@ SRCS= CF.cpp \ LibCxx.cpp \ LibCxxList.cpp \ LibCxxMap.cpp \ + LibCxxUnorderedMap.cpp \ LibStdcpp.cpp \ NSArray.cpp \ NSDictionary.cpp \ @@ -23,7 +24,8 @@ SRCS= CF.cpp \ TypeCategoryMap.cpp \ TypeFormat.cpp \ TypeSummary.cpp \ - TypeSynthetic.cpp + TypeSynthetic.cpp \ + ValueObjectPrinter.cpp TGHDRS= DiagnosticCommonKinds \ DeclNodes \ diff --git a/lib/clang/liblldbHostCommon/Makefile b/lib/clang/liblldbHostCommon/Makefile index e787cbcc3db36..f2022bbf11036 100644 --- a/lib/clang/liblldbHostCommon/Makefile +++ b/lib/clang/liblldbHostCommon/Makefile @@ -7,10 +7,13 @@ LIB= lldbHostCommon SRCDIR= tools/lldb/source/Host/common SRCS= Condition.cpp \ DynamicLibrary.cpp \ + Editline.cpp \ File.cpp \ FileSpec.cpp \ Host.cpp \ Mutex.cpp \ + OptionParser.cpp \ + ProcessRunLock.cpp \ SocketAddress.cpp \ Symbols.cpp \ Terminal.cpp \ diff --git a/lib/clang/liblldbPluginProcessElfCore/Makefile b/lib/clang/liblldbPluginProcessElfCore/Makefile index 1d5dec38ec87a..30198b591fb37 100644 --- a/lib/clang/liblldbPluginProcessElfCore/Makefile +++ b/lib/clang/liblldbPluginProcessElfCore/Makefile @@ -10,8 +10,8 @@ CFLAGS+=-I${.CURDIR}/../../../contrib/llvm/tools/lldb/source/Plugins/Process/Uti SRCDIR= tools/lldb/source/Plugins/Process/elf-core SRCS= ProcessElfCore.cpp \ ThreadElfCore.cpp \ - RegisterContextCoreLinux_x86_64.cpp \ - RegisterContextCoreFreeBSD_x86_64.cpp + RegisterContextPOSIXCore_mips64.cpp \ + RegisterContextPOSIXCore_x86_64.cpp TGHDRS= DiagnosticCommonKinds \ DeclNodes \ diff --git a/lib/clang/liblldbPluginProcessFreeBSD/Makefile b/lib/clang/liblldbPluginProcessFreeBSD/Makefile index 80e668eccef0d..2002b7d2abf6b 100644 --- a/lib/clang/liblldbPluginProcessFreeBSD/Makefile +++ b/lib/clang/liblldbPluginProcessFreeBSD/Makefile @@ -9,7 +9,8 @@ CFLAGS+=-I${.CURDIR}/../../../contrib/llvm/tools/lldb/source/Plugins/Process/Fre CFLAGS+=-I${.CURDIR}/../../../contrib/llvm/tools/lldb/source/Plugins/Process/POSIX SRCDIR= tools/lldb/source/Plugins/Process/FreeBSD -SRCS= ProcessFreeBSD.cpp \ +SRCS= FreeBSDThread.cpp \ + ProcessFreeBSD.cpp \ ProcessMonitor.cpp TGHDRS= DiagnosticCommonKinds \ diff --git a/lib/clang/liblldbPluginProcessPOSIX/Makefile b/lib/clang/liblldbPluginProcessPOSIX/Makefile index cee18c577b982..f681fd343260c 100644 --- a/lib/clang/liblldbPluginProcessPOSIX/Makefile +++ b/lib/clang/liblldbPluginProcessPOSIX/Makefile @@ -15,10 +15,15 @@ SRCS= POSIXStopInfo.cpp \ ProcessMessage.cpp \ ProcessPOSIX.cpp \ ProcessPOSIXLog.cpp \ + RegisterContextFreeBSD_i386.cpp \ + RegisterContextFreeBSD_mips64.cpp \ RegisterContextFreeBSD_x86_64.cpp \ - RegisterContext_i386.cpp \ + RegisterContextLinux_i386.cpp \ RegisterContextLinux_x86_64.cpp \ - RegisterContext_x86_64.cpp + RegisterContextPOSIXProcessMonitor_mips64.cpp \ + RegisterContextPOSIXProcessMonitor_x86.cpp \ + RegisterContextPOSIX_mips64.cpp \ + RegisterContextPOSIX_x86.cpp TGHDRS= DiagnosticCommonKinds \ DeclNodes \ diff --git a/lib/clang/liblldbPluginProcessUtility/Makefile b/lib/clang/liblldbPluginProcessUtility/Makefile index d0b221f4f872b..1459254681704 100644 --- a/lib/clang/liblldbPluginProcessUtility/Makefile +++ b/lib/clang/liblldbPluginProcessUtility/Makefile @@ -6,11 +6,14 @@ LIB= lldbPluginProcessUtility SRCDIR= tools/lldb/source/Plugins/Process/Utility SRCS= DynamicRegisterInfo.cpp \ + HistoryThread.cpp \ + HistoryUnwind.cpp \ InferiorCallPOSIX.cpp \ RegisterContextDarwin_arm.cpp \ RegisterContextDarwin_i386.cpp \ RegisterContextDarwin_x86_64.cpp \ RegisterContextDummy.cpp \ + RegisterContextHistory.cpp \ RegisterContextLLDB.cpp \ RegisterContextMach_arm.cpp \ RegisterContextMach_i386.cpp \ diff --git a/lib/clang/liblldbPluginSymbolFileDWARF/Makefile b/lib/clang/liblldbPluginSymbolFileDWARF/Makefile index 92845e4153a18..ac23199b67ce2 100644 --- a/lib/clang/liblldbPluginSymbolFileDWARF/Makefile +++ b/lib/clang/liblldbPluginSymbolFileDWARF/Makefile @@ -7,6 +7,7 @@ LIB= lldbPluginSymbolFileDWARF SRCDIR= tools/lldb/source/Plugins/SymbolFile/DWARF SRCS= DWARFAbbreviationDeclaration.cpp \ DWARFCompileUnit.cpp \ + DWARFDataExtractor.cpp \ DWARFDebugAbbrev.cpp \ DWARFDebugAranges.cpp \ DWARFDebugArangeSet.cpp \ diff --git a/lib/clang/liblldbTarget/Makefile b/lib/clang/liblldbTarget/Makefile index c6384be78a413..2e0226d597540 100644 --- a/lib/clang/liblldbTarget/Makefile +++ b/lib/clang/liblldbTarget/Makefile @@ -17,12 +17,17 @@ SRCS= ABI.cpp \ PathMappingList.cpp \ Platform.cpp \ Process.cpp \ + Queue.cpp \ + QueueItem.cpp \ + QueueList.cpp \ RegisterContext.cpp \ + SectionLoadHistory.cpp \ SectionLoadList.cpp \ StackFrame.cpp \ StackFrameList.cpp \ StackID.cpp \ StopInfo.cpp \ + SystemRuntime.cpp \ Target.cpp \ TargetList.cpp \ Thread.cpp \ diff --git a/lib/clang/liblldbUtility/Makefile b/lib/clang/liblldbUtility/Makefile index 9c944e43de2ca..e5723b2fdad9f 100644 --- a/lib/clang/liblldbUtility/Makefile +++ b/lib/clang/liblldbUtility/Makefile @@ -9,7 +9,6 @@ SRCS= ARM_DWARF_Registers.cpp \ KQueue.cpp \ PseudoTerminal.cpp \ Range.cpp \ - RefCounter.cpp \ SharingPtr.cpp \ StringExtractor.cpp \ StringExtractorGDBRemote.cpp \ diff --git a/lib/clang/libllvmanalysis/Makefile b/lib/clang/libllvmanalysis/Makefile index 1bd8e9eb6dddd..34725fc39cb26 100644 --- a/lib/clang/libllvmanalysis/Makefile +++ b/lib/clang/libllvmanalysis/Makefile @@ -13,11 +13,13 @@ SRCS= AliasAnalysis.cpp \ Analysis.cpp \ BasicAliasAnalysis.cpp \ BranchProbabilityInfo.cpp \ + CFG.cpp \ CFGPrinter.cpp \ CaptureTracking.cpp \ CodeMetrics.cpp \ ConstantFolding.cpp \ CostModel.cpp \ + Delinearization.cpp \ DependenceAnalysis.cpp \ DomPrinter.cpp \ DominanceFrontier.cpp \ @@ -39,17 +41,7 @@ SRCS= AliasAnalysis.cpp \ ModuleDebugInfoPrinter.cpp \ NoAliasAnalysis.cpp \ PHITransAddr.cpp \ - PathNumbering.cpp \ - PathProfileInfo.cpp \ - PathProfileVerifier.cpp \ PostDominators.cpp \ - ProfileDataLoader.cpp \ - ProfileDataLoaderPass.cpp \ - ProfileEstimatorPass.cpp \ - ProfileInfo.cpp \ - ProfileInfoLoader.cpp \ - ProfileInfoLoaderPass.cpp \ - ProfileVerifierPass.cpp \ PtrUseVisitor.cpp \ RegionInfo.cpp \ RegionPass.cpp \ diff --git a/lib/clang/libllvmarchive/Makefile b/lib/clang/libllvmarchive/Makefile deleted file mode 100644 index d5534050083cf..0000000000000 --- a/lib/clang/libllvmarchive/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# $FreeBSD$ - -.include <bsd.own.mk> - -LIB= llvmarchive - -SRCDIR= lib/Archive -SRCS= Archive.cpp \ - ArchiveReader.cpp \ - ArchiveWriter.cpp - -.include "../clang.lib.mk" diff --git a/lib/clang/libllvmarchive/Makefile.depend b/lib/clang/libllvmarchive/Makefile.depend deleted file mode 100644 index 422d37c93228e..0000000000000 --- a/lib/clang/libllvmarchive/Makefile.depend +++ /dev/null @@ -1,17 +0,0 @@ -# Autogenerated - do NOT edit! - -DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,} - -DIRDEPS = \ - gnu/lib/libstdc++ \ - gnu/lib/libsupc++ \ - include \ - include/xlocale \ - lib/msun \ - - -.include <dirdeps.mk> - -.if ${DEP_RELDIR} == ${_DEP_RELDIR} -# local dependencies - needed for -jN in clean tree -.endif diff --git a/lib/clang/libllvmarmdesc/Makefile b/lib/clang/libllvmarmdesc/Makefile index 777e669a4edef..73999adb1317e 100644 --- a/lib/clang/libllvmarmdesc/Makefile +++ b/lib/clang/libllvmarmdesc/Makefile @@ -8,11 +8,12 @@ SRCDIR= lib/Target/ARM/MCTargetDesc SRCS= ARMAsmBackend.cpp \ ARMELFObjectWriter.cpp \ ARMELFStreamer.cpp \ - ARMMachObjectWriter.cpp \ ARMMCAsmInfo.cpp \ ARMMCCodeEmitter.cpp \ ARMMCExpr.cpp \ ARMMCTargetDesc.cpp \ + ARMMachORelocationInfo.cpp \ + ARMMachObjectWriter.cpp \ ARMUnwindOpAsm.cpp CFLAGS+= -I${LLVM_SRCS}/${SRCDIR}/.. diff --git a/lib/clang/libllvmasmprinter/Makefile b/lib/clang/libllvmasmprinter/Makefile index 5df08988827d3..afb0ecf727539 100644 --- a/lib/clang/libllvmasmprinter/Makefile +++ b/lib/clang/libllvmasmprinter/Makefile @@ -10,6 +10,7 @@ SRCS= ARMException.cpp \ AsmPrinterDwarf.cpp \ AsmPrinterInlineAsm.cpp \ DIE.cpp \ + DIEHash.cpp \ DwarfAccelTable.cpp \ DwarfCFIException.cpp \ DwarfCompileUnit.cpp \ diff --git a/lib/clang/libllvmcodegen/Makefile b/lib/clang/libllvmcodegen/Makefile index 1d41a6affbb3e..e43f39dc23b92 100644 --- a/lib/clang/libllvmcodegen/Makefile +++ b/lib/clang/libllvmcodegen/Makefile @@ -41,6 +41,7 @@ SRCS= AggressiveAntiDepBreaker.cpp \ LiveRangeCalc.cpp \ LiveRangeEdit.cpp \ LiveRegMatrix.cpp \ + LiveRegUnits.cpp \ LiveStackAnalysis.cpp \ LiveVariables.cpp \ LocalStackSlotAllocation.cpp \ @@ -94,16 +95,15 @@ SRCS= AggressiveAntiDepBreaker.cpp \ ScheduleDAGPrinter.cpp \ ScoreboardHazardRecognizer.cpp \ ShadowStackGC.cpp \ - ShrinkWrapping.cpp \ SjLjEHPrepare.cpp \ SlotIndexes.cpp \ SpillPlacement.cpp \ Spiller.cpp \ SplitKit.cpp \ StackColoring.cpp \ + StackMaps.cpp \ StackProtector.cpp \ StackSlotColoring.cpp \ - StrongPHIElimination.cpp \ TailDuplication.cpp \ TargetFrameLoweringImpl.cpp \ TargetInstrInfo.cpp \ diff --git a/lib/clang/libllvmcore/Makefile b/lib/clang/libllvmcore/Makefile index 4cbf3d63aaa91..137b1c31a5f49 100644 --- a/lib/clang/libllvmcore/Makefile +++ b/lib/clang/libllvmcore/Makefile @@ -29,6 +29,7 @@ SRCS= AsmWriter.cpp \ LLVMContext.cpp \ LLVMContextImpl.cpp \ LeakDetector.cpp \ + LegacyPassManager.cpp \ Metadata.cpp \ Module.cpp \ Pass.cpp \ diff --git a/lib/clang/libllvmdebuginfo/Makefile b/lib/clang/libllvmdebuginfo/Makefile index 72218ad82fd1d..c8039dcad5648 100644 --- a/lib/clang/libllvmdebuginfo/Makefile +++ b/lib/clang/libllvmdebuginfo/Makefile @@ -15,7 +15,10 @@ SRCS= DIContext.cpp \ DWARFDebugFrame.cpp \ DWARFDebugInfoEntry.cpp \ DWARFDebugLine.cpp \ + DWARFDebugLoc.cpp \ DWARFDebugRangeList.cpp \ - DWARFFormValue.cpp + DWARFFormValue.cpp \ + DWARFTypeUnit.cpp \ + DWARFUnit.cpp .include "../clang.lib.mk" diff --git a/lib/clang/libllvmexecutionengine/Makefile b/lib/clang/libllvmexecutionengine/Makefile index 3ec39c78658fb..382dd88f79695 100644 --- a/lib/clang/libllvmexecutionengine/Makefile +++ b/lib/clang/libllvmexecutionengine/Makefile @@ -7,6 +7,7 @@ LIB= llvmexecutionengine SRCDIR= lib/ExecutionEngine SRCS= ExecutionEngine.cpp \ ExecutionEngineBindings.cpp \ + RTDyldMemoryManager.cpp \ TargetSelect.cpp .include "../clang.lib.mk" diff --git a/lib/clang/libllvminstrumentation/Makefile b/lib/clang/libllvminstrumentation/Makefile index e5e8b591e9a67..faba349ae4943 100644 --- a/lib/clang/libllvminstrumentation/Makefile +++ b/lib/clang/libllvminstrumentation/Makefile @@ -6,15 +6,12 @@ LIB= llvminstrumentation SRCDIR= lib/Transforms/Instrumentation SRCS= AddressSanitizer.cpp \ - BlackList.cpp \ BoundsChecking.cpp \ - EdgeProfiling.cpp \ + DataFlowSanitizer.cpp \ + DebugIR.cpp \ GCOVProfiling.cpp \ MemorySanitizer.cpp \ Instrumentation.cpp \ - OptimalEdgeProfiling.cpp \ - PathProfiling.cpp \ - ProfilingUtils.cpp \ ThreadSanitizer.cpp TGHDRS= Intrinsics diff --git a/lib/clang/libllvmjit/Makefile b/lib/clang/libllvmjit/Makefile index 682f704b441e9..a04eeb614041c 100644 --- a/lib/clang/libllvmjit/Makefile +++ b/lib/clang/libllvmjit/Makefile @@ -6,7 +6,6 @@ LIB= llvmjit SRCDIR= lib/ExecutionEngine/JIT SRCS= JIT.cpp \ - JITDwarfEmitter.cpp \ JITEmitter.cpp \ JITMemoryManager.cpp diff --git a/lib/clang/libllvmmc/Makefile b/lib/clang/libllvmmc/Makefile index 045d2178645da..7fdc474eb7f11 100644 --- a/lib/clang/libllvmmc/Makefile +++ b/lib/clang/libllvmmc/Makefile @@ -10,6 +10,7 @@ SRCS= ELFObjectWriter.cpp \ MCAsmInfo.cpp \ MCAsmInfoCOFF.cpp \ MCAsmInfoDarwin.cpp \ + MCAsmInfoELF.cpp \ MCAsmStreamer.cpp \ MCAssembler.cpp \ MCAtom.cpp \ @@ -21,6 +22,8 @@ SRCS= ELFObjectWriter.cpp \ MCELFObjectTargetWriter.cpp \ MCELFStreamer.cpp \ MCExpr.cpp \ + MCExternalSymbolizer.cpp \ + MCFunction.cpp \ MCInst.cpp \ MCInstPrinter.cpp \ MCInstrAnalysis.cpp \ @@ -28,12 +31,16 @@ SRCS= ELFObjectWriter.cpp \ MCMachOStreamer.cpp \ MCMachObjectTargetWriter.cpp \ MCModule.cpp \ + MCModuleYAML.cpp \ MCNullStreamer.cpp \ + MCObjectDisassembler.cpp \ MCObjectFileInfo.cpp \ MCObjectStreamer.cpp \ + MCObjectSymbolizer.cpp \ MCObjectWriter.cpp \ MCPureStreamer.cpp \ MCRegisterInfo.cpp \ + MCRelocationInfo.cpp \ MCSection.cpp \ MCSectionCOFF.cpp \ MCSectionELF.cpp \ @@ -41,6 +48,7 @@ SRCS= ELFObjectWriter.cpp \ MCStreamer.cpp \ MCSubtargetInfo.cpp \ MCSymbol.cpp \ + MCSymbolizer.cpp \ MCValue.cpp \ MCWin64EH.cpp \ MachObjectWriter.cpp \ diff --git a/lib/clang/libllvmmipscodegen/Makefile b/lib/clang/libllvmmipscodegen/Makefile index e5a99c9421633..9ba70992b0cab 100644 --- a/lib/clang/libllvmmipscodegen/Makefile +++ b/lib/clang/libllvmmipscodegen/Makefile @@ -6,6 +6,7 @@ LIB= llvmmipscodegen SRCDIR= lib/Target/Mips SRCS= Mips16FrameLowering.cpp \ + Mips16HardFloat.cpp \ Mips16ISelDAGToDAG.cpp \ Mips16ISelLowering.cpp \ Mips16InstrInfo.cpp \ diff --git a/lib/clang/libllvmmipsdesc/Makefile b/lib/clang/libllvmmipsdesc/Makefile index c5e60c648a782..07cbbfa6b74d8 100644 --- a/lib/clang/libllvmmipsdesc/Makefile +++ b/lib/clang/libllvmmipsdesc/Makefile @@ -6,13 +6,12 @@ LIB= llvmmipsdesc SRCDIR= lib/Target/Mips/MCTargetDesc SRCS= MipsAsmBackend.cpp \ - MipsDirectObjLower.cpp \ MipsELFObjectWriter.cpp \ - MipsELFStreamer.cpp \ MipsMCAsmInfo.cpp \ MipsMCCodeEmitter.cpp \ MipsMCTargetDesc.cpp \ - MipsReginfo.cpp + MipsReginfo.cpp \ + MipsTargetStreamer.cpp CFLAGS+= -I${LLVM_SRCS}/${SRCDIR}/.. TGHDRS= MipsGenInstrInfo \ diff --git a/lib/clang/libllvmobject/Makefile b/lib/clang/libllvmobject/Makefile index 7358c137c8ed8..7e480930b3121 100644 --- a/lib/clang/libllvmobject/Makefile +++ b/lib/clang/libllvmobject/Makefile @@ -8,10 +8,15 @@ SRCDIR= lib/Object SRCS= Archive.cpp \ Binary.cpp \ COFFObjectFile.cpp \ + COFFYAML.cpp \ + ELF.cpp \ ELFObjectFile.cpp \ + ELFYAML.cpp \ Error.cpp \ MachOObjectFile.cpp \ + MachOUniversal.cpp \ Object.cpp \ - ObjectFile.cpp + ObjectFile.cpp \ + YAML.cpp .include "../clang.lib.mk" diff --git a/lib/clang/libllvmoption/Makefile b/lib/clang/libllvmoption/Makefile new file mode 100644 index 0000000000000..bf88dba9aa97f --- /dev/null +++ b/lib/clang/libllvmoption/Makefile @@ -0,0 +1,13 @@ +# $FreeBSD$ + +.include <bsd.own.mk> + +LIB= llvmoption + +SRCDIR= lib/Option +SRCS= Arg.cpp \ + ArgList.cpp \ + OptTable.cpp \ + Option.cpp + +.include "../clang.lib.mk" diff --git a/lib/clang/libllvmpowerpcasmparser/Makefile b/lib/clang/libllvmpowerpcasmparser/Makefile new file mode 100644 index 0000000000000..ff1f533a64467 --- /dev/null +++ b/lib/clang/libllvmpowerpcasmparser/Makefile @@ -0,0 +1,16 @@ +# $FreeBSD$ + +.include <bsd.own.mk> + +LIB= llvmpowerpcasmparser + +SRCDIR= lib/Target/PowerPC/AsmParser +INCDIR= lib/Target/PowerPC +SRCS= PPCAsmParser.cpp + +TGHDRS= PPCGenAsmMatcher \ + PPCGenInstrInfo \ + PPCGenRegisterInfo \ + PPCGenSubtargetInfo + +.include "../clang.lib.mk" diff --git a/lib/clang/libllvmpowerpccodegen/Makefile b/lib/clang/libllvmpowerpccodegen/Makefile index 0c77b5c48a2c7..9fd268bf23bb6 100644 --- a/lib/clang/libllvmpowerpccodegen/Makefile +++ b/lib/clang/libllvmpowerpccodegen/Makefile @@ -9,6 +9,7 @@ SRCS= PPCAsmPrinter.cpp \ PPCBranchSelector.cpp \ PPCCTRLoops.cpp \ PPCCodeEmitter.cpp \ + PPCFastISel.cpp \ PPCFrameLowering.cpp \ PPCHazardRecognizers.cpp \ PPCISelDAGToDAG.cpp \ @@ -21,12 +22,14 @@ SRCS= PPCAsmPrinter.cpp \ PPCSelectionDAGInfo.cpp \ PPCSubtarget.cpp \ PPCTargetMachine.cpp \ + PPCTargetObjectFile.cpp \ PPCTargetTransformInfo.cpp TGHDRS= Intrinsics \ PPCGenCallingConv \ PPCGenCodeEmitter \ PPCGenDAGISel \ + PPCGenFastISel \ PPCGenInstrInfo \ PPCGenMCCodeEmitter \ PPCGenRegisterInfo \ diff --git a/lib/clang/libllvmpowerpcdesc/Makefile b/lib/clang/libllvmpowerpcdesc/Makefile index e48b484d00f96..b64b9487ac9a9 100644 --- a/lib/clang/libllvmpowerpcdesc/Makefile +++ b/lib/clang/libllvmpowerpcdesc/Makefile @@ -6,11 +6,13 @@ LIB= llvmpowerpcdesc SRCDIR= lib/Target/PowerPC/MCTargetDesc SRCS= PPCAsmBackend.cpp \ + PPCELFObjectWriter.cpp \ PPCMCAsmInfo.cpp \ PPCMCCodeEmitter.cpp \ + PPCMCExpr.cpp \ PPCMCTargetDesc.cpp \ - PPCPredicates.cpp \ - PPCELFObjectWriter.cpp + PPCMachObjectWriter.cpp \ + PPCPredicates.cpp CFLAGS+= -I${LLVM_SRCS}/${SRCDIR}/.. TGHDRS= PPCGenInstrInfo \ diff --git a/lib/clang/libllvmscalaropts/Makefile b/lib/clang/libllvmscalaropts/Makefile index 38d945c11a803..1f4edffeede93 100644 --- a/lib/clang/libllvmscalaropts/Makefile +++ b/lib/clang/libllvmscalaropts/Makefile @@ -6,42 +6,41 @@ LIB= llvmscalaropts SRCDIR= lib/Transforms/Scalar SRCS= ADCE.cpp \ - BasicBlockPlacement.cpp \ CodeGenPrepare.cpp \ ConstantProp.cpp \ CorrelatedValuePropagation.cpp \ DCE.cpp \ DeadStoreElimination.cpp \ EarlyCSE.cpp \ - GlobalMerge.cpp \ + FlattenCFGPass.cpp \ GVN.cpp \ + GlobalMerge.cpp \ IndVarSimplify.cpp \ JumpThreading.cpp \ LICM.cpp \ LoopDeletion.cpp \ LoopIdiomRecognize.cpp \ - LoopInstSimplify.cpp \ + LoopRerollPass.cpp \ LoopRotation.cpp \ LoopStrengthReduce.cpp \ LoopUnrollPass.cpp \ LoopUnswitch.cpp \ LowerAtomic.cpp \ MemCpyOptimizer.cpp \ + PartiallyInlineLibCalls.cpp \ Reassociate.cpp \ Reg2Mem.cpp \ SCCP.cpp \ SROA.cpp \ - Scalar.cpp \ + SampleProfile.cpp \ ScalarReplAggregates.cpp \ SimplifyCFGPass.cpp \ - SimplifyLibCalls.cpp \ Sink.cpp \ + StructurizeCFG.cpp \ TailRecursionElimination.cpp .if ${MK_CLANG_EXTRAS} != "no" SRCS+= LoopInstSimplify.cpp \ - LowerAtomic.cpp \ - Reg2Mem.cpp \ Scalar.cpp .endif diff --git a/lib/clang/libllvmsparcasmparser/Makefile b/lib/clang/libllvmsparcasmparser/Makefile new file mode 100644 index 0000000000000..f4e4f25c8a70e --- /dev/null +++ b/lib/clang/libllvmsparcasmparser/Makefile @@ -0,0 +1,16 @@ +# $FreeBSD$ + +.include <bsd.own.mk> + +LIB= llvmsparcasmparser + +SRCDIR= lib/Target/Sparc/AsmParser +INCDIR= lib/Target/Sparc +SRCS= SparcAsmParser.cpp + +TGHDRS= SparcGenAsmMatcher \ + SparcGenInstrInfo \ + SparcGenRegisterInfo \ + SparcGenSubtargetInfo + +.include "../clang.lib.mk" diff --git a/lib/clang/libllvmsparccodegen/Makefile b/lib/clang/libllvmsparccodegen/Makefile new file mode 100644 index 0000000000000..36cf0a6952ad6 --- /dev/null +++ b/lib/clang/libllvmsparccodegen/Makefile @@ -0,0 +1,34 @@ +# $FreeBSD$ + +.include <bsd.own.mk> + +LIB= llvmsparccodegen + +SRCDIR= lib/Target/Sparc +SRCS= DelaySlotFiller.cpp \ + SparcAsmPrinter.cpp \ + SparcCodeEmitter.cpp \ + SparcFrameLowering.cpp \ + SparcISelDAGToDAG.cpp \ + SparcISelLowering.cpp \ + SparcInstrInfo.cpp \ + SparcJITInfo.cpp \ + SparcMCInstLower.cpp \ + SparcMachineFunctionInfo.cpp \ + SparcRegisterInfo.cpp \ + SparcSelectionDAGInfo.cpp \ + SparcSubtarget.cpp \ + SparcTargetMachine.cpp \ + SparcTargetObjectFile.cpp + +TGHDRS= Intrinsics \ + SparcGenAsmWriter \ + SparcGenCallingConv \ + SparcGenCodeEmitter \ + SparcGenDAGISel \ + SparcGenInstrInfo \ + SparcGenMCCodeEmitter \ + SparcGenRegisterInfo \ + SparcGenSubtargetInfo + +.include "../clang.lib.mk" diff --git a/lib/clang/libllvmsparcdesc/Makefile b/lib/clang/libllvmsparcdesc/Makefile new file mode 100644 index 0000000000000..20605fbc501ab --- /dev/null +++ b/lib/clang/libllvmsparcdesc/Makefile @@ -0,0 +1,22 @@ +# $FreeBSD$ + +.include <bsd.own.mk> + +LIB= llvmsparcdesc + +SRCDIR= lib/Target/Sparc/MCTargetDesc +SRCS= SparcAsmBackend.cpp \ + SparcELFObjectWriter.cpp \ + SparcMCAsmInfo.cpp \ + SparcMCCodeEmitter.cpp \ + SparcMCExpr.cpp \ + SparcMCTargetDesc.cpp \ + SparcTargetStreamer.cpp +CFLAGS+= -I${LLVM_SRCS}/${SRCDIR}/.. + +TGHDRS= SparcGenInstrInfo \ + SparcGenMCCodeEmitter \ + SparcGenRegisterInfo \ + SparcGenSubtargetInfo + +.include "../clang.lib.mk" diff --git a/lib/clang/libllvmsparcdisassembler/Makefile b/lib/clang/libllvmsparcdisassembler/Makefile new file mode 100644 index 0000000000000..a388ff225d113 --- /dev/null +++ b/lib/clang/libllvmsparcdisassembler/Makefile @@ -0,0 +1,16 @@ +# $FreeBSD$ + +.include <bsd.own.mk> + +LIB= llvmsparcdisassembler + +SRCDIR= lib/Target/Sparc/Disassembler +INCDIR= lib/Target/Sparc +SRCS= SparcDisassembler.cpp + +TGHDRS= SparcGenDisassemblerTables \ + SparcGenInstrInfo \ + SparcGenRegisterInfo \ + SparcGenSubtargetInfo + +.include "../clang.lib.mk" diff --git a/lib/clang/libllvmsparcinfo/Makefile b/lib/clang/libllvmsparcinfo/Makefile new file mode 100644 index 0000000000000..6c8052e332561 --- /dev/null +++ b/lib/clang/libllvmsparcinfo/Makefile @@ -0,0 +1,15 @@ +# $FreeBSD$ + +.include <bsd.own.mk> + +LIB= llvmsparcinfo + +SRCDIR= lib/Target/Sparc/TargetInfo +INCDIR= lib/Target/Sparc +SRCS= SparcTargetInfo.cpp + +TGHDRS= SparcGenInstrInfo \ + SparcGenRegisterInfo \ + SparcGenSubtargetInfo + +.include "../clang.lib.mk" diff --git a/lib/clang/libllvmsparcinstprinter/Makefile b/lib/clang/libllvmsparcinstprinter/Makefile new file mode 100644 index 0000000000000..e15c55e4d06fe --- /dev/null +++ b/lib/clang/libllvmsparcinstprinter/Makefile @@ -0,0 +1,16 @@ +# $FreeBSD$ + +.include <bsd.own.mk> + +LIB= llvmsparcinstprinter + +SRCDIR= lib/Target/Sparc/InstPrinter +INCDIR= lib/Target/Sparc +SRCS= SparcInstPrinter.cpp + +TGHDRS= SparcGenAsmWriter \ + SparcGenInstrInfo \ + SparcGenRegisterInfo \ + SparcGenSubtargetInfo + +.include "../clang.lib.mk" diff --git a/lib/clang/libllvmsupport/Makefile b/lib/clang/libllvmsupport/Makefile index ff9b9cb110e77..eb3f633286cb0 100644 --- a/lib/clang/libllvmsupport/Makefile +++ b/lib/clang/libllvmsupport/Makefile @@ -18,6 +18,7 @@ SRCS= APFloat.cpp \ ConvertUTFWrapper.cpp \ CrashRecoveryContext.cpp \ DAGDeltaAlgorithm.cpp \ + DataExtractor.cpp \ Debug.cpp \ DeltaAlgorithm.cpp \ Dwarf.cpp \ @@ -38,13 +39,13 @@ SRCS= APFloat.cpp \ IsNAN.cpp \ Locale.cpp \ LockFileManager.cpp \ + MD5.cpp \ ManagedStatic.cpp \ Memory.cpp \ MemoryBuffer.cpp \ MemoryObject.cpp \ Mutex.cpp \ Path.cpp \ - PathV2.cpp \ PluginLoader.cpp \ PrettyStackTrace.cpp \ Process.cpp \ @@ -62,6 +63,7 @@ SRCS= APFloat.cpp \ StringMap.cpp \ StringPool.cpp \ StringRef.cpp \ + StringRefMemoryObject.cpp \ TargetRegistry.cpp \ ThreadLocal.cpp \ Threading.cpp \ @@ -70,6 +72,7 @@ SRCS= APFloat.cpp \ ToolOutputFile.cpp \ Triple.cpp \ Twine.cpp \ + Unicode.cpp \ Valgrind.cpp \ Watchdog.cpp \ YAMLParser.cpp \ @@ -85,8 +88,7 @@ SRCS= APFloat.cpp \ system_error.cpp .if ${MK_CLANG_EXTRAS} != "no" || ${MK_LLDB} != "no" -SRCS+= DataExtractor.cpp \ - Disassembler.cpp +SRCS+= Disassembler.cpp .endif .if ${MK_CLANG_EXTRAS} != "no" diff --git a/lib/clang/libllvmtransformutils/Makefile b/lib/clang/libllvmtransformutils/Makefile index cfdc85f2454f6..f74209220254d 100644 --- a/lib/clang/libllvmtransformutils/Makefile +++ b/lib/clang/libllvmtransformutils/Makefile @@ -14,6 +14,8 @@ SRCS= BasicBlockUtils.cpp \ CmpInstAnalysis.cpp \ CodeExtractor.cpp \ DemoteRegToStack.cpp \ + FlattenCFG.cpp \ + GlobalStatus.cpp \ InlineFunction.cpp \ InstructionNamer.cpp \ IntegerDivision.cpp \ @@ -34,6 +36,7 @@ SRCS= BasicBlockUtils.cpp \ SimplifyIndVar.cpp \ SimplifyInstructions.cpp \ SimplifyLibCalls.cpp \ + SpecialCaseList.cpp \ UnifyFunctionExitNodes.cpp \ ValueMapper.cpp diff --git a/lib/clang/libllvmvectorize/Makefile b/lib/clang/libllvmvectorize/Makefile index 9a760faf664ef..7a63c9e739c65 100644 --- a/lib/clang/libllvmvectorize/Makefile +++ b/lib/clang/libllvmvectorize/Makefile @@ -8,7 +8,6 @@ SRCDIR= lib/Transforms/Vectorize SRCS= BBVectorize.cpp \ LoopVectorize.cpp \ SLPVectorizer.cpp \ - VecUtils.cpp \ Vectorize.cpp TGHDRS= Intrinsics diff --git a/lib/clang/libllvmx86desc/Makefile b/lib/clang/libllvmx86desc/Makefile index a1771293738c7..6401649df690b 100644 --- a/lib/clang/libllvmx86desc/Makefile +++ b/lib/clang/libllvmx86desc/Makefile @@ -7,10 +7,12 @@ LIB= llvmx86desc SRCDIR= lib/Target/X86/MCTargetDesc SRCS= X86AsmBackend.cpp \ X86ELFObjectWriter.cpp \ - X86MachObjectWriter.cpp \ + X86ELFRelocationInfo.cpp \ X86MCAsmInfo.cpp \ X86MCCodeEmitter.cpp \ X86MCTargetDesc.cpp \ + X86MachORelocationInfo.cpp \ + X86MachObjectWriter.cpp \ X86WinCOFFObjectWriter.cpp CFLAGS+= -I${LLVM_SRCS}/${SRCDIR}/.. diff --git a/lib/libcapsicum/Makefile b/lib/libcapsicum/Makefile new file mode 100644 index 0000000000000..061edfcb90675 --- /dev/null +++ b/lib/libcapsicum/Makefile @@ -0,0 +1,47 @@ +# $FreeBSD$ + +LIB= capsicum + +SHLIB_MAJOR= 0 +SHLIBDIR?= /lib + +SRCS= libcapsicum.c +SRCS+= libcapsicum_dns.c +SRCS+= libcapsicum_grp.c +SRCS+= libcapsicum_pwd.c +SRCS+= libcapsicum_random.c +SRCS+= libcapsicum_service.c +SRCS+= libcapsicum_sysctl.c + +INCS= libcapsicum.h +INCS+= libcapsicum_dns.h +INCS+= libcapsicum_grp.h +INCS+= libcapsicum_pwd.h +INCS+= libcapsicum_random.h +INCS+= libcapsicum_service.h +INCS+= libcapsicum_sysctl.h + +DPADD= ${LIBNV} +LDADD= -lnv + +CFLAGS+=-I${.CURDIR} +CFLAGS+=-I${.CURDIR}/../libnv + +WARNS?= 6 + +MAN+= libcapsicum.3 + +MLINKS+=libcapsicum.3 cap_init.3 +MLINKS+=libcapsicum.3 cap_wrap.3 +MLINKS+=libcapsicum.3 cap_unwrap.3 +MLINKS+=libcapsicum.3 cap_sock.3 +MLINKS+=libcapsicum.3 cap_clone.3 +MLINKS+=libcapsicum.3 cap_close.3 +MLINKS+=libcapsicum.3 cap_limit_get.3 +MLINKS+=libcapsicum.3 cap_limit_set.3 +MLINKS+=libcapsicum.3 cap_send_nvlist.3 +MLINKS+=libcapsicum.3 cap_recv_nvlist.3 +MLINKS+=libcapsicum.3 cap_xfer_nvlist.3 +MLINKS+=libcapsicum.3 cap_service_open.3 + +.include <bsd.lib.mk> diff --git a/lib/libcapsicum/libcapsicum.3 b/lib/libcapsicum/libcapsicum.3 new file mode 100644 index 0000000000000..efeec2f131f27 --- /dev/null +++ b/lib/libcapsicum/libcapsicum.3 @@ -0,0 +1,288 @@ +.\" Copyright (c) 2013 The FreeBSD Foundation +.\" All rights reserved. +.\" +.\" This documentation was written by Pawel Jakub Dawidek under sponsorship +.\" from the FreeBSD Foundation. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd April 14, 2014 +.Dt LIBCAPSICUM 3 +.Os +.Sh NAME +.Nm cap_init , +.Nm cap_wrap , +.Nm cap_unwrap , +.Nm cap_sock , +.Nm cap_clone , +.Nm cap_close , +.Nm cap_limit_get , +.Nm cap_limit_set , +.Nm cap_send_nvlist , +.Nm cap_recv_nvlist , +.Nm cap_xfer_nvlist , +.Nm cap_service_open +.Nd "library for handling application capabilities" +.Sh LIBRARY +.Lb libcapsicum +.Sh SYNOPSIS +.In libcapsicum.h +.In nv.h +.Ft "cap_channel_t *" +.Fn cap_init "void" +.Ft "cap_channel_t *" +.Fn cap_wrap "int sock" +.Ft "int" +.Fn cap_unwrap "cap_channel_t *chan" +.Ft "int" +.Fn cap_sock "const cap_channel_t *chan" +.Ft "cap_channel_t *" +.Fn cap_clone "const cap_channel_t *chan" +.Ft "void" +.Fn cap_close "cap_channel_t *chan" +.Ft "int" +.Fn cap_limit_get "const cap_channel_t *chan" "nvlist_t **limitsp" +.Ft "int" +.Fn cap_limit_set "const cap_channel_t *chan" "nvlist_t *limits" +.Ft "int" +.Fn cap_send_nvlist "const cap_channel_t *chan" "const nvlist_t *nvl" +.Ft "nvlist_t *" +.Fn cap_recv_nvlist "const cap_channel_t *chan" +.Ft "nvlist_t *" +.Fn cap_xfer_nvlist "const cap_channel_t *chan" "nvlist_t *nvl" +.In libcapsicum_service.h +.Ft "cap_channel_t *" +.Fn cap_service_open "const cap_channel_t *chan" "const char *name" +.Sh DESCRIPTION +The +.Nm libcapsicum +library allows to manage application capabilities through the +.Xr casperd 8 +daemon. +.Pp +The application capability (represented by the +.Vt cap_channel_t +type) is a communication channel between the caller and the +.Xr casperd 8 +daemon or an instance of one of its services. +A capability to the +.Xr casperd 8 +daemon obtained with the +.Fn cap_init +function allows to create capabilities to casper's services via the +.Fn cap_service_open +function. +.Pp +The +.Fn cap_init +function opens capability to the +.Xr casperd 8 +daemon. +.Pp +The +.Fn cap_wrap +function creates +.Vt cap_channel_t +based on the given socket. +The function is used when capability is inherited through +.Xr execve 2 +or send over +.Xr unix 4 +domain socket as a regular file descriptor and has to be represented as +.Vt cap_channel_t +again. +.Pp +The +.Fn cap_unwrap +function is the opposite of the +.Fn cap_wrap +function. +It frees the +.Vt cap_channel_t +structure and returns +.Xr unix 4 +domain socket associated with it. +.Pp +The +.Fn cap_clone +function clones the given capability. +.Pp +The +.Fn cap_close +function closes the given capability. +.Pp +The +.Fn cap_sock +function returns +.Xr unix 4 +domain socket descriptor associated with the given capability for use with +system calls like +.Xr kevent 2 , +.Xr poll 2 +and +.Xr select 2 . +.Pp +The +.Fn cap_limit_get +function stores current limits of the given capability in the +.Fa limitsp +argument. +If the function return +.Va 0 +and +.Dv NULL +is stored in +.Fa limitsp +it means there are no limits set. +.Pp +The +.Fn cap_limit_set +function sets limits for the given capability. +The limits are provided as nvlist. +The exact format depends on the service the capability represents. +.Pp +The +.Fn cap_send_nvlist +function sends the given nvlist over the given capability. +This is low level interface to communicate with casper services. +Most services should provide higher level API. +.Pp +The +.Fn cap_recv_nvlist +function receives the given nvlist over the given capability. +.Pp +The +.Fn cap_xfer_nvlist +function sends the given nvlist, destroys it and receives new nvlist in +response over the given capability. +It does not matter if the function succeeds or fails, the nvlist given +for sending will always be destroyed once the function returns. +.Pp +The +.Fn cap_service_open +function opens casper service of the given name through casper capability +obtained via the +.Fn cap_init +function. +The function returns capability that provides access to opened service. +.Sh RETURN VALUES +The +.Fn cap_clone , +.Fn cap_init , +.Fn cap_recv_nvlist , +.Fn cap_service_open , +.Fn cap_wrap +and +.Fn cap_xfer_nvlist +functions return +.Dv NULL +and set the +.Va errno +variable on failure. +.Pp +The +.Fn cap_limit_get , +.Fn cap_limit_set +and +.Fn cap_send_nvlist +functions return +.Dv -1 +and set the +.Va errno +variable on failure. +.Pp +The +.Fn cap_close , +.Fn cap_sock +and +.Fn cap_unwrap +functions always succeed. +.Sh EXAMPLES +The following example first opens capability to the +.Xr casperd 8 +daemon, then using this capability creates new capability to the +.Nm system.dns +casper service and uses the latter capability to resolve IP address. +.Bd -literal +cap_channel_t *capcas, *capdns; +nvlist_t *limits; +const char *ipstr = "127.0.0.1"; +struct in_addr ip; +struct hostent *hp; + +/* Open capability to the Casper daemon. */ +capcas = cap_init(); +if (capcas == NULL) + err(1, "Unable to contact Casper daemon"); + +/* Enter capability mode sandbox. */ +if (cap_enter() < 0 && errno != ENOSYS) + err(1, "Unable to enter capability mode"); + +/* Use Casper capability to create capability to the system.dns service. */ +capdns = cap_service_open(capcas, "system.dns"); +if (capdns == NULL) + err(1, "Unable to open system.dns service"); + +/* Close Casper capability, we don't need it anymore. */ +cap_close(capcas); + +/* Limit system.dns to reverse DNS lookups and IPv4 addresses. */ +limits = nvlist_create(0); +nvlist_add_string(limits, "type", "ADDR"); +nvlist_add_number(limits, "family", (uint64_t)AF_INET); +if (cap_limit_set(capdns, limits) < 0) + err(1, "Unable to limit access to the system.dns service"); + +/* Convert IP address in C-string to in_addr. */ +if (!inet_aton(ipstr, &ip)) + errx(1, "Unable to parse IP address %s.", ipstr); + +/* Find hostname for the given IP address. */ +hp = cap_gethostbyaddr(capdns, (const void *)&ip, sizeof(ip), AF_INET); +if (hp == NULL) + errx(1, "No name associated with %s.", ipstr); + +printf("Name associated with %s is %s.\\n", ipstr, hp->h_name); +.Ed +.Sh SEE ALSO +.Xr cap_enter 2 , +.Xr execve 2 , +.Xr kevent 2 , +.Xr poll 2 , +.Xr select 2 , +.Xr cap_gethostbyaddr 3 , +.Xr err 3 , +.Xr gethostbyaddr 3 , +.Xr inet_aton 3 , +.Xr nv 3 , +.Xr capsicum 4 , +.Xr unix 4 , +.Xr casperd 8 +.Sh AUTHORS +The +.Nm libcapsicum +library was implemented by +.An Pawel Jakub Dawidek Aq pawel@dawidek.net +under sponsorship from the FreeBSD Foundation. diff --git a/lib/libcapsicum/libcapsicum.c b/lib/libcapsicum/libcapsicum.c new file mode 100644 index 0000000000000..79ca8716261a2 --- /dev/null +++ b/lib/libcapsicum/libcapsicum.c @@ -0,0 +1,266 @@ +/*- + * Copyright (c) 2012-2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> + +#include <assert.h> +#include <errno.h> +#include <fcntl.h> +#include <stdbool.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "libcapsicum.h" +#include "libcapsicum_impl.h" +#include "nv.h" + +/* + * Structure describing communication channel between two separated processes. + */ +#define CAP_CHANNEL_MAGIC 0xcac8a31 +struct cap_channel { + /* + * Magic value helps to ensure that a pointer to the right structure is + * passed to our functions. + */ + int cch_magic; + /* Socket descriptor for IPC. */ + int cch_sock; +}; + +bool +fd_is_valid(int fd) +{ + + return (fcntl(fd, F_GETFL) != -1 || errno != EBADF); +} + +cap_channel_t * +cap_init(void) +{ + cap_channel_t *chan; + struct sockaddr_un sun; + int serrno, sock; + + bzero(&sun, sizeof(sun)); + sun.sun_family = AF_UNIX; + strlcpy(sun.sun_path, CASPER_SOCKPATH, sizeof(sun.sun_path)); + sun.sun_len = SUN_LEN(&sun); + + sock = socket(AF_UNIX, SOCK_STREAM, 0); + if (sock == -1) + return (NULL); + if (connect(sock, (struct sockaddr *)&sun, sizeof(sun)) < 0) { + serrno = errno; + close(sock); + errno = serrno; + return (NULL); + } + chan = cap_wrap(sock); + if (chan == NULL) { + serrno = errno; + close(sock); + errno = serrno; + return (NULL); + } + return (chan); +} + +cap_channel_t * +cap_wrap(int sock) +{ + cap_channel_t *chan; + + if (!fd_is_valid(sock)) + return (NULL); + + chan = malloc(sizeof(*chan)); + if (chan != NULL) { + chan->cch_sock = sock; + chan->cch_magic = CAP_CHANNEL_MAGIC; + } + + return (chan); +} + +int +cap_unwrap(cap_channel_t *chan) +{ + int sock; + + assert(chan != NULL); + assert(chan->cch_magic == CAP_CHANNEL_MAGIC); + + sock = chan->cch_sock; + chan->cch_magic = 0; + free(chan); + + return (sock); +} + +cap_channel_t * +cap_clone(const cap_channel_t *chan) +{ + cap_channel_t *newchan; + nvlist_t *nvl; + int newsock; + + assert(chan != NULL); + assert(chan->cch_magic == CAP_CHANNEL_MAGIC); + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", "clone"); + nvl = cap_xfer_nvlist(chan, nvl); + if (nvl == NULL) + return (NULL); + if (nvlist_get_number(nvl, "error") != 0) { + errno = (int)nvlist_get_number(nvl, "error"); + nvlist_destroy(nvl); + return (NULL); + } + newsock = nvlist_take_descriptor(nvl, "sock"); + nvlist_destroy(nvl); + newchan = cap_wrap(newsock); + if (newchan == NULL) { + int serrno; + + serrno = errno; + close(newsock); + errno = serrno; + } + + return (newchan); +} + +void +cap_close(cap_channel_t *chan) +{ + + assert(chan != NULL); + assert(chan->cch_magic == CAP_CHANNEL_MAGIC); + + chan->cch_magic = 0; + close(chan->cch_sock); + free(chan); +} + +int +cap_sock(const cap_channel_t *chan) +{ + + assert(chan != NULL); + assert(chan->cch_magic == CAP_CHANNEL_MAGIC); + + return (chan->cch_sock); +} + +int +cap_limit_set(const cap_channel_t *chan, nvlist_t *limits) +{ + nvlist_t *nvlmsg; + int error; + + nvlmsg = nvlist_create(0); + nvlist_add_string(nvlmsg, "cmd", "limit_set"); + nvlist_add_nvlist(nvlmsg, "limits", limits); + nvlmsg = cap_xfer_nvlist(chan, nvlmsg); + if (nvlmsg == NULL) { + nvlist_destroy(limits); + return (-1); + } + error = (int)nvlist_get_number(nvlmsg, "error"); + nvlist_destroy(nvlmsg); + nvlist_destroy(limits); + if (error != 0) { + errno = error; + return (-1); + } + return (0); +} + +int +cap_limit_get(const cap_channel_t *chan, nvlist_t **limitsp) +{ + nvlist_t *nvlmsg; + int error; + + nvlmsg = nvlist_create(0); + nvlist_add_string(nvlmsg, "cmd", "limit_get"); + nvlmsg = cap_xfer_nvlist(chan, nvlmsg); + if (nvlmsg == NULL) + return (-1); + error = (int)nvlist_get_number(nvlmsg, "error"); + if (error != 0) { + nvlist_destroy(nvlmsg); + errno = error; + return (-1); + } + if (nvlist_exists_null(nvlmsg, "limits")) + *limitsp = NULL; + else + *limitsp = nvlist_take_nvlist(nvlmsg, "limits"); + nvlist_destroy(nvlmsg); + return (0); +} + +int +cap_send_nvlist(const cap_channel_t *chan, const nvlist_t *nvl) +{ + + assert(chan != NULL); + assert(chan->cch_magic == CAP_CHANNEL_MAGIC); + + return (nvlist_send(chan->cch_sock, nvl)); +} + +nvlist_t * +cap_recv_nvlist(const cap_channel_t *chan) +{ + + assert(chan != NULL); + assert(chan->cch_magic == CAP_CHANNEL_MAGIC); + + return (nvlist_recv(chan->cch_sock)); +} + +nvlist_t * +cap_xfer_nvlist(const cap_channel_t *chan, nvlist_t *nvl) +{ + + assert(chan != NULL); + assert(chan->cch_magic == CAP_CHANNEL_MAGIC); + + return (nvlist_xfer(chan->cch_sock, nvl)); +} diff --git a/lib/libcapsicum/libcapsicum.h b/lib/libcapsicum/libcapsicum.h new file mode 100644 index 0000000000000..4f8c59752ad80 --- /dev/null +++ b/lib/libcapsicum/libcapsicum.h @@ -0,0 +1,115 @@ +/*- + * Copyright (c) 2012-2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _LIBCAPSICUM_H_ +#define _LIBCAPSICUM_H_ + +#ifndef _NVLIST_T_DECLARED +#define _NVLIST_T_DECLARED +struct nvlist; + +typedef struct nvlist nvlist_t; +#endif + +#ifndef _CAP_CHANNEL_T_DECLARED +#define _CAP_CHANNEL_T_DECLARED +struct cap_channel; + +typedef struct cap_channel cap_channel_t; +#endif + +/* + * The function opens unrestricted communication channel to Casper. + */ +cap_channel_t *cap_init(void); + +/* + * The function creates cap_channel_t based on the given socket. + */ +cap_channel_t *cap_wrap(int sock); + +/* + * The function returns communication socket and frees cap_channel_t. + */ +int cap_unwrap(cap_channel_t *chan); + +/* + * The function clones the given capability. + */ +cap_channel_t *cap_clone(const cap_channel_t *chan); + +/* + * The function closes the given capability. + */ +void cap_close(cap_channel_t *chan); + +/* + * The function returns socket descriptor associated with the given + * cap_channel_t for use with select(2)/kqueue(2)/etc. + */ +int cap_sock(const cap_channel_t *chan); + +/* + * The function limits the given capability. + * It always destroys 'limits' on return. + */ +int cap_limit_set(const cap_channel_t *chan, nvlist_t *limits); + +/* + * The function returns current limits of the given capability. + */ +int cap_limit_get(const cap_channel_t *chan, nvlist_t **limitsp); + +#ifdef TODO +/* + * The function registers a service within provided Casper's capability. + * It will run with the same privileges the process has at the time of + * calling this function. + */ +int cap_service_register(cap_channel_t *chan, const char *name, + cap_func_t *func); +#endif + +/* + * Function sends nvlist over the given capability. + */ +int cap_send_nvlist(const cap_channel_t *chan, const nvlist_t *nvl); +/* + * Function receives nvlist over the given capability. + */ +nvlist_t *cap_recv_nvlist(const cap_channel_t *chan); +/* + * Function sends the given nvlist, destroys it and receives new nvlist in + * response over the given capability. + */ +nvlist_t *cap_xfer_nvlist(const cap_channel_t *chan, nvlist_t *nvl); + +#endif /* !_LIBCAPSICUM_H_ */ diff --git a/lib/libcapsicum/libcapsicum_dns.c b/lib/libcapsicum/libcapsicum_dns.c new file mode 100644 index 0000000000000..170e0d07d2d95 --- /dev/null +++ b/lib/libcapsicum/libcapsicum_dns.c @@ -0,0 +1,346 @@ +/*- + * Copyright (c) 2012-2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <netdb.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <nv.h> + +#include "libcapsicum.h" +#include "libcapsicum_dns.h" + +static struct hostent hent; + +static void +hostent_free(struct hostent *hp) +{ + unsigned int ii; + + free(hp->h_name); + hp->h_name = NULL; + if (hp->h_aliases != NULL) { + for (ii = 0; hp->h_aliases[ii] != NULL; ii++) + free(hp->h_aliases[ii]); + free(hp->h_aliases); + hp->h_aliases = NULL; + } + if (hp->h_addr_list != NULL) { + for (ii = 0; hp->h_addr_list[ii] != NULL; ii++) + free(hp->h_addr_list[ii]); + free(hp->h_addr_list); + hp->h_addr_list = NULL; + } +} + +static struct hostent * +hostent_unpack(const nvlist_t *nvl, struct hostent *hp) +{ + unsigned int ii, nitems; + + hostent_free(hp); + + hp->h_name = strdup(nvlist_get_string(nvl, "name")); + if (hp->h_name == NULL) + goto fail; + hp->h_addrtype = (int)nvlist_get_number(nvl, "addrtype"); + hp->h_length = (int)nvlist_get_number(nvl, "length"); + + nitems = (unsigned int)nvlist_get_number(nvl, "naliases"); + hp->h_aliases = calloc(sizeof(hp->h_aliases[0]), nitems + 1); + if (hp->h_aliases == NULL) + goto fail; + for (ii = 0; ii < nitems; ii++) { + hp->h_aliases[ii] = + strdup(nvlist_getf_string(nvl, "alias%u", ii)); + if (hp->h_aliases[ii] == NULL) + goto fail; + } + hp->h_aliases[ii] = NULL; + + nitems = (unsigned int)nvlist_get_number(nvl, "naddrs"); + hp->h_addr_list = calloc(sizeof(hp->h_addr_list[0]), nitems + 1); + if (hp->h_addr_list == NULL) + goto fail; + for (ii = 0; ii < nitems; ii++) { + hp->h_addr_list[ii] = malloc(hp->h_length); + if (hp->h_addr_list[ii] == NULL) + goto fail; + bcopy(nvlist_getf_binary(nvl, NULL, "addr%u", ii), + hp->h_addr_list[ii], hp->h_length); + } + hp->h_addr_list[ii] = NULL; + + return (hp); +fail: + hostent_free(hp); + h_errno = NO_RECOVERY; + return (NULL); +} + +struct hostent * +cap_gethostbyname(cap_channel_t *chan, const char *name) +{ + + return (cap_gethostbyname2(chan, name, AF_INET)); +} + +struct hostent * +cap_gethostbyname2(cap_channel_t *chan, const char *name, int type) +{ + struct hostent *hp; + nvlist_t *nvl; + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", "gethostbyname"); + nvlist_add_number(nvl, "family", (uint64_t)type); + nvlist_add_string(nvl, "name", name); + nvl = cap_xfer_nvlist(chan, nvl); + if (nvl == NULL) { + h_errno = NO_RECOVERY; + return (NULL); + } + if (nvlist_get_number(nvl, "error") != 0) { + h_errno = (int)nvlist_get_number(nvl, "error"); + nvlist_destroy(nvl); + return (NULL); + } + + hp = hostent_unpack(nvl, &hent); + nvlist_destroy(nvl); + return (hp); +} + +struct hostent * +cap_gethostbyaddr(cap_channel_t *chan, const void *addr, socklen_t len, + int type) +{ + struct hostent *hp; + nvlist_t *nvl; + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", "gethostbyaddr"); + nvlist_add_binary(nvl, "addr", addr, (size_t)len); + nvlist_add_number(nvl, "family", (uint64_t)type); + nvl = cap_xfer_nvlist(chan, nvl); + if (nvl == NULL) { + h_errno = NO_RECOVERY; + return (NULL); + } + if (nvlist_get_number(nvl, "error") != 0) { + h_errno = (int)nvlist_get_number(nvl, "error"); + nvlist_destroy(nvl); + return (NULL); + } + hp = hostent_unpack(nvl, &hent); + nvlist_destroy(nvl); + return (hp); +} + +static struct addrinfo * +addrinfo_unpack(const nvlist_t *nvl) +{ + struct addrinfo *ai; + const void *addr; + size_t addrlen; + const char *canonname; + + addr = nvlist_get_binary(nvl, "ai_addr", &addrlen); + ai = malloc(sizeof(*ai) + addrlen); + if (ai == NULL) + return (NULL); + ai->ai_flags = (int)nvlist_get_number(nvl, "ai_flags"); + ai->ai_family = (int)nvlist_get_number(nvl, "ai_family"); + ai->ai_socktype = (int)nvlist_get_number(nvl, "ai_socktype"); + ai->ai_protocol = (int)nvlist_get_number(nvl, "ai_protocol"); + ai->ai_addrlen = (socklen_t)addrlen; + canonname = nvlist_get_string(nvl, "ai_canonname"); + if (canonname != NULL) { + ai->ai_canonname = strdup(canonname); + if (ai->ai_canonname == NULL) { + free(ai); + return (NULL); + } + } else { + ai->ai_canonname = NULL; + } + ai->ai_addr = (void *)(ai + 1); + bcopy(addr, ai->ai_addr, addrlen); + ai->ai_next = NULL; + + return (ai); +} + +int +cap_getaddrinfo(cap_channel_t *chan, const char *hostname, const char *servname, + const struct addrinfo *hints, struct addrinfo **res) +{ + struct addrinfo *firstai, *prevai, *curai; + unsigned int ii; + const nvlist_t *nvlai; + nvlist_t *nvl; + int error; + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", "getaddrinfo"); + nvlist_add_string(nvl, "hostname", hostname); + nvlist_add_string(nvl, "servname", servname); + if (hints != NULL) { + nvlist_add_number(nvl, "hints.ai_flags", + (uint64_t)hints->ai_flags); + nvlist_add_number(nvl, "hints.ai_family", + (uint64_t)hints->ai_family); + nvlist_add_number(nvl, "hints.ai_socktype", + (uint64_t)hints->ai_socktype); + nvlist_add_number(nvl, "hints.ai_protocol", + (uint64_t)hints->ai_protocol); + } + nvl = cap_xfer_nvlist(chan, nvl); + if (nvl == NULL) + return (EAI_MEMORY); + if (nvlist_get_number(nvl, "error") != 0) { + error = (int)nvlist_get_number(nvl, "error"); + nvlist_destroy(nvl); + return (error); + } + + nvlai = NULL; + firstai = prevai = curai = NULL; + for (ii = 0; ; ii++) { + if (!nvlist_existsf_nvlist(nvl, "res%u", ii)) + break; + nvlai = nvlist_getf_nvlist(nvl, "res%u", ii); + curai = addrinfo_unpack(nvlai); + if (curai == NULL) + break; + if (prevai != NULL) + prevai->ai_next = curai; + else if (firstai == NULL) + firstai = curai; + } + nvlist_destroy(nvl); + if (curai == NULL && nvlai != NULL) { + if (firstai == NULL) + freeaddrinfo(firstai); + return (EAI_MEMORY); + } + + *res = firstai; + return (0); +} + +int +cap_getnameinfo(cap_channel_t *chan, const struct sockaddr *sa, socklen_t salen, + char *host, size_t hostlen, char *serv, size_t servlen, int flags) +{ + nvlist_t *nvl; + int error; + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", "getnameinfo"); + nvlist_add_number(nvl, "hostlen", (uint64_t)hostlen); + nvlist_add_number(nvl, "servlen", (uint64_t)servlen); + nvlist_add_binary(nvl, "sa", sa, (size_t)salen); + nvlist_add_number(nvl, "flags", (uint64_t)flags); + nvl = cap_xfer_nvlist(chan, nvl); + if (nvl == NULL) + return (EAI_MEMORY); + if (nvlist_get_number(nvl, "error") != 0) { + error = (int)nvlist_get_number(nvl, "error"); + nvlist_destroy(nvl); + return (error); + } + + if (host != NULL) + strlcpy(host, nvlist_get_string(nvl, "host"), hostlen + 1); + if (serv != NULL) + strlcpy(serv, nvlist_get_string(nvl, "serv"), servlen + 1); + nvlist_destroy(nvl); + return (0); +} + +static void +limit_remove(nvlist_t *limits, const char *prefix) +{ + const char *name; + size_t prefixlen; + void *cookie; + + prefixlen = strlen(prefix); +again: + cookie = NULL; + while ((name = nvlist_next(limits, NULL, &cookie)) != NULL) { + if (strncmp(name, prefix, prefixlen) == 0) { + nvlist_free(limits, name); + goto again; + } + } +} + +int +cap_dns_type_limit(cap_channel_t *chan, const char * const *types, + size_t ntypes) +{ + nvlist_t *limits; + unsigned int i; + + if (cap_limit_get(chan, &limits) < 0) + return (-1); + if (limits == NULL) + limits = nvlist_create(0); + else + limit_remove(limits, "type"); + for (i = 0; i < ntypes; i++) + nvlist_addf_string(limits, types[i], "type%u", i); + return (cap_limit_set(chan, limits)); +} + +int +cap_dns_family_limit(cap_channel_t *chan, const int *families, + size_t nfamilies) +{ + nvlist_t *limits; + unsigned int i; + + if (cap_limit_get(chan, &limits) < 0) + return (-1); + if (limits == NULL) + limits = nvlist_create(0); + else + limit_remove(limits, "family"); + for (i = 0; i < nfamilies; i++) { + nvlist_addf_number(limits, (uint64_t)families[i], + "family%u", i); + } + return (cap_limit_set(chan, limits)); +} diff --git a/lib/libcapsicum/libcapsicum_dns.h b/lib/libcapsicum/libcapsicum_dns.h new file mode 100644 index 0000000000000..02235107cec49 --- /dev/null +++ b/lib/libcapsicum/libcapsicum_dns.h @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2012 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _LIBCAPSICUM_DNS_H_ +#define _LIBCAPSICUM_DNS_H_ + +#include <sys/socket.h> /* socklen_t */ + +struct addrinfo; +struct hostent; + +struct hostent *cap_gethostbyname(cap_channel_t *chan, const char *name); +struct hostent *cap_gethostbyname2(cap_channel_t *chan, const char *name, + int type); +struct hostent *cap_gethostbyaddr(cap_channel_t *chan, const void *addr, + socklen_t len, int type); + +int cap_getaddrinfo(cap_channel_t *chan, const char *hostname, + const char *servname, const struct addrinfo *hints, struct addrinfo **res); +int cap_getnameinfo(cap_channel_t *chan, const struct sockaddr *sa, + socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, + int flags); + +int cap_dns_type_limit(cap_channel_t *chan, const char * const *types, + size_t ntypes); +int cap_dns_family_limit(cap_channel_t *chan, const int *families, + size_t nfamilies); + +#endif /* !_LIBCAPSICUM_DNS_H_ */ diff --git a/lib/libcapsicum/libcapsicum_grp.c b/lib/libcapsicum/libcapsicum_grp.c new file mode 100644 index 0000000000000..c679ce9afbd8b --- /dev/null +++ b/lib/libcapsicum/libcapsicum_grp.c @@ -0,0 +1,426 @@ +/*- + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> + +#include <assert.h> +#include <errno.h> +#include <grp.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <dnv.h> +#include <nv.h> + +#include "libcapsicum.h" +#include "libcapsicum_grp.h" + +static struct group ggrp; +static char *gbuffer; +static size_t gbufsize; + +static int +group_resize(void) +{ + char *buf; + + if (gbufsize == 0) + gbufsize = 1024; + else + gbufsize *= 2; + + buf = gbuffer; + gbuffer = realloc(buf, gbufsize); + if (gbuffer == NULL) { + free(buf); + gbufsize = 0; + return (ENOMEM); + } + memset(gbuffer, 0, gbufsize); + + return (0); +} + +static int +group_unpack_string(const nvlist_t *nvl, const char *fieldname, char **fieldp, + char **bufferp, size_t *bufsizep) +{ + const char *str; + size_t len; + + str = nvlist_get_string(nvl, fieldname); + len = strlcpy(*bufferp, str, *bufsizep); + if (len >= *bufsizep) + return (ERANGE); + *fieldp = *bufferp; + *bufferp += len + 1; + *bufsizep -= len + 1; + + return (0); +} + +static int +group_unpack_members(const nvlist_t *nvl, char ***fieldp, char **bufferp, + size_t *bufsizep) +{ + const char *mem; + char **outstrs, *str; + size_t nmem, datasize, strsize; + unsigned int ii; + + if (!nvlist_exists_number(nvl, "gr_nmem")) { + datasize = _ALIGNBYTES + sizeof(char *); + if (datasize >= *bufsizep) + return (ERANGE); + outstrs = (char **)_ALIGN(*bufferp); + outstrs[0] = NULL; + *fieldp = outstrs; + *bufferp += datasize; + *bufsizep -= datasize; + return (0); + } + + nmem = (size_t)nvlist_get_number(nvl, "gr_nmem"); + datasize = _ALIGNBYTES + sizeof(char *) * (nmem + 1); + for (ii = 0; ii < nmem; ii++) { + mem = dnvlist_getf_string(nvl, NULL, "gr_mem[%u]", ii); + if (mem == NULL) + return (EINVAL); + datasize += strlen(mem) + 1; + } + + if (datasize >= *bufsizep) + return (ERANGE); + + outstrs = (char **)_ALIGN(*bufferp); + str = (char *)outstrs + sizeof(char *) * (nmem + 1); + for (ii = 0; ii < nmem; ii++) { + mem = nvlist_getf_string(nvl, "gr_mem[%u]", ii); + strsize = strlen(mem) + 1; + memcpy(str, mem, strsize); + outstrs[ii] = str; + str += strsize; + } + assert(ii == nmem); + outstrs[ii] = NULL; + + *fieldp = outstrs; + *bufferp += datasize; + *bufsizep -= datasize; + + return (0); +} + +static int +group_unpack(const nvlist_t *nvl, struct group *grp, char *buffer, + size_t bufsize) +{ + int error; + + if (!nvlist_exists_string(nvl, "gr_name")) + return (EINVAL); + + memset(grp, 0, sizeof(*grp)); + + error = group_unpack_string(nvl, "gr_name", &grp->gr_name, &buffer, + &bufsize); + if (error != 0) + return (error); + error = group_unpack_string(nvl, "gr_passwd", &grp->gr_passwd, &buffer, + &bufsize); + if (error != 0) + return (error); + grp->gr_gid = (gid_t)nvlist_get_number(nvl, "gr_gid"); + error = group_unpack_members(nvl, &grp->gr_mem, &buffer, &bufsize); + if (error != 0) + return (error); + + return (0); +} + +static int +cap_getgrcommon_r(cap_channel_t *chan, const char *cmd, const char *name, + gid_t gid, struct group *grp, char *buffer, size_t bufsize, + struct group **result) +{ + nvlist_t *nvl; + bool getgr_r; + int error; + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", cmd); + if (strcmp(cmd, "getgrent") == 0 || strcmp(cmd, "getgrent_r") == 0) { + /* Add nothing. */ + } else if (strcmp(cmd, "getgrnam") == 0 || + strcmp(cmd, "getgrnam_r") == 0) { + nvlist_add_string(nvl, "name", name); + } else if (strcmp(cmd, "getgrgid") == 0 || + strcmp(cmd, "getgrgid_r") == 0) { + nvlist_add_number(nvl, "gid", (uint64_t)gid); + } else { + abort(); + } + nvl = cap_xfer_nvlist(chan, nvl); + if (nvl == NULL) { + assert(errno != 0); + *result = NULL; + return (errno); + } + error = (int)nvlist_get_number(nvl, "error"); + if (error != 0) { + nvlist_destroy(nvl); + *result = NULL; + return (error); + } + + if (!nvlist_exists_string(nvl, "gr_name")) { + /* Not found. */ + nvlist_destroy(nvl); + *result = NULL; + return (0); + } + + getgr_r = (strcmp(cmd, "getgrent_r") == 0 || + strcmp(cmd, "getgrnam_r") == 0 || strcmp(cmd, "getgrgid_r") == 0); + + for (;;) { + error = group_unpack(nvl, grp, buffer, bufsize); + if (getgr_r || error != ERANGE) + break; + assert(buffer == gbuffer); + assert(bufsize == gbufsize); + error = group_resize(); + if (error != 0) + break; + /* Update pointers after resize. */ + buffer = gbuffer; + bufsize = gbufsize; + } + + nvlist_destroy(nvl); + + if (error == 0) + *result = grp; + else + *result = NULL; + + return (error); +} + +static struct group * +cap_getgrcommon(cap_channel_t *chan, const char *cmd, const char *name, + gid_t gid) +{ + struct group *result; + int error, serrno; + + serrno = errno; + + error = cap_getgrcommon_r(chan, cmd, name, gid, &ggrp, gbuffer, + gbufsize, &result); + if (error != 0) { + errno = error; + return (NULL); + } + + errno = serrno; + + return (result); +} + +struct group * +cap_getgrent(cap_channel_t *chan) +{ + + return (cap_getgrcommon(chan, "getgrent", NULL, 0)); +} + +struct group * +cap_getgrnam(cap_channel_t *chan, const char *name) +{ + + return (cap_getgrcommon(chan, "getgrnam", name, 0)); +} + +struct group * +cap_getgrgid(cap_channel_t *chan, gid_t gid) +{ + + return (cap_getgrcommon(chan, "getgrgid", NULL, gid)); +} + +int +cap_getgrent_r(cap_channel_t *chan, struct group *grp, char *buffer, + size_t bufsize, struct group **result) +{ + + return (cap_getgrcommon_r(chan, "getgrent_r", NULL, 0, grp, buffer, + bufsize, result)); +} + +int +cap_getgrnam_r(cap_channel_t *chan, const char *name, struct group *grp, + char *buffer, size_t bufsize, struct group **result) +{ + + return (cap_getgrcommon_r(chan, "getgrnam_r", name, 0, grp, buffer, + bufsize, result)); +} + +int +cap_getgrgid_r(cap_channel_t *chan, gid_t gid, struct group *grp, char *buffer, + size_t bufsize, struct group **result) +{ + + return (cap_getgrcommon_r(chan, "getgrgid_r", NULL, gid, grp, buffer, + bufsize, result)); +} + +int +cap_setgroupent(cap_channel_t *chan, int stayopen) +{ + nvlist_t *nvl; + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", "setgroupent"); + nvlist_add_bool(nvl, "stayopen", stayopen != 0); + nvl = cap_xfer_nvlist(chan, nvl); + if (nvl == NULL) + return (0); + if (nvlist_get_number(nvl, "error") != 0) { + errno = nvlist_get_number(nvl, "error"); + nvlist_destroy(nvl); + return (0); + } + nvlist_destroy(nvl); + + return (1); +} + +int +cap_setgrent(cap_channel_t *chan) +{ + nvlist_t *nvl; + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", "setgrent"); + nvl = cap_xfer_nvlist(chan, nvl); + if (nvl == NULL) + return (0); + if (nvlist_get_number(nvl, "error") != 0) { + errno = nvlist_get_number(nvl, "error"); + nvlist_destroy(nvl); + return (0); + } + nvlist_destroy(nvl); + + return (1); +} + +void +cap_endgrent(cap_channel_t *chan) +{ + nvlist_t *nvl; + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", "endgrent"); + /* Ignore any errors, we have no way to report them. */ + nvlist_destroy(cap_xfer_nvlist(chan, nvl)); +} + +int +cap_grp_limit_cmds(cap_channel_t *chan, const char * const *cmds, size_t ncmds) +{ + nvlist_t *limits, *nvl; + unsigned int i; + + if (cap_limit_get(chan, &limits) < 0) + return (-1); + if (limits == NULL) { + limits = nvlist_create(0); + } else { + if (nvlist_exists_nvlist(limits, "cmds")) + nvlist_free_nvlist(limits, "cmds"); + } + nvl = nvlist_create(0); + for (i = 0; i < ncmds; i++) + nvlist_add_null(nvl, cmds[i]); + nvlist_move_nvlist(limits, "cmds", nvl); + return (cap_limit_set(chan, limits)); +} + +int +cap_grp_limit_fields(cap_channel_t *chan, const char * const *fields, + size_t nfields) +{ + nvlist_t *limits, *nvl; + unsigned int i; + + if (cap_limit_get(chan, &limits) < 0) + return (-1); + if (limits == NULL) { + limits = nvlist_create(0); + } else { + if (nvlist_exists_nvlist(limits, "fields")) + nvlist_free_nvlist(limits, "fields"); + } + nvl = nvlist_create(0); + for (i = 0; i < nfields; i++) + nvlist_add_null(nvl, fields[i]); + nvlist_move_nvlist(limits, "fields", nvl); + return (cap_limit_set(chan, limits)); +} + +int +cap_grp_limit_groups(cap_channel_t *chan, const char * const *names, + size_t nnames, gid_t *gids, size_t ngids) +{ + nvlist_t *limits, *groups; + unsigned int i; + + if (cap_limit_get(chan, &limits) < 0) + return (-1); + if (limits == NULL) { + limits = nvlist_create(0); + } else { + if (nvlist_exists_nvlist(limits, "groups")) + nvlist_free_nvlist(limits, "groups"); + } + groups = nvlist_create(0); + for (i = 0; i < ngids; i++) + nvlist_addf_number(groups, (uint64_t)gids[i], "gid%u", i); + for (i = 0; i < nnames; i++) + nvlist_addf_string(groups, names[i], "name%u", i); + nvlist_move_nvlist(limits, "groups", groups); + return (cap_limit_set(chan, limits)); +} diff --git a/lib/libcapsicum/libcapsicum_grp.h b/lib/libcapsicum/libcapsicum_grp.h new file mode 100644 index 0000000000000..e0b44f0e1996c --- /dev/null +++ b/lib/libcapsicum/libcapsicum_grp.h @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _LIBCAPSICUM_GRP_H_ +#define _LIBCAPSICUM_GRP_H_ + +struct group *cap_getgrent(cap_channel_t *chan); +struct group *cap_getgrnam(cap_channel_t *chan, const char *name); +struct group *cap_getgrgid(cap_channel_t *chan, gid_t gid); + +int cap_getgrent_r(cap_channel_t *chan, struct group *grp, char *buffer, + size_t bufsize, struct group **result); +int cap_getgrnam_r(cap_channel_t *chan, const char *name, struct group *grp, + char *buffer, size_t bufsize, struct group **result); +int cap_getgrgid_r(cap_channel_t *chan, gid_t gid, struct group *grp, + char *buffer, size_t bufsize, struct group **result); + +int cap_setgroupent(cap_channel_t *chan, int stayopen); +int cap_setgrent(cap_channel_t *chan); +void cap_endgrent(cap_channel_t *chan); + +int cap_grp_limit_cmds(cap_channel_t *chan, const char * const *cmds, + size_t ncmds); +int cap_grp_limit_fields(cap_channel_t *chan, const char * const *fields, + size_t nfields); +int cap_grp_limit_groups(cap_channel_t *chan, const char * const *names, + size_t nnames, gid_t *gids, size_t ngids); + +#endif /* !_LIBCAPSICUM_GRP_H_ */ diff --git a/lib/libdwarf/dwarf_form.c b/lib/libcapsicum/libcapsicum_impl.h index 6fdf35e9b1946..ce6f49fdfcda6 100644 --- a/lib/libdwarf/dwarf_form.c +++ b/lib/libcapsicum/libcapsicum_impl.h @@ -1,7 +1,10 @@ /*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) + * Copyright (c) 2012-2013 The FreeBSD Foundation * All rights reserved. * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -11,10 +14,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -26,22 +29,11 @@ * $FreeBSD$ */ -#include "_libdwarf.h" - -int -dwarf_whatform(Dwarf_Attribute at, Dwarf_Half *return_form, Dwarf_Error *err) -{ - int ret = DWARF_E_NONE; - - if (err == NULL) - return DWARF_E_ERROR; +#ifndef _LIBCAPSICUM_IMPL_H_ +#define _LIBCAPSICUM_IMPL_H_ - if (at == NULL || return_form == NULL) { - DWARF_SET_ERROR(err, DWARF_E_ARGUMENT); - return DWARF_E_ARGUMENT; - } +#define CASPER_SOCKPATH "/var/run/casper" - *return_form = at->at_form; +bool fd_is_valid(int fd); - return ret; -} +#endif /* !_LIBCAPSICUM_IMPL_H_ */ diff --git a/lib/libcapsicum/libcapsicum_pwd.c b/lib/libcapsicum/libcapsicum_pwd.c new file mode 100644 index 0000000000000..792fb6698128e --- /dev/null +++ b/lib/libcapsicum/libcapsicum_pwd.c @@ -0,0 +1,384 @@ +/*- + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> + +#include <assert.h> +#include <errno.h> +#include <pwd.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <nv.h> + +#include "libcapsicum.h" +#include "libcapsicum_pwd.h" + +static struct passwd gpwd; +static char *gbuffer; +static size_t gbufsize; + +static int +passwd_resize(void) +{ + char *buf; + + if (gbufsize == 0) + gbufsize = 1024; + else + gbufsize *= 2; + + buf = gbuffer; + gbuffer = realloc(buf, gbufsize); + if (gbuffer == NULL) { + free(buf); + gbufsize = 0; + return (ENOMEM); + } + memset(gbuffer, 0, gbufsize); + + return (0); +} + +static int +passwd_unpack_string(const nvlist_t *nvl, const char *fieldname, char **fieldp, + char **bufferp, size_t *bufsizep) +{ + const char *str; + size_t len; + + str = nvlist_get_string(nvl, fieldname); + len = strlcpy(*bufferp, str, *bufsizep); + if (len >= *bufsizep) + return (ERANGE); + *fieldp = *bufferp; + *bufferp += len + 1; + *bufsizep -= len + 1; + + return (0); +} + +static int +passwd_unpack(const nvlist_t *nvl, struct passwd *pwd, char *buffer, + size_t bufsize) +{ + int error; + + if (!nvlist_exists_string(nvl, "pw_name")) + return (EINVAL); + + memset(pwd, 0, sizeof(*pwd)); + + error = passwd_unpack_string(nvl, "pw_name", &pwd->pw_name, &buffer, + &bufsize); + if (error != 0) + return (error); + pwd->pw_uid = (uid_t)nvlist_get_number(nvl, "pw_uid"); + pwd->pw_gid = (gid_t)nvlist_get_number(nvl, "pw_gid"); + pwd->pw_change = (time_t)nvlist_get_number(nvl, "pw_change"); + error = passwd_unpack_string(nvl, "pw_passwd", &pwd->pw_passwd, &buffer, + &bufsize); + if (error != 0) + return (error); + error = passwd_unpack_string(nvl, "pw_class", &pwd->pw_class, &buffer, + &bufsize); + if (error != 0) + return (error); + error = passwd_unpack_string(nvl, "pw_gecos", &pwd->pw_gecos, &buffer, + &bufsize); + if (error != 0) + return (error); + error = passwd_unpack_string(nvl, "pw_dir", &pwd->pw_dir, &buffer, + &bufsize); + if (error != 0) + return (error); + error = passwd_unpack_string(nvl, "pw_shell", &pwd->pw_shell, &buffer, + &bufsize); + if (error != 0) + return (error); + pwd->pw_expire = (time_t)nvlist_get_number(nvl, "pw_expire"); + pwd->pw_fields = (int)nvlist_get_number(nvl, "pw_fields"); + + return (0); +} + +static int +cap_getpwcommon_r(cap_channel_t *chan, const char *cmd, const char *login, + uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, + struct passwd **result) +{ + nvlist_t *nvl; + bool getpw_r; + int error; + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", cmd); + if (strcmp(cmd, "getpwent") == 0 || strcmp(cmd, "getpwent_r") == 0) { + /* Add nothing. */ + } else if (strcmp(cmd, "getpwnam") == 0 || + strcmp(cmd, "getpwnam_r") == 0) { + nvlist_add_string(nvl, "name", login); + } else if (strcmp(cmd, "getpwuid") == 0 || + strcmp(cmd, "getpwuid_r") == 0) { + nvlist_add_number(nvl, "uid", (uint64_t)uid); + } else { + abort(); + } + nvl = cap_xfer_nvlist(chan, nvl); + if (nvl == NULL) { + assert(errno != 0); + *result = NULL; + return (errno); + } + error = (int)nvlist_get_number(nvl, "error"); + if (error != 0) { + nvlist_destroy(nvl); + *result = NULL; + return (error); + } + + if (!nvlist_exists_string(nvl, "pw_name")) { + /* Not found. */ + nvlist_destroy(nvl); + *result = NULL; + return (0); + } + + getpw_r = (strcmp(cmd, "getpwent_r") == 0 || + strcmp(cmd, "getpwnam_r") == 0 || strcmp(cmd, "getpwuid_r") == 0); + + for (;;) { + error = passwd_unpack(nvl, pwd, buffer, bufsize); + if (getpw_r || error != ERANGE) + break; + assert(buffer == gbuffer); + assert(bufsize == gbufsize); + error = passwd_resize(); + if (error != 0) + break; + /* Update pointers after resize. */ + buffer = gbuffer; + bufsize = gbufsize; + } + + nvlist_destroy(nvl); + + if (error == 0) + *result = pwd; + else + *result = NULL; + + return (error); +} + +static struct passwd * +cap_getpwcommon(cap_channel_t *chan, const char *cmd, const char *login, + uid_t uid) +{ + struct passwd *result; + int error, serrno; + + serrno = errno; + + error = cap_getpwcommon_r(chan, cmd, login, uid, &gpwd, gbuffer, + gbufsize, &result); + if (error != 0) { + errno = error; + return (NULL); + } + + errno = serrno; + + return (result); +} + +struct passwd * +cap_getpwent(cap_channel_t *chan) +{ + + return (cap_getpwcommon(chan, "getpwent", NULL, 0)); +} + +struct passwd * +cap_getpwnam(cap_channel_t *chan, const char *login) +{ + + return (cap_getpwcommon(chan, "getpwnam", login, 0)); +} + +struct passwd * +cap_getpwuid(cap_channel_t *chan, uid_t uid) +{ + + return (cap_getpwcommon(chan, "getpwuid", NULL, uid)); +} + +int +cap_getpwent_r(cap_channel_t *chan, struct passwd *pwd, char *buffer, + size_t bufsize, struct passwd **result) +{ + + return (cap_getpwcommon_r(chan, "getpwent_r", NULL, 0, pwd, buffer, + bufsize, result)); +} + +int +cap_getpwnam_r(cap_channel_t *chan, const char *name, struct passwd *pwd, + char *buffer, size_t bufsize, struct passwd **result) +{ + + return (cap_getpwcommon_r(chan, "getpwnam_r", name, 0, pwd, buffer, + bufsize, result)); +} + +int +cap_getpwuid_r(cap_channel_t *chan, uid_t uid, struct passwd *pwd, char *buffer, + size_t bufsize, struct passwd **result) +{ + + return (cap_getpwcommon_r(chan, "getpwuid_r", NULL, uid, pwd, buffer, + bufsize, result)); +} + +int +cap_setpassent(cap_channel_t *chan, int stayopen) +{ + nvlist_t *nvl; + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", "setpassent"); + nvlist_add_bool(nvl, "stayopen", stayopen != 0); + nvl = cap_xfer_nvlist(chan, nvl); + if (nvl == NULL) + return (0); + if (nvlist_get_number(nvl, "error") != 0) { + errno = nvlist_get_number(nvl, "error"); + nvlist_destroy(nvl); + return (0); + } + nvlist_destroy(nvl); + + return (1); +} + +static void +cap_set_end_pwent(cap_channel_t *chan, const char *cmd) +{ + nvlist_t *nvl; + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", cmd); + /* Ignore any errors, we have no way to report them. */ + nvlist_destroy(cap_xfer_nvlist(chan, nvl)); +} + +void +cap_setpwent(cap_channel_t *chan) +{ + + cap_set_end_pwent(chan, "setpwent"); +} + +void +cap_endpwent(cap_channel_t *chan) +{ + + cap_set_end_pwent(chan, "endpwent"); +} + +int +cap_pwd_limit_cmds(cap_channel_t *chan, const char * const *cmds, size_t ncmds) +{ + nvlist_t *limits, *nvl; + unsigned int i; + + if (cap_limit_get(chan, &limits) < 0) + return (-1); + if (limits == NULL) { + limits = nvlist_create(0); + } else { + if (nvlist_exists_nvlist(limits, "cmds")) + nvlist_free_nvlist(limits, "cmds"); + } + nvl = nvlist_create(0); + for (i = 0; i < ncmds; i++) + nvlist_add_null(nvl, cmds[i]); + nvlist_move_nvlist(limits, "cmds", nvl); + return (cap_limit_set(chan, limits)); +} + +int +cap_pwd_limit_fields(cap_channel_t *chan, const char * const *fields, + size_t nfields) +{ + nvlist_t *limits, *nvl; + unsigned int i; + + if (cap_limit_get(chan, &limits) < 0) + return (-1); + if (limits == NULL) { + limits = nvlist_create(0); + } else { + if (nvlist_exists_nvlist(limits, "fields")) + nvlist_free_nvlist(limits, "fields"); + } + nvl = nvlist_create(0); + for (i = 0; i < nfields; i++) + nvlist_add_null(nvl, fields[i]); + nvlist_move_nvlist(limits, "fields", nvl); + return (cap_limit_set(chan, limits)); +} + +int +cap_pwd_limit_users(cap_channel_t *chan, const char * const *names, + size_t nnames, uid_t *uids, size_t nuids) +{ + nvlist_t *limits, *users; + unsigned int i; + + if (cap_limit_get(chan, &limits) < 0) + return (-1); + if (limits == NULL) { + limits = nvlist_create(0); + } else { + if (nvlist_exists_nvlist(limits, "users")) + nvlist_free_nvlist(limits, "users"); + } + users = nvlist_create(0); + for (i = 0; i < nuids; i++) + nvlist_addf_number(users, (uint64_t)uids[i], "uid%u", i); + for (i = 0; i < nnames; i++) + nvlist_addf_string(users, names[i], "name%u", i); + nvlist_move_nvlist(limits, "users", users); + return (cap_limit_set(chan, limits)); +} diff --git a/lib/libcapsicum/libcapsicum_pwd.h b/lib/libcapsicum/libcapsicum_pwd.h new file mode 100644 index 0000000000000..960a490faf862 --- /dev/null +++ b/lib/libcapsicum/libcapsicum_pwd.h @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _LIBCAPSICUM_PWD_H_ +#define _LIBCAPSICUM_PWD_H_ + +struct passwd *cap_getpwent(cap_channel_t *chan); +struct passwd *cap_getpwnam(cap_channel_t *chan, const char *login); +struct passwd *cap_getpwuid(cap_channel_t *chan, uid_t uid); + +int cap_getpwent_r(cap_channel_t *chan, struct passwd *pwd, char *buffer, + size_t bufsize, struct passwd **result); +int cap_getpwnam_r(cap_channel_t *chan, const char *name, struct passwd *pwd, + char *buffer, size_t bufsize, struct passwd **result); +int cap_getpwuid_r(cap_channel_t *chan, uid_t uid, struct passwd *pwd, + char *buffer, size_t bufsize, struct passwd **result); + +int cap_setpassent(cap_channel_t *chan, int stayopen); +void cap_setpwent(cap_channel_t *chan); +void cap_endpwent(cap_channel_t *chan); + +int cap_pwd_limit_cmds(cap_channel_t *chan, const char * const *cmds, + size_t ncmds); +int cap_pwd_limit_fields(cap_channel_t *chan, const char * const *fields, + size_t nfields); +int cap_pwd_limit_users(cap_channel_t *chan, const char * const *names, + size_t nnames, uid_t *uids, size_t nuids); + +#endif /* !_LIBCAPSICUM_PWD_H_ */ diff --git a/lib/libcapsicum/libcapsicum_random.c b/lib/libcapsicum/libcapsicum_random.c new file mode 100644 index 0000000000000..eed97e287ac6c --- /dev/null +++ b/lib/libcapsicum/libcapsicum_random.c @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <assert.h> +#include <errno.h> +#include <string.h> + +#include <nv.h> + +#include "libcapsicum.h" +#include "libcapsicum_random.h" + +#define MAXSIZE (1024 * 1024) + +int +cap_random_buf(cap_channel_t *chan, void *buf, size_t nbytes) +{ + nvlist_t *nvl; + const void *randbuf; + uint8_t *ptr; + size_t left, randbufsize; + + left = nbytes; + ptr = buf; + + while (left > 0) { + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", "generate"); + nvlist_add_number(nvl, "size", + (uint64_t)(left > MAXSIZE ? MAXSIZE : left)); + nvl = cap_xfer_nvlist(chan, nvl); + if (nvl == NULL) + return (-1); + if (nvlist_get_number(nvl, "error") != 0) { + errno = (int)nvlist_get_number(nvl, "error"); + nvlist_destroy(nvl); + return (-1); + } + + randbuf = nvlist_get_binary(nvl, "data", &randbufsize); + memcpy(ptr, randbuf, randbufsize); + + nvlist_destroy(nvl); + + ptr += randbufsize; + assert(left >= randbufsize); + left -= randbufsize; + } + + return (0); +} diff --git a/lib/libdwarf/dwarf_errno.c b/lib/libcapsicum/libcapsicum_random.h index d54ebfa963471..672afa04f2934 100644 --- a/lib/libdwarf/dwarf_errno.c +++ b/lib/libcapsicum/libcapsicum_random.h @@ -1,7 +1,10 @@ /*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) + * Copyright (c) 2013 The FreeBSD Foundation * All rights reserved. * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -11,10 +14,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -26,13 +29,9 @@ * $FreeBSD$ */ -#include "_libdwarf.h" +#ifndef _LIBCAPSICUM_RANDOM_H_ +#define _LIBCAPSICUM_RANDOM_H_ -int -dwarf_errno(Dwarf_Error *err) -{ - if (err == NULL) - return -1; +int cap_random_buf(cap_channel_t *chan, void *buf, size_t nbytes); - return (err->err_error); -} +#endif /* !_LIBCAPSICUM_RANDOM_H_ */ diff --git a/lib/libcapsicum/libcapsicum_service.c b/lib/libcapsicum/libcapsicum_service.c new file mode 100644 index 0000000000000..412766864d25e --- /dev/null +++ b/lib/libcapsicum/libcapsicum_service.c @@ -0,0 +1,96 @@ +/*- + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <assert.h> +#include <errno.h> +#include <string.h> +#include <unistd.h> + +#include <nv.h> +#include "msgio.h" + +#include "libcapsicum.h" +#include "libcapsicum_impl.h" +#include "libcapsicum_service.h" + +cap_channel_t * +cap_service_open(const cap_channel_t *chan, const char *name) +{ + cap_channel_t *newchan; + nvlist_t *nvl; + int sock, error; + + sock = -1; + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", "open"); + nvlist_add_string(nvl, "service", name); + if (fd_is_valid(STDERR_FILENO)) + nvlist_add_descriptor(nvl, "stderrfd", STDERR_FILENO); + nvl = cap_xfer_nvlist(chan, nvl); + if (nvl == NULL) + return (NULL); + error = (int)nvlist_get_number(nvl, "error"); + if (error != 0) { + nvlist_destroy(nvl); + errno = error; + return (NULL); + } + sock = nvlist_take_descriptor(nvl, "chanfd"); + assert(sock >= 0); + nvlist_destroy(nvl); + nvl = NULL; + if (cred_send(sock) == -1) + goto fail; + newchan = cap_wrap(sock); + if (newchan == NULL) + goto fail; + return (newchan); +fail: + error = errno; + close(sock); + errno = error; + return (NULL); +} + +int +cap_service_limit(const cap_channel_t *chan, const char * const *names, + size_t nnames) +{ + nvlist_t *limits; + unsigned int i; + + limits = nvlist_create(0); + for (i = 0; i < nnames; i++) + nvlist_add_null(limits, names[i]); + return (cap_limit_set(chan, limits)); +} diff --git a/lib/libdwarf/dwarf_dealloc.c b/lib/libcapsicum/libcapsicum_service.h index dd910a003c7f8..05c654f7bf10d 100644 --- a/lib/libdwarf/dwarf_dealloc.c +++ b/lib/libcapsicum/libcapsicum_service.h @@ -1,7 +1,10 @@ /*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) + * Copyright (c) 2013 The FreeBSD Foundation * All rights reserved. * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -11,10 +14,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -26,16 +29,12 @@ * $FreeBSD$ */ -#include "_libdwarf.h" +#ifndef _LIBCAPSICUM_SERVICE_H_ +#define _LIBCAPSICUM_SERVICE_H_ + +cap_channel_t *cap_service_open(const cap_channel_t *chan, const char *name); + +int cap_service_limit(const cap_channel_t *chan, const char * const *names, + size_t nnames); -void -dwarf_dealloc(Dwarf_Debug dbg __unused, Dwarf_Ptr p __unused, Dwarf_Unsigned alloc_type __unused) -{ - /* - * This libdwarf implementation doesn't use this style - * of memory allocation. It doesn't copy things to return - * them to the client, so the client doesn't need to - * remember to free them. - */ - return; -} +#endif /* !_LIBCAPSICUM_SERVICE_H_ */ diff --git a/lib/libcapsicum/libcapsicum_sysctl.c b/lib/libcapsicum/libcapsicum_sysctl.c new file mode 100644 index 0000000000000..6ea951bc27ead --- /dev/null +++ b/lib/libcapsicum/libcapsicum_sysctl.c @@ -0,0 +1,86 @@ +/*- + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <errno.h> +#include <string.h> + +#include <nv.h> + +#include "libcapsicum.h" +#include "libcapsicum_sysctl.h" + +int +cap_sysctlbyname(cap_channel_t *chan, const char *name, void *oldp, + size_t *oldlenp, const void *newp, size_t newlen) +{ + nvlist_t *nvl; + const uint8_t *retoldp; + uint8_t operation; + size_t oldlen; + + operation = 0; + if (oldp != NULL) + operation |= CAP_SYSCTL_READ; + if (newp != NULL) + operation |= CAP_SYSCTL_WRITE; + + nvl = nvlist_create(0); + nvlist_add_string(nvl, "cmd", "sysctl"); + nvlist_add_string(nvl, "name", name); + nvlist_add_number(nvl, "operation", (uint64_t)operation); + if (oldp == NULL && oldlenp != NULL) + nvlist_add_null(nvl, "justsize"); + else if (oldlenp != NULL) + nvlist_add_number(nvl, "oldlen", (uint64_t)*oldlenp); + if (newp != NULL) + nvlist_add_binary(nvl, "newp", newp, newlen); + nvl = cap_xfer_nvlist(chan, nvl); + if (nvl == NULL) + return (-1); + if (nvlist_get_number(nvl, "error") != 0) { + errno = (int)nvlist_get_number(nvl, "error"); + nvlist_destroy(nvl); + return (-1); + } + + if (oldp == NULL && oldlenp != NULL) { + *oldlenp = (size_t)nvlist_get_number(nvl, "oldlen"); + } else if (oldp != NULL) { + retoldp = nvlist_get_binary(nvl, "oldp", &oldlen); + memcpy(oldp, retoldp, oldlen); + if (oldlenp != NULL) + *oldlenp = oldlen; + } + nvlist_destroy(nvl); + + return (0); +} diff --git a/lib/libdwarf/dwarf_abbrev.c b/lib/libcapsicum/libcapsicum_sysctl.h index aae575c3ba1af..d0df1437cec50 100644 --- a/lib/libdwarf/dwarf_abbrev.c +++ b/lib/libcapsicum/libcapsicum_sysctl.h @@ -1,7 +1,10 @@ /*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) + * Copyright (c) 2013 The FreeBSD Foundation * All rights reserved. * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -11,10 +14,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -26,46 +29,15 @@ * $FreeBSD$ */ -#include <stdlib.h> -#include "_libdwarf.h" - -int -dwarf_abbrev_add(Dwarf_CU cu, uint64_t entry, uint64_t tag, uint8_t children, Dwarf_Abbrev *ap, Dwarf_Error *error) -{ - Dwarf_Abbrev a; - int ret = DWARF_E_NONE; - - if ((a = malloc(sizeof(struct _Dwarf_Abbrev))) == NULL) { - DWARF_SET_ERROR(error, DWARF_E_MEMORY); - return DWARF_E_MEMORY; - } - - /* Initialise the abbrev structure. */ - a->a_entry = entry; - a->a_tag = tag; - a->a_children = children; - - /* Initialise the list of attributes. */ - STAILQ_INIT(&a->a_attrib); - - /* Add the abbrev to the list in the compilation unit. */ - STAILQ_INSERT_TAIL(&cu->cu_abbrev, a, a_next); - - if (ap != NULL) - *ap = a; - - return ret; -} +#ifndef _LIBCAPSICUM_SYSCTL_H_ +#define _LIBCAPSICUM_SYSCTL_H_ -Dwarf_Abbrev -dwarf_abbrev_find(Dwarf_CU cu, uint64_t entry) -{ - Dwarf_Abbrev a = NULL; +#define CAP_SYSCTL_READ 0x01 +#define CAP_SYSCTL_WRITE 0x02 +#define CAP_SYSCTL_RDWR (CAP_SYSCTL_READ | CAP_SYSCTL_WRITE) +#define CAP_SYSCTL_RECURSIVE 0x04 - STAILQ_FOREACH(a, &cu->cu_abbrev, a_next) { - if (a->a_entry == entry) - break; - } +int cap_sysctlbyname(cap_channel_t *chan, const char *name, void *oldp, + size_t *oldlenp, const void *newp, size_t newlen); - return a; -} +#endif /* !_LIBCAPSICUM_SYSCTL_H_ */ diff --git a/lib/libcompiler_rt/Makefile b/lib/libcompiler_rt/Makefile index 8c560d7b36818..5f8039bc166f0 100644 --- a/lib/libcompiler_rt/Makefile +++ b/lib/libcompiler_rt/Makefile @@ -165,7 +165,9 @@ SRCF+= stdatomic .endif .for file in ${SRCF} -. if ${MACHINE_CPUARCH} != "arm" && exists(${CRTSRC}/${CRTARCH}/${file}.S) +. if ${MACHINE_ARCH} == "armv6hf" && exists(${CRTSRC}/${CRTARCH}/${file}vfp.S) +SRCS+= ${file}vfp.S +. elif (${MACHINE_CPUARCH} != "arm" || ${MACHINE_ARCH} == "armv6hf") && exists(${CRTSRC}/${CRTARCH}/${file}.S) SRCS+= ${file}.S . else SRCS+= ${file}.c diff --git a/lib/libcrypt/Makefile b/lib/libcrypt/Makefile index 7274e287bded1..aca24d8f8af31 100644 --- a/lib/libcrypt/Makefile +++ b/lib/libcrypt/Makefile @@ -9,7 +9,7 @@ SHLIBDIR?= /lib SHLIB_MAJOR= 5 LIB= crypt -.PATH: ${.CURDIR}/../libmd +.PATH: ${.CURDIR}/../libmd ${.CURDIR}/../../sys/crypto/sha2 SRCS= crypt.c misc.c \ crypt-md5.c md5c.c \ crypt-nthash.c md4c.c \ @@ -37,4 +37,9 @@ WARNS?= 2 PRECIOUSLIB= +.if ${MK_TESTS} != "no" +SUBDIR+= tests +.endif + .include <bsd.lib.mk> +.include <bsd.subdir.mk> diff --git a/lib/libcrypt/crypt.3 b/lib/libcrypt/crypt.3 index f14a6eb9d902b..50829c2fa43be 100644 --- a/lib/libcrypt/crypt.3 +++ b/lib/libcrypt/crypt.3 @@ -29,7 +29,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 9, 2011 +.Dd March 9, 2014 .Dt CRYPT 3 .Os .Sh NAME @@ -63,11 +63,16 @@ Currently these include the .Tn MD5 hash, .Tn NT-Hash -(compatible with Microsoft's NT scheme) +.Pq compatible with Microsoft's NT scheme and .Tn Blowfish . -The algorithm used will depend upon the format of the Salt (following -the Modular Crypt Format (MCF)), if +The algorithm used will depend upon the format of the Salt +.Po +following +the Modular Crypt Format +.Pq MCF +.Pc , +if .Tn DES and/or .Tn Blowfish @@ -77,8 +82,10 @@ has been called to change the default. .Pp The first argument to .Nm -is the data to hash (usually a password), in a -.Dv null Ns -terminated +is the data to hash +.Pq usually a password , +in a +.Dv NUL Ns -terminated string. The second is the salt, in one of three forms: .Pp @@ -96,22 +103,19 @@ If it begins with the string then the Modular Crypt Format is used, as outlined below. .It Traditional If neither of the above is true, it assumes the Traditional Format, -using the entire string as the salt (or the first portion). +using the entire string as the salt +.Pq or the first portion . .El .Pp All routines are designed to be time-consuming. -A brief test on a -.Tn Pentium -166/MMX shows the -.Tn DES -crypt to do approximately 2640 crypts -a CPU second and MD5 to do about 62 crypts a CPU second. .Ss DES Extended Format: The .Ar key -is divided into groups of 8 characters (the last group is null-padded) -and the low-order 7 bits of each character (56 bits per group) are -used to form the +is divided into groups of 8 characters +.Pq the last group is NUL-padded +and the low-order 7 bits of each character +.Pq 56 bits per group +are used to form the .Tn DES key as follows: the first group of 56 bits becomes the initial @@ -127,7 +131,8 @@ The salt is a 9-character array consisting of an underscore followed by 4 bytes of iteration count and 4 bytes of salt. These are encoded as printable characters, 6 bits per character, least significant character first. -The values 0 to 63 are encoded as ``./0-9A-Za-z''. +The values 0 to 63 are encoded as +.Dq ./0-9A-Za-z . This allows 24 bits for both .Fa count and @@ -138,7 +143,8 @@ The introduces disorder in the .Tn DES algorithm in one of 16777216 or 4096 possible ways -(i.e., with 24 or 12 bits: if bit +.Po +i.e., with 24 or 12 bits: if bit .Em i of the .Ar salt @@ -148,7 +154,8 @@ and .Em i+24 are swapped in the .Tn DES -E-box output). +E-box output +.Pc . .Pp The .Tn DES @@ -157,11 +164,13 @@ key is used to encrypt a 64-bit constant using iterations of .Tn DES . The value returned is a -.Dv null Ns -terminated -string, 20 or 13 bytes (plus null) in length, consisting of the +.Dv NUL Ns -terminated +string, 20 or 13 bytes +.Pq plus NUL +in length, consisting of the .Ar salt followed by the encoded 64-bit encryption. -.Ss "Modular" crypt: +.Ss Modular crypt: If the salt begins with the string .Fa $digit$ then the Modular Crypt Format is used. @@ -170,11 +179,10 @@ The represents which algorithm is used in encryption. Following the token is the actual salt to use in the encryption. -The length of the salt is limited -to 8 characters--because the length of the returned output is also limited -(_PASSWORD_LEN). -The salt must be terminated with the end of the string -(NULL) or a dollar sign. +The maximum length of the salt used depends upon the module. +The salt must be terminated with the end of the string character +.Pq NUL +or a dollar sign. Any characters after the dollar sign are ignored. .Pp Currently supported algorithms are: @@ -199,7 +207,7 @@ An example salt would be: .Bl -tag -width 6n -offset indent .It Cm "$4$thesalt$rest" .El -.Ss "Traditional" crypt: +.Ss Traditional crypt: The algorithm used will depend upon whether .Fn crypt_set_format has been called and whether a global default format has been specified. @@ -216,7 +224,7 @@ if it is available, or MD5 if not. .Pp How the salt is used will depend upon the algorithm for the hash. For -best results, specify at least two characters of salt. +best results, specify at least eight characters of salt. .Pp The .Fn crypt_get_format diff --git a/lib/libcrypt/crypt.c b/lib/libcrypt/crypt.c index bfcbb2049b5aa..040fdc1b90af6 100644 --- a/lib/libcrypt/crypt.c +++ b/lib/libcrypt/crypt.c @@ -1,6 +1,7 @@ -/* - * Copyright (c) 1999 - * Mark Murray. All rights reserved. +/*- + * Copyright (c) 1999 Mark Murray + * Copyright (c) 2014 Dag-Erling Smørgrav + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,114 +29,88 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> -#include <string.h> + #include <libutil.h> +#include <string.h> #include <unistd.h> + #include "crypt.h" -static const struct { +/* + * List of supported crypt(3) formats. The first element in the list will + * be the default. + */ +static const struct crypt_format { const char *const name; char *(*const func)(const char *, const char *); const char *const magic; -} crypt_types[] = { -#ifdef HAS_DES - { - "des", - crypt_des, - NULL - }, -#endif - { - "md5", - crypt_md5, - "$1$" - }, +} crypt_formats[] = { + /* default format */ + { "sha512", crypt_sha512, "$6$" }, + + /* other supported formats */ + { "md5", crypt_md5, "$1$" }, #ifdef HAS_BLOWFISH - { - "blf", - crypt_blowfish, - "$2" - }, + { "blf", crypt_blowfish, "$2" }, #endif - { - "nth", - crypt_nthash, - "$3$" - }, - { - "sha256", - crypt_sha256, - "$5$" - }, - { - "sha512", - crypt_sha512, - "$6$" - }, - { - NULL, - NULL, - NULL - } -}; - + { "nth", crypt_nthash, "$3$" }, + { "sha256", crypt_sha256, "$5$" }, #ifdef HAS_DES -#define CRYPT_DEFAULT "des" -#else -#define CRYPT_DEFAULT "md5" + { "des", crypt_des, "_" }, #endif -static int crypt_type = -1; + /* sentinel */ + { NULL, NULL, NULL } +}; -static void -crypt_setdefault(void) -{ - size_t i; +static const struct crypt_format *crypt_format = &crypt_formats[0]; - if (crypt_type != -1) - return; - for (i = 0; i < sizeof(crypt_types) / sizeof(crypt_types[0]) - 1; i++) { - if (strcmp(CRYPT_DEFAULT, crypt_types[i].name) == 0) { - crypt_type = (int)i; - return; - } - } - crypt_type = 0; -} +#define DES_SALT_ALPHABET \ + "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +/* + * Returns the name of the currently selected format. + */ const char * crypt_get_format(void) { - crypt_setdefault(); - return (crypt_types[crypt_type].name); + return (crypt_format->name); } +/* + * Selects the format to use for subsequent crypt(3) invocations. + */ int -crypt_set_format(const char *type) +crypt_set_format(const char *format) { - size_t i; + const struct crypt_format *cf; - crypt_setdefault(); - for (i = 0; i < sizeof(crypt_types) / sizeof(crypt_types[0]) - 1; i++) { - if (strcmp(type, crypt_types[i].name) == 0) { - crypt_type = (int)i; + for (cf = crypt_formats; cf->name != NULL; ++cf) { + if (strcasecmp(cf->name, format) == 0) { + crypt_format = cf; return (1); } } return (0); } +/* + * Hash the given password with the given salt. If the salt begins with a + * magic string (e.g. "$6$" for sha512), the corresponding format is used; + * otherwise, the currently selected format is used. + */ char * crypt(const char *passwd, const char *salt) { - size_t i; + const struct crypt_format *cf; - crypt_setdefault(); - for (i = 0; i < sizeof(crypt_types) / sizeof(crypt_types[0]) - 1; i++) { - if (crypt_types[i].magic != NULL && strncmp(salt, - crypt_types[i].magic, strlen(crypt_types[i].magic)) == 0) - return (crypt_types[i].func(passwd, salt)); - } - return (crypt_types[crypt_type].func(passwd, salt)); + for (cf = crypt_formats; cf->name != NULL; ++cf) + if (cf->magic != NULL && strstr(salt, cf->magic) == salt) + return (cf->func(passwd, salt)); +#ifdef HAS_DES + if (strlen(salt) == 13 && strspn(salt, DES_SALT_ALPHABET) == 13) + return (crypt_des(passwd, salt)); +#endif + return (crypt_format->func(passwd, salt)); } diff --git a/lib/libcrypt/tests/Makefile b/lib/libcrypt/tests/Makefile index 3190dbe9492e5..2a0f1fbeaf5db 100644 --- a/lib/libcrypt/tests/Makefile +++ b/lib/libcrypt/tests/Makefile @@ -2,9 +2,11 @@ # exercise libcrypt -TESTS_C= crypt_tests +TESTSDIR= ${TESTSBASE}/lib/libcrypt + +ATF_TESTS_C= crypt_tests CFLAGS+= -I${.CURDIR:H} LDADD+= -L${.OBJDIR:H} -lcrypt -.include <atf.test.mk> +.include <bsd.test.mk> diff --git a/lib/libcrypt/tests/crypt_tests.c b/lib/libcrypt/tests/crypt_tests.c index d0db8aba95002..2b2f9e6ebed9c 100644 --- a/lib/libcrypt/tests/crypt_tests.c +++ b/lib/libcrypt/tests/crypt_tests.c @@ -42,7 +42,7 @@ ATF_TC_BODY(invalid, tc) /* * This function must not do anything except enumerate - * the test cases, else atf-run is likely to be upset. + * the test cases, per atf-c-api(3). */ ATF_TP_ADD_TCS(tp) { diff --git a/lib/libdwarf/Makefile b/lib/libdwarf/Makefile index dbd7895cd06a1..9d4df830ff07d 100644 --- a/lib/libdwarf/Makefile +++ b/lib/libdwarf/Makefile @@ -1,9 +1,16 @@ # $FreeBSD$ +.include <bsd.own.mk> + +TOP= ${.CURDIR}/../../contrib/elftoolchain +SRCDIR= ${TOP}/libdwarf + +.PATH: ${SRCDIR} LIB= dwarf SRCS= \ dwarf_abbrev.c \ + dwarf_arange.c \ dwarf_attr.c \ dwarf_attrval.c \ dwarf_cu.c \ @@ -11,19 +18,329 @@ SRCS= \ dwarf_die.c \ dwarf_dump.c \ dwarf_errmsg.c \ - dwarf_errno.c \ dwarf_finish.c \ dwarf_form.c \ - dwarf_func.c \ + dwarf_frame.c \ + dwarf_funcs.c \ dwarf_init.c \ - dwarf_loc.c + dwarf_lineno.c \ + dwarf_loclist.c \ + dwarf_macinfo.c \ + dwarf_pro_arange.c \ + dwarf_pro_attr.c \ + dwarf_pro_die.c \ + dwarf_pro_expr.c \ + dwarf_pro_finish.c \ + dwarf_pro_frame.c \ + dwarf_pro_funcs.c \ + dwarf_pro_init.c \ + dwarf_pro_lineno.c \ + dwarf_pro_macinfo.c \ + dwarf_pro_pubnames.c \ + dwarf_pro_reloc.c \ + dwarf_pro_sections.c \ + dwarf_pro_types.c \ + dwarf_pro_vars.c \ + dwarf_pro_weaks.c \ + dwarf_pubnames.c \ + dwarf_pubtypes.c \ + dwarf_ranges.c \ + dwarf_reloc.c \ + dwarf_seterror.c \ + dwarf_str.c \ + dwarf_types.c \ + dwarf_vars.c \ + dwarf_weaks.c \ + libdwarf.c \ + libdwarf_abbrev.c \ + libdwarf_arange.c \ + libdwarf_attr.c \ + libdwarf_die.c \ + libdwarf_error.c \ + libdwarf_elf_access.c \ + libdwarf_elf_init.c \ + libdwarf_frame.c \ + libdwarf_info.c \ + libdwarf_init.c \ + libdwarf_lineno.c \ + libdwarf_loc.c \ + libdwarf_loclist.c \ + libdwarf_macinfo.c \ + libdwarf_nametbl.c \ + libdwarf_ranges.c \ + libdwarf_reloc.c \ + libdwarf_rw.c \ + libdwarf_sections.c \ + libdwarf_str.c + +INCS= dwarf.h libdwarf.h + +# +# We need to link against the correct version of these files. One +# solution is to include ../../sys in the include path. This causes +# problems when a header file in sys depends on a file in another +# part of the tree, e.g. a machine dependent header. +# +SRCS+= sys/elf32.h sys/elf64.h sys/elf_common.h + +GENSRCS= dwarf_pubnames.c dwarf_pubtypes.c dwarf_weaks.c \ + dwarf_funcs.c dwarf_vars.c dwarf_types.c \ + dwarf_pro_pubnames.c dwarf_pro_weaks.c \ + dwarf_pro_funcs.c dwarf_pro_types.c \ + dwarf_pro_vars.c +CLEANFILES= ${GENSRCS} +CLEANDIRS= sys +CFLAGS+= -I. -I${SRCDIR} -I${TOP}/common -I${TOP}/libelf -INCS= dwarf.h libdwarf.h +sys/elf32.h sys/elf64.h sys/elf_common.h: ${.CURDIR}/../../sys/${.TARGET} + mkdir -p ${.OBJDIR}/sys + ln -sf ${.CURDIR}/../../sys/${.TARGET} ${.TARGET} -CFLAGS+= -I${.CURDIR} +LDADD+= -lelf +DPADD+= ${LIBELF} -SHLIB_MAJOR= 3 +SHLIB_MAJOR= 4 -WITHOUT_MAN= +MAN= dwarf.3 \ + dwarf_add_arange.3 \ + dwarf_add_AT_comp_dir.3 \ + dwarf_add_AT_const_value_string.3 \ + dwarf_add_AT_dataref.3 \ + dwarf_add_AT_flag.3 \ + dwarf_add_AT_location_expr.3 \ + dwarf_add_AT_name.3 \ + dwarf_add_AT_producer.3 \ + dwarf_add_AT_ref_address.3 \ + dwarf_add_AT_reference.3 \ + dwarf_add_AT_signed_const.3 \ + dwarf_add_AT_string.3 \ + dwarf_add_AT_targ_address.3 \ + dwarf_add_die_to_debug.3 \ + dwarf_add_directory_decl.3 \ + dwarf_add_expr_addr.3 \ + dwarf_add_expr_gen.3 \ + dwarf_add_fde_inst.3 \ + dwarf_add_file_decl.3 \ + dwarf_add_frame_cie.3 \ + dwarf_add_frame_fde.3 \ + dwarf_add_funcname.3 \ + dwarf_add_line_entry.3 \ + dwarf_add_pubname.3 \ + dwarf_add_typename.3 \ + dwarf_add_varname.3 \ + dwarf_add_weakname.3 \ + dwarf_attr.3 \ + dwarf_attrlist.3 \ + dwarf_attrval_signed.3 \ + dwarf_child.3 \ + dwarf_dealloc.3 \ + dwarf_def_macro.3 \ + dwarf_die_abbrev_code.3 \ + dwarf_die_link.3 \ + dwarf_diename.3 \ + dwarf_dieoffset.3 \ + dwarf_end_macro_file.3 \ + dwarf_errmsg.3 \ + dwarf_errno.3 \ + dwarf_expand_frame_instructions.3 \ + dwarf_expr_current_offset.3 \ + dwarf_expr_into_block.3 \ + dwarf_fde_cfa_offset.3 \ + dwarf_find_macro_value_start.3 \ + dwarf_finish.3 \ + dwarf_formaddr.3 \ + dwarf_formblock.3 \ + dwarf_formexprloc.3 \ + dwarf_formflag.3 \ + dwarf_formref.3 \ + dwarf_formsig8.3 \ + dwarf_formstring.3 \ + dwarf_formudata.3 \ + dwarf_get_abbrev.3 \ + dwarf_get_abbrev_children_flag.3 \ + dwarf_get_abbrev_code.3 \ + dwarf_get_abbrev_entry.3 \ + dwarf_get_abbrev_tag.3 \ + dwarf_get_address_size.3 \ + dwarf_get_arange.3 \ + dwarf_get_arange_info.3 \ + dwarf_get_aranges.3 \ + dwarf_get_AT_name.3 \ + dwarf_get_cie_index.3 \ + dwarf_get_cie_info.3 \ + dwarf_get_cie_of_fde.3 \ + dwarf_get_cu_die_offset.3 \ + dwarf_get_elf.3 \ + dwarf_get_fde_at_pc.3 \ + dwarf_get_fde_info_for_all_regs.3 \ + dwarf_get_fde_info_for_all_regs3.3 \ + dwarf_get_fde_info_for_cfa_reg3.3 \ + dwarf_get_fde_info_for_reg.3 \ + dwarf_get_fde_info_for_reg3.3 \ + dwarf_get_fde_instr_bytes.3 \ + dwarf_get_fde_list.3 \ + dwarf_get_fde_n.3 \ + dwarf_get_fde_range.3 \ + dwarf_get_form_class.3 \ + dwarf_get_funcs.3 \ + dwarf_get_globals.3 \ + dwarf_get_loclist_entry.3 \ + dwarf_get_macro_details.3 \ + dwarf_get_pubtypes.3 \ + dwarf_get_ranges.3 \ + dwarf_get_relocation_info.3 \ + dwarf_get_relocation_info_count.3 \ + dwarf_get_section_bytes.3 \ + dwarf_get_str.3 \ + dwarf_get_types.3 \ + dwarf_get_vars.3 \ + dwarf_get_weaks.3 \ + dwarf_hasattr.3 \ + dwarf_hasform.3 \ + dwarf_highpc.3 \ + dwarf_init.3 \ + dwarf_lineno.3 \ + dwarf_lne_end_sequence.3 \ + dwarf_lne_set_address.3 \ + dwarf_loclist.3 \ + dwarf_loclist_from_expr.3 \ + dwarf_new_die.3 \ + dwarf_new_expr.3 \ + dwarf_new_fde.3 \ + dwarf_next_cu_header.3 \ + dwarf_object_init.3 \ + dwarf_producer_init.3 \ + dwarf_producer_set_isa.3 \ + dwarf_reset_section_bytes.3 \ + dwarf_seterrarg.3 \ + dwarf_set_frame_cfa_value.3 \ + dwarf_set_reloc_application.3 \ + dwarf_srcfiles.3 \ + dwarf_srclines.3 \ + dwarf_start_macro_file.3 \ + dwarf_tag.3 \ + dwarf_transform_to_disk_form.3 \ + dwarf_undef_macro.3 \ + dwarf_vendor_ext.3 \ + dwarf_whatattr.3 + +MLINKS+= \ + dwarf_add_AT_const_value_string.3 dwarf_add_AT_const_value_signedint.3 \ + dwarf_add_AT_const_value_string.3 dwarf_add_AT_const_value_unsignedint.3 \ + dwarf_add_AT_signed_const.3 dwarf_add_AT_unsigned_const.3 \ + dwarf_add_AT_targ_address.3 dwarf_add_AT_targ_address_b.3 \ + dwarf_add_arange.3 dwarf_add_arange_b.3 \ + dwarf_add_expr_addr.3 dwarf_add_expr_addr_b.3 \ + dwarf_add_frame_fde.3 dwarf_add_frame_fde_b.3 \ + dwarf_attrval_signed.3 dwarf_attrval_flag.3 \ + dwarf_attrval_signed.3 dwarf_attrval_string.3 \ + dwarf_attrval_signed.3 dwarf_attrval_unsigned.3 \ + dwarf_child.3 dwarf_offdie.3 \ + dwarf_child.3 dwarf_siblingof.3 \ + dwarf_dealloc.3 dwarf_fde_cie_list_dealloc.3 \ + dwarf_dealloc.3 dwarf_funcs_dealloc.3 \ + dwarf_dealloc.3 dwarf_globals_dealloc.3 \ + dwarf_dealloc.3 dwarf_pubtypes_dealloc.3 \ + dwarf_dealloc.3 dwarf_types_dealloc.3 \ + dwarf_dealloc.3 dwarf_vars_dealloc.3 \ + dwarf_dealloc.3 dwarf_weaks_dealloc.3 \ + dwarf_dealloc.3 dwarf_ranges_dealloc.3 \ + dwarf_dealloc.3 dwarf_srclines_dealloc.3 \ + dwarf_init.3 dwarf_elf_init.3 \ + dwarf_dieoffset.3 dwarf_die_CU_offset.3 \ + dwarf_dieoffset.3 dwarf_die_CU_offset_range.3 \ + dwarf_dieoffset.3 dwarf_get_cu_die_offset_given_cu_header_offset.3 \ + dwarf_finish.3 dwarf_object_finish.3 \ + dwarf_formref.3 dwarf_global_formref.3 \ + dwarf_formudata.3 dwarf_formsdata.3 \ + dwarf_get_AT_name.3 dwarf_get_ACCESS_name.3 \ + dwarf_get_AT_name.3 dwarf_get_ATE_name.3 \ + dwarf_get_AT_name.3 dwarf_get_CC_name.3 \ + dwarf_get_AT_name.3 dwarf_get_CFA_name.3 \ + dwarf_get_AT_name.3 dwarf_get_CHILDREN_name.3 \ + dwarf_get_AT_name.3 dwarf_get_DS_name.3 \ + dwarf_get_AT_name.3 dwarf_get_DSC_name.3 \ + dwarf_get_AT_name.3 dwarf_get_EH_name.3 \ + dwarf_get_AT_name.3 dwarf_get_END_name.3 \ + dwarf_get_AT_name.3 dwarf_get_FORM_name.3 \ + dwarf_get_AT_name.3 dwarf_get_ID_name.3 \ + dwarf_get_AT_name.3 dwarf_get_INL_name.3 \ + dwarf_get_AT_name.3 dwarf_get_LANG_name.3 \ + dwarf_get_AT_name.3 dwarf_get_LNE_name.3 \ + dwarf_get_AT_name.3 dwarf_get_LNS_name.3 \ + dwarf_get_AT_name.3 dwarf_get_MACINFO_name.3 \ + dwarf_get_AT_name.3 dwarf_get_OP_name.3 \ + dwarf_get_AT_name.3 dwarf_get_ORD_name.3 \ + dwarf_get_AT_name.3 dwarf_get_TAG_name.3 \ + dwarf_get_AT_name.3 dwarf_get_VIRTUALITY_name.3 \ + dwarf_get_AT_name.3 dwarf_get_VIS_name.3 \ + dwarf_get_cu_die_offset.3 dwarf_get_arange_cu_header_offset.3 \ + dwarf_get_fde_list.3 dwarf_get_fde_list_eh.3 \ + dwarf_get_funcs.3 dwarf_func_die_offset.3 \ + dwarf_get_funcs.3 dwarf_func_cu_offset.3 \ + dwarf_get_funcs.3 dwarf_func_name_offsets.3 \ + dwarf_get_funcs.3 dwarf_funcname.3 \ + dwarf_get_globals.3 dwarf_global_die_offset.3 \ + dwarf_get_globals.3 dwarf_global_cu_offset.3 \ + dwarf_get_globals.3 dwarf_global_name_offsets.3 \ + dwarf_get_globals.3 dwarf_globname.3 \ + dwarf_get_pubtypes.3 dwarf_pubtype_die_offset.3 \ + dwarf_get_pubtypes.3 dwarf_pubtype_cu_offset.3 \ + dwarf_get_pubtypes.3 dwarf_pubtype_name_offsets.3 \ + dwarf_get_pubtypes.3 dwarf_pubtypename.3 \ + dwarf_get_ranges.3 dwarf_get_ranges_a.3 \ + dwarf_get_types.3 dwarf_type_die_offset.3 \ + dwarf_get_types.3 dwarf_type_cu_offset.3 \ + dwarf_get_types.3 dwarf_type_name_offsets.3 \ + dwarf_get_types.3 dwarf_typename.3 \ + dwarf_get_vars.3 dwarf_var_die_offset.3 \ + dwarf_get_vars.3 dwarf_var_cu_offset.3 \ + dwarf_get_vars.3 dwarf_var_name_offsets.3 \ + dwarf_get_vars.3 dwarf_varname.3 \ + dwarf_get_weaks.3 dwarf_weak_die_offset.3 \ + dwarf_get_weaks.3 dwarf_weak_cu_offset.3 \ + dwarf_get_weaks.3 dwarf_weak_name_offsets.3 \ + dwarf_get_weaks.3 dwarf_weakname.3 \ + dwarf_hasform.3 dwarf_whatform.3 \ + dwarf_hasform.3 dwarf_whatform_direct.3 \ + dwarf_highpc.3 dwarf_arrayorder.3 \ + dwarf_highpc.3 dwarf_bitoffset.3 \ + dwarf_highpc.3 dwarf_bitsize.3 \ + dwarf_highpc.3 dwarf_bytesize.3 \ + dwarf_highpc.3 dwarf_lowpc.3 \ + dwarf_highpc.3 dwarf_srclang.3 \ + dwarf_lineno.3 dwarf_lineaddr.3 \ + dwarf_lineno.3 dwarf_linebeginstatement.3 \ + dwarf_lineno.3 dwarf_lineblock.3 \ + dwarf_lineno.3 dwarf_lineendsequence.3 \ + dwarf_lineno.3 dwarf_lineoff.3 \ + dwarf_lineno.3 dwarf_linesrc.3 \ + dwarf_lineno.3 dwarf_line_srcfileno.3 \ + dwarf_loclist.3 dwarf_loclist_n.3 \ + dwarf_loclist_from_expr.3 dwarf_loclist_from_expr_a.3 \ + dwarf_producer_init.3 dwarf_producer_init_b.3 \ + dwarf_seterrarg.3 dwarf_seterrhand.3 \ + dwarf_set_frame_cfa_value.3 dwarf_set_frame_rule_initial_value.3 \ + dwarf_set_frame_cfa_value.3 dwarf_set_frame_rule_table_size.3 \ + dwarf_set_frame_cfa_value.3 dwarf_set_frame_same_value.3 \ + dwarf_set_frame_cfa_value.3 dwarf_set_frame_undefined_value.3 + +dwarf_pubnames.c: dwarf_nametbl.m4 dwarf_pubnames.m4 +dwarf_pubtypes.c: dwarf_nametbl.m4 dwarf_pubtypes.m4 +dwarf_weaks.c: dwarf_nametbl.m4 dwarf_weaks.m4 +dwarf_funcs.c: dwarf_nametbl.m4 dwarf_funcs.m4 +dwarf_vars.c: dwarf_nametbl.m4 dwarf_vars.m4 +dwarf_types.c: dwarf_nametbl.m4 dwarf_types.m4 +dwarf_pro_pubnames.c: dwarf_pro_nametbl.m4 dwarf_pro_pubnames.m4 +dwarf_pro_weaks.c: dwarf_pro_nametbl.m4 dwarf_pro_weaks.m4 +dwarf_pro_funcs.c: dwarf_pro_nametbl.m4 dwarf_pro_funcs.m4 +dwarf_pro_types.c: dwarf_pro_nametbl.m4 dwarf_pro_types.m4 +dwarf_pro_vars.c: dwarf_pro_nametbl.m4 dwarf_pro_vars.m4 .include <bsd.lib.mk> + +# Keep the .SUFFIXES line after the include of bsd.lib.mk +.SUFFIXES: .m4 .c +.m4.c: + m4 -D SRCDIR=${SRCDIR} ${M4FLAGS} ${.IMPSRC} > ${.TARGET} + diff --git a/lib/libdwarf/_libdwarf.h b/lib/libdwarf/_libdwarf.h deleted file mode 100644 index 828250eba1029..0000000000000 --- a/lib/libdwarf/_libdwarf.h +++ /dev/null @@ -1,199 +0,0 @@ -/*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __LIBDWARF_H_ -#define __LIBDWARF_H_ - -#include <sys/param.h> -#include <sys/queue.h> -#include <stdio.h> -#include <gelf.h> -#include "dwarf.h" -#include "libdwarf.h" - -#define DWARF_debug_abbrev 0 -#define DWARF_debug_aranges 1 -#define DWARF_debug_frame 2 -#define DWARF_debug_info 3 -#define DWARF_debug_line 4 -#define DWARF_debug_pubnames 5 -#define DWARF_eh_frame 6 -#define DWARF_debug_macinfo 7 -#define DWARF_debug_str 8 -#define DWARF_debug_loc 9 -#define DWARF_debug_pubtypes 10 -#define DWARF_debug_ranges 11 -#define DWARF_debug_static_func 12 -#define DWARF_debug_static_vars 13 -#define DWARF_debug_types 14 -#define DWARF_debug_weaknames 15 -#define DWARF_symtab 16 -#define DWARF_strtab 17 -#define DWARF_DEBUG_SNAMES 18 - -#define DWARF_DIE_HASH_SIZE 8191 - -#define DWARF_SET_ERROR(_e, _err) do { \ - _e->err_error = _err; \ - _e->elf_error = 0; \ - _e->err_func = __func__; \ - _e->err_line = __LINE__; \ - _e->err_msg[0] = '\0'; \ - } while (0) - -#define DWARF_SET_ELF_ERROR(_e, _err) do { \ - _e->err_error = DWARF_E_ELF; \ - _e->elf_error = _err; \ - _e->err_func = __func__; \ - _e->err_line = __LINE__; \ - _e->err_msg[0] = '\0'; \ - } while (0) - -struct _Dwarf_AttrValue { - uint64_t av_attrib; /* DW_AT_ */ - uint64_t av_form; /* DW_FORM_ */ - union { - uint64_t u64; - int64_t s64; - const char *s; - uint8_t *u8p; - } u[2]; /* Value. */ - STAILQ_ENTRY(_Dwarf_AttrValue) - av_next; /* Next attribute value. */ -}; - -struct _Dwarf_Die { - int die_level; /* Parent-child level. */ - uint64_t die_offset; /* DIE offset in section. */ - uint64_t die_abnum; /* Abbrev number. */ - Dwarf_Abbrev die_a; /* Abbrev pointer. */ - Dwarf_CU die_cu; /* Compilation unit pointer. */ - const char *die_name; /* Ptr to the name string. */ - STAILQ_HEAD(, _Dwarf_AttrValue) - die_attrval; /* List of attribute values. */ - STAILQ_ENTRY(_Dwarf_Die) - die_next; /* Next die in list. */ - STAILQ_ENTRY(_Dwarf_Die) - die_hash; /* Next die in hash table. */ -}; - -struct _Dwarf_Attribute { - uint64_t at_attrib; /* DW_AT_ */ - uint64_t at_form; /* DW_FORM_ */ - STAILQ_ENTRY(_Dwarf_Attribute) - at_next; /* Next attribute. */ -}; - -struct _Dwarf_Abbrev { - uint64_t a_entry; /* Abbrev entry. */ - uint64_t a_tag; /* Tag: DW_TAG_ */ - uint8_t a_children; /* DW_CHILDREN_no or DW_CHILDREN_yes */ - STAILQ_HEAD(, _Dwarf_Attribute) - a_attrib; /* List of attributes. */ - STAILQ_ENTRY(_Dwarf_Abbrev) - a_next; /* Next abbrev. */ -}; - -struct _Dwarf_CU { - uint64_t cu_offset; /* Offset to the this compilation unit. */ - uint32_t cu_length; /* Length of CU data. */ - uint32_t cu_header_length; - /* Length of the CU header. */ - uint16_t cu_version; /* DWARF version. */ - uint64_t cu_abbrev_offset; - /* Offset into .debug_abbrev. */ - uint8_t cu_pointer_size; - /* Number of bytes in pointer. */ - uint64_t cu_next_offset; - /* Offset to the next compilation unit. */ - STAILQ_HEAD(, _Dwarf_Abbrev) - cu_abbrev; /* List of abbrevs. */ - STAILQ_HEAD(, _Dwarf_Die) - cu_die; /* List of dies. */ - STAILQ_HEAD(, _Dwarf_Die) - cu_die_hash[DWARF_DIE_HASH_SIZE]; - /* Hash of dies. */ - STAILQ_ENTRY(_Dwarf_CU) - cu_next; /* Next compilation unit. */ -}; - -typedef struct _Dwarf_section { - Elf_Scn *s_scn; /* Section pointer. */ - GElf_Shdr s_shdr; /* Copy of the section header. */ - char *s_sname; /* Ptr to the section name. */ - uint32_t s_shnum; /* Section number. */ - Elf_Data *s_data; /* Section data. */ -} Dwarf_section; - -struct _Dwarf_Debug { - Elf *dbg_elf; /* Ptr to the ELF handle. */ - GElf_Ehdr dbg_ehdr; /* Copy of the ELF header. */ - int dbg_elf_close; /* True if elf_end() required. */ - int dbg_mode; /* Access mode. */ - size_t dbg_stnum; /* Section header string table section number. */ - int dbg_offsize; /* DWARF offset size. */ - Dwarf_section dbg_s[DWARF_DEBUG_SNAMES]; - /* Array of section information. */ - STAILQ_HEAD(, _Dwarf_CU) - dbg_cu; /* List of compilation units. */ - Dwarf_CU dbg_cu_current; - /* Ptr to the current compilation unit. */ - - STAILQ_HEAD(, _Dwarf_Func) dbg_func; /* List of functions */ -}; - -struct _Dwarf_Func { - Dwarf_Die func_die; - const char *func_name; - Dwarf_Addr func_low_pc; - Dwarf_Addr func_high_pc; - int func_is_inlined; - /* inlined instance */ - STAILQ_HEAD(, _Dwarf_Inlined_Func) func_inlined_instances; - STAILQ_ENTRY(_Dwarf_Func) func_next; -}; - -struct _Dwarf_Inlined_Func { - struct _Dwarf_Func *ifunc_origin; - Dwarf_Die ifunc_abstract; - Dwarf_Die ifunc_concrete; - Dwarf_Addr ifunc_low_pc; - Dwarf_Addr ifunc_high_pc; - STAILQ_ENTRY(_Dwarf_Inlined_Func) ifunc_next; -}; - -void dwarf_build_function_table(Dwarf_Debug dbg); - -#ifdef DWARF_DEBUG -#include <assert.h> -#define DWARF_ASSERT(x) assert(x) -#else -#define DWARF_ASSERT(x) -#endif - -#endif /* !__LIBDWARF_H_ */ diff --git a/lib/libdwarf/dwarf.h b/lib/libdwarf/dwarf.h deleted file mode 100644 index 6eb20776e64f5..0000000000000 --- a/lib/libdwarf/dwarf.h +++ /dev/null @@ -1,479 +0,0 @@ -/*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - *notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - *notice, this list of conditions and the following disclaimer in the - *documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED.IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _DWARF_H_ -#define _DWARF_H_ - -#define DW_TAG_array_type 0x01 -#define DW_TAG_class_type 0x02 -#define DW_TAG_entry_point 0x03 -#define DW_TAG_enumeration_type 0x04 -#define DW_TAG_formal_parameter 0x05 -#define DW_TAG_imported_declaration 0x08 -#define DW_TAG_label 0x0a -#define DW_TAG_lexical_block 0x0b -#define DW_TAG_member 0x0d -#define DW_TAG_pointer_type 0x0f -#define DW_TAG_reference_type 0x10 -#define DW_TAG_compile_unit 0x11 -#define DW_TAG_string_type 0x12 -#define DW_TAG_structure_type 0x13 -#define DW_TAG_subroutine_type 0x15 -#define DW_TAG_typedef 0x16 -#define DW_TAG_union_type 0x17 -#define DW_TAG_unspecified_parameters 0x18 -#define DW_TAG_variant 0x19 -#define DW_TAG_common_block 0x1a -#define DW_TAG_common_inclusion 0x1b -#define DW_TAG_inheritance 0x1c -#define DW_TAG_inlined_subroutine 0x1d -#define DW_TAG_module 0x1e -#define DW_TAG_ptr_to_member_type 0x1f -#define DW_TAG_set_type 0x20 -#define DW_TAG_subrange_type 0x21 -#define DW_TAG_with_stmt 0x22 -#define DW_TAG_access_declaration 0x23 -#define DW_TAG_base_type 0x24 -#define DW_TAG_catch_block 0x25 -#define DW_TAG_const_type 0x26 -#define DW_TAG_constant 0x27 -#define DW_TAG_enumerator 0x28 -#define DW_TAG_friend 0x2a -#define DW_TAG_namelist 0x2b -#define DW_TAG_namelist_item 0x2c -#define DW_TAG_packed_type 0x2d -#define DW_TAG_subprogram 0x2e -#define DW_TAG_template_type_parameter 0x2f -#define DW_TAG_template_type_param 0x2f -#define DW_TAG_template_value_parameter 0x30 -#define DW_TAG_template_value_param 0x30 -#define DW_TAG_thrown_type 0x31 -#define DW_TAG_try_block 0x32 -#define DW_TAG_variant_part 0x33 -#define DW_TAG_variable 0x34 -#define DW_TAG_volatile_type 0x35 -#define DW_TAG_dwarf_procedure 0x36 -#define DW_TAG_restrict_type 0x37 -#define DW_TAG_interface_type 0x38 -#define DW_TAG_namespace 0x39 -#define DW_TAG_imported_module 0x3a -#define DW_TAG_unspecified_type 0x3b -#define DW_TAG_partial_unit 0x3c -#define DW_TAG_imported_unit 0x3d -#define DW_TAG_condition 0x3f -#define DW_TAG_shared_type 0x40 - -#define DW_TAG_lo_user 0x4080 - -#define DW_TAG_hi_user 0xffff - -#define DW_CHILDREN_no 0x00 -#define DW_CHILDREN_yes 0x01 - -#define DW_AT_sibling 0x01 -#define DW_AT_location 0x02 -#define DW_AT_name 0x03 -#define DW_AT_ordering 0x09 -#define DW_AT_subscr_data 0x0a -#define DW_AT_byte_size 0x0b -#define DW_AT_bit_offset 0x0c -#define DW_AT_bit_size 0x0d -#define DW_AT_element_list 0x0f -#define DW_AT_stmt_list 0x10 -#define DW_AT_low_pc 0x11 -#define DW_AT_high_pc 0x12 -#define DW_AT_language 0x13 -#define DW_AT_member 0x14 -#define DW_AT_discr 0x15 -#define DW_AT_discr_value 0x16 -#define DW_AT_visibility 0x17 -#define DW_AT_import 0x18 -#define DW_AT_string_length 0x19 -#define DW_AT_common_reference 0x1a -#define DW_AT_comp_dir 0x1b -#define DW_AT_const_value 0x1c -#define DW_AT_containing_type 0x1d -#define DW_AT_default_value 0x1e -#define DW_AT_inline 0x20 -#define DW_AT_is_optional 0x21 -#define DW_AT_lower_bound 0x22 -#define DW_AT_producer 0x25 -#define DW_AT_prototyped 0x27 -#define DW_AT_return_addr 0x2a -#define DW_AT_start_scope 0x2c -#define DW_AT_bit_stride 0x2e -#define DW_AT_stride_size 0x2e -#define DW_AT_upper_bound 0x2f -#define DW_AT_abstract_origin 0x31 -#define DW_AT_accessibility 0x32 -#define DW_AT_address_class 0x33 -#define DW_AT_artificial 0x34 -#define DW_AT_base_types 0x35 -#define DW_AT_calling_convention 0x36 -#define DW_AT_count 0x37 -#define DW_AT_data_member_location 0x38 -#define DW_AT_decl_column 0x39 -#define DW_AT_decl_file 0x3a -#define DW_AT_decl_line 0x3b -#define DW_AT_declaration 0x3c -#define DW_AT_discr_list 0x3d -#define DW_AT_encoding 0x3e -#define DW_AT_external 0x3f -#define DW_AT_frame_base 0x40 -#define DW_AT_friend 0x41 -#define DW_AT_identifier_case 0x42 -#define DW_AT_macro_info 0x43 -#define DW_AT_namelist_item 0x44 -#define DW_AT_priority 0x45 -#define DW_AT_segment 0x46 -#define DW_AT_specification 0x47 -#define DW_AT_static_link 0x48 -#define DW_AT_type 0x49 -#define DW_AT_use_location 0x4a -#define DW_AT_variable_parameter 0x4b -#define DW_AT_virtuality 0x4c -#define DW_AT_vtable_elem_location 0x4d - -#define DW_AT_lo_user 0x2000 - -#define DW_AT_hi_user 0x3fff - -#define DW_FORM_addr 0x01 -#define DW_FORM_block2 0x03 -#define DW_FORM_block4 0x04 -#define DW_FORM_data2 0x05 -#define DW_FORM_data4 0x06 -#define DW_FORM_data8 0x07 -#define DW_FORM_string 0x08 -#define DW_FORM_block 0x09 -#define DW_FORM_block1 0x0a -#define DW_FORM_data1 0x0b -#define DW_FORM_flag 0x0c -#define DW_FORM_sdata 0x0d -#define DW_FORM_strp 0x0e -#define DW_FORM_udata 0x0f -#define DW_FORM_ref_addr 0x10 -#define DW_FORM_ref1 0x11 -#define DW_FORM_ref2 0x12 -#define DW_FORM_ref4 0x13 -#define DW_FORM_ref8 0x14 -#define DW_FORM_ref_udata 0x15 -#define DW_FORM_indirect 0x16 -#define DW_FORM_flag_present 0x19 - -#define DW_OP_addr 0x03 -#define DW_OP_deref 0x06 -#define DW_OP_const1u 0x08 -#define DW_OP_const1s 0x09 -#define DW_OP_const2u 0x0a -#define DW_OP_const2s 0x0b -#define DW_OP_const4u 0x0c -#define DW_OP_const4s 0x0d -#define DW_OP_const8u 0x0e -#define DW_OP_const8s 0x0f -#define DW_OP_constu 0x10 -#define DW_OP_consts 0x11 -#define DW_OP_dup 0x12 -#define DW_OP_drop 0x13 -#define DW_OP_over 0x14 -#define DW_OP_pick 0x15 -#define DW_OP_swap 0x16 -#define DW_OP_rot 0x17 -#define DW_OP_xderef 0x18 -#define DW_OP_abs 0x19 -#define DW_OP_and 0x1a -#define DW_OP_div 0x1b -#define DW_OP_minus 0x1c -#define DW_OP_mod 0x1d -#define DW_OP_mul 0x1e -#define DW_OP_neg 0x1f -#define DW_OP_not 0x20 -#define DW_OP_or 0x21 -#define DW_OP_plus 0x22 -#define DW_OP_plus_uconst 0x23 -#define DW_OP_shl 0x24 -#define DW_OP_shr 0x25 -#define DW_OP_shra 0x26 -#define DW_OP_xor 0x27 -#define DW_OP_bra 0x28 -#define DW_OP_eq 0x29 -#define DW_OP_ge 0x2a -#define DW_OP_gt 0x2b -#define DW_OP_le 0x2c -#define DW_OP_lt 0x2d -#define DW_OP_ne 0x2e -#define DW_OP_skip 0x2f -#define DW_OP_lit0 0x30 -#define DW_OP_lit1 0x31 -#define DW_OP_lit2 0x32 -#define DW_OP_lit3 0x33 -#define DW_OP_lit4 0x34 -#define DW_OP_lit5 0x35 -#define DW_OP_lit6 0x36 -#define DW_OP_lit7 0x37 -#define DW_OP_lit8 0x38 -#define DW_OP_lit9 0x39 -#define DW_OP_lit10 0x3a -#define DW_OP_lit11 0x3b -#define DW_OP_lit12 0x3c -#define DW_OP_lit13 0x3d -#define DW_OP_lit14 0x3e -#define DW_OP_lit15 0x3f -#define DW_OP_lit16 0x40 -#define DW_OP_lit17 0x41 -#define DW_OP_lit18 0x42 -#define DW_OP_lit19 0x43 -#define DW_OP_lit20 0x44 -#define DW_OP_lit21 0x45 -#define DW_OP_lit22 0x46 -#define DW_OP_lit23 0x47 -#define DW_OP_lit24 0x48 -#define DW_OP_lit25 0x49 -#define DW_OP_lit26 0x4a -#define DW_OP_lit27 0x4b -#define DW_OP_lit28 0x4c -#define DW_OP_lit29 0x4d -#define DW_OP_lit30 0x4e -#define DW_OP_lit31 0x4f -#define DW_OP_reg0 0x50 -#define DW_OP_reg1 0x51 -#define DW_OP_reg2 0x52 -#define DW_OP_reg3 0x53 -#define DW_OP_reg4 0x54 -#define DW_OP_reg5 0x55 -#define DW_OP_reg6 0x56 -#define DW_OP_reg7 0x57 -#define DW_OP_reg8 0x58 -#define DW_OP_reg9 0x59 -#define DW_OP_reg10 0x5a -#define DW_OP_reg11 0x5b -#define DW_OP_reg12 0x5c -#define DW_OP_reg13 0x5d -#define DW_OP_reg14 0x5e -#define DW_OP_reg15 0x5f -#define DW_OP_reg16 0x60 -#define DW_OP_reg17 0x61 -#define DW_OP_reg18 0x62 -#define DW_OP_reg19 0x63 -#define DW_OP_reg20 0x64 -#define DW_OP_reg21 0x65 -#define DW_OP_reg22 0x66 -#define DW_OP_reg23 0x67 -#define DW_OP_reg24 0x68 -#define DW_OP_reg25 0x69 -#define DW_OP_reg26 0x6a -#define DW_OP_reg27 0x6b -#define DW_OP_reg28 0x6c -#define DW_OP_reg29 0x6d -#define DW_OP_reg30 0x6e -#define DW_OP_reg31 0x6f -#define DW_OP_breg0 0x70 -#define DW_OP_breg1 0x71 -#define DW_OP_breg2 0x72 -#define DW_OP_breg3 0x73 -#define DW_OP_breg4 0x74 -#define DW_OP_breg5 0x75 -#define DW_OP_breg6 0x76 -#define DW_OP_breg7 0x77 -#define DW_OP_breg8 0x78 -#define DW_OP_breg9 0x79 -#define DW_OP_breg10 0x7a -#define DW_OP_breg11 0x7b -#define DW_OP_breg12 0x7c -#define DW_OP_breg13 0x7d -#define DW_OP_breg14 0x7e -#define DW_OP_breg15 0x7f -#define DW_OP_breg16 0x80 -#define DW_OP_breg17 0x81 -#define DW_OP_breg18 0x82 -#define DW_OP_breg19 0x83 -#define DW_OP_breg20 0x84 -#define DW_OP_breg21 0x85 -#define DW_OP_breg22 0x86 -#define DW_OP_breg23 0x87 -#define DW_OP_breg24 0x88 -#define DW_OP_breg25 0x89 -#define DW_OP_breg26 0x8a -#define DW_OP_breg27 0x8b -#define DW_OP_breg28 0x8c -#define DW_OP_breg29 0x8d -#define DW_OP_breg30 0x8e -#define DW_OP_breg31 0x8f -#define DW_OP_regx 0x90 -#define DW_OP_fbreg 0x91 -#define DW_OP_bregx 0x92 -#define DW_OP_piece 0x93 -#define DW_OP_deref_size 0x94 -#define DW_OP_xderef_size 0x95 -#define DW_OP_nop 0x96 - -#define DW_OP_lo_user 0xe0 - -#define DW_OP_hi_user 0xff - -#define DW_ATE_address 0x1 -#define DW_ATE_boolean 0x2 -#define DW_ATE_complex_float 0x3 -#define DW_ATE_float 0x4 -#define DW_ATE_signed 0x5 -#define DW_ATE_signed_char 0x6 -#define DW_ATE_unsigned 0x7 -#define DW_ATE_unsigned_char 0x8 -#define DW_ATE_imaginary_float 0x9 -#define DW_ATE_packed_decimal 0xa -#define DW_ATE_numeric_string 0xb -#define DW_ATE_edited 0xc -#define DW_ATE_signed_fixed 0xd -#define DW_ATE_unsigned_fixed 0xe -#define DW_ATE_decimal_float 0xf - -#define DW_ATE_lo_user 0x80 - -#define DW_ATE_hi_user 0xff - -#define DW_ACCESS_public 0x01 -#define DW_ACCESS_protected 0x02 -#define DW_ACCESS_private 0x03 - -#define DW_VIS_local 0x01 -#define DW_VIS_exported 0x02 -#define DW_VIS_qualified 0x03 - -#define DW_VIRTUALITY_none 0x00 -#define DW_VIRTUALITY_virtual 0x01 -#define DW_VIRTUALITY_pure_virtual 0x02 - -#define DW_LANG_C89 0x0001 -#define DW_LANG_C 0x0002 -#define DW_LANG_Ada83 0x0003 -#define DW_LANG_C_plus_plus 0x0004 -#define DW_LANG_Cobol74 0x0005 -#define DW_LANG_Cobol85 0x0006 -#define DW_LANG_Fortran77 0x0007 -#define DW_LANG_Fortran90 0x0008 -#define DW_LANG_Pascal83 0x0009 -#define DW_LANG_Modula2 0x000a -#define DW_LANG_Java 0x000b -#define DW_LANG_C99 0x000c -#define DW_LANG_Ada95 0x000d -#define DW_LANG_Fortran95 0x000e -#define DW_LANG_PLI 0x000f -#define DW_LANG_ObjC 0x0010 -#define DW_LANG_ObjC_plus_plus 0x0011 -#define DW_LANG_UPC 0x0012 -#define DW_LANG_D 0x0013 - -#define DW_LANG_lo_user 0x8000 - -#define DW_LANG_hi_user 0xffff - -#define DW_ID_case_sensitive 0x00 -#define DW_ID_up_case 0x01 -#define DW_ID_down_case 0x02 -#define DW_ID_case_insensitive 0x03 - -#define DW_CC_normal 0x01 -#define DW_CC_program 0x02 -#define DW_CC_nocall 0x03 - -#define DW_CC_lo_user 0x40 - -#define DW_CC_hi_user 0xff - -#define DW_INL_not_inlined 0x00 -#define DW_INL_inlined 0x01 -#define DW_INL_declared_not_inlined 0x02 -#define DW_INL_declared_inlined 0x03 - -#define DW_ORD_row_major 0x00 -#define DW_ORD_col_major 0x01 - -#define DW_DSC_label 0x00 -#define DW_DSC_range 0x01 - -#define DW_LNS_copy 0x01 -#define DW_LNS_advance_pc 0x02 -#define DW_LNS_advance_line 0x03 -#define DW_LNS_set_file 0x04 -#define DW_LNS_set_column 0x05 -#define DW_LNS_negate_stmt 0x06 -#define DW_LNS_set_basic_block 0x07 -#define DW_LNS_const_add_pc 0x08 -#define DW_LNS_fixed_advance_pc 0x09 -#define DW_LNS_set_prologue_end 0x0a -#define DW_LNS_set_epilogue_begin 0x0b -#define DW_LNS_set_isa 0x0c - -#define DW_LNE_end_sequence 0x01 -#define DW_LNE_set_address 0x02 -#define DW_LNE_define_file 0x03 - -#define DW_LNE_lo_user 0x80 - -#define DW_LNE_hi_user 0xff - -#define DW_MACINFO_define 0x01 -#define DW_MACINFO_undef 0x02 -#define DW_MACINFO_start_file 0x03 -#define DW_MACINFO_end_file 0x04 -#define DW_MACINFO_vendor_ext 0xff - -#define DW_CFA_advance_loc 0x40 -#define DW_CFA_offset 0x80 -#define DW_CFA_restore 0xc0 -#define DW_CFA_extended 0 - -#define DW_CFA_nop 0x00 -#define DW_CFA_set_loc 0x01 -#define DW_CFA_advance_loc1 0x02 -#define DW_CFA_advance_loc2 0x03 -#define DW_CFA_advance_loc4 0x04 -#define DW_CFA_offset_extended 0x05 -#define DW_CFA_restore_extended 0x06 -#define DW_CFA_undefined 0x07 -#define DW_CFA_same_value 0x08 -#define DW_CFA_register 0x09 -#define DW_CFA_remember_state 0x0a -#define DW_CFA_restore_state 0x0b -#define DW_CFA_def_cfa 0x0c -#define DW_CFA_def_cfa_register 0x0d -#define DW_CFA_def_cfa_offset 0x0e -#define DW_CFA_def_cfa_expression 0x0f -#define DW_CFA_expression 0x10 -#define DW_CFA_cfa_offset_extended_sf 0x11 -#define DW_CFA_def_cfa_sf 0x12 -#define DW_CFA_def_cfa_offset_sf 0x13 -#define DW_CFA_val_offset 0x14 -#define DW_CFA_val_offset_sf 0x15 -#define DW_CFA_val_expression 0x16 - -#define DW_CFA_lo_user 0x1c - -#define DW_CFA_high_user 0x3f - -#endif /* !_DWARF_H_ */ diff --git a/lib/libdwarf/dwarf_attr.c b/lib/libdwarf/dwarf_attr.c deleted file mode 100644 index 3c9d4c826d219..0000000000000 --- a/lib/libdwarf/dwarf_attr.c +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <stdlib.h> -#include <string.h> -#include "_libdwarf.h" - -int -dwarf_attr(Dwarf_Die die, Dwarf_Half attr, Dwarf_Attribute *atp, Dwarf_Error *err) -{ - Dwarf_Attribute at; - Dwarf_Abbrev a; - int ret = DWARF_E_NONE; - - if (err == NULL) - return DWARF_E_ERROR; - - if (die == NULL || atp == NULL || (a = die->die_a) == NULL) { - DWARF_SET_ERROR(err, DWARF_E_ARGUMENT); - return DWARF_E_ARGUMENT; - } - - STAILQ_FOREACH(at, &a->a_attrib, at_next) - if (at->at_attrib == attr) - break; - - *atp = at; - - if (at == NULL) { - DWARF_SET_ERROR(err, DWARF_E_NO_ENTRY); - ret = DWARF_E_NO_ENTRY; - } - - return ret; -} - -int -dwarf_attr_add(Dwarf_Abbrev a, uint64_t attr, uint64_t form, Dwarf_Attribute *atp, Dwarf_Error *error) -{ - Dwarf_Attribute at; - int ret = DWARF_E_NONE; - - if (error == NULL) - return DWARF_E_ERROR; - - if (a == NULL) { - DWARF_SET_ERROR(error, DWARF_E_ARGUMENT); - return DWARF_E_ARGUMENT; - } - - if ((at = malloc(sizeof(struct _Dwarf_Attribute))) == NULL) { - DWARF_SET_ERROR(error, DWARF_E_MEMORY); - return DWARF_E_MEMORY; - } - - /* Initialise the attribute structure. */ - at->at_attrib = attr; - at->at_form = form; - - /* Add the attribute to the list in the abbrev. */ - STAILQ_INSERT_TAIL(&a->a_attrib, at, at_next); - - if (atp != NULL) - *atp = at; - - return ret; -} diff --git a/lib/libdwarf/dwarf_attrval.c b/lib/libdwarf/dwarf_attrval.c deleted file mode 100644 index 25286dea5e2c1..0000000000000 --- a/lib/libdwarf/dwarf_attrval.c +++ /dev/null @@ -1,271 +0,0 @@ -/*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include "_libdwarf.h" - -Dwarf_AttrValue -dwarf_attrval_find(Dwarf_Die die, Dwarf_Half attr) -{ - Dwarf_AttrValue av; - - STAILQ_FOREACH(av, &die->die_attrval, av_next) { - if (av->av_attrib == attr) - break; - } - - return av; -} - -int -dwarf_attrval_add(Dwarf_Die die, Dwarf_AttrValue avref, Dwarf_AttrValue *avp, Dwarf_Error *error) -{ - Dwarf_AttrValue av; - int ret = DWARF_E_NONE; - - if ((av = malloc(sizeof(struct _Dwarf_AttrValue))) == NULL) { - DWARF_SET_ERROR(error, DWARF_E_MEMORY); - return DWARF_E_MEMORY; - } - - memcpy(av, avref, sizeof(struct _Dwarf_AttrValue)); - - /* Add the attribute value to the list in the die. */ - STAILQ_INSERT_TAIL(&die->die_attrval, av, av_next); - - /* Save a pointer to the attribute name if this is one. */ - if (av->av_attrib == DW_AT_name) - switch (av->av_form) { - case DW_FORM_strp: - die->die_name = av->u[1].s; - break; - case DW_FORM_string: - die->die_name = av->u[0].s; - break; - default: - break; - } - - if (avp != NULL) - *avp = av; - - return ret; -} - -int -dwarf_attrval_flag(Dwarf_Die die, uint64_t attr, Dwarf_Bool *valp, Dwarf_Error *err) -{ - Dwarf_AttrValue av; - int ret = DWARF_E_NONE; - - if (err == NULL) - return DWARF_E_ERROR; - - if (die == NULL || valp == NULL) { - DWARF_SET_ERROR(err, DWARF_E_ARGUMENT); - return DWARF_E_ARGUMENT; - } - - *valp = 0; - - if ((av = dwarf_attrval_find(die, attr)) == NULL) { - DWARF_SET_ERROR(err, DWARF_E_NO_ENTRY); - ret = DWARF_E_NO_ENTRY; - } else { - switch (av->av_form) { - case DW_FORM_flag: - case DW_FORM_flag_present: - *valp = (Dwarf_Bool) av->u[0].u64; - break; - default: - printf("%s(%d): av->av_form '%s' (0x%lx) not handled\n", - __func__,__LINE__,get_form_desc(av->av_form), - (u_long) av->av_form); - DWARF_SET_ERROR(err, DWARF_E_BAD_FORM); - ret = DWARF_E_BAD_FORM; - } - } - - return ret; -} - -int -dwarf_attrval_string(Dwarf_Die die, uint64_t attr, const char **strp, Dwarf_Error *err) -{ - Dwarf_AttrValue av; - int ret = DWARF_E_NONE; - - if (err == NULL) - return DWARF_E_ERROR; - - if (die == NULL || strp == NULL) { - DWARF_SET_ERROR(err, DWARF_E_ARGUMENT); - return DWARF_E_ARGUMENT; - } - - *strp = NULL; - - if (attr == DW_AT_name) - *strp = die->die_name; - else if ((av = dwarf_attrval_find(die, attr)) == NULL) { - DWARF_SET_ERROR(err, DWARF_E_NO_ENTRY); - ret = DWARF_E_NO_ENTRY; - } else { - switch (av->av_form) { - case DW_FORM_strp: - *strp = av->u[1].s; - break; - case DW_FORM_string: - *strp = av->u[0].s; - break; - default: - printf("%s(%d): av->av_form '%s' (0x%lx) not handled\n", - __func__,__LINE__,get_form_desc(av->av_form), - (u_long) av->av_form); - DWARF_SET_ERROR(err, DWARF_E_BAD_FORM); - ret = DWARF_E_BAD_FORM; - } - } - - return ret; -} - -int -dwarf_attrval_signed(Dwarf_Die die, uint64_t attr, Dwarf_Signed *valp, Dwarf_Error *err) -{ - Dwarf_AttrValue av; - int ret = DWARF_E_NONE; - - if (err == NULL) - return DWARF_E_ERROR; - - if (die == NULL || valp == NULL) { - DWARF_SET_ERROR(err, DWARF_E_ARGUMENT); - return DWARF_E_ARGUMENT; - } - - *valp = 0; - - if ((av = dwarf_attrval_find(die, attr)) == NULL) { - DWARF_SET_ERROR(err, DWARF_E_NO_ENTRY); - ret = DWARF_E_NO_ENTRY; - } else { - switch (av->av_form) { - case DW_FORM_data1: - case DW_FORM_sdata: - *valp = av->u[0].s64; - break; - default: - printf("%s(%d): av->av_form '%s' (0x%lx) not handled\n", - __func__,__LINE__,get_form_desc(av->av_form), - (u_long) av->av_form); - DWARF_SET_ERROR(err, DWARF_E_BAD_FORM); - ret = DWARF_E_BAD_FORM; - } - } - - return ret; -} - -int -dwarf_attrval_unsigned(Dwarf_Die die, uint64_t attr, Dwarf_Unsigned *valp, Dwarf_Error *err) -{ - Dwarf_AttrValue av; - int ret = DWARF_E_NONE; - - if (err == NULL) - return DWARF_E_ERROR; - - if (die == NULL || valp == NULL) { - DWARF_SET_ERROR(err, DWARF_E_ARGUMENT); - return DWARF_E_ARGUMENT; - } - - *valp = 0; - - if ((av = dwarf_attrval_find(die, attr)) == NULL && attr != DW_AT_type) { - DWARF_SET_ERROR(err, DWARF_E_NO_ENTRY); - ret = DWARF_E_NO_ENTRY; - } else if (av == NULL && (av = dwarf_attrval_find(die, - DW_AT_abstract_origin)) != NULL) { - Dwarf_Die die1; - Dwarf_Unsigned val; - - switch (av->av_form) { - case DW_FORM_data1: - case DW_FORM_data2: - case DW_FORM_data4: - case DW_FORM_data8: - case DW_FORM_ref1: - case DW_FORM_ref2: - case DW_FORM_ref4: - case DW_FORM_ref8: - case DW_FORM_ref_udata: - val = av->u[0].u64; - - if ((die1 = dwarf_die_find(die, val)) == NULL || - (av = dwarf_attrval_find(die1, attr)) == NULL) { - DWARF_SET_ERROR(err, DWARF_E_NO_ENTRY); - ret = DWARF_E_NO_ENTRY; - } - break; - default: - printf("%s(%d): av->av_form '%s' (0x%lx) not handled\n", - __func__,__LINE__,get_form_desc(av->av_form), - (u_long) av->av_form); - DWARF_SET_ERROR(err, DWARF_E_BAD_FORM); - ret = DWARF_E_BAD_FORM; - } - } - - if (ret == DWARF_E_NONE) { - switch (av->av_form) { - case DW_FORM_data1: - case DW_FORM_data2: - case DW_FORM_data4: - case DW_FORM_data8: - case DW_FORM_ref1: - case DW_FORM_ref2: - case DW_FORM_ref4: - case DW_FORM_ref8: - case DW_FORM_ref_udata: - *valp = av->u[0].u64; - break; - default: - printf("%s(%d): av->av_form '%s' (0x%lx) not handled\n", - __func__,__LINE__,get_form_desc(av->av_form), - (u_long) av->av_form); - DWARF_SET_ERROR(err, DWARF_E_BAD_FORM); - ret = DWARF_E_BAD_FORM; - } - } - - return ret; -} diff --git a/lib/libdwarf/dwarf_cu.c b/lib/libdwarf/dwarf_cu.c deleted file mode 100644 index 325ffdcaa30e5..0000000000000 --- a/lib/libdwarf/dwarf_cu.c +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include "_libdwarf.h" - -int -dwarf_next_cu_header(Dwarf_Debug dbg, Dwarf_Unsigned *cu_header_length, - Dwarf_Half *cu_version, Dwarf_Unsigned *cu_abbrev_offset, - Dwarf_Half *cu_pointer_size, Dwarf_Unsigned *cu_next_offset, Dwarf_Error *error) -{ - Dwarf_CU next; - - if (error == NULL) - return DWARF_E_ERROR; - - if (dbg == NULL || cu_header_length == NULL || cu_version == NULL || - cu_abbrev_offset == NULL || cu_pointer_size == NULL || - cu_next_offset == NULL) { - DWARF_SET_ERROR(error, DWARF_E_ARGUMENT); - return DWARF_E_ERROR; - } - - if (dbg->dbg_cu_current == NULL) - dbg->dbg_cu_current = STAILQ_FIRST(&dbg->dbg_cu); - else if ((next = STAILQ_NEXT(dbg->dbg_cu_current, cu_next)) == NULL) { - DWARF_SET_ERROR(error, DWARF_E_NO_ENTRY); - return DWARF_E_NO_ENTRY; - } else - dbg->dbg_cu_current = next; - - if (dbg->dbg_cu_current == NULL) { - DWARF_SET_ERROR(error, DWARF_E_NO_ENTRY); - return DWARF_E_NO_ENTRY; - } - - *cu_header_length = dbg->dbg_cu_current->cu_header_length; - *cu_version = dbg->dbg_cu_current->cu_version; - *cu_abbrev_offset = dbg->dbg_cu_current->cu_abbrev_offset; - *cu_pointer_size = dbg->dbg_cu_current->cu_pointer_size; - *cu_next_offset = dbg->dbg_cu_current->cu_next_offset; - - return DWARF_E_NONE; -} diff --git a/lib/libdwarf/dwarf_die.c b/lib/libdwarf/dwarf_die.c deleted file mode 100644 index 486811efd1767..0000000000000 --- a/lib/libdwarf/dwarf_die.c +++ /dev/null @@ -1,189 +0,0 @@ -/*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <stdlib.h> -#include "_libdwarf.h" - -int -dwarf_die_add(Dwarf_CU cu, int level, uint64_t offset, uint64_t abnum, Dwarf_Abbrev a, Dwarf_Die *diep, Dwarf_Error *err) -{ - Dwarf_Die die; - uint64_t key; - int ret = DWARF_E_NONE; - - if (err == NULL) - return DWARF_E_ERROR; - - if (cu == NULL || a == NULL) { - DWARF_SET_ERROR(err, DWARF_E_ARGUMENT); - return DWARF_E_ARGUMENT; - } - - if ((die = malloc(sizeof(struct _Dwarf_Die))) == NULL) { - DWARF_SET_ERROR(err, DWARF_E_MEMORY); - return DWARF_E_MEMORY; - } - - /* Initialise the abbrev structure. */ - die->die_level = level; - die->die_offset = offset; - die->die_abnum = abnum; - die->die_a = a; - die->die_cu = cu; - die->die_name = ""; - - /* Initialise the list of attribute values. */ - STAILQ_INIT(&die->die_attrval); - - /* Add the die to the list in the compilation unit. */ - STAILQ_INSERT_TAIL(&cu->cu_die, die, die_next); - - /* Add the die to the hash table in the compilation unit. */ - key = offset % DWARF_DIE_HASH_SIZE; - STAILQ_INSERT_TAIL(&cu->cu_die_hash[key], die, die_hash); - - if (diep != NULL) - *diep = die; - - return ret; -} - -int -dwarf_dieoffset(Dwarf_Die die, Dwarf_Off *ret_offset, Dwarf_Error *err __unused) -{ - *ret_offset = die->die_offset; - - return DWARF_E_NONE; -} - -int -dwarf_child(Dwarf_Die die, Dwarf_Die *ret_die, Dwarf_Error *err) -{ - Dwarf_Die next; - int ret = DWARF_E_NONE; - - if (err == NULL) - return DWARF_E_ERROR; - - if (die == NULL || ret_die == NULL) { - DWARF_SET_ERROR(err, DWARF_E_ARGUMENT); - return DWARF_E_ARGUMENT; - } - - if ((next = STAILQ_NEXT(die, die_next)) == NULL || - next->die_level != die->die_level + 1) { - *ret_die = NULL; - DWARF_SET_ERROR(err, DWARF_E_NO_ENTRY); - ret = DWARF_E_NO_ENTRY; - } else - *ret_die = next; - - return ret; -} - -int -dwarf_tag(Dwarf_Die die, Dwarf_Half *tag, Dwarf_Error *err) -{ - Dwarf_Abbrev a; - - if (err == NULL) - return DWARF_E_ERROR; - - if (die == NULL || tag == NULL || (a = die->die_a) == NULL) { - DWARF_SET_ERROR(err, DWARF_E_ARGUMENT); - return DWARF_E_ARGUMENT; - } - - *tag = a->a_tag; - - return DWARF_E_NONE; -} - -int -dwarf_siblingof(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Die *caller_ret_die, Dwarf_Error *err) -{ - Dwarf_Die next; - Dwarf_CU cu; - int ret = DWARF_E_NONE; - - if (err == NULL) - return DWARF_E_ERROR; - - if (dbg == NULL || caller_ret_die == NULL) { - DWARF_SET_ERROR(err, DWARF_E_ARGUMENT); - return DWARF_E_ARGUMENT; - } - - if ((cu = dbg->dbg_cu_current) == NULL) { - DWARF_SET_ERROR(err, DWARF_E_CU_CURRENT); - return DWARF_E_CU_CURRENT; - } - - if (die == NULL) { - *caller_ret_die = STAILQ_FIRST(&cu->cu_die); - - if (*caller_ret_die == NULL) { - DWARF_SET_ERROR(err, DWARF_E_NO_ENTRY); - ret = DWARF_E_NO_ENTRY; - } - } else { - next = die; - while ((next = STAILQ_NEXT(next, die_next)) != NULL) { - if (next->die_level < die->die_level) { - next = NULL; - break; - } - if (next->die_level == die->die_level) { - *caller_ret_die = next; - break; - } - } - - if (next == NULL) { - *caller_ret_die = NULL; - DWARF_SET_ERROR(err, DWARF_E_NO_ENTRY); - ret = DWARF_E_NO_ENTRY; - } - } - - return ret; -} - -Dwarf_Die -dwarf_die_find(Dwarf_Die die, Dwarf_Unsigned off) -{ - Dwarf_CU cu = die->die_cu; - Dwarf_Die die1; - - STAILQ_FOREACH(die1, &cu->cu_die, die_next) { - if (die1->die_offset == off) - return (die1); - } - - return (NULL); -} diff --git a/lib/libdwarf/dwarf_dump.c b/lib/libdwarf/dwarf_dump.c deleted file mode 100644 index dc22800fa41e6..0000000000000 --- a/lib/libdwarf/dwarf_dump.c +++ /dev/null @@ -1,895 +0,0 @@ -/*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <stdlib.h> -#include <string.h> -#include "_libdwarf.h" - -const char * -get_sht_desc(uint32_t sh_type) -{ - switch (sh_type) { - case SHT_NULL: - return "inactive"; - case SHT_PROGBITS: - return "program defined information"; - case SHT_SYMTAB: - return "symbol table section"; - case SHT_STRTAB: - return "string table section"; - case SHT_RELA: - return "relocation section with addends"; - case SHT_HASH: - return "symbol hash table section"; - case SHT_DYNAMIC: - return "dynamic section"; - case SHT_NOTE: - return "note section"; - case SHT_NOBITS: - return "no space section"; - case SHT_REL: - return "relocation section - no addends"; - case SHT_SHLIB: - return "reserved - purpose unknown"; - case SHT_DYNSYM: - return "dynamic symbol table section"; - case SHT_INIT_ARRAY: - return "Initialization function pointers."; - case SHT_FINI_ARRAY: - return "Termination function pointers."; - case SHT_PREINIT_ARRAY: - return "Pre-initialization function ptrs."; - case SHT_GROUP: - return "Section group."; - case SHT_SYMTAB_SHNDX: - return "Section indexes (see SHN_XINDEX)."; - case SHT_GNU_verdef: - return "Symbol versions provided"; - case SHT_GNU_verneed: - return "Symbol versions required"; - case SHT_GNU_versym: - return "Symbol version table"; - case SHT_AMD64_UNWIND: - return "AMD64 unwind"; - default: - return "Unknown"; - } -} - -const char * -get_attr_desc(uint32_t attr) -{ - switch (attr) { - case DW_AT_abstract_origin: - return "DW_AT_abstract_origin"; - case DW_AT_accessibility: - return "DW_AT_accessibility"; - case DW_AT_address_class: - return "DW_AT_address_class"; - case DW_AT_artificial: - return "DW_AT_artificial"; - case DW_AT_base_types: - return "DW_AT_base_types"; - case DW_AT_bit_offset: - return "DW_AT_bit_offset"; - case DW_AT_bit_size: - return "DW_AT_bit_size"; - case DW_AT_byte_size: - return "DW_AT_byte_size"; - case DW_AT_calling_convention: - return "DW_AT_calling_convention"; - case DW_AT_common_reference: - return "DW_AT_common_reference"; - case DW_AT_comp_dir: - return "DW_AT_comp_dir"; - case DW_AT_const_value: - return "DW_AT_const_value"; - case DW_AT_containing_type: - return "DW_AT_containing_type"; - case DW_AT_count: - return "DW_AT_count"; - case DW_AT_data_member_location: - return "DW_AT_data_member_location"; - case DW_AT_decl_column: - return "DW_AT_decl_column"; - case DW_AT_decl_file: - return "DW_AT_decl_file"; - case DW_AT_decl_line: - return "DW_AT_decl_line"; - case DW_AT_declaration: - return "DW_AT_declaration"; - case DW_AT_default_value: - return "DW_AT_default_value"; - case DW_AT_discr: - return "DW_AT_discr"; - case DW_AT_discr_list: - return "DW_AT_discr_list"; - case DW_AT_discr_value: - return "DW_AT_discr_value"; - case DW_AT_element_list: - return "DW_AT_element_list"; - case DW_AT_encoding: - return "DW_AT_encoding"; - case DW_AT_external: - return "DW_AT_external"; - case DW_AT_frame_base: - return "DW_AT_frame_base"; - case DW_AT_friend: - return "DW_AT_friend"; - case DW_AT_high_pc: - return "DW_AT_high_pc"; - case DW_AT_identifier_case: - return "DW_AT_identifier_case"; - case DW_AT_import: - return "DW_AT_import"; - case DW_AT_inline: - return "DW_AT_inline"; - case DW_AT_is_optional: - return "DW_AT_is_optional"; - case DW_AT_language: - return "DW_AT_language"; - case DW_AT_location: - return "DW_AT_location"; - case DW_AT_low_pc: - return "DW_AT_low_pc"; - case DW_AT_lower_bound: - return "DW_AT_lower_bound"; - case DW_AT_macro_info: - return "DW_AT_macro_info"; - case DW_AT_member: - return "DW_AT_member"; - case DW_AT_name: - return "DW_AT_name"; - case DW_AT_namelist_item: - return "DW_AT_namelist_item"; - case DW_AT_ordering: - return "DW_AT_ordering"; - case DW_AT_priority: - return "DW_AT_priority"; - case DW_AT_producer: - return "DW_AT_producer"; - case DW_AT_prototyped: - return "DW_AT_prototyped"; - case DW_AT_return_addr: - return "DW_AT_return_addr"; - case DW_AT_segment: - return "DW_AT_segment"; - case DW_AT_sibling: - return "DW_AT_sibling"; - case DW_AT_specification: - return "DW_AT_specification"; - case DW_AT_start_scope: - return "DW_AT_start_scope"; - case DW_AT_static_link: - return "DW_AT_static_link"; - case DW_AT_stmt_list: - return "DW_AT_stmt_list"; - case DW_AT_stride_size: - return "DW_AT_stride_size"; - case DW_AT_string_length: - return "DW_AT_string_length"; - case DW_AT_subscr_data: - return "DW_AT_subscr_data"; - case DW_AT_type: - return "DW_AT_type"; - case DW_AT_upper_bound: - return "DW_AT_upper_bound"; - case DW_AT_use_location: - return "DW_AT_use_location"; - case DW_AT_variable_parameter: - return "DW_AT_variable_parameter"; - case DW_AT_virtuality: - return "DW_AT_virtuality"; - case DW_AT_visibility: - return "DW_AT_visibility"; - case DW_AT_vtable_elem_location: - return "DW_AT_vtable_elem_location"; - default: - break; - } - - return "Unknown attribute"; -} - -const char * -get_form_desc(uint32_t form) -{ - switch (form) { - case DW_FORM_addr: - return "DW_FORM_addr"; - case DW_FORM_block: - return "DW_FORM_block"; - case DW_FORM_block1: - return "DW_FORM_block1"; - case DW_FORM_block2: - return "DW_FORM_block2"; - case DW_FORM_block4: - return "DW_FORM_block4"; - case DW_FORM_data1: - return "DW_FORM_data1"; - case DW_FORM_data2: - return "DW_FORM_data2"; - case DW_FORM_data4: - return "DW_FORM_data4"; - case DW_FORM_data8: - return "DW_FORM_data8"; - case DW_FORM_flag: - return "DW_FORM_flag"; - case DW_FORM_flag_present: - return "DW_FORM_flag_present"; - case DW_FORM_indirect: - return "DW_FORM_indirect"; - case DW_FORM_ref1: - return "DW_FORM_ref1"; - case DW_FORM_ref2: - return "DW_FORM_ref2"; - case DW_FORM_ref4: - return "DW_FORM_ref4"; - case DW_FORM_ref8: - return "DW_FORM_ref8"; - case DW_FORM_ref_addr: - return "DW_FORM_ref_addr"; - case DW_FORM_ref_udata: - return "DW_FORM_ref_udata"; - case DW_FORM_sdata: - return "DW_FORM_sdata"; - case DW_FORM_string: - return "DW_FORM_string"; - case DW_FORM_strp: - return "DW_FORM_strp"; - case DW_FORM_udata: - return "DW_FORM_udata"; - default: - break; - } - - return "Unknown attribute"; -} - -const char * -get_tag_desc(uint32_t tag) -{ - switch (tag) { - case DW_TAG_access_declaration: - return "DW_TAG_access_declaration"; - case DW_TAG_array_type: - return "DW_TAG_array_type"; - case DW_TAG_base_type: - return "DW_TAG_base_type"; - case DW_TAG_catch_block: - return "DW_TAG_catch_block"; - case DW_TAG_class_type: - return "DW_TAG_class_type"; - case DW_TAG_common_block: - return "DW_TAG_common_block"; - case DW_TAG_common_inclusion: - return "DW_TAG_common_inclusion"; - case DW_TAG_compile_unit: - return "DW_TAG_compile_unit"; - case DW_TAG_condition: - return "DW_TAG_condition"; - case DW_TAG_const_type: - return "DW_TAG_const_type"; - case DW_TAG_constant: - return "DW_TAG_constant"; - case DW_TAG_dwarf_procedure: - return "DW_TAG_dwarf_procedure"; - case DW_TAG_entry_point: - return "DW_TAG_entry_point"; - case DW_TAG_enumeration_type: - return "DW_TAG_enumeration_type"; - case DW_TAG_enumerator: - return "DW_TAG_enumerator"; - case DW_TAG_formal_parameter: - return "DW_TAG_formal_parameter"; - case DW_TAG_friend: - return "DW_TAG_friend"; - case DW_TAG_imported_declaration: - return "DW_TAG_imported_declaration"; - case DW_TAG_imported_module: - return "DW_TAG_imported_module"; - case DW_TAG_imported_unit: - return "DW_TAG_imported_unit"; - case DW_TAG_inheritance: - return "DW_TAG_inheritance"; - case DW_TAG_inlined_subroutine: - return "DW_TAG_inlined_subroutine"; - case DW_TAG_interface_type: - return "DW_TAG_interface_type"; - case DW_TAG_label: - return "DW_TAG_label"; - case DW_TAG_lexical_block: - return "DW_TAG_lexical_block"; - case DW_TAG_member: - return "DW_TAG_member"; - case DW_TAG_module: - return "DW_TAG_module"; - case DW_TAG_namelist: - return "DW_TAG_namelist"; - case DW_TAG_namelist_item: - return "DW_TAG_namelist_item"; - case DW_TAG_namespace: - return "DW_TAG_namespace"; - case DW_TAG_packed_type: - return "DW_TAG_packed_type"; - case DW_TAG_partial_unit: - return "DW_TAG_partial_unit"; - case DW_TAG_pointer_type: - return "DW_TAG_pointer_type"; - case DW_TAG_ptr_to_member_type: - return "DW_TAG_ptr_to_member_type"; - case DW_TAG_reference_type: - return "DW_TAG_reference_type"; - case DW_TAG_restrict_type: - return "DW_TAG_restrict_type"; - case DW_TAG_set_type: - return "DW_TAG_set_type"; - case DW_TAG_shared_type: - return "DW_TAG_shared_type"; - case DW_TAG_string_type: - return "DW_TAG_string_type"; - case DW_TAG_structure_type: - return "DW_TAG_structure_type"; - case DW_TAG_subprogram: - return "DW_TAG_subprogram"; - case DW_TAG_subrange_type: - return "DW_TAG_subrange_type"; - case DW_TAG_subroutine_type: - return "DW_TAG_subroutine_type"; - case DW_TAG_template_type_parameter: - return "DW_TAG_template_type_parameter"; - case DW_TAG_template_value_parameter: - return "DW_TAG_template_value_parameter"; - case DW_TAG_thrown_type: - return "DW_TAG_thrown_type"; - case DW_TAG_try_block: - return "DW_TAG_try_block"; - case DW_TAG_typedef: - return "DW_TAG_typedef"; - case DW_TAG_union_type: - return "DW_TAG_union_type"; - case DW_TAG_unspecified_parameters: - return "DW_TAG_unspecified_parameters"; - case DW_TAG_unspecified_type: - return "DW_TAG_unspecified_type"; - case DW_TAG_variable: - return "DW_TAG_variable"; - case DW_TAG_variant: - return "DW_TAG_variant"; - case DW_TAG_variant_part: - return "DW_TAG_variant_part"; - case DW_TAG_volatile_type: - return "DW_TAG_volatile_type"; - case DW_TAG_with_stmt: - return "DW_TAG_with_stmt"; - default: - break; - } - - return "Unknown tag"; -} - -void -dwarf_dump_abbrev(Dwarf_Debug dbg) -{ - Dwarf_Abbrev a; - Dwarf_Attribute at; - Dwarf_CU cu; - - printf("Contents of the .debug_abbrev section:\n\nEntry Tag\n"); - - STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) { - STAILQ_FOREACH(a, &cu->cu_abbrev, a_next) { - printf("%5lu %-30s [%s children]\n", - (u_long) a->a_entry, get_tag_desc(a->a_tag), - (a->a_children == DW_CHILDREN_yes) ? "has" : "no"); - - STAILQ_FOREACH(at, &a->a_attrib, at_next) - printf(" %-30s %s\n", get_attr_desc(at->at_attrib), - get_form_desc(at->at_form)); - } - } -} -#ifdef DOODAD - case DW_AT_inline: - switch (uvalue) - { - case DW_INL_not_inlined: - printf (_("(not inlined)")); - break; - case DW_INL_inlined: - printf (_("(inlined)")); - break; - case DW_INL_declared_not_inlined: - printf (_("(declared as inline but ignored)")); - break; - case DW_INL_declared_inlined: - printf (_("(declared as inline and inlined)")); - break; - default: - printf (_(" (Unknown inline attribute value: %lx)"), uvalue); - break; - } - break; - - case DW_AT_language: - switch (uvalue) - { - case DW_LANG_C: printf ("(non-ANSI C)"); break; - case DW_LANG_C89: printf ("(ANSI C)"); break; - case DW_LANG_C_plus_plus: printf ("(C++)"); break; - case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; - case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; - case DW_LANG_Modula2: printf ("(Modula 2)"); break; - case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; - case DW_LANG_Ada83: printf ("(Ada)"); break; - case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; - case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; - /* DWARF 2.1 values. */ - case DW_LANG_C99: printf ("(ANSI C99)"); break; - case DW_LANG_Ada95: printf ("(ADA 95)"); break; - case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; - /* MIPS extension. */ - case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; - /* UPC extension. */ - case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; - default: - printf ("(Unknown: %lx)", uvalue); - break; - } - break; - - case DW_AT_encoding: - switch (uvalue) - { - case DW_ATE_void: printf ("(void)"); break; - case DW_ATE_address: printf ("(machine address)"); break; - case DW_ATE_boolean: printf ("(boolean)"); break; - case DW_ATE_complex_float: printf ("(complex float)"); break; - case DW_ATE_float: printf ("(float)"); break; - case DW_ATE_signed: printf ("(signed)"); break; - case DW_ATE_signed_char: printf ("(signed char)"); break; - case DW_ATE_unsigned: printf ("(unsigned)"); break; - case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; - /* DWARF 2.1 value. */ - case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; - default: - if (uvalue >= DW_ATE_lo_user - && uvalue <= DW_ATE_hi_user) - printf ("(user defined type)"); - else - printf ("(unknown type)"); - break; - } - break; - - case DW_AT_accessibility: - switch (uvalue) - { - case DW_ACCESS_public: printf ("(public)"); break; - case DW_ACCESS_protected: printf ("(protected)"); break; - case DW_ACCESS_private: printf ("(private)"); break; - default: - printf ("(unknown accessibility)"); - break; - } - break; - - case DW_AT_visibility: - switch (uvalue) - { - case DW_VIS_local: printf ("(local)"); break; - case DW_VIS_exported: printf ("(exported)"); break; - case DW_VIS_qualified: printf ("(qualified)"); break; - default: printf ("(unknown visibility)"); break; - } - break; - - case DW_AT_virtuality: - switch (uvalue) - { - case DW_VIRTUALITY_none: printf ("(none)"); break; - case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; - case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; - default: printf ("(unknown virtuality)"); break; - } - break; - - case DW_AT_identifier_case: - switch (uvalue) - { - case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; - case DW_ID_up_case: printf ("(up_case)"); break; - case DW_ID_down_case: printf ("(down_case)"); break; - case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; - default: printf ("(unknown case)"); break; - } - break; - - case DW_AT_calling_convention: - switch (uvalue) - { - case DW_CC_normal: printf ("(normal)"); break; - case DW_CC_program: printf ("(program)"); break; - case DW_CC_nocall: printf ("(nocall)"); break; - default: - if (uvalue >= DW_CC_lo_user - && uvalue <= DW_CC_hi_user) - printf ("(user defined)"); - else - printf ("(unknown convention)"); - } - break; - - case DW_AT_ordering: - switch (uvalue) - { - case -1: printf ("(undefined)"); break; - case 0: printf ("(row major)"); break; - case 1: printf ("(column major)"); break; - } - break; - - case DW_AT_frame_base: - case DW_AT_location: - case DW_AT_data_member_location: - case DW_AT_vtable_elem_location: - case DW_AT_allocated: - case DW_AT_associated: - case DW_AT_data_location: - case DW_AT_stride: - case DW_AT_upper_bound: - case DW_AT_lower_bound: - if (block_start) - { - printf ("("); - decode_location_expression (block_start, pointer_size, uvalue); - printf (")"); - } - else if (form == DW_FORM_data4 || form == DW_FORM_data8) - { - printf ("("); - printf ("location list"); - printf (")"); - } - break; -#endif - -static void -dwarf_dump_av_attr(Dwarf_Die die __unused, Dwarf_AttrValue av) -{ - switch (av->av_attrib) { - case DW_AT_accessibility: - break; - - case DW_AT_calling_convention: - break; - - case DW_AT_encoding: - break; - - case DW_AT_identifier_case: - break; - - case DW_AT_inline: - break; - - case DW_AT_language: - break; - - case DW_AT_ordering: - break; - - case DW_AT_virtuality: - break; - - case DW_AT_visibility: - break; - - case DW_AT_frame_base: - case DW_AT_location: - case DW_AT_data_member_location: - case DW_AT_vtable_elem_location: - case DW_AT_upper_bound: - case DW_AT_lower_bound: - break; - - default: - break; - } -} - -void -dwarf_dump_av(Dwarf_Die die, Dwarf_AttrValue av) -{ - uint64_t i; - - printf(" %-30s : %-16s ", - get_attr_desc(av->av_attrib), - get_form_desc(av->av_form)); - - switch (av->av_form) { - case DW_FORM_addr: - printf("0x%llx", (unsigned long long) av->u[0].u64); - break; - case DW_FORM_block: - case DW_FORM_block1: - case DW_FORM_block2: - case DW_FORM_block4: - printf("%lu byte block:", (u_long) av->u[0].u64); - for (i = 0; i < av->u[0].u64; i++) - printf(" %02x", av->u[1].u8p[i]); - break; - case DW_FORM_data1: - case DW_FORM_data2: - case DW_FORM_data4: - case DW_FORM_data8: - case DW_FORM_flag: - case DW_FORM_flag_present: - printf("%llu", (unsigned long long) av->u[0].u64); - break; - case DW_FORM_ref1: - case DW_FORM_ref2: - case DW_FORM_ref4: - case DW_FORM_ref8: - case DW_FORM_ref_udata: - printf("<%llx>", (unsigned long long) (av->u[0].u64 + - die->die_cu->cu_offset)); - break; - case DW_FORM_string: - printf("%s", av->u[0].s); - break; - case DW_FORM_strp: - printf("(indirect string, offset 0x%llx): %s", - (unsigned long long) av->u[0].u64, av->u[1].s); - break; - default: - printf("unknown form"); - break; - } - - /* Dump any extra attribute-specific information. */ - dwarf_dump_av_attr(die, av); - - printf("\n"); -} - -void -dwarf_dump_die_at_offset(Dwarf_Debug dbg, Dwarf_Off off) -{ - Dwarf_CU cu; - Dwarf_Die die; - - if (dbg == NULL) - return; - - STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) { - STAILQ_FOREACH(die, &cu->cu_die, die_next) { - if ((off_t) die->die_offset == off) { - dwarf_dump_die(die); - return; - } - } - } -} - -void -dwarf_dump_die(Dwarf_Die die) -{ - Dwarf_AttrValue av; - - printf("<%d><%llx>: Abbrev number: %llu (%s)\n", - die->die_level, (unsigned long long) die->die_offset, - (unsigned long long) die->die_abnum, - get_tag_desc(die->die_a->a_tag)); - - STAILQ_FOREACH(av, &die->die_attrval, av_next) - dwarf_dump_av(die, av); -} - -void -dwarf_dump_raw(Dwarf_Debug dbg) -{ - Dwarf_CU cu; - char *p = (char *) dbg; - int i; - - printf("dbg %p\n",dbg); - - if (dbg == NULL) - return; - - for (i = 0; i < (int) sizeof(*dbg); i++) { - if (*p >= 0x20 && *p < 0x7f) { - printf(" %c",*p++ & 0xff); - } else { - printf(" %02x",*p++ & 0xff); - } - } - printf("\n"); - - STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) { - p = (char *) cu; - printf("cu %p\n",cu); - for (i = 0; i < (int) sizeof(*cu); i++) { - if (*p >= 0x20 && *p < 0x7f) { - printf(" %c",*p++ & 0xff); - } else { - printf(" %02x",*p++ & 0xff); - } - } - printf("\n"); - } -} - -static void -dwarf_dump_tree_dies(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Error *error) -{ - Dwarf_Die child; - int ret; - - do { - dwarf_dump_die(die); - - if ((ret = dwarf_child(die, &child, error) == DWARF_E_NO_ENTRY)) { - /* No children. */ - } else if (ret != DWARF_E_NONE) { - printf("Error %s\n", dwarf_errmsg(error)); - return; - } else - dwarf_dump_tree_dies(dbg, child, error); - - if (dwarf_siblingof(dbg, die, &die, error) != DWARF_E_NONE) - die = NULL; - - } while (die != NULL); -} - -void -dwarf_dump_tree(Dwarf_Debug dbg) -{ - Dwarf_CU cu; - Dwarf_Die die; - Dwarf_Error error; - Dwarf_Half cu_pointer_size; - Dwarf_Half cu_version; - Dwarf_Unsigned cu_abbrev_offset; - Dwarf_Unsigned cu_header_length; - Dwarf_Unsigned cu_next_offset; - - STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) { - printf ("\nCompilation Unit @ offset %llx:\n", - (unsigned long long) cu->cu_offset); - printf (" Length: %lu\n", (u_long) cu->cu_length); - printf (" Version: %hu\n", cu->cu_version); - printf (" Abbrev Offset: %lu\n", (u_long) cu->cu_abbrev_offset); - printf (" Pointer Size: %u\n", (u_int) cu->cu_pointer_size); - - if (dwarf_next_cu_header(dbg, &cu_header_length, - &cu_version, &cu_abbrev_offset, &cu_pointer_size, - &cu_next_offset, &error) != DWARF_E_NONE) { - printf("Error %s\n", dwarf_errmsg(&error)); - return; - } - - if (dwarf_siblingof(dbg, NULL, &die, &error) != DWARF_E_NONE) { - printf("Error %s\n", dwarf_errmsg(&error)); - return; - } - - dwarf_dump_tree_dies(dbg, die, &error); - - } -} - -void -dwarf_dump_info(Dwarf_Debug dbg) -{ - Dwarf_CU cu; - Dwarf_Die die; - - printf("Contents of the .debug_info section:\n"); - - STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) { - printf ("\nCompilation Unit @ offset %llx:\n", - (unsigned long long) cu->cu_offset); - printf (" Length: %lu\n", (u_long) cu->cu_length); - printf (" Version: %hu\n", cu->cu_version); - printf (" Abbrev Offset: %lu\n", (u_long) cu->cu_abbrev_offset); - printf (" Pointer Size: %u\n", (u_int) cu->cu_pointer_size); - - STAILQ_FOREACH(die, &cu->cu_die, die_next) - dwarf_dump_die(die); - } -} - - -void -dwarf_dump_shstrtab(Dwarf_Debug dbg) -{ - char *name; - int indx = 0; - - printf("---------------------\nSection header string table contents:\n"); - while ((name = elf_strptr(dbg->dbg_elf, dbg->dbg_stnum, indx)) != NULL) { - printf("%5d '%s'\n",indx,name); - indx += strlen(name) + 1; - } -} - -void -dwarf_dump_strtab(Dwarf_Debug dbg) -{ - char *name; - int indx = 0; - - printf("---------------------\nString table contents:\n"); - while ((name = elf_strptr(dbg->dbg_elf, dbg->dbg_s[DWARF_strtab].s_shnum, indx)) != NULL) { - printf("%5d '%s'\n",indx,name); - indx += strlen(name) + 1; - } -} - -void -dwarf_dump_dbgstr(Dwarf_Debug dbg) -{ - char *name; - int indx = 0; - - printf("---------------------\nDebug string table contents:\n"); - while ((name = elf_strptr(dbg->dbg_elf, dbg->dbg_s[DWARF_debug_str].s_shnum, indx)) != NULL) { - printf("%5d '%s'\n",indx,name); - indx += strlen(name) + 1; - } -} - -void -dwarf_dump_symtab(Dwarf_Debug dbg) -{ - GElf_Sym sym; - char *name; - int indx = 0; - - printf("---------------------\nSymbol table contents:\n"); - while (gelf_getsym(dbg->dbg_s[DWARF_symtab].s_data, indx++, &sym) != NULL) { - if ((name = elf_strptr(dbg->dbg_elf, dbg->dbg_s[DWARF_strtab].s_shnum, sym.st_name)) == NULL) - printf("sym.st_name %u indx %d sym.st_size %lu\n",sym.st_name,indx,(u_long) sym.st_size); - else - printf("'%s' sym.st_name %u indx %d sym.st_size %lu\n",name,sym.st_name,indx,(u_long) sym.st_size); - } -} - -void -dwarf_dump(Dwarf_Debug dbg) -{ - dwarf_dump_strtab(dbg); - dwarf_dump_shstrtab(dbg); - dwarf_dump_dbgstr(dbg); - dwarf_dump_symtab(dbg); - dwarf_dump_info(dbg); -} diff --git a/lib/libdwarf/dwarf_errmsg.c b/lib/libdwarf/dwarf_errmsg.c deleted file mode 100644 index ca37740318ed4..0000000000000 --- a/lib/libdwarf/dwarf_errmsg.c +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <stdio.h> -#include "_libdwarf.h" - -static const char *_libdwarf_errors[] = { -#define DEFINE_ERROR(N,S) [DWARF_E_##N] = S - DEFINE_ERROR(NONE, "No Error"), - DEFINE_ERROR(ERROR, "An error"), - DEFINE_ERROR(NO_ENTRY, "No entry found"), - DEFINE_ERROR(ARGUMENT, "Invalid argument"), - DEFINE_ERROR(DEBUG_INFO, "Debug info NULL"), - DEFINE_ERROR(MEMORY, "Insufficient memory"), - DEFINE_ERROR(ELF, "ELF error"), - DEFINE_ERROR(INVALID_CU, "Invalid compilation unit data"), - DEFINE_ERROR(CU_VERSION, "Wrong CU version. Only 2 and 3 supported"), - DEFINE_ERROR(MISSING_ABBREV, "Abbrev not found"), - DEFINE_ERROR(NOT_IMPLEMENTED, "Unimplemented code at"), - DEFINE_ERROR(CU_CURRENT, "No current compilation unit"), - DEFINE_ERROR(BAD_FORM, "Wrong form type for attribute value"), - DEFINE_ERROR(INVALID_EXPR, "Invalid DWARF expression"), - DEFINE_ERROR(NUM, "Unknown DWARF error") -#undef DEFINE_ERROR -}; - -const char * -dwarf_errmsg(Dwarf_Error *error) -{ - const char *p; - - if (error == NULL) - return NULL; - - if (error->err_error < 0 || error->err_error >= DWARF_E_NUM) - return _libdwarf_errors[DWARF_E_NUM]; - else if (error->err_error == DWARF_E_NONE) - return _libdwarf_errors[DWARF_E_NONE]; - else - p = _libdwarf_errors[error->err_error]; - - if (error->err_error == DWARF_E_ELF) - snprintf(error->err_msg, sizeof(error->err_msg), - "ELF error : %s [%s(%d)]", elf_errmsg(error->elf_error), - error->err_func, error->err_line); - else - snprintf(error->err_msg, sizeof(error->err_msg), - "%s [%s(%d)]", p, error->err_func, error->err_line); - - return (const char *) error->err_msg; -} diff --git a/lib/libdwarf/dwarf_finish.c b/lib/libdwarf/dwarf_finish.c deleted file mode 100644 index d665ed9e37c48..0000000000000 --- a/lib/libdwarf/dwarf_finish.c +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <stdlib.h> -#include "_libdwarf.h" - -int -dwarf_finish(Dwarf_Debug *dbgp, Dwarf_Error *error) -{ - Dwarf_Abbrev ab; - Dwarf_Abbrev tab; - Dwarf_Attribute at; - Dwarf_Attribute tat; - Dwarf_AttrValue av; - Dwarf_AttrValue tav; - Dwarf_CU cu; - Dwarf_CU tcu; - Dwarf_Debug dbg; - Dwarf_Die die; - Dwarf_Die tdie; - - if (error == NULL) - /* Can only return a generic error. */ - return DWARF_E_ERROR; - - if (dbgp == NULL) { - DWARF_SET_ERROR(error, DWARF_E_ARGUMENT); - return DWARF_E_ERROR; - } - - if ((dbg = *dbgp) == NULL) - return DWARF_E_NONE; - - /* Free entries in the compilation unit list. */ - STAILQ_FOREACH_SAFE(cu, &dbg->dbg_cu, cu_next, tcu) { - /* Free entries in the die list */ - STAILQ_FOREACH_SAFE(die, &cu->cu_die, die_next, tdie) { - /* Free entries in the attribute value list */ - STAILQ_FOREACH_SAFE(av, &die->die_attrval, av_next, tav) { - STAILQ_REMOVE(&die->die_attrval, av, _Dwarf_AttrValue, av_next); - free(av); - } - - STAILQ_REMOVE(&cu->cu_die, die, _Dwarf_Die, die_next); - free(die); - } - - /* Free entries in the abbrev list */ - STAILQ_FOREACH_SAFE(ab, &cu->cu_abbrev, a_next, tab) { - /* Free entries in the attribute list */ - STAILQ_FOREACH_SAFE(at, &ab->a_attrib, at_next, tat) { - STAILQ_REMOVE(&ab->a_attrib, at, _Dwarf_Attribute, at_next); - free(at); - } - - STAILQ_REMOVE(&cu->cu_abbrev, ab, _Dwarf_Abbrev, a_next); - free(ab); - } - - STAILQ_REMOVE(&dbg->dbg_cu, cu, _Dwarf_CU, cu_next); - free(cu); - } - - if (dbg->dbg_elf_close) - /* Free resources associated with the ELF file. */ - elf_end(dbg->dbg_elf); - - free(dbg); - - *dbgp = NULL; - - return DWARF_E_NONE; -} diff --git a/lib/libdwarf/dwarf_func.c b/lib/libdwarf/dwarf_func.c deleted file mode 100644 index b00d858ee601f..0000000000000 --- a/lib/libdwarf/dwarf_func.c +++ /dev/null @@ -1,227 +0,0 @@ -/*- - * Copyright (c) 2008-2009, 2011, Juniper Networks, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * JNPR: dwarf_func.c 336441 2009-10-17 09:19:54Z deo - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <stdlib.h> -#include <string.h> -#include <libdwarf.h> -#include <_libdwarf.h> - -static void -dwarf_add_function(Dwarf_Debug dbg, Dwarf_Func func) -{ - - STAILQ_INSERT_TAIL(&dbg->dbg_func, func, func_next); -} - -int -dwarf_function_get_addr_range(Dwarf_Func f, Dwarf_Addr *low_pc, - Dwarf_Addr *high_pc) -{ - - *low_pc = f->func_low_pc; - *high_pc = f->func_high_pc; - return 0; -} - -int -dwarf_inlined_function_get_addr_range(Dwarf_Inlined_Func f, Dwarf_Addr *low_pc, - Dwarf_Addr *high_pc) -{ - - *low_pc = f->ifunc_low_pc; - *high_pc = f->ifunc_high_pc; - return 0; -} - -int -dwarf_function_is_inlined(Dwarf_Func f) -{ - - if (f->func_is_inlined == DW_INL_inlined || - f->func_is_inlined == DW_INL_declared_inlined) - return 1; - else - return 0; -} - -Dwarf_Func -dwarf_find_function_by_name(Dwarf_Debug dbg, const char *name) -{ - /* XXX: replace with a fast version */ - - Dwarf_Func func; - STAILQ_FOREACH(func, &dbg->dbg_func, func_next) { - if (strcmp(name, func->func_name) == 0) - return func; - } - return NULL; -} - -Dwarf_Func -dwarf_find_function_by_offset(Dwarf_Debug dbg, Dwarf_Off off) -{ - - Dwarf_Func func; - Dwarf_Die die; - /* printf("look for %llx\n", off); */ - STAILQ_FOREACH(func, &dbg->dbg_func, func_next) { - die = func->func_die; - if ((off_t)die->die_offset == off) { - return func; - } - } - return NULL; -} - -void -dwarf_build_function_table(Dwarf_Debug dbg) -{ - Dwarf_CU cu; - Dwarf_AttrValue av; - Dwarf_Die die, origin_die; - Dwarf_Func func, origin_func; - Dwarf_Inlined_Func ifunc; - unsigned long long offset; - const char *name; - Dwarf_Error error; - - /* - * find out all the functions - */ - STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) { - STAILQ_FOREACH(die, &cu->cu_die, die_next) { - if (die->die_a->a_tag == DW_TAG_subprogram) { - /* - * Some function has multiple entries, i.e. - * if a function is inlined, it has many - * abstract/concrete instances, the abstract - * instances are with DW_TAG_subprogram. - */ - dwarf_attrval_string(die, DW_AT_name, &name, - &error); - func = dwarf_find_function_by_name(dbg, name); - if (func == NULL) { - func = malloc( - sizeof(struct _Dwarf_Func)); - DWARF_ASSERT(func); - - func->func_die = die; - func->func_name = name; - STAILQ_INIT( - &func->func_inlined_instances); - - dwarf_add_function(dbg, func); - STAILQ_FOREACH(av, &die->die_attrval, - av_next) { - switch (av->av_attrib) { - case DW_AT_low_pc: - func->func_low_pc = - av->u[0].u64; - break; - case DW_AT_high_pc: - func->func_high_pc = - av->u[0].u64; - break; - case DW_AT_inline: - func->func_is_inlined = - av->u[0].u64; - break; - } - } - } - } - } - } - - /* - * Now check the concrete inlined instances. - */ - STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) { - STAILQ_FOREACH(die, &cu->cu_die, die_next) { - if (die->die_a->a_tag == DW_TAG_inlined_subroutine) { - ifunc = malloc( - sizeof(struct _Dwarf_Inlined_Func)); - DWARF_ASSERT(ifunc); - STAILQ_FOREACH(av, &die->die_attrval, av_next) { - switch (av->av_attrib) { - case DW_AT_abstract_origin: - offset = av->u[0].u64 + - die->die_cu->cu_offset; - origin_die = dwarf_die_find( - die, offset); - DWARF_ASSERT(origin_die != 0); - - /* - * the abstract origin must - * have been merged with - * another die - */ - dwarf_attrval_string( - origin_die, DW_AT_name, - &name, &error); - origin_func = - dwarf_find_function_by_name - (dbg, name); - DWARF_ASSERT(origin_func != 0); - - STAILQ_INSERT_TAIL( - &origin_func-> - func_inlined_instances, - ifunc, ifunc_next); - - break; - case DW_AT_low_pc: - ifunc->ifunc_low_pc = - av->u[0].u64; - break; - case DW_AT_high_pc: - ifunc->ifunc_high_pc = - av->u[0].u64; - break; - } - } - } - } - } -} - -void -dwarf_function_iterate_inlined_instance(Dwarf_Func func, - Dwarf_Inlined_Callback f, void *data) -{ - Dwarf_Inlined_Func ifunc; - - if (!dwarf_function_is_inlined(func)) - return; - STAILQ_FOREACH(ifunc, &func->func_inlined_instances, ifunc_next) { - f(ifunc, data); - } -} diff --git a/lib/libdwarf/dwarf_init.c b/lib/libdwarf/dwarf_init.c deleted file mode 100644 index ce8536337b2f5..0000000000000 --- a/lib/libdwarf/dwarf_init.c +++ /dev/null @@ -1,756 +0,0 @@ -/*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <stdlib.h> -#include <string.h> -#include "_libdwarf.h" - -static const char *debug_snames[DWARF_DEBUG_SNAMES] = { - ".debug_abbrev", - ".debug_aranges", - ".debug_frame", - ".debug_info", - ".debug_line", - ".debug_pubnames", - ".eh_frame", - ".debug_macinfo", - ".debug_str", - ".debug_loc", - ".debug_pubtypes", - ".debug_ranges", - ".debug_static_func", - ".debug_static_vars", - ".debug_types", - ".debug_weaknames", - ".symtab", - ".strtab" -}; - -static uint64_t (*dwarf_read) (Elf_Data **, uint64_t *, int); -static void (*dwarf_write) (Elf_Data **, uint64_t *, uint64_t, int); - -static uint64_t -dwarf_read_lsb(Elf_Data **dp, uint64_t *offsetp, int bytes_to_read) -{ - uint64_t ret = 0; - - uint8_t *src = (uint8_t *) (*dp)->d_buf + *offsetp; - - switch (bytes_to_read) { - case 8: - ret |= ((uint64_t) src[4]) << 32 | ((uint64_t) src[5]) << 40; - ret |= ((uint64_t) src[6]) << 48 | ((uint64_t) src[7]) << 56; - case 4: - ret |= ((uint64_t) src[2]) << 16 | ((uint64_t) src[3]) << 24; - case 2: - ret |= ((uint64_t) src[1]) << 8; - case 1: - ret |= src[0]; - break; - default: - return 0; - break; - } - - *offsetp += bytes_to_read; - - return ret; -} - -static uint64_t -dwarf_read_msb(Elf_Data **dp, uint64_t *offsetp, int bytes_to_read) -{ - uint64_t ret = 0; - - uint8_t *src = (uint8_t *) (*dp)->d_buf + *offsetp; - - switch (bytes_to_read) { - case 1: - ret = src[0]; - break; - case 2: - ret = src[1] | ((uint64_t) src[0]) << 8; - break; - case 4: - ret = src[3] | ((uint64_t) src[2]) << 8; - ret |= ((uint64_t) src[1]) << 16 | ((uint64_t) src[0]) << 24; - break; - case 8: - ret = src[7] | ((uint64_t) src[6]) << 8; - ret |= ((uint64_t) src[5]) << 16 | ((uint64_t) src[4]) << 24; - ret |= ((uint64_t) src[3]) << 32 | ((uint64_t) src[2]) << 40; - ret |= ((uint64_t) src[1]) << 48 | ((uint64_t) src[0]) << 56; - break; - default: - return 0; - break; - } - - *offsetp += bytes_to_read; - - return ret; -} - -static void -dwarf_write_lsb(Elf_Data **dp, uint64_t *offsetp, uint64_t value, int bytes_to_write) -{ - uint8_t *dst = (uint8_t *) (*dp)->d_buf + *offsetp; - - switch (bytes_to_write) { - case 8: - dst[7] = (value >> 56) & 0xff; - dst[6] = (value >> 48) & 0xff; - dst[5] = (value >> 40) & 0xff; - dst[4] = (value >> 32) & 0xff; - case 4: - dst[3] = (value >> 24) & 0xff; - dst[2] = (value >> 16) & 0xff; - case 2: - dst[1] = (value >> 8) & 0xff; - case 1: - dst[0] = value & 0xff; - break; - default: - return; - break; - } - - *offsetp += bytes_to_write; -} - -static void -dwarf_write_msb(Elf_Data **dp, uint64_t *offsetp, uint64_t value, int bytes_to_write) -{ - uint8_t *dst = (uint8_t *) (*dp)->d_buf + *offsetp; - - switch (bytes_to_write) { - case 8: - dst[7] = value & 0xff; - dst[6] = (value >> 8) & 0xff; - dst[5] = (value >> 16) & 0xff; - dst[4] = (value >> 24) & 0xff; - value >>= 32; - case 4: - dst[3] = value & 0xff; - dst[2] = (value >> 8) & 0xff; - value >>= 16; - case 2: - dst[1] = value & 0xff; - value >>= 8; - case 1: - dst[0] = value & 0xff; - break; - default: - return; - break; - } - - *offsetp += bytes_to_write; -} - -static int64_t -dwarf_read_sleb128(Elf_Data **dp, uint64_t *offsetp) -{ - int64_t ret = 0; - uint8_t b; - int shift = 0; - - uint8_t *src = (uint8_t *) (*dp)->d_buf + *offsetp; - - do { - b = *src++; - - ret |= ((b & 0x7f) << shift); - - (*offsetp)++; - - shift += 7; - } while ((b & 0x80) != 0); - - if (shift < 64 && (b & 0x40) != 0) - ret |= (-1 << shift); - - return ret; -} - -static uint64_t -dwarf_read_uleb128(Elf_Data **dp, uint64_t *offsetp) -{ - uint64_t ret = 0; - uint8_t b; - int shift = 0; - - uint8_t *src = (uint8_t *) (*dp)->d_buf + *offsetp; - - do { - b = *src++; - - ret |= ((b & 0x7f) << shift); - - (*offsetp)++; - - shift += 7; - } while ((b & 0x80) != 0); - - return ret; -} - -static const char * -dwarf_read_string(Elf_Data **dp, uint64_t *offsetp) -{ - char *ret; - - char *src = (char *) (*dp)->d_buf + *offsetp; - - ret = src; - - while (*src != '\0' && *offsetp < (*dp)->d_size) { - src++; - (*offsetp)++; - } - - if (*src == '\0' && *offsetp < (*dp)->d_size) - (*offsetp)++; - - return ret; -} - -static uint8_t * -dwarf_read_block(Elf_Data **dp, uint64_t *offsetp, uint64_t length) -{ - uint8_t *ret; - - uint8_t *src = (char *) (*dp)->d_buf + *offsetp; - - ret = src; - - (*offsetp) += length; - - return ret; -} - -static int -dwarf_apply_relocations(Dwarf_Debug dbg, Elf_Data *reld, int secindx) -{ - Elf_Data *d; - GElf_Rela rela; - int indx = 0; - int ret = DWARF_E_NONE; - uint64_t offset; - - /* Point to the data to be relocated: */ - d = dbg->dbg_s[secindx].s_data; - - /* Enter a loop to process each relocation addend: */ - while (gelf_getrela(reld, indx++, &rela) != NULL) { - GElf_Sym sym; - Elf64_Xword symindx = ELF64_R_SYM(rela.r_info); - - if (gelf_getsym(dbg->dbg_s[DWARF_symtab].s_data, symindx, &sym) == NULL) { - printf("Couldn't find symbol index %lu for relocation\n",(u_long) symindx); - continue; - } - - offset = rela.r_offset; - - dwarf_write(&d, &offset, rela.r_addend, dbg->dbg_offsize); - } - - return ret; -} - -static int -dwarf_relocate(Dwarf_Debug dbg, Dwarf_Error *error) -{ - Elf_Scn *scn = NULL; - GElf_Shdr shdr; - int i; - int ret = DWARF_E_NONE; - - /* Look for sections which relocate the debug sections. */ - while ((scn = elf_nextscn(dbg->dbg_elf, scn)) != NULL) { - if (gelf_getshdr(scn, &shdr) == NULL) { - DWARF_SET_ELF_ERROR(error, elf_errno()); - return DWARF_E_ELF; - } - - if (shdr.sh_type != SHT_RELA || shdr.sh_size == 0) - continue; - - for (i = 0; i < DWARF_DEBUG_SNAMES; i++) { - if (dbg->dbg_s[i].s_shnum == shdr.sh_info && - dbg->dbg_s[DWARF_symtab].s_shnum == shdr.sh_link) { - Elf_Data *rd; - - /* Get the relocation data. */ - if ((rd = elf_getdata(scn, NULL)) == NULL) { - DWARF_SET_ELF_ERROR(error, elf_errno()); - return DWARF_E_ELF; - } - - /* Apply the relocations. */ - dwarf_apply_relocations(dbg, rd, i); - break; - } - } - } - - return ret; -} - -static int -dwarf_init_attr(Dwarf_Debug dbg, Elf_Data **dp, uint64_t *offsetp, - Dwarf_CU cu, Dwarf_Die die, Dwarf_Attribute at, uint64_t form, - Dwarf_Error *error) -{ - int ret = DWARF_E_NONE; - struct _Dwarf_AttrValue avref; - - memset(&avref, 0, sizeof(avref)); - avref.av_attrib = at->at_attrib; - avref.av_form = at->at_form; - - switch (form) { - case DW_FORM_addr: - avref.u[0].u64 = dwarf_read(dp, offsetp, cu->cu_pointer_size); - break; - case DW_FORM_block: - avref.u[0].u64 = dwarf_read_uleb128(dp, offsetp); - avref.u[1].u8p = dwarf_read_block(dp, offsetp, avref.u[0].u64); - break; - case DW_FORM_block1: - avref.u[0].u64 = dwarf_read(dp, offsetp, 1); - avref.u[1].u8p = dwarf_read_block(dp, offsetp, avref.u[0].u64); - break; - case DW_FORM_block2: - avref.u[0].u64 = dwarf_read(dp, offsetp, 2); - avref.u[1].u8p = dwarf_read_block(dp, offsetp, avref.u[0].u64); - break; - case DW_FORM_block4: - avref.u[0].u64 = dwarf_read(dp, offsetp, 4); - avref.u[1].u8p = dwarf_read_block(dp, offsetp, avref.u[0].u64); - break; - case DW_FORM_data1: - case DW_FORM_flag: - case DW_FORM_ref1: - avref.u[0].u64 = dwarf_read(dp, offsetp, 1); - break; - case DW_FORM_data2: - case DW_FORM_ref2: - avref.u[0].u64 = dwarf_read(dp, offsetp, 2); - break; - case DW_FORM_data4: - case DW_FORM_ref4: - avref.u[0].u64 = dwarf_read(dp, offsetp, 4); - break; - case DW_FORM_data8: - case DW_FORM_ref8: - avref.u[0].u64 = dwarf_read(dp, offsetp, 8); - break; - case DW_FORM_indirect: - form = dwarf_read_uleb128(dp, offsetp); - return dwarf_init_attr(dbg, dp, offsetp, cu, die, at, form, error); - case DW_FORM_ref_addr: - if (cu->cu_version == 2) - avref.u[0].u64 = dwarf_read(dp, offsetp, cu->cu_pointer_size); - else if (cu->cu_version == 3) - avref.u[0].u64 = dwarf_read(dp, offsetp, dbg->dbg_offsize); - break; - case DW_FORM_ref_udata: - case DW_FORM_udata: - avref.u[0].u64 = dwarf_read_uleb128(dp, offsetp); - break; - case DW_FORM_sdata: - avref.u[0].s64 = dwarf_read_sleb128(dp, offsetp); - break; - case DW_FORM_string: - avref.u[0].s = dwarf_read_string(dp, offsetp); - break; - case DW_FORM_strp: - avref.u[0].u64 = dwarf_read(dp, offsetp, dbg->dbg_offsize); - avref.u[1].s = elf_strptr(dbg->dbg_elf, - dbg->dbg_s[DWARF_debug_str].s_shnum, avref.u[0].u64); - break; - case DW_FORM_flag_present: - /* This form has no value encoded in the DIE. */ - avref.u[0].u64 = 1; - break; - default: - DWARF_SET_ERROR(error, DWARF_E_NOT_IMPLEMENTED); - ret = DWARF_E_NOT_IMPLEMENTED; - break; - } - - if (ret == DWARF_E_NONE) - ret = dwarf_attrval_add(die, &avref, NULL, error); - - return ret; -} - -static int -dwarf_init_abbrev(Dwarf_Debug dbg, Dwarf_CU cu, Dwarf_Error *error) -{ - Dwarf_Abbrev a; - Elf_Data *d; - int ret = DWARF_E_NONE; - uint64_t attr; - uint64_t entry; - uint64_t form; - uint64_t offset; - uint64_t tag; - u_int8_t children; - - d = dbg->dbg_s[DWARF_debug_abbrev].s_data; - - offset = cu->cu_abbrev_offset; - - while (offset < d->d_size) { - - entry = dwarf_read_uleb128(&d, &offset); - - /* Check if this is the end of the data: */ - if (entry == 0) - break; - - tag = dwarf_read_uleb128(&d, &offset); - - children = dwarf_read(&d, &offset, 1); - - if ((ret = dwarf_abbrev_add(cu, entry, tag, children, &a, error)) != DWARF_E_NONE) - break; - - do { - attr = dwarf_read_uleb128(&d, &offset); - form = dwarf_read_uleb128(&d, &offset); - - if (attr != 0) - if ((ret = dwarf_attr_add(a, attr, form, NULL, error)) != DWARF_E_NONE) - return ret; - } while (attr != 0); - } - - return ret; -} - -static int -dwarf_init_info(Dwarf_Debug dbg, Dwarf_Error *error) -{ - Dwarf_CU cu; - Elf_Data *d = NULL; - Elf_Scn *scn; - int i; - int level = 0; - int relocated = 0; - int ret = DWARF_E_NONE; - uint64_t length; - uint64_t next_offset; - uint64_t offset = 0; - - scn = dbg->dbg_s[DWARF_debug_info].s_scn; - - d = dbg->dbg_s[DWARF_debug_info].s_data; - - while (offset < d->d_size) { - /* Allocate memory for the first compilation unit. */ - if ((cu = calloc(sizeof(struct _Dwarf_CU), 1)) == NULL) { - DWARF_SET_ERROR(error, DWARF_E_MEMORY); - return DWARF_E_MEMORY; - } - - /* Save the offet to this compilation unit: */ - cu->cu_offset = offset; - - length = dwarf_read(&d, &offset, 4); - if (length == 0xffffffff) { - length = dwarf_read(&d, &offset, 8); - dbg->dbg_offsize = 8; - } else - dbg->dbg_offsize = 4; - - /* - * Check if there is enough ELF data for this CU. - * This assumes that libelf gives us the entire - * section in one Elf_Data object. - */ - if (length > d->d_size - offset) { - free(cu); - DWARF_SET_ERROR(error, DWARF_E_INVALID_CU); - return DWARF_E_INVALID_CU; - } - - /* Relocate the DWARF sections if necessary: */ - if (!relocated) { - if ((ret = dwarf_relocate(dbg, error)) != DWARF_E_NONE) - return ret; - relocated = 1; - } - - /* Compute the offset to the next compilation unit: */ - next_offset = offset + length; - - /* Initialise the compilation unit. */ - cu->cu_length = length; - cu->cu_header_length = (dbg->dbg_offsize == 4) ? 4 : 12; - cu->cu_version = dwarf_read(&d, &offset, 2); - cu->cu_abbrev_offset = dwarf_read(&d, &offset, dbg->dbg_offsize); - cu->cu_pointer_size = dwarf_read(&d, &offset, 1); - cu->cu_next_offset = next_offset; - - /* Initialise the list of abbrevs. */ - STAILQ_INIT(&cu->cu_abbrev); - - /* Initialise the list of dies. */ - STAILQ_INIT(&cu->cu_die); - - /* Initialise the hash table of dies. */ - for (i = 0; i < DWARF_DIE_HASH_SIZE; i++) - STAILQ_INIT(&cu->cu_die_hash[i]); - - /* Add the compilation unit to the list. */ - STAILQ_INSERT_TAIL(&dbg->dbg_cu, cu, cu_next); - - if (cu->cu_version != 2 && cu->cu_version != 3) { - DWARF_SET_ERROR(error, DWARF_E_CU_VERSION); - ret = DWARF_E_CU_VERSION; - break; - } - - /* Parse the .debug_abbrev info for this CU: */ - if ((ret = dwarf_init_abbrev(dbg, cu, error)) != DWARF_E_NONE) - break; - - level = 0; - - while (offset < next_offset && offset < d->d_size) { - Dwarf_Abbrev a; - Dwarf_Attribute at; - Dwarf_Die die; - uint64_t abnum; - uint64_t die_offset = offset; - - abnum = dwarf_read_uleb128(&d, &offset); - - if (abnum == 0) { - level--; - continue; - } - - if ((a = dwarf_abbrev_find(cu, abnum)) == NULL) { - DWARF_SET_ERROR(error, DWARF_E_MISSING_ABBREV); - return DWARF_E_MISSING_ABBREV; - } - - if ((ret = dwarf_die_add(cu, level, die_offset, - abnum, a, &die, error)) != DWARF_E_NONE) - return ret; - - STAILQ_FOREACH(at, &a->a_attrib, at_next) { - if ((ret = dwarf_init_attr(dbg, &d, &offset, - cu, die, at, at->at_form, error)) != DWARF_E_NONE) - return ret; - } - - if (a->a_children == DW_CHILDREN_yes) - level++; - } - - offset = next_offset; - } - - /* Build the function table. */ - dwarf_build_function_table(dbg); - - return ret; -} - -static int -dwarf_elf_read(Dwarf_Debug dbg, Dwarf_Error *error) -{ - GElf_Shdr shdr; - Elf_Scn *scn = NULL; - char *sname; - int i; - int ret = DWARF_E_NONE; - - /* Get a copy of the ELF header. */ - if (gelf_getehdr(dbg->dbg_elf, &dbg->dbg_ehdr) == NULL) { - DWARF_SET_ELF_ERROR(error, elf_errno()); - return DWARF_E_ELF; - } - - /* Check the ELF data format: */ - switch (dbg->dbg_ehdr.e_ident[EI_DATA]) { - case ELFDATA2MSB: - dwarf_read = dwarf_read_msb; - dwarf_write = dwarf_write_msb; - break; - - case ELFDATA2LSB: - case ELFDATANONE: - default: - dwarf_read = dwarf_read_lsb; - dwarf_write = dwarf_write_lsb; - break; - } - - /* Get the section index to the string table. */ - if (elf_getshstrndx(dbg->dbg_elf, &dbg->dbg_stnum) == 0) { - DWARF_SET_ELF_ERROR(error, elf_errno()); - return DWARF_E_ELF; - } - - /* Look for the debug sections. */ - while ((scn = elf_nextscn(dbg->dbg_elf, scn)) != NULL) { - /* Get a copy of the section header: */ - if (gelf_getshdr(scn, &shdr) == NULL) { - DWARF_SET_ELF_ERROR(error, elf_errno()); - return DWARF_E_ELF; - } - - /* Get a pointer to the section name: */ - if ((sname = elf_strptr(dbg->dbg_elf, dbg->dbg_stnum, shdr.sh_name)) == NULL) { - DWARF_SET_ELF_ERROR(error, elf_errno()); - return DWARF_E_ELF; - } - - /* - * Look up the section name to check if it's - * one we need for DWARF. - */ - for (i = 0; i < DWARF_DEBUG_SNAMES; i++) { - if (strcmp(sname, debug_snames[i]) == 0) { - dbg->dbg_s[i].s_sname = sname; - dbg->dbg_s[i].s_shnum = elf_ndxscn(scn); - dbg->dbg_s[i].s_scn = scn; - memcpy(&dbg->dbg_s[i].s_shdr, &shdr, sizeof(shdr)); - if ((dbg->dbg_s[i].s_data = elf_getdata(scn, NULL)) == NULL) { - DWARF_SET_ELF_ERROR(error, elf_errno()); - return DWARF_E_ELF; - } - break; - } - } - } - - /* Check if any of the required sections are missing: */ - if (dbg->dbg_s[DWARF_debug_abbrev].s_scn == NULL || - dbg->dbg_s[DWARF_debug_info].s_scn == NULL) { - /* Missing debug information. */ - DWARF_SET_ERROR(error, DWARF_E_DEBUG_INFO); - return DWARF_E_DEBUG_INFO; - } - - /* Initialise the compilation-units: */ - ret = dwarf_init_info(dbg, error); - - return ret; -} - -int -dwarf_elf_init(Elf *elf, int mode, Dwarf_Debug *ret_dbg, Dwarf_Error *error) -{ - Dwarf_Debug dbg; - int ret = DWARF_E_NONE; - - if (error == NULL) - /* Can only return a generic error. */ - return DWARF_E_ERROR; - - if (elf == NULL || ret_dbg == NULL) { - DWARF_SET_ERROR(error, DWARF_E_ARGUMENT); - ret = DWARF_E_ARGUMENT; - } else if ((dbg = calloc(sizeof(struct _Dwarf_Debug), 1)) == NULL) { - DWARF_SET_ERROR(error, DWARF_E_MEMORY); - ret = DWARF_E_MEMORY; - } else { - dbg->dbg_elf = elf; - dbg->dbg_elf_close = 0; - dbg->dbg_mode = mode; - - STAILQ_INIT(&dbg->dbg_cu); - STAILQ_INIT(&dbg->dbg_func); - - *ret_dbg = dbg; - - /* Read the ELF sections. */ - ret = dwarf_elf_read(dbg, error); - } - - return ret; -} - -int -dwarf_init(int fd, int mode, Dwarf_Debug *ret_dbg, Dwarf_Error *error) -{ - Dwarf_Error lerror; - Elf *elf; - Elf_Cmd c; - int ret; - - if (error == NULL) - /* Can only return a generic error. */ - return DWARF_E_ERROR; - - if (fd < 0 || ret_dbg == NULL) { - DWARF_SET_ERROR(error, DWARF_E_ARGUMENT); - return DWARF_E_ERROR; - } - - /* Translate the DWARF mode to ELF mode. */ - switch (mode) { - default: - case DW_DLC_READ: - c = ELF_C_READ; - break; - } - - if (elf_version(EV_CURRENT) == EV_NONE) { - DWARF_SET_ELF_ERROR(error, elf_errno()); - return DWARF_E_ERROR; - } - - if ((elf = elf_begin(fd, c, NULL)) == NULL) { - DWARF_SET_ELF_ERROR(error, elf_errno()); - return DWARF_E_ERROR; - } - - ret = dwarf_elf_init(elf, mode, ret_dbg, error); - - if (*ret_dbg != NULL) - /* Remember to close the ELF file. */ - (*ret_dbg)->dbg_elf_close = 1; - - if (ret != DWARF_E_NONE) { - if (*ret_dbg != NULL) { - dwarf_finish(ret_dbg, &lerror); - } else - elf_end(elf); - } - - return ret; -} diff --git a/lib/libdwarf/dwarf_loc.c b/lib/libdwarf/dwarf_loc.c deleted file mode 100644 index 12d4cab6249ed..0000000000000 --- a/lib/libdwarf/dwarf_loc.c +++ /dev/null @@ -1,613 +0,0 @@ -/*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <stdlib.h> -#include "_libdwarf.h" - -static int64_t -dwarf_decode_sleb128(uint8_t **dp) -{ - int64_t ret = 0; - uint8_t b; - int shift = 0; - - uint8_t *src = *dp; - - do { - b = *src++; - - ret |= ((b & 0x7f) << shift); - - shift += 7; - } while ((b & 0x80) != 0); - - if (shift < 64 && (b & 0x40) != 0) - ret |= (-1 << shift); - - *dp = src; - - return ret; -} - -static uint64_t -dwarf_decode_uleb128(uint8_t **dp) -{ - uint64_t ret = 0; - uint8_t b; - int shift = 0; - - uint8_t *src = *dp; - - do { - b = *src++; - - ret |= ((b & 0x7f) << shift); - - shift += 7; - } while ((b & 0x80) != 0); - - *dp = src; - - return ret; -} - -/* - * Given an array of bytes of length 'len' representing a - * DWARF expression, compute the number of operations based - * on there being one byte describing the operation and - * zero or more bytes of operands as defined in the standard - * for each operation type. - */ -int -dwarf_op_num(uint8_t pointer_size, uint8_t *p, int len) -{ - int count = 0; - int64_t sval; - uint64_t uval; - uint8_t *last = p + len; - - /* - * Process each byte. If an error occurs, then the - * count will be set to -1. - */ - while (p < last && count >= 0) { - count++; - - switch (*p++) { - /* Operations with no operands. */ - case DW_OP_deref: - case DW_OP_reg0: - case DW_OP_reg1: - case DW_OP_reg2: - case DW_OP_reg3: - case DW_OP_reg4: - case DW_OP_reg5: - case DW_OP_reg6: - case DW_OP_reg7: - case DW_OP_reg8: - case DW_OP_reg9: - case DW_OP_reg10: - case DW_OP_reg11: - case DW_OP_reg12: - case DW_OP_reg13: - case DW_OP_reg14: - case DW_OP_reg15: - case DW_OP_reg16: - case DW_OP_reg17: - case DW_OP_reg18: - case DW_OP_reg19: - case DW_OP_reg20: - case DW_OP_reg21: - case DW_OP_reg22: - case DW_OP_reg23: - case DW_OP_reg24: - case DW_OP_reg25: - case DW_OP_reg26: - case DW_OP_reg27: - case DW_OP_reg28: - case DW_OP_reg29: - case DW_OP_reg30: - case DW_OP_reg31: - - case DW_OP_lit0: - case DW_OP_lit1: - case DW_OP_lit2: - case DW_OP_lit3: - case DW_OP_lit4: - case DW_OP_lit5: - case DW_OP_lit6: - case DW_OP_lit7: - case DW_OP_lit8: - case DW_OP_lit9: - case DW_OP_lit10: - case DW_OP_lit11: - case DW_OP_lit12: - case DW_OP_lit13: - case DW_OP_lit14: - case DW_OP_lit15: - case DW_OP_lit16: - case DW_OP_lit17: - case DW_OP_lit18: - case DW_OP_lit19: - case DW_OP_lit20: - case DW_OP_lit21: - case DW_OP_lit22: - case DW_OP_lit23: - case DW_OP_lit24: - case DW_OP_lit25: - case DW_OP_lit26: - case DW_OP_lit27: - case DW_OP_lit28: - case DW_OP_lit29: - case DW_OP_lit30: - case DW_OP_lit31: - - case DW_OP_dup: - case DW_OP_drop: - - case DW_OP_over: - - case DW_OP_swap: - case DW_OP_rot: - case DW_OP_xderef: - - case DW_OP_abs: - case DW_OP_and: - case DW_OP_div: - case DW_OP_minus: - case DW_OP_mod: - case DW_OP_mul: - case DW_OP_neg: - case DW_OP_not: - case DW_OP_or: - case DW_OP_plus: - - case DW_OP_shl: - case DW_OP_shr: - case DW_OP_shra: - case DW_OP_xor: - - case DW_OP_eq: - case DW_OP_ge: - case DW_OP_gt: - case DW_OP_le: - case DW_OP_lt: - case DW_OP_ne: - - case DW_OP_nop: - break; - - /* Operations with 1-byte operands. */ - case DW_OP_const1u: - case DW_OP_const1s: - case DW_OP_pick: - case DW_OP_deref_size: - case DW_OP_xderef_size: - p++; - break; - - /* Operations with 2-byte operands. */ - case DW_OP_const2u: - case DW_OP_const2s: - case DW_OP_bra: - case DW_OP_skip: - p += 2; - break; - - /* Operations with 4-byte operands. */ - case DW_OP_const4u: - case DW_OP_const4s: - p += 4; - break; - - /* Operations with 8-byte operands. */ - case DW_OP_const8u: - case DW_OP_const8s: - p += 8; - break; - - /* Operations with an unsigned LEB128 operand. */ - case DW_OP_constu: - case DW_OP_plus_uconst: - case DW_OP_regx: - case DW_OP_piece: - uval = dwarf_decode_uleb128(&p); - break; - - /* Operations with a signed LEB128 operand. */ - case DW_OP_consts: - case DW_OP_breg0: - case DW_OP_breg1: - case DW_OP_breg2: - case DW_OP_breg3: - case DW_OP_breg4: - case DW_OP_breg5: - case DW_OP_breg6: - case DW_OP_breg7: - case DW_OP_breg8: - case DW_OP_breg9: - case DW_OP_breg10: - case DW_OP_breg11: - case DW_OP_breg12: - case DW_OP_breg13: - case DW_OP_breg14: - case DW_OP_breg15: - case DW_OP_breg16: - case DW_OP_breg17: - case DW_OP_breg18: - case DW_OP_breg19: - case DW_OP_breg20: - case DW_OP_breg21: - case DW_OP_breg22: - case DW_OP_breg23: - case DW_OP_breg24: - case DW_OP_breg25: - case DW_OP_breg26: - case DW_OP_breg27: - case DW_OP_breg28: - case DW_OP_breg29: - case DW_OP_breg30: - case DW_OP_breg31: - case DW_OP_fbreg: - sval = dwarf_decode_sleb128(&p); - break; - - /* - * Operations with an unsigned LEB128 operand - * followed by a signed LEB128 operand. - */ - case DW_OP_bregx: - uval = dwarf_decode_uleb128(&p); - sval = dwarf_decode_sleb128(&p); - break; - - /* Target address size operand. */ - case DW_OP_addr: - p += pointer_size; - break; - - /* All other operations cause an error. */ - default: - count = -1; - break; - } - } - - return count; -} - -static int -dwarf_loc_fill(Dwarf_Locdesc *lbuf, uint8_t pointer_size, uint8_t *p, int len) -{ - int count = 0; - int ret = DWARF_E_NONE; - uint64_t operand1; - uint64_t operand2; - uint8_t *last = p + len; - - /* - * Process each byte. If an error occurs, then the - * count will be set to -1. - */ - while (p < last && ret == DWARF_E_NONE) { - operand1 = 0; - operand2 = 0; - - lbuf->ld_s[count].lr_atom = *p; - - switch (*p++) { - /* Operations with no operands. */ - case DW_OP_deref: - case DW_OP_reg0: - case DW_OP_reg1: - case DW_OP_reg2: - case DW_OP_reg3: - case DW_OP_reg4: - case DW_OP_reg5: - case DW_OP_reg6: - case DW_OP_reg7: - case DW_OP_reg8: - case DW_OP_reg9: - case DW_OP_reg10: - case DW_OP_reg11: - case DW_OP_reg12: - case DW_OP_reg13: - case DW_OP_reg14: - case DW_OP_reg15: - case DW_OP_reg16: - case DW_OP_reg17: - case DW_OP_reg18: - case DW_OP_reg19: - case DW_OP_reg20: - case DW_OP_reg21: - case DW_OP_reg22: - case DW_OP_reg23: - case DW_OP_reg24: - case DW_OP_reg25: - case DW_OP_reg26: - case DW_OP_reg27: - case DW_OP_reg28: - case DW_OP_reg29: - case DW_OP_reg30: - case DW_OP_reg31: - - case DW_OP_lit0: - case DW_OP_lit1: - case DW_OP_lit2: - case DW_OP_lit3: - case DW_OP_lit4: - case DW_OP_lit5: - case DW_OP_lit6: - case DW_OP_lit7: - case DW_OP_lit8: - case DW_OP_lit9: - case DW_OP_lit10: - case DW_OP_lit11: - case DW_OP_lit12: - case DW_OP_lit13: - case DW_OP_lit14: - case DW_OP_lit15: - case DW_OP_lit16: - case DW_OP_lit17: - case DW_OP_lit18: - case DW_OP_lit19: - case DW_OP_lit20: - case DW_OP_lit21: - case DW_OP_lit22: - case DW_OP_lit23: - case DW_OP_lit24: - case DW_OP_lit25: - case DW_OP_lit26: - case DW_OP_lit27: - case DW_OP_lit28: - case DW_OP_lit29: - case DW_OP_lit30: - case DW_OP_lit31: - - case DW_OP_dup: - case DW_OP_drop: - - case DW_OP_over: - - case DW_OP_swap: - case DW_OP_rot: - case DW_OP_xderef: - - case DW_OP_abs: - case DW_OP_and: - case DW_OP_div: - case DW_OP_minus: - case DW_OP_mod: - case DW_OP_mul: - case DW_OP_neg: - case DW_OP_not: - case DW_OP_or: - case DW_OP_plus: - - case DW_OP_shl: - case DW_OP_shr: - case DW_OP_shra: - case DW_OP_xor: - - case DW_OP_eq: - case DW_OP_ge: - case DW_OP_gt: - case DW_OP_le: - case DW_OP_lt: - case DW_OP_ne: - - case DW_OP_nop: - break; - - /* Operations with 1-byte operands. */ - case DW_OP_const1u: - case DW_OP_const1s: - case DW_OP_pick: - case DW_OP_deref_size: - case DW_OP_xderef_size: - operand1 = *p++; - break; - - /* Operations with 2-byte operands. */ - case DW_OP_const2u: - case DW_OP_const2s: - case DW_OP_bra: - case DW_OP_skip: - p += 2; - break; - - /* Operations with 4-byte operands. */ - case DW_OP_const4u: - case DW_OP_const4s: - p += 4; - break; - - /* Operations with 8-byte operands. */ - case DW_OP_const8u: - case DW_OP_const8s: - p += 8; - break; - - /* Operations with an unsigned LEB128 operand. */ - case DW_OP_constu: - case DW_OP_plus_uconst: - case DW_OP_regx: - case DW_OP_piece: - operand1 = dwarf_decode_uleb128(&p); - break; - - /* Operations with a signed LEB128 operand. */ - case DW_OP_consts: - case DW_OP_breg0: - case DW_OP_breg1: - case DW_OP_breg2: - case DW_OP_breg3: - case DW_OP_breg4: - case DW_OP_breg5: - case DW_OP_breg6: - case DW_OP_breg7: - case DW_OP_breg8: - case DW_OP_breg9: - case DW_OP_breg10: - case DW_OP_breg11: - case DW_OP_breg12: - case DW_OP_breg13: - case DW_OP_breg14: - case DW_OP_breg15: - case DW_OP_breg16: - case DW_OP_breg17: - case DW_OP_breg18: - case DW_OP_breg19: - case DW_OP_breg20: - case DW_OP_breg21: - case DW_OP_breg22: - case DW_OP_breg23: - case DW_OP_breg24: - case DW_OP_breg25: - case DW_OP_breg26: - case DW_OP_breg27: - case DW_OP_breg28: - case DW_OP_breg29: - case DW_OP_breg30: - case DW_OP_breg31: - case DW_OP_fbreg: - operand1 = dwarf_decode_sleb128(&p); - break; - - /* - * Operations with an unsigned LEB128 operand - * followed by a signed LEB128 operand. - */ - case DW_OP_bregx: - operand1 = dwarf_decode_uleb128(&p); - operand2 = dwarf_decode_sleb128(&p); - break; - - /* Target address size operand. */ - case DW_OP_addr: - p += pointer_size; - break; - - /* All other operations cause an error. */ - default: - break; - } - - lbuf->ld_s[count].lr_number = operand1; - lbuf->ld_s[count].lr_number2 = operand2; - - count++; - } - - return ret; -} - -int -dwarf_locdesc(Dwarf_Die die, uint64_t attr, Dwarf_Locdesc **llbuf, Dwarf_Signed *lenp, Dwarf_Error *err) -{ - Dwarf_AttrValue av; - Dwarf_Locdesc *lbuf; - int num; - int ret = DWARF_E_NONE; - - if (err == NULL) - return DWARF_E_ERROR; - - if (die == NULL || llbuf == NULL || lenp == NULL) { - DWARF_SET_ERROR(err, DWARF_E_ARGUMENT); - return DWARF_E_ARGUMENT; - } - - if ((av = dwarf_attrval_find(die, attr)) == NULL) { - DWARF_SET_ERROR(err, DWARF_E_NO_ENTRY); - ret = DWARF_E_NO_ENTRY; - } else if ((lbuf = calloc(sizeof(Dwarf_Locdesc), 1)) == NULL) { - DWARF_SET_ERROR(err, DWARF_E_MEMORY); - ret = DWARF_E_MEMORY; - } else { - *lenp = 0; - switch (av->av_form) { - case DW_FORM_block: - case DW_FORM_block1: - case DW_FORM_block2: - case DW_FORM_block4: - /* Compute the number of locations: */ - if ((num = dwarf_op_num(die->die_cu->cu_pointer_size, - av->u[1].u8p, av->u[0].u64)) < 0) { - DWARF_SET_ERROR(err, DWARF_E_INVALID_EXPR); - ret = DWARF_E_INVALID_EXPR; - - /* Allocate an array of location structures. */ - } else if ((lbuf->ld_s = - calloc(sizeof(Dwarf_Loc), num)) == NULL) { - DWARF_SET_ERROR(err, DWARF_E_MEMORY); - ret = DWARF_E_MEMORY; - - /* Fill the array of location structures. */ - } else if ((ret = dwarf_loc_fill(lbuf, - die->die_cu->cu_pointer_size, - av->u[1].u8p, av->u[0].u64)) != DWARF_E_NONE) { - free(lbuf->ld_s); - } else - /* Only one descriptor is returned. */ - *lenp = 1; - break; - default: - printf("%s(%d): form %s not handled\n",__func__, - __LINE__,get_form_desc(av->av_form)); - DWARF_SET_ERROR(err, DWARF_E_NOT_IMPLEMENTED); - ret = DWARF_E_ERROR; - } - - if (ret == DWARF_E_NONE) { - *llbuf = lbuf; - } else - free(lbuf); - } - - return ret; -} - -int -dwarf_locdesc_free(Dwarf_Locdesc *lbuf, Dwarf_Error *err) -{ - if (err == NULL) - return DWARF_E_ERROR; - - if (lbuf == NULL) { - DWARF_SET_ERROR(err, DWARF_E_ARGUMENT); - return DWARF_E_ARGUMENT; - } - - if (lbuf->ld_s != NULL) - free(lbuf->ld_s); - - free(lbuf); - - return DWARF_E_NONE; -} diff --git a/lib/libdwarf/libdwarf.h b/lib/libdwarf/libdwarf.h deleted file mode 100644 index 04192b7ead646..0000000000000 --- a/lib/libdwarf/libdwarf.h +++ /dev/null @@ -1,176 +0,0 @@ -/*- - * Copyright (c) 2007 John Birrell (jb@freebsd.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _LIBDWARF_H_ -#define _LIBDWARF_H_ - -#include <libelf.h> - -typedef int Dwarf_Bool; -typedef off_t Dwarf_Off; -typedef uint64_t Dwarf_Unsigned; -typedef uint16_t Dwarf_Half; -typedef uint8_t Dwarf_Small; -typedef int64_t Dwarf_Signed; -typedef uint64_t Dwarf_Addr; -typedef void *Dwarf_Ptr; - -/* Forward definitions. */ -typedef struct _Dwarf_Abbrev *Dwarf_Abbrev; -typedef struct _Dwarf_Arange *Dwarf_Arange; -typedef struct _Dwarf_Attribute *Dwarf_Attribute; -typedef struct _Dwarf_AttrValue *Dwarf_AttrValue; -typedef struct _Dwarf_CU *Dwarf_CU; -typedef struct _Dwarf_Cie *Dwarf_Cie; -typedef struct _Dwarf_Debug *Dwarf_Debug; -typedef struct _Dwarf_Die *Dwarf_Die; -typedef struct _Dwarf_Fde *Dwarf_Fde; -typedef struct _Dwarf_Func *Dwarf_Func; -typedef struct _Dwarf_Inlined_Func *Dwarf_Inlined_Func; -typedef struct _Dwarf_Global *Dwarf_Global; -typedef struct _Dwarf_Line *Dwarf_Line; -typedef struct _Dwarf_Type *Dwarf_Type; -typedef struct _Dwarf_Var *Dwarf_Var; -typedef struct _Dwarf_Weak *Dwarf_Weak; - -typedef struct { - Dwarf_Small lr_atom; - Dwarf_Unsigned lr_number; - Dwarf_Unsigned lr_number2; - Dwarf_Unsigned lr_offset; -} Dwarf_Loc; - -typedef struct { - Dwarf_Addr ld_lopc; - Dwarf_Addr ld_hipc; - Dwarf_Half ld_cents; - Dwarf_Loc *ld_s; -} Dwarf_Locdesc; - -/* receiver function for dwarf_function_iterate_inlined_instance() API */ -typedef void (*Dwarf_Inlined_Callback)(Dwarf_Inlined_Func, void *); - -/* - * Error numbers which are specific to this implementation. - */ -enum { - DWARF_E_NONE, /* No error. */ - DWARF_E_ERROR, /* An error! */ - DWARF_E_NO_ENTRY, /* No entry. */ - DWARF_E_ARGUMENT, /* Invalid argument. */ - DWARF_E_DEBUG_INFO, /* Debug info NULL. */ - DWARF_E_MEMORY, /* Insufficient memory. */ - DWARF_E_ELF, /* ELF error. */ - DWARF_E_INVALID_CU, /* Invalid compilation unit data. */ - DWARF_E_CU_VERSION, /* Wrong CU version. */ - DWARF_E_MISSING_ABBREV, /* Abbrev not found. */ - DWARF_E_NOT_IMPLEMENTED, /* Not implemented. */ - DWARF_E_CU_CURRENT, /* No current compilation unit. */ - DWARF_E_BAD_FORM, /* Wrong form type for attribute value. */ - DWARF_E_INVALID_EXPR, /* Invalid DWARF expression. */ - DWARF_E_NUM /* Max error number. */ -}; - -typedef struct _Dwarf_Error { - int err_error; /* DWARF error. */ - int elf_error; /* ELF error. */ - const char *err_func; /* Function name where error occurred. */ - int err_line; /* Line number where error occurred. */ - char err_msg[1024]; /* Formatted error message. */ -} Dwarf_Error; - -/* - * Return values which have to be compatible with other - * implementations of libdwarf. - */ -#define DW_DLV_NO_ENTRY DWARF_E_NO_ENTRY -#define DW_DLV_OK DWARF_E_NONE -#define DW_DLE_DEBUG_INFO_NULL DWARF_E_DEBUG_INFO - -#define DW_DLC_READ 0 /* read only access */ - -/* Function prototype definitions. */ -__BEGIN_DECLS -Dwarf_Abbrev dwarf_abbrev_find(Dwarf_CU, uint64_t); -Dwarf_AttrValue dwarf_attrval_find(Dwarf_Die, Dwarf_Half); -Dwarf_Die dwarf_die_find(Dwarf_Die, Dwarf_Unsigned); -const char *dwarf_errmsg(Dwarf_Error *); -const char *get_sht_desc(uint32_t); -const char *get_attr_desc(uint32_t); -const char *get_form_desc(uint32_t); -const char *get_tag_desc(uint32_t); -int dwarf_abbrev_add(Dwarf_CU, uint64_t, uint64_t, uint8_t, Dwarf_Abbrev *, Dwarf_Error *); -int dwarf_attr(Dwarf_Die, Dwarf_Half, Dwarf_Attribute *, Dwarf_Error *); -int dwarf_attr_add(Dwarf_Abbrev, uint64_t, uint64_t, Dwarf_Attribute *, Dwarf_Error *); -int dwarf_attrval(Dwarf_Die, Dwarf_Half, Dwarf_AttrValue *, Dwarf_Error *); -int dwarf_attrval_add(Dwarf_Die, Dwarf_AttrValue, Dwarf_AttrValue *, Dwarf_Error *); -int dwarf_attrval_flag(Dwarf_Die, uint64_t, Dwarf_Bool *, Dwarf_Error *); -int dwarf_attrval_signed(Dwarf_Die, uint64_t, Dwarf_Signed *, Dwarf_Error *); -int dwarf_attrval_string(Dwarf_Die, uint64_t, const char **, Dwarf_Error *); -int dwarf_attrval_unsigned(Dwarf_Die, uint64_t, Dwarf_Unsigned *, Dwarf_Error *); -int dwarf_child(Dwarf_Die, Dwarf_Die *, Dwarf_Error *); -int dwarf_die_add(Dwarf_CU, int, uint64_t, uint64_t, Dwarf_Abbrev, Dwarf_Die *, Dwarf_Error *); -int dwarf_dieoffset(Dwarf_Die, Dwarf_Off *, Dwarf_Error *); -int dwarf_elf_init(Elf *, int, Dwarf_Debug *, Dwarf_Error *); -int dwarf_errno(Dwarf_Error *); -int dwarf_finish(Dwarf_Debug *, Dwarf_Error *); -int dwarf_locdesc(Dwarf_Die, uint64_t, Dwarf_Locdesc **, Dwarf_Signed *, Dwarf_Error *); -int dwarf_locdesc_free(Dwarf_Locdesc *, Dwarf_Error *); -int dwarf_init(int, int, Dwarf_Debug *, Dwarf_Error *); -int dwarf_next_cu_header(Dwarf_Debug, Dwarf_Unsigned *, Dwarf_Half *, - Dwarf_Unsigned *, Dwarf_Half *, Dwarf_Unsigned *, Dwarf_Error *); -int dwarf_op_num(uint8_t, uint8_t *, int); -int dwarf_siblingof(Dwarf_Debug, Dwarf_Die, Dwarf_Die *, Dwarf_Error *); -int dwarf_tag(Dwarf_Die, Dwarf_Half *, Dwarf_Error *); -int dwarf_whatform(Dwarf_Attribute, Dwarf_Half *, Dwarf_Error *); -void dwarf_dealloc(Dwarf_Debug, Dwarf_Ptr, Dwarf_Unsigned); -void dwarf_dump(Dwarf_Debug); -void dwarf_dump_abbrev(Dwarf_Debug); -void dwarf_dump_av(Dwarf_Die, Dwarf_AttrValue); -void dwarf_dump_dbgstr(Dwarf_Debug); -void dwarf_dump_die(Dwarf_Die); -void dwarf_dump_die_at_offset(Dwarf_Debug, Dwarf_Off); -void dwarf_dump_info(Dwarf_Debug); -void dwarf_dump_shstrtab(Dwarf_Debug); -void dwarf_dump_strtab(Dwarf_Debug); -void dwarf_dump_symtab(Dwarf_Debug); -void dwarf_dump_raw(Dwarf_Debug); -void dwarf_dump_tree(Dwarf_Debug); -Dwarf_Func dwarf_find_function_by_offset(Dwarf_Debug dbg, Dwarf_Off off); -Dwarf_Func dwarf_find_function_by_name(Dwarf_Debug dbg, const char *name); -int dwarf_function_get_addr_range(Dwarf_Func f, - Dwarf_Addr *low_pc, Dwarf_Addr *high_pc); -int dwarf_function_is_inlined(Dwarf_Func f); -void dwarf_function_iterate_inlined_instance(Dwarf_Func func, - Dwarf_Inlined_Callback f, void *data); -int dwarf_inlined_function_get_addr_range(Dwarf_Inlined_Func f, - Dwarf_Addr *low_pc, Dwarf_Addr *high_pc); - -__END_DECLS - -#endif /* !_LIBDWARF_H_ */ diff --git a/lib/libiconv/Makefile b/lib/libiconv/Makefile index 71c288573256f..19495976e8711 100644 --- a/lib/libiconv/Makefile +++ b/lib/libiconv/Makefile @@ -19,6 +19,7 @@ SRCS= citrus_bcs.c citrus_bcs_strtol.c citrus_bcs_strtoul.c \ citrus_module.c citrus_none.c citrus_pivot_factory.c \ citrus_prop.c citrus_stdenc.c iconv.c -CFLAGS+= --param max-inline-insns-single=128 -I ${.CURDIR}/../../include -I${.CURDIR}/../libc/include +CFLAGS.gcc+= --param max-inline-insns-single=128 +CFLAGS+= -I ${.CURDIR}/../../include -I${.CURDIR}/../libc/include .include <bsd.lib.mk> diff --git a/lib/libmd/Makefile b/lib/libmd/Makefile index d0fe7054fa4db..727fd86217169 100644 --- a/lib/libmd/Makefile +++ b/lib/libmd/Makefile @@ -43,7 +43,7 @@ CLEANFILES+= md[245]hl.c md[245].ref md[245].3 mddriver \ sha256.ref sha256hl.c sha512.ref sha512hl.c CFLAGS+= -I${.CURDIR} -.PATH: ${.CURDIR}/${MACHINE_ARCH} +.PATH: ${.CURDIR}/${MACHINE_ARCH} ${.CURDIR}/../../sys/crypto/sha2 .if exists(${MACHINE_ARCH}/sha.S) SRCS+= sha.S diff --git a/lib/libmd/ripemd.3 b/lib/libmd/ripemd.3 index 6c2f21c79ae3c..2c9d2d3c8cc3a 100644 --- a/lib/libmd/ripemd.3 +++ b/lib/libmd/ripemd.3 @@ -9,7 +9,7 @@ .\" From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp .\" $FreeBSD$ .\" -.Dd February 26, 1999 +.Dd March 28, 2014 .Dt RIPEMD 3 .Os .Sh NAME @@ -123,7 +123,6 @@ If the .Fa buf argument is non-null it must point to at least 41 characters of buffer space. .Sh SEE ALSO -.Xr md2 3 , .Xr md4 3 , .Xr md5 3 , .Xr sha 3 diff --git a/lib/libmd/sha.3 b/lib/libmd/sha.3 index f4e2f192b5395..fe5c339d15db6 100644 --- a/lib/libmd/sha.3 +++ b/lib/libmd/sha.3 @@ -9,7 +9,7 @@ .\" From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp .\" $FreeBSD$ .\" -.Dd February 25, 1999 +.Dd March 28, 2014 .Dt SHA 3 .Os .Sh NAME @@ -154,7 +154,6 @@ If the .Fa buf argument is non-null it must point to at least 41 characters of buffer space. .Sh SEE ALSO -.Xr md2 3 , .Xr md4 3 , .Xr md5 3 , .Xr ripemd 3 , diff --git a/lib/libmd/sha256.3 b/lib/libmd/sha256.3 index f40e6dfd8b4c8..6117e70987b50 100644 --- a/lib/libmd/sha256.3 +++ b/lib/libmd/sha256.3 @@ -9,7 +9,7 @@ .\" From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp .\" $FreeBSD$ .\" -.Dd September 14, 2005 +.Dd March 28, 2014 .Dt SHA256 3 .Os .Sh NAME @@ -120,7 +120,6 @@ If the .Fa buf argument is non-null it must point to at least 65 characters of buffer space. .Sh SEE ALSO -.Xr md2 3 , .Xr md4 3 , .Xr md5 3 , .Xr ripemd 3 , diff --git a/lib/libmd/sha256.h b/lib/libmd/sha256.h index ce51787a737ea..1b6a4f4c57557 100644 --- a/lib/libmd/sha256.h +++ b/lib/libmd/sha256.h @@ -33,7 +33,7 @@ typedef struct SHA256Context { uint32_t state[8]; - uint32_t count[2]; + uint64_t count; unsigned char buf[64]; } SHA256_CTX; diff --git a/lib/libmd/sha256c.c b/lib/libmd/sha256c.c index c95fd318a5aa5..76cec8ec3815e 100644 --- a/lib/libmd/sha256c.c +++ b/lib/libmd/sha256c.c @@ -208,10 +208,10 @@ SHA256_Pad(SHA256_CTX * ctx) * Convert length to a vector of bytes -- we do this now rather * than later because the length will change after we pad. */ - be32enc_vect(len, ctx->count, 8); + be64enc(len, ctx->count); /* Add 1--64 bytes so that the resulting length is 56 mod 64 */ - r = (ctx->count[1] >> 3) & 0x3f; + r = (ctx->count >> 3) & 0x3f; plen = (r < 56) ? (56 - r) : (120 - r); SHA256_Update(ctx, PAD, (size_t)plen); @@ -225,7 +225,7 @@ SHA256_Init(SHA256_CTX * ctx) { /* Zero bits processed so far */ - ctx->count[0] = ctx->count[1] = 0; + ctx->count = 0; /* Magic initialization constants */ ctx->state[0] = 0x6A09E667; @@ -242,21 +242,18 @@ SHA256_Init(SHA256_CTX * ctx) void SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len) { - uint32_t bitlen[2]; + uint64_t bitlen; uint32_t r; const unsigned char *src = in; /* Number of bytes left in the buffer from previous updates */ - r = (ctx->count[1] >> 3) & 0x3f; + r = (ctx->count >> 3) & 0x3f; /* Convert the length into a number of bits */ - bitlen[1] = ((uint32_t)len) << 3; - bitlen[0] = (uint32_t)(len >> 29); + bitlen = len << 3; /* Update number of bits */ - if ((ctx->count[1] += bitlen[1]) < bitlen[1]) - ctx->count[0]++; - ctx->count[0] += bitlen[0]; + ctx->count += bitlen; /* Handle the case where we don't need to perform any transforms */ if (len < 64 - r) { diff --git a/lib/libmd/sha512.3 b/lib/libmd/sha512.3 index 953ee25539a70..bcb52522088a0 100644 --- a/lib/libmd/sha512.3 +++ b/lib/libmd/sha512.3 @@ -9,7 +9,7 @@ .\" From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp .\" $FreeBSD$ .\" -.Dd April 1, 2011 +.Dd March 28, 2014 .Dt SHA512 3 .Os .Sh NAME @@ -120,7 +120,6 @@ If the .Fa buf argument is non-null it must point to at least 65 characters of buffer space. .Sh SEE ALSO -.Xr md2 3 , .Xr md4 3 , .Xr md5 3 , .Xr ripemd 3 , diff --git a/lib/libvmmapi/vmmapi_freebsd.c b/lib/libvmmapi/vmmapi_freebsd.c index 9bd2988129ebc..d8011845541b9 100644 --- a/lib/libvmmapi/vmmapi_freebsd.c +++ b/lib/libvmmapi/vmmapi_freebsd.c @@ -35,14 +35,176 @@ __FBSDID("$FreeBSD$"); #include <machine/segments.h> #include <machine/vmm.h> +#include <errno.h> +#include <string.h> + #include "vmmapi.h" +#define I386_TSS_SIZE 104 + +#define DESC_PRESENT 0x00000080 +#define DESC_LONGMODE 0x00002000 +#define DESC_DEF32 0x00004000 +#define DESC_GRAN 0x00008000 #define DESC_UNUSABLE 0x00010000 #define GUEST_NULL_SEL 0 #define GUEST_CODE_SEL 1 #define GUEST_DATA_SEL 2 -#define GUEST_GDTR_LIMIT (3 * 8 - 1) +#define GUEST_TSS_SEL 3 +#define GUEST_GDTR_LIMIT64 (3 * 8 - 1) + +static struct segment_descriptor i386_gdt[] = { + {}, /* NULL */ + { .sd_lolimit = 0xffff, .sd_type = SDT_MEMER, /* CODE */ + .sd_p = 1, .sd_hilimit = 0xf, .sd_def32 = 1, .sd_gran = 1 }, + { .sd_lolimit = 0xffff, .sd_type = SDT_MEMRW, /* DATA */ + .sd_p = 1, .sd_hilimit = 0xf, .sd_def32 = 1, .sd_gran = 1 }, + { .sd_lolimit = I386_TSS_SIZE - 1, /* TSS */ + .sd_type = SDT_SYS386TSS, .sd_p = 1 } +}; + +/* + * Setup the 'vcpu' register set such that it will begin execution at + * 'eip' in flat mode. + */ +int +vm_setup_freebsd_registers_i386(struct vmctx *vmctx, int vcpu, uint32_t eip, + uint32_t gdtbase, uint32_t esp) +{ + uint64_t cr0, rflags, desc_base; + uint32_t desc_access, desc_limit, tssbase; + uint16_t gsel; + struct segment_descriptor *gdt; + int error, tmp; + + /* A 32-bit guest requires unrestricted mode. */ + error = vm_get_capability(vmctx, vcpu, VM_CAP_UNRESTRICTED_GUEST, &tmp); + if (error) + goto done; + error = vm_set_capability(vmctx, vcpu, VM_CAP_UNRESTRICTED_GUEST, 1); + if (error) + goto done; + + cr0 = CR0_PE | CR0_NE; + if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR0, cr0)) != 0) + goto done; + + if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR4, 0)) != 0) + goto done; + + /* + * Forcing EFER to 0 causes bhyve to clear the "IA-32e guest + * mode" entry control. + */ + if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_EFER, 0))) + goto done; + + gdt = vm_map_gpa(vmctx, gdtbase, 0x1000); + if (gdt == NULL) + return (EFAULT); + memcpy(gdt, i386_gdt, sizeof(i386_gdt)); + desc_base = gdtbase; + desc_limit = sizeof(i386_gdt) - 1; + error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_GDTR, + desc_base, desc_limit, 0); + if (error != 0) + goto done; + + /* Place the TSS one page above the GDT. */ + tssbase = gdtbase + 0x1000; + gdt[3].sd_lobase = tssbase; + + rflags = 0x2; + error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RFLAGS, rflags); + if (error) + goto done; + + desc_base = 0; + desc_limit = 0xffffffff; + desc_access = DESC_GRAN | DESC_DEF32 | DESC_PRESENT | SDT_MEMERA; + error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_CS, + desc_base, desc_limit, desc_access); + + desc_access = DESC_GRAN | DESC_DEF32 | DESC_PRESENT | SDT_MEMRWA; + error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_DS, + desc_base, desc_limit, desc_access); + if (error) + goto done; + + error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_ES, + desc_base, desc_limit, desc_access); + if (error) + goto done; + + error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_FS, + desc_base, desc_limit, desc_access); + if (error) + goto done; + + error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_GS, + desc_base, desc_limit, desc_access); + if (error) + goto done; + + error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_SS, + desc_base, desc_limit, desc_access); + if (error) + goto done; + + desc_base = tssbase; + desc_limit = I386_TSS_SIZE - 1; + desc_access = DESC_PRESENT | SDT_SYS386BSY; + error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_TR, + desc_base, desc_limit, desc_access); + if (error) + goto done; + + + error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_LDTR, 0, 0, + DESC_UNUSABLE); + if (error) + goto done; + + gsel = GSEL(GUEST_CODE_SEL, SEL_KPL); + if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CS, gsel)) != 0) + goto done; + + gsel = GSEL(GUEST_DATA_SEL, SEL_KPL); + if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_DS, gsel)) != 0) + goto done; + + if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_ES, gsel)) != 0) + goto done; + + if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_FS, gsel)) != 0) + goto done; + + if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_GS, gsel)) != 0) + goto done; + + if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_SS, gsel)) != 0) + goto done; + + gsel = GSEL(GUEST_TSS_SEL, SEL_KPL); + if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_TR, gsel)) != 0) + goto done; + + /* LDTR is pointing to the null selector */ + if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_LDTR, 0)) != 0) + goto done; + + /* entry point */ + if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RIP, eip)) != 0) + goto done; + + if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RSP, esp)) != 0) + goto done; + + error = 0; +done: + return (error); +} void vm_setup_freebsd_gdt(uint64_t *gdtr) @@ -168,7 +330,7 @@ vm_setup_freebsd_registers(struct vmctx *vmctx, int vcpu, goto done; desc_base = gdtbase; - desc_limit = GUEST_GDTR_LIMIT; + desc_limit = GUEST_GDTR_LIMIT64; error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_GDTR, desc_base, desc_limit, 0); if (error != 0) |
