Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 693444 | Differences between
and this patch

Collapse All | Expand All

(-)libstuff/llvm.c (+10 lines)
Lines 1-3 Link Here
1
#ifdef LLVM_SUPPORT
2
1
#include <stdio.h>
3
#include <stdio.h>
2
#include <stdlib.h>
4
#include <stdlib.h>
3
#include <libc.h>
5
#include <libc.h>
Lines 6-11 Link Here
6
#include "llvm-c/Disassembler.h"
8
#include "llvm-c/Disassembler.h"
7
#include "stuff/llvm.h"
9
#include "stuff/llvm.h"
8
#include "stuff/allocate.h"
10
#include "stuff/allocate.h"
11
#include "stuff/execute.h"
9
#include <mach-o/dyld.h>
12
#include <mach-o/dyld.h>
10
13
11
/*
14
/*
Lines 65-70 Link Here
65
	    if(llvm_handle == NULL){
68
	    if(llvm_handle == NULL){
66
		free(llvm_path);
69
		free(llvm_path);
67
		llvm_path = NULL;
70
		llvm_path = NULL;
71
		try_hard_to_find_llvm_tool_in_prefix(&llvm_path, "lib", LIB_LLVM);
72
	        llvm_handle = dlopen(llvm_path, RTLD_NOW);
73
	    }
74
	    if(llvm_handle == NULL){
75
		free(llvm_path);
76
		llvm_path = NULL;
68
		llvm_handle = dlopen("/Applications/Xcode.app/Contents/"
77
		llvm_handle = dlopen("/Applications/Xcode.app/Contents/"
69
				     "Developer/Toolchains/XcodeDefault."
78
				     "Developer/Toolchains/XcodeDefault."
70
				     "xctoolchain/usr/lib/" LIB_LLVM,
79
				     "xctoolchain/usr/lib/" LIB_LLVM,
Lines 202-204 Link Here
202
	    return(NULL);
211
	    return(NULL);
203
	return(version());
212
	return(version());
204
}
213
}
214
#endif /* LLVM_SUPPORT */
(-)libstuff/lto.c (+7 lines)
Lines 9-14 Link Here
9
#include "stuff/ofile.h"
9
#include "stuff/ofile.h"
10
#include "stuff/lto.h"
10
#include "stuff/lto.h"
11
#include "stuff/allocate.h"
11
#include "stuff/allocate.h"
12
#include "stuff/execute.h"
12
#include <mach-o/nlist.h>
13
#include <mach-o/nlist.h>
13
#include <mach-o/dyld.h>
14
#include <mach-o/dyld.h>
14
15
Lines 118-123 Link Here
118
	    if(lto_handle == NULL){
119
	    if(lto_handle == NULL){
119
		free(lto_path);
120
		free(lto_path);
120
		lto_path = NULL;
121
		lto_path = NULL;
122
		try_hard_to_find_llvm_tool_in_prefix(&lto_path, "lib", "libLTO.dylib");
123
	        lto_handle = dlopen(lto_path, RTLD_NOW);
124
	    }
125
	    if(lto_handle == NULL){
126
		free(lto_path);
127
		lto_path = NULL;
121
		lto_handle = dlopen("/Applications/Xcode.app/Contents/"
128
		lto_handle = dlopen("/Applications/Xcode.app/Contents/"
122
				    "Developer/Toolchains/XcodeDefault."
129
				    "Developer/Toolchains/XcodeDefault."
123
				    "xctoolchain/usr/lib/libLTO.dylib",
130
				    "xctoolchain/usr/lib/libLTO.dylib",
(-)otool/arm64_disasm.c (+2 lines)
Lines 1-3 Link Here
1
#ifdef LLVM_SUPPORT
1
#include <stdio.h>
2
#include <stdio.h>
2
#include <string.h>
3
#include <string.h>
3
#include <stdlib.h>
4
#include <stdlib.h>
Lines 964-966 Link Here
964
	    printf("\t.long\t0x%08x\n", opcode);
965
	    printf("\t.long\t0x%08x\n", opcode);
965
	return(4);
966
	return(4);
966
}
967
}
968
#endif /* LLVM_SUPPORT */
(-)otool/i386_disasm.c (+2 lines)
Lines 54-59 Link Here
54
NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
54
NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
55
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
55
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
56
*/
56
*/
57
#ifdef LLVM_SUPPORT
57
#include <stdio.h>
58
#include <stdio.h>
58
#include <stdlib.h>
59
#include <stdlib.h>
59
#include <string.h>
60
#include <string.h>
Lines 5363-5365 Link Here
5363
{
5364
{
5364
	llvm_disasm_dispose(dc);
5365
	llvm_disasm_dispose(dc);
5365
}
5366
}
5367
#endif /* LLVM_SUPPORT */
(-)otool/arm_disasm.c (+2 lines)
Lines 22-27 Link Here
22
   USA.
22
   USA.
23
*/
23
*/
24
24
25
#ifdef LLVM_SUPPORT
25
#include <stdlib.h>
26
#include <stdlib.h>
26
#include <string.h>
27
#include <string.h>
27
#include "stuff/arch.h"
28
#include "stuff/arch.h"
Lines 5948-5950 Link Here
5948
            }
5949
            }
5949
        }
5950
        }
5950
}
5951
}
5952
#endif /* LLVM_SUPPORT */
(-)otool/main.c (-2 / +22 lines)
Lines 41-47 Link Here
41
#include "stuff/allocate.h"
41
#include "stuff/allocate.h"
42
#include "stuff/symbol.h"
42
#include "stuff/symbol.h"
43
#include "stuff/symbol.h"
43
#include "stuff/symbol.h"
44
#ifdef LLVM_SUPPORT
44
#include "stuff/llvm.h"
45
#include "stuff/llvm.h"
46
#endif /* LLVM_SUPPORT */
45
#include "stuff/guess_short_name.h"
47
#include "stuff/guess_short_name.h"
46
#include "stuff/execute.h"
48
#include "stuff/execute.h"
47
#include "otool.h"
49
#include "otool.h"
Lines 394-400 Link Here
394
    uint32_t narch_flags;
396
    uint32_t narch_flags;
395
    enum bool all_archs, use_member_syntax, version;
397
    enum bool all_archs, use_member_syntax, version;
396
    char **files;
398
    char **files;
397
#ifndef LLVM_OTOOL
399
#if !defined(LLVM_OTOOL) && defined(LLVM_SUPPORT)
398
    const char *disssembler_version;
400
    const char *disssembler_version;
399
#endif /* !defined(LLVM_OTOOL) */
401
#endif /* !defined(LLVM_OTOOL) */
400
402
Lines 433-439 Link Here
433
			"llvm-otool(1):"
435
			"llvm-otool(1):"
434
#endif /* LLVM_OTOOL */
436
#endif /* LLVM_OTOOL */
435
			" Apple Inc. version %s\n", apple_version);
437
			" Apple Inc. version %s\n", apple_version);
436
#ifndef LLVM_OTOOL
438
#if !defined(LLVM_OTOOL) && defined(LLVM_SUPPORT)
437
		disssembler_version = llvm_disasm_version_string();
439
		disssembler_version = llvm_disasm_version_string();
438
		if(disssembler_version != NULL)
440
		if(disssembler_version != NULL)
439
		    fprintf(stderr, "disassmbler: %s\n", disssembler_version);
441
		    fprintf(stderr, "disassmbler: %s\n", disssembler_version);
Lines 819-824 Link Here
819
	objdump = cmd_with_prefix("objdump");
821
	objdump = cmd_with_prefix("objdump");
820
	if(stat(objdump, &stat_buf) == -1)
822
	if(stat(objdump, &stat_buf) == -1)
821
	    objdump = cmd_with_prefix("llvm-objdump");
823
	    objdump = cmd_with_prefix("llvm-objdump");
824
	if(stat(objdump, &stat_buf) == -1)
825
		try_hard_to_find_llvm_tool_in_prefix(&objdump, "bin", "llvm-objdump");
822
826
823
	reset_execute_list();
827
	reset_execute_list();
824
	add_execute_list(objdump);
828
	add_execute_list(objdump);
Lines 3945-3963 Link Here
3945
    uint64_t cur_addr;
3949
    uint64_t cur_addr;
3946
    unsigned short short_word;
3950
    unsigned short short_word;
3947
    unsigned char byte_word;
3951
    unsigned char byte_word;
3952
#ifdef LLVM_SUPPORT
3948
    LLVMDisasmContextRef arm64_dc;
3953
    LLVMDisasmContextRef arm64_dc;
3949
    LLVMDisasmContextRef arm_dc, thumb_dc, i386_dc, x86_64_dc;
3954
    LLVMDisasmContextRef arm_dc, thumb_dc, i386_dc, x86_64_dc;
3955
#endif /* LLVM_SUPPORT */
3950
    uint32_t n, ninsts;
3956
    uint32_t n, ninsts;
3951
    struct inst *insts;
3957
    struct inst *insts;
3952
    char *sect_start;
3958
    char *sect_start;
3953
3959
3954
	host_byte_sex = get_host_byte_sex();
3960
	host_byte_sex = get_host_byte_sex();
3955
	swapped = host_byte_sex != object_byte_sex;
3961
	swapped = host_byte_sex != object_byte_sex;
3962
#ifdef LLVM_SUPPORT
3956
	arm_dc = NULL;
3963
	arm_dc = NULL;
3957
	thumb_dc = NULL;
3964
	thumb_dc = NULL;
3958
	i386_dc = NULL;
3965
	i386_dc = NULL;
3959
	x86_64_dc = NULL;
3966
	x86_64_dc = NULL;
3960
	arm64_dc = NULL;
3967
	arm64_dc = NULL;
3968
#endif /* LLVM_SUPPORT */
3961
	n = 0;
3969
	n = 0;
3962
	ninsts = 0;
3970
	ninsts = 0;
3963
	insts = NULL;
3971
	insts = NULL;
Lines 3994-3999 Link Here
3994
		cur_addr = addr;
4002
		cur_addr = addr;
3995
		sect_start = sect;
4003
		sect_start = sect;
3996
	    }
4004
	    }
4005
#ifdef LLVM_SUPPORT
3997
	    if(cputype == CPU_TYPE_ARM &&
4006
	    if(cputype == CPU_TYPE_ARM &&
3998
	       (cpusubtype == CPU_SUBTYPE_ARM_V7 ||
4007
	       (cpusubtype == CPU_SUBTYPE_ARM_V7 ||
3999
	        cpusubtype == CPU_SUBTYPE_ARM_V7F ||
4008
	        cpusubtype == CPU_SUBTYPE_ARM_V7F ||
Lines 4075-4080 Link Here
4075
		llvm_disasm_set_options(arm64_dc,
4084
		llvm_disasm_set_options(arm64_dc,
4076
		    LLVMDisassembler_Option_PrintLatency);
4085
		    LLVMDisassembler_Option_PrintLatency);
4077
	    }
4086
	    }
4087
#endif /* LLVM_SUPPORT */
4078
	    if(gflag){
4088
	    if(gflag){
4079
		ninsts = 100;
4089
		ninsts = 100;
4080
		insts = allocate(sizeof(struct inst) * ninsts);
4090
		insts = allocate(sizeof(struct inst) * ninsts);
Lines 4120-4125 Link Here
4120
				nsorted_symbols, strings, strings_size,
4130
				nsorted_symbols, strings, strings_size,
4121
				indirect_symbols, nindirect_symbols,
4131
				indirect_symbols, nindirect_symbols,
4122
				load_commands, ncmds, sizeofcmds, verbose);
4132
				load_commands, ncmds, sizeofcmds, verbose);
4133
#ifdef LLVM_SUPPORT
4123
		else if(cputype == CPU_TYPE_X86_64)
4134
		else if(cputype == CPU_TYPE_X86_64)
4124
		    j = i386_disassemble(sect, (uint32_t)size - i, cur_addr, addr,
4135
		    j = i386_disassemble(sect, (uint32_t)size - i, cur_addr, addr,
4125
				object_byte_sex, relocs, nrelocs, ext_relocs,
4136
				object_byte_sex, relocs, nrelocs, ext_relocs,
Lines 4130-4135 Link Here
4130
				load_commands, ncmds, sizeofcmds, verbose,
4141
				load_commands, ncmds, sizeofcmds, verbose,
4131
				llvm_mc, i386_dc, x86_64_dc , object_addr,
4142
				llvm_mc, i386_dc, x86_64_dc , object_addr,
4132
				object_size, &(insts[n]), NULL, 0);
4143
				object_size, &(insts[n]), NULL, 0);
4144
#endif /* LLVM_SUPPORT */
4133
	 	else if(cputype == CPU_TYPE_MC680x0)
4145
	 	else if(cputype == CPU_TYPE_MC680x0)
4134
		    j = m68k_disassemble(sect, (uint32_t)size - i,
4146
		    j = m68k_disassemble(sect, (uint32_t)size - i,
4135
				 (uint32_t)cur_addr, (uint32_t)addr,
4147
				 (uint32_t)cur_addr, (uint32_t)addr,
Lines 4144-4149 Link Here
4144
				object_byte_sex, relocs, nrelocs, symbols,
4156
				object_byte_sex, relocs, nrelocs, symbols,
4145
				nsymbols, sorted_symbols, nsorted_symbols,
4157
				nsymbols, sorted_symbols, nsorted_symbols,
4146
				strings, strings_size, verbose);
4158
				strings, strings_size, verbose);
4159
#ifdef LLVM_SUPPORT
4147
		else if(cputype == CPU_TYPE_I386)
4160
		else if(cputype == CPU_TYPE_I386)
4148
		    j = i386_disassemble(sect, (uint32_t)size - i,cur_addr,addr,
4161
		    j = i386_disassemble(sect, (uint32_t)size - i,cur_addr,addr,
4149
				object_byte_sex, relocs, nrelocs, ext_relocs,
4162
				object_byte_sex, relocs, nrelocs, ext_relocs,
Lines 4154-4159 Link Here
4154
				load_commands, ncmds, sizeofcmds, verbose,
4167
				load_commands, ncmds, sizeofcmds, verbose,
4155
				llvm_mc, i386_dc, x86_64_dc, object_addr,
4168
				llvm_mc, i386_dc, x86_64_dc, object_addr,
4156
				object_size, &(insts[n]), NULL, 0);
4169
				object_size, &(insts[n]), NULL, 0);
4170
#endif /* LLVM_SUPPORT */
4157
		else if(cputype == CPU_TYPE_MC88000)
4171
		else if(cputype == CPU_TYPE_MC88000)
4158
		    j = m88k_disassemble(sect, (uint32_t)size - i,
4172
		    j = m88k_disassemble(sect, (uint32_t)size - i,
4159
				 (uint32_t)cur_addr, (uint32_t)addr,
4173
				 (uint32_t)cur_addr, (uint32_t)addr,
Lines 4183-4188 Link Here
4183
				strings, strings_size, indirect_symbols,
4197
				strings, strings_size, indirect_symbols,
4184
				nindirect_symbols, load_commands, ncmds,
4198
				nindirect_symbols, load_commands, ncmds,
4185
				sizeofcmds, verbose);
4199
				sizeofcmds, verbose);
4200
#ifdef LLVM_SUPPORT
4186
		else if(cputype == CPU_TYPE_ARM)
4201
		else if(cputype == CPU_TYPE_ARM)
4187
		    j = arm_disassemble(sect, (uint32_t)size - i,
4202
		    j = arm_disassemble(sect, (uint32_t)size - i,
4188
				(uint32_t)cur_addr, (uint32_t)addr,
4203
				(uint32_t)cur_addr, (uint32_t)addr,
Lines 4203-4208 Link Here
4203
				strings_size, indirect_symbols, nindirect_symbols,
4218
				strings_size, indirect_symbols, nindirect_symbols,
4204
				cputype, load_commands, ncmds, sizeofcmds,
4219
				cputype, load_commands, ncmds, sizeofcmds,
4205
				object_addr, object_size, verbose, arm64_dc);
4220
				object_addr, object_size, verbose, arm64_dc);
4221
#endif /* LLVM_SUPPORT */
4206
		
4222
		
4207
		else{
4223
		else{
4208
		    printf("Can't disassemble unknown cputype %d\n", cputype);
4224
		    printf("Can't disassemble unknown cputype %d\n", cputype);
Lines 4250-4255 Link Here
4250
		    cur_addr = insts[i].address;
4266
		    cur_addr = insts[i].address;
4251
		    offset = (uint32_t)(cur_addr - addr);
4267
		    offset = (uint32_t)(cur_addr - addr);
4252
		    sect = sect_start + offset;
4268
		    sect = sect_start + offset;
4269
#ifdef LLVM_SUPPORT
4253
		    if(cputype == CPU_TYPE_X86_64 || cputype == CPU_TYPE_I386)
4270
		    if(cputype == CPU_TYPE_X86_64 || cputype == CPU_TYPE_I386)
4254
			j = i386_disassemble(sect, (uint32_t)size - offset,
4271
			j = i386_disassemble(sect, (uint32_t)size - offset,
4255
					     cur_addr,
4272
					     cur_addr,
Lines 4272-4277 Link Here
4272
				    sizeofcmds, cpusubtype, verbose, arm_dc,
4289
				    sizeofcmds, cpusubtype, verbose, arm_dc,
4273
				    thumb_dc, object_addr, object_size, dices,
4290
				    thumb_dc, object_addr, object_size, dices,
4274
				    ndices, seg_addr, &(insts[i]), insts, n);
4291
				    ndices, seg_addr, &(insts[i]), insts, n);
4292
#endif /* LLVM_SUPPORT */
4275
		}
4293
		}
4276
4294
4277
		/* Free up allocated space */
4295
		/* Free up allocated space */
Lines 4281-4286 Link Here
4281
		}
4299
		}
4282
		free(insts);
4300
		free(insts);
4283
	    }
4301
	    }
4302
#ifdef LLVM_SUPPORT
4284
	    if(i386_dc != NULL)
4303
	    if(i386_dc != NULL)
4285
		delete_arm_llvm_disassembler(i386_dc);
4304
		delete_arm_llvm_disassembler(i386_dc);
4286
	    if(x86_64_dc != NULL)
4305
	    if(x86_64_dc != NULL)
Lines 4291-4296 Link Here
4291
		delete_arm_llvm_disassembler(thumb_dc);
4310
		delete_arm_llvm_disassembler(thumb_dc);
4292
	    if(arm64_dc != NULL)
4311
	    if(arm64_dc != NULL)
4293
		delete_arm64_llvm_disassembler(arm64_dc);
4312
		delete_arm64_llvm_disassembler(arm64_dc);
4313
#endif /* LLVM_SUPPORT */
4294
	}
4314
	}
4295
	else{
4315
	else{
4296
	    if(cputype == CPU_TYPE_I386 || cputype == CPU_TYPE_X86_64){
4316
	    if(cputype == CPU_TYPE_I386 || cputype == CPU_TYPE_X86_64){
(-)as/driver.c (+2 lines)
Lines 296-301 Link Here
296
	    arch_flag.cputype == CPU_TYPE_ARM64_32 ||
296
	    arch_flag.cputype == CPU_TYPE_ARM64_32 ||
297
	    arch_flag.cputype == CPU_TYPE_ARM)){
297
	    arch_flag.cputype == CPU_TYPE_ARM)){
298
	    as = makestr(prefix, CLANG, NULL);
298
	    as = makestr(prefix, CLANG, NULL);
299
	    if(access(as, F_OK) != 0)
300
			try_hard_to_find_llvm_tool_in_prefix(&as, "bin", CLANG);
299
	    if(access(as, F_OK) != 0){
301
	    if(access(as, F_OK) != 0){
300
		printf("%s: assembler (%s) not installed\n", progname, as);
302
		printf("%s: assembler (%s) not installed\n", progname, as);
301
		exit(1);
303
		exit(1);
(-)libstuff/execute.c (+47 lines)
Lines 194-197 Link Here
194
{
194
{
195
	return(execute(runlist.strings, verbose));
195
	return(execute(runlist.strings, verbose));
196
}
196
}
197
/* try really, really hard to find an LLVM tool or library in prefix */
198
__private_extern__
199
void
200
try_hard_to_find_llvm_tool_in_prefix(
201
char **dest,
202
const char *subdir,
203
const char *file)
204
{
205
	char *path;
206
	int most_likely_llvm_major = 5;
207
	int llvm_majors[][2] = {
208
		/* llvm 3 and below weren't slotted */
209
		{most_likely_llvm_major, 4},
210
		{10, most_likely_llvm_major + 1}
211
	};
212
	int i, j;
213
	char buf[10];
214
215
	if (strcmp("@GENTOO_PORTAGE_EPREFIX@", "") == 0)
216
		return;
217
218
	/* prefer prefix /usr for llvm 3 and older as well as in case some
219
	 * gcc-config-ish scheme emrges for llvm as well */
220
	path = makestr("@GENTOO_PORTAGE_EPREFIX@/usr/", subdir, "/", file, NULL);
221
	if (access(path, F_OK) == 0) {
222
		*dest = path;
223
		return;
224
	}
225
226
	free(path);
227
228
	for (i = 0; i < sizeof(llvm_majors)/sizeof(llvm_majors[0]); ++i) {
229
		for (j = llvm_majors[i][0]; j >= llvm_majors[i][1]; --j) {
230
			snprintf(buf, sizeof(buf), "%d", j);
231
			path = makestr("@GENTOO_PORTAGE_EPREFIX@/usr/lib/llvm/", buf, "/", subdir, "/", file, NULL);
232
			if (access(path, F_OK) == 0) {
233
				*dest = path;
234
				return;
235
			}
236
237
			free(path);
238
		}
239
	}
240
241
	/* not found, *dest untouched */
242
	return;
243
}
197
#endif /* !defined(RLD) */
244
#endif /* !defined(RLD) */
(-)otool/otool.h (-1 lines)
Lines 29-35 Link Here
29
 * @APPLE_LICENSE_HEADER_END@
29
 * @APPLE_LICENSE_HEADER_END@
30
 */
30
 */
31
#include <stuff/bool.h>
31
#include <stuff/bool.h>
32
#include "llvm-c/Disassembler.h"
33
32
34
/* Name of this program for error messages (argv[0]) */
33
/* Name of this program for error messages (argv[0]) */
35
extern char *progname;
34
extern char *progname;
(-)include/stuff/execute.h (+3 lines)
Lines 47-49 Link Here
47
47
48
__private_extern__ int execute_list(
48
__private_extern__ int execute_list(
49
    int verbose);
49
    int verbose);
50
51
__private_extern__ void try_hard_to_find_llvm_tool_in_prefix(
52
    char **, const char *, const char *);
(-)include/architecture/sparc/reg.h (-1 / +2 lines)
Lines 40-46 Link Here
40
 * Usage is u.u_ar0[XX].
40
 * Usage is u.u_ar0[XX].
41
 */
41
 */
42
#define	PSR	(0)
42
#define	PSR	(0)
43
#define	PC	(1)
43
/* not used anywhere and breaks llvm-c/Disassembler.h
44
#define	PC	(1) */
44
#define	nPC	(2)
45
#define	nPC	(2)
45
#define	SPARC_Y	(3)
46
#define	SPARC_Y	(3)
46
#define	G1	(4)
47
#define	G1	(4)

Return to bug 693444