blob: 55684f7023d277a12d87885fbfa6ad607963ad32 [file] [log] [blame]
Gabor Greife16561c2007-07-05 17:07:56 +00001//===-- lib/Archive/ArchiveInternals.h -------------------------*- C++ -*-===//
Chris Lattner5b183222007-05-06 19:49:28 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner5b183222007-05-06 19:49:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// Internal implementation header for LLVM Archive files.
11//
12//===----------------------------------------------------------------------===//
13
Gabor Greife16561c2007-07-05 17:07:56 +000014#ifndef LIB_ARCHIVE_ARCHIVEINTERNALS_H
15#define LIB_ARCHIVE_ARCHIVEINTERNALS_H
Chris Lattner5b183222007-05-06 19:49:28 +000016
17#include "llvm/Bitcode/Archive.h"
Michael J. Spencer447762d2010-11-29 18:16:10 +000018#include "llvm/Support/TimeValue.h"
Chris Lattner5b183222007-05-06 19:49:28 +000019#include "llvm/ADT/StringExtras.h"
20
Anton Korobeynikov579f0712008-02-20 11:08:44 +000021#include <cstring>
22
Chris Lattner5b183222007-05-06 19:49:28 +000023#define ARFILE_MAGIC "!<arch>\n" ///< magic string
24#define ARFILE_MAGIC_LEN (sizeof(ARFILE_MAGIC)-1) ///< length of magic string
25#define ARFILE_SVR4_SYMTAB_NAME "/ " ///< SVR4 symtab entry name
26#define ARFILE_LLVM_SYMTAB_NAME "#_LLVM_SYM_TAB_#" ///< LLVM symtab entry name
27#define ARFILE_BSD4_SYMTAB_NAME "__.SYMDEF SORTED" ///< BSD4 symtab entry name
28#define ARFILE_STRTAB_NAME "// " ///< Name of string table
29#define ARFILE_PAD "\n" ///< inter-file align padding
30#define ARFILE_MEMBER_MAGIC "`\n" ///< fmag field magic #
31
32namespace llvm {
33
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +000034 class LLVMContext;
Owen Anderson6773d382009-07-01 16:58:40 +000035
Gabor Greife16561c2007-07-05 17:07:56 +000036 /// The ArchiveMemberHeader structure is used internally for bitcode
Chris Lattner5b183222007-05-06 19:49:28 +000037 /// archives.
38 /// The header precedes each file member in the archive. This structure is
39 /// defined using character arrays for direct and correct interpretation
40 /// regardless of the endianess of the machine that produced it.
41 /// @brief Archive File Member Header
42 class ArchiveMemberHeader {
43 /// @name Data
44 /// @{
45 public:
46 char name[16]; ///< Name of the file member.
47 char date[12]; ///< File date, decimal seconds since Epoch
48 char uid[6]; ///< user id in ASCII decimal
49 char gid[6]; ///< group id in ASCII decimal
50 char mode[8]; ///< file mode in ASCII octal
51 char size[10]; ///< file size in ASCII decimal
52 char fmag[2]; ///< Always contains ARFILE_MAGIC_TERMINATOR
53
54 /// @}
55 /// @name Methods
56 /// @{
57 public:
58 void init() {
59 memset(name,' ',16);
60 memset(date,' ',12);
61 memset(uid,' ',6);
62 memset(gid,' ',6);
63 memset(mode,' ',8);
64 memset(size,' ',10);
65 fmag[0] = '`';
66 fmag[1] = '\n';
67 }
68
69 bool checkSignature() {
70 return 0 == memcmp(fmag, ARFILE_MEMBER_MAGIC,2);
71 }
72 };
73
Gabor Greife16561c2007-07-05 17:07:56 +000074 // Get just the externally visible defined symbols from the bitcode
75 bool GetBitcodeSymbols(const sys::Path& fName,
Owen Anderson2a154432009-07-01 23:13:44 +000076 LLVMContext& Context,
Chris Lattner5b183222007-05-06 19:49:28 +000077 std::vector<std::string>& symbols,
78 std::string* ErrMsg);
79
Benjamin Kramer3576b742010-04-19 16:15:31 +000080 Module* GetBitcodeSymbols(const char *Buffer, unsigned Length,
Jeffrey Yasskin091217b2010-01-27 20:34:15 +000081 const std::string& ModuleID,
82 LLVMContext& Context,
83 std::vector<std::string>& symbols,
84 std::string* ErrMsg);
Chris Lattner5b183222007-05-06 19:49:28 +000085}
86
87#endif
88
89// vim: sw=2 ai