blob: f6c87e899f25b498c8850d4b62be5023d55ef207 [file] [log] [blame]
Gabor Greifa99be512007-07-05 17:07:56 +00001//===-- lib/Archive/ArchiveInternals.h -------------------------*- C++ -*-===//
Misha Brukman2b37d7c2005-04-21 21:13:18 +00002//
Reid Spencer362cbf02004-11-06 08:51:45 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman2b37d7c2005-04-21 21:13:18 +00007//
Reid Spencer362cbf02004-11-06 08:51:45 +00008//===----------------------------------------------------------------------===//
9//
10// Internal implementation header for LLVM Archive files.
11//
12//===----------------------------------------------------------------------===//
13
Gabor Greifa99be512007-07-05 17:07:56 +000014#ifndef LIB_ARCHIVE_ARCHIVEINTERNALS_H
15#define LIB_ARCHIVE_ARCHIVEINTERNALS_H
Reid Spencer362cbf02004-11-06 08:51:45 +000016
Chandler Carrutha1514e22012-12-04 07:12:27 +000017#include "llvm/ADT/StringExtras.h"
Chris Lattnerc1d56242007-05-06 09:28:33 +000018#include "llvm/Bitcode/Archive.h"
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000019#include "llvm/Support/TimeValue.h"
Anton Korobeynikovae9f3a32008-02-20 11:08:44 +000020#include <cstring>
21
Misha Brukman2b37d7c2005-04-21 21:13:18 +000022#define ARFILE_MAGIC "!<arch>\n" ///< magic string
23#define ARFILE_MAGIC_LEN (sizeof(ARFILE_MAGIC)-1) ///< length of magic string
Reid Spencer9a29db42004-11-20 07:29:40 +000024#define ARFILE_SVR4_SYMTAB_NAME "/ " ///< SVR4 symtab entry name
25#define ARFILE_LLVM_SYMTAB_NAME "#_LLVM_SYM_TAB_#" ///< LLVM symtab entry name
26#define ARFILE_BSD4_SYMTAB_NAME "__.SYMDEF SORTED" ///< BSD4 symtab entry name
27#define ARFILE_STRTAB_NAME "// " ///< Name of string table
Reid Spencerbc9fc842004-11-14 21:57:46 +000028#define ARFILE_PAD "\n" ///< inter-file align padding
29#define ARFILE_MEMBER_MAGIC "`\n" ///< fmag field magic #
Reid Spencer362cbf02004-11-06 08:51:45 +000030
31namespace llvm {
32
Benjamin Kramer12ddd402009-08-11 17:45:13 +000033 class LLVMContext;
Owen Anderson8b477ed2009-07-01 16:58:40 +000034
Gabor Greifa99be512007-07-05 17:07:56 +000035 /// The ArchiveMemberHeader structure is used internally for bitcode
Misha Brukman2b37d7c2005-04-21 21:13:18 +000036 /// archives.
37 /// The header precedes each file member in the archive. This structure is
Reid Spencer362cbf02004-11-06 08:51:45 +000038 /// defined using character arrays for direct and correct interpretation
39 /// regardless of the endianess of the machine that produced it.
40 /// @brief Archive File Member Header
41 class ArchiveMemberHeader {
Reid Spencerbc9fc842004-11-14 21:57:46 +000042 /// @name Data
43 /// @{
44 public:
Misha Brukman2b37d7c2005-04-21 21:13:18 +000045 char name[16]; ///< Name of the file member.
Reid Spencerbc9fc842004-11-14 21:57:46 +000046 char date[12]; ///< File date, decimal seconds since Epoch
47 char uid[6]; ///< user id in ASCII decimal
48 char gid[6]; ///< group id in ASCII decimal
49 char mode[8]; ///< file mode in ASCII octal
50 char size[10]; ///< file size in ASCII decimal
51 char fmag[2]; ///< Always contains ARFILE_MAGIC_TERMINATOR
52
53 /// @}
54 /// @name Methods
55 /// @{
Reid Spencer362cbf02004-11-06 08:51:45 +000056 public:
57 void init() {
58 memset(name,' ',16);
59 memset(date,' ',12);
60 memset(uid,' ',6);
61 memset(gid,' ',6);
62 memset(mode,' ',8);
63 memset(size,' ',10);
64 fmag[0] = '`';
65 fmag[1] = '\n';
66 }
Reid Spencer362cbf02004-11-06 08:51:45 +000067
Roman Divacky651e8002012-09-05 22:09:23 +000068 bool checkSignature() const {
Reid Spencerbc9fc842004-11-14 21:57:46 +000069 return 0 == memcmp(fmag, ARFILE_MEMBER_MAGIC,2);
Reid Spencer362cbf02004-11-06 08:51:45 +000070 }
Reid Spencer362cbf02004-11-06 08:51:45 +000071 };
Chris Lattnerf36c7b82007-02-07 23:53:17 +000072
Gabor Greifa99be512007-07-05 17:07:56 +000073 // Get just the externally visible defined symbols from the bitcode
74 bool GetBitcodeSymbols(const sys::Path& fName,
Owen Anderson4434ed42009-07-01 23:13:44 +000075 LLVMContext& Context,
Chris Lattnerf36c7b82007-02-07 23:53:17 +000076 std::vector<std::string>& symbols,
Chris Lattnerc1d56242007-05-06 09:28:33 +000077 std::string* ErrMsg);
Chris Lattnerf36c7b82007-02-07 23:53:17 +000078
Benjamin Kramer9d44e702010-04-19 16:15:31 +000079 Module* GetBitcodeSymbols(const char *Buffer, unsigned Length,
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +000080 const std::string& ModuleID,
81 LLVMContext& Context,
82 std::vector<std::string>& symbols,
83 std::string* ErrMsg);
Reid Spencer362cbf02004-11-06 08:51:45 +000084}
85
86#endif
87
88// vim: sw=2 ai