Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / tools / llvm-c-test / object.c
blob278911b0bc6f1b68d0b32c8d5eb535944eee29de
1 /*===-- object.c - tool for testing libLLVM and llvm-c API ----------------===*\
2 |* *|
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 |* Exceptions. *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 |* *|
8 |*===----------------------------------------------------------------------===*|
9 |* *|
10 |* This file implements the --object-list-sections and --object-list-symbols *|
11 |* commands in llvm-c-test. *|
12 |* *|
13 \*===----------------------------------------------------------------------===*/
15 #include "llvm-c-test.h"
16 #include "llvm-c/Object.h"
17 #include <stdio.h>
18 #include <stdlib.h>
20 int llvm_object_list_sections(void) {
21 LLVMMemoryBufferRef MB;
22 LLVMObjectFileRef O;
23 LLVMSectionIteratorRef sect;
24 char *msg = NULL;
26 if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
27 fprintf(stderr, "Error reading file: %s\n", msg);
28 exit(1);
31 O = LLVMCreateObjectFile(MB);
32 if (!O) {
33 fprintf(stderr, "Error reading object\n");
34 exit(1);
37 sect = LLVMGetSections(O);
38 while (!LLVMIsSectionIteratorAtEnd(O, sect)) {
39 printf("'%s': @0x%08" PRIx64 " +%" PRIu64 "\n", LLVMGetSectionName(sect),
40 LLVMGetSectionAddress(sect), LLVMGetSectionSize(sect));
42 LLVMMoveToNextSection(sect);
45 LLVMDisposeSectionIterator(sect);
47 LLVMDisposeObjectFile(O);
49 return 0;
52 int llvm_object_list_symbols(void) {
53 LLVMMemoryBufferRef MB;
54 LLVMObjectFileRef O;
55 LLVMSectionIteratorRef sect;
56 LLVMSymbolIteratorRef sym;
57 char *msg = NULL;
59 if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
60 fprintf(stderr, "Error reading file: %s\n", msg);
61 exit(1);
64 O = LLVMCreateObjectFile(MB);
65 if (!O) {
66 fprintf(stderr, "Error reading object\n");
67 exit(1);
70 sect = LLVMGetSections(O);
71 sym = LLVMGetSymbols(O);
72 while (!LLVMIsSymbolIteratorAtEnd(O, sym)) {
74 LLVMMoveToContainingSection(sect, sym);
75 printf("%s @0x%08" PRIx64 " +%" PRIu64 " (%s)\n", LLVMGetSymbolName(sym),
76 LLVMGetSymbolAddress(sym), LLVMGetSymbolSize(sym),
77 LLVMGetSectionName(sect));
79 LLVMMoveToNextSymbol(sym);
82 LLVMDisposeSymbolIterator(sym);
84 LLVMDisposeObjectFile(O);
86 return 0;