1/*
 2 * Copyright (c) 2016 Apple, Inc. All rights reserved.
 3 *
 4 * @APPLE_LICENSE_HEADER_START@
 5 * 
 6 * This file contains Original Code and/or Modifications of Original Code
 7 * as defined in and that are subject to the Apple Public Source License
 8 * Version 2.0 (the 'License'). You may not use this file except in
 9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 * 
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 * 
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*	ranlib.h	4.1	83/05/03	*/
24#ifndef _MACH_O_RANLIB_H_
25#define _MACH_O_RANLIB_H_
26
27#include <stdint.h>
28#include <sys/types.h>		/* off_t */
29
30/*
31 * There are two known orders of table of contents for archives.  The first is
32 * the order ranlib(1) originally produced and still produces without any
33 * options.  This table of contents has the archive member name "__.SYMDEF"
34 * This order has the ranlib structures in the order the objects appear in the
35 * archive and the symbol names of those objects in the order of symbol table.
36 * The second know order is sorted by symbol name and is produced with the -s
37 * option to ranlib(1).  This table of contents has the archive member name
38 * "__.SYMDEF SORTED" and many programs (notably the 1.0 version of ld(1) can't
39 * tell the difference between names because of the imbedded blank in the name
40 * and works with either table of contents).  This second order is used by the
41 * post 1.0 link editor to produce faster linking.  The original 1.0 version of
42 * ranlib(1) gets confused when it is run on a archive with the second type of
43 * table of contents because it and ar(1) which it uses use different ways to
44 * determined the member name (ar(1) treats all blanks in the name as
45 * significant and ranlib(1) only checks for the first one).
46 */
47#define SYMDEF		"__.SYMDEF"
48#define SYMDEF_SORTED	"__.SYMDEF SORTED"
49
50/*
51 * Structure of the __.SYMDEF table of contents for an archive.
52 * __.SYMDEF begins with a uint32_t giving the size in bytes of the ranlib
53 * structures which immediately follow, and then continues with a string
54 * table consisting of a uint32_t giving the number of bytes of strings which
55 * follow and then the strings themselves.  The ran_strx fields index the
56 * string table whose first byte is numbered 0.
57 */
58struct	ranlib {
59    union {
60	uint32_t	ran_strx;	/* string table index of */
61#ifndef __LP64__
62	char		*ran_name;	/* symbol defined by */
63#endif
64    } ran_un;
65    uint32_t		ran_off;	/* library member at this offset */
66};
67
68#define SYMDEF_64		"__.SYMDEF_64"
69#define SYMDEF_64_SORTED	"__.SYMDEF_64 SORTED"
70
71/*
72 * The support for the 64-bit table of contents described here is a work in
73 * progress and not yet fully supported in all the Apple Developer Tools.
74 *
75 * When an archive offset to a library member is more than 32-bits then this is
76 * the structure of the __.SYMDEF_64 table of contents for an archive.
77 * __.SYMDEF_64 begins with a uint64_t giving the size in bytes of the ranlib
78 * structures which immediately follow, and then continues with a string
79 * table consisting of a uint64_t giving the number of bytes of strings which
80 * follow and then the strings themselves.  The ran_strx fields index the
81 * string table whose first byte is numbered 0.
82 */
83
84struct	ranlib_64 {
85    union {
86	uint64_t	ran_strx;	/* string table index of */
87    } ran_un;
88    uint64_t		ran_off;	/* library member at this offset */
89};
90#endif /* _MACH_O_RANLIB_H_ */