2 * Copyright (c) 1999-2007 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
26 #include "objc-private.h"
27 #include "objc-file.h"
29 #define GETSECT(name, type, sectname) \
30 type *name(const header_info *hi, size_t *outCount) \
32 unsigned long byteCount = 0; \
33 type *data = (type *) \
34 getsectiondata(hi->mhdr, SEG_DATA, sectname, &byteCount); \
35 *outCount = byteCount / sizeof(type); \
39 // function name content type section name
40 GETSECT(_getObjc2SelectorRefs, SEL, "__objc_selrefs");
41 GETSECT(_getObjc2MessageRefs, message_ref_t, "__objc_msgrefs");
42 GETSECT(_getObjc2ClassRefs, Class, "__objc_classrefs");
43 GETSECT(_getObjc2SuperRefs, Class, "__objc_superrefs");
44 GETSECT(_getObjc2ClassList, classref_t, "__objc_classlist");
45 GETSECT(_getObjc2NonlazyClassList, classref_t, "__objc_nlclslist");
46 GETSECT(_getObjc2CategoryList, category_t *, "__objc_catlist");
47 GETSECT(_getObjc2NonlazyCategoryList, category_t *, "__objc_nlcatlist");
48 GETSECT(_getObjc2ProtocolList, protocol_t *, "__objc_protolist");
49 GETSECT(_getObjc2ProtocolRefs, protocol_t *, "__objc_protorefs");
53 _getObjcImageInfo(const headerType *mhdr, size_t *outBytes)
55 unsigned long byteCount = 0;
56 objc_image_info *data = (objc_image_info *)
57 getsectiondata(mhdr, SEG_DATA, "__objc_imageinfo", &byteCount);
58 *outBytes = byteCount;
63 static const segmentType *
64 getsegbynamefromheader(const headerType *head, const char *segname)
66 const segmentType *sgp;
69 sgp = (const segmentType *) (head + 1);
70 for (i = 0; i < head->ncmds; i++){
71 if (sgp->cmd == SEGMENT_CMD) {
72 if (strncmp(sgp->segname, segname, sizeof(sgp->segname)) == 0) {
76 sgp = (const segmentType *)((char *)sgp + sgp->cmdsize);
82 _hasObjcContents(const header_info *hi)
84 // Look for a __DATA,__objc* section other than __DATA,__objc_imageinfo
85 const segmentType *seg = getsegbynamefromheader(hi->mhdr, "__DATA");
88 const sectionType *sect;
90 for (i = 0; i < seg->nsects; i++) {
91 sect = ((const sectionType *)(seg+1))+i;
92 if (0 == strncmp(sect->sectname, "__objc_", 7) &&
93 0 != strncmp(sect->sectname, "__objc_imageinfo", 16))