[LLVMbugs] [Bug 13129] New: Targets.cpp:(.text+0xb8f): undefined reference to `llvm::MCSectionMachO::ParseSectionSpecifier(llvm::StringRef, llvm::StringRef&, llvm::StringRef&, unsigned int&, bool&, unsigned int&)'

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Jun 16 18:37:26 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13129

             Bug #: 13129
           Summary: Targets.cpp:(.text+0xb8f): undefined reference to
                    `llvm::MCSectionMachO::ParseSectionSpecifier(llvm::Str
                    ingRef, llvm::StringRef&, llvm::StringRef&, unsigned
                    int&, bool&, unsigned int&)'
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Archive library
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: satyaprakash.prasad at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


This my code:

#include <cstdio>
#include <string>
#include <sstream>

#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Parse/ParseAST.h"
#include "clang/Rewrite/Rewriter.h"
#include "clang/Rewrite/Rewriters.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/raw_ostream.h"

using namespace clang;
using namespace std;

// By implementing RecursiveASTVisitor, we can specify which AST nodes
// we're interested in by overriding relevant methods.
class MyASTVisitor : public RecursiveASTVisitor<MyASTVisitor>
{
public:
    MyASTVisitor(Rewriter &R)
        : TheRewriter(R)
    {}

    bool VisitStmt(Stmt *s) {
        // Only care about If statements.
        if (isa<IfStmt>(s)) {
            IfStmt *IfStatement = cast<IfStmt>(s);
            Stmt *Then = IfStatement->getThen();

            TheRewriter.InsertText(Then->getLocStart(),
                                   "// the 'if' part\n",
                                   true, true);

            Stmt *Else = IfStatement->getElse();
            if (Else)
                TheRewriter.InsertText(Else->getLocStart(),
                                       "// the 'else' part\n",
                                       true, true);
        }

        return true;
    }

    bool VisitFunctionDecl(FunctionDecl *f) {
        // Only function definitions (with bodies), not declarations.
        if (f->hasBody()) {
            Stmt *FuncBody = f->getBody();

            // Type name as string
            QualType QT = f->getResultType();
            string TypeStr = QT.getAsString();

            // Function name
            DeclarationName DeclName = f->getNameInfo().getName();
            string FuncName = DeclName.getAsString();

            // Add comment before
            stringstream SSBefore;
            SSBefore << "// Begin function " << FuncName << " returning "
                     << TypeStr << "\n";
            SourceLocation ST = f->getSourceRange().getBegin();
            TheRewriter.InsertText(ST, SSBefore.str(), true, true);

            // And after
            stringstream SSAfter;
            SSAfter << "\n// End function " << FuncName << "\n";
            ST = FuncBody->getLocEnd().getLocWithOffset(1);
            TheRewriter.InsertText(ST, SSAfter.str(), true, true);
        }

        return true;
    }

private:
    void AddBraces(Stmt *s);

    Rewriter &TheRewriter;
};

// Implementation of the ASTConsumer interface for reading an AST produced
// by the Clang parser.
class MyASTConsumer : public ASTConsumer
{
public:
    MyASTConsumer(Rewriter &R)
        : Visitor(R)
    {}

    // Override the method that gets called for each parsed top-level
    // declaration.
    virtual bool HandleTopLevelDecl(DeclGroupRef DR) {
        for (DeclGroupRef::iterator b = DR.begin(), e = DR.end();
             b != e; ++b)
            // Traverse the declaration using our AST visitor.
            Visitor.TraverseDecl(*b);
        return true;
    }

private:
    MyASTVisitor Visitor;
};

int main(int argc, char *argv[])
{
    if (argc != 2) {
        llvm::errs() << "Usage: rewritersample <filename>\n";
        return 1;
    }

    // CompilerInstance will hold the instance of the Clang compiler for us,
    // managing the various objects needed to run the compiler.
    CompilerInstance TheCompInst;
    TheCompInst.createDiagnostics(0, 0);

    // Initialize target info with the default triple for our platform.
    TargetOptions TO;
    TO.Triple = llvm::sys::getDefaultTargetTriple();
    TargetInfo *TI = TargetInfo::CreateTargetInfo(
        TheCompInst.getDiagnostics(), TO);
    TheCompInst.setTarget(TI);

    TheCompInst.createFileManager();
    FileManager &FileMgr = TheCompInst.getFileManager();
    TheCompInst.createSourceManager(FileMgr);
    SourceManager &SourceMgr = TheCompInst.getSourceManager();
    TheCompInst.createPreprocessor();
    TheCompInst.createASTContext();

    // A Rewriter helps us manage the code rewriting task.
    Rewriter TheRewriter;
    TheRewriter.setSourceMgr(SourceMgr, TheCompInst.getLangOpts());

    // Set the main file handled by the source manager to the input file.
    const FileEntry *FileIn = FileMgr.getFile(argv[1]);
    SourceMgr.createMainFileID(FileIn);
    TheCompInst.getDiagnosticClient().BeginSourceFile(
        TheCompInst.getLangOpts(),
        &TheCompInst.getPreprocessor());

    // Create an AST consumer instance which is going to get called by
    // ParseAST.
    MyASTConsumer TheConsumer(TheRewriter);

    // Parse the file to AST, registering our consumer as the AST consumer.
    ParseAST(TheCompInst.getPreprocessor(), &TheConsumer,
             TheCompInst.getASTContext());

    // At this point the rewriter's buffer should be full with the rewritten
    // file contents.
    const RewriteBuffer *RewriteBuf =
        TheRewriter.getRewriteBufferFor(SourceMgr.getMainFileID());
    llvm::outs() << string(RewriteBuf->begin(), RewriteBuf->end());

    return 0;
}


Makefile:

CXX = g++
CFLAGS = -fno-rtti -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS

LLVM_SRC_PATH =  llvm
LLVM_BUILD_PATH = llvm/build

LLVM_BIN_PATH = $(LLVM_BUILD_PATH)/Debug+Asserts/bin
LLVM_RELEASE_PATH = $(LLVM_BUILD_PATH)/Release+Asserts
LLVM_DEBUG_PATH = $(LLVM_BUILD_PATH)/Debug+Asserts
LLVM_LIBS=core mc
LLVM_CONFIG_COMMAND = $(LLVM_BIN_PATH)/llvm-config --cxxflags --ldflags \
                                        --libs $(LLVM_LIBS)
CLANG_BUILD_FLAGS = -I$(LLVM_SRC_PATH)/llvm/tools/clang/include/ \
                                      -I$(LLVM_BUILD_PATH)/tools/clang/include
\
                                        -I$(LLVM_SRC_PATH)/llvm/include \
                                        -I$(LLVM_BUILD_PATH)/include

CLANGLIBS = \
  -L$(LLVM_RELEASE_PATH)/lib -lclangFrontendTool -L$(LLVM_RELEASE_PATH)/lib
-lclangFrontend -L$(LLVM_RELEASE_PATH)/lib -lclangDriver \
  -L$(LLVM_RELEASE_PATH)/lib -lclangSerialization -L$(LLVM_RELEASE_PATH)/lib
-lclangCodeGen -L$(LLVM_RELEASE_PATH)/lib -lclangParse \
  -L$(LLVM_RELEASE_PATH)/lib -lclangSema -L$(LLVM_RELEASE_PATH)/lib
-lclangStaticAnalyzerFrontend \
  -L$(LLVM_RELEASE_PATH)/lib -lclangStaticAnalyzerCheckers
-L$(LLVM_RELEASE_PATH)/lib -lclangStaticAnalyzerCore \
  -L$(LLVM_RELEASE_PATH)/lib -lclangAnalysis -L$(LLVM_RELEASE_PATH)/lib
-lclangARCMigrate -lclangRewrite \
  -L$(LLVM_RELEASE_PATH)/lib -lclangEdit -L$(LLVM_RELEASE_PATH)/lib -lclangAST
-L$(LLVM_RELEASE_PATH)/lib -lclangLex -L$(LLVM_RELEASE_PATH)/lib -lLLVMSupport
-L$(LLVM_RELEASE_PATH)/lib -lclangSema -L$(LLVM_RELEASE_PATH)/lib
-lclangSerialization -L$(LLVM_RELEASE_PATH)/lib -lclangLex
-L$(LLVM_RELEASE_PATH)/lib -lclangParse -L$(LLVM_RELEASE_PATH)/lib -lclangBasic
-lpthread -ldl


rewritersample: rewritersample.cpp
        $(CXX) rewritersample.cpp $(CFLAGS) -o rewritersample \
                $(CLANG_BUILD_FLAGS) $(CLANGLIBS)

clean:
        rm -rf *.o *.ll rewritersample


I get undefined reference to `llvm::MCSectionMachO::ParseSectionSpecifier:

llvm/build/Release+Asserts/bin 1045> make -f Makefile

g++ rewritersample.cpp -fno-rtti -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
-o rewritersample \
                -Illvm/llvm/tools/clang/include/
-Illvm/build/tools/clang/include -Illvm/llvm/include -Illvm/build/include
-Lllvm/build/Release+Asserts/lib -lclangFrontendTool
-Lllvm/build/Release+Asserts/lib -lclangFrontend
-Lllvm/build/Release+Asserts/lib -lclangDriver -Lllvm/build/Release+Asserts/lib
-lclangSerialization -Lllvm/build/Release+Asserts/lib -lclangCodeGen
-Lllvm/build/Release+Asserts/lib -lclangParse -Lllvm/build/Release+Asserts/lib
-lclangSema -Lllvm/build/Release+Asserts/lib -lclangStaticAnalyzerFrontend
-Lllvm/build/Release+Asserts/lib -lclangStaticAnalyzerCheckers
-Lllvm/build/Release+Asserts/lib -lclangStaticAnalyzerCore
-Lllvm/build/Release+Asserts/lib -lclangAnalysis
-Lllvm/build/Release+Asserts/lib -lclangARCMigrate -lclangRewrite
-Lllvm/build/Release+Asserts/lib -lclangEdit -Lllvm/build/Release+Asserts/lib
-lclangAST -Lllvm/build/Release+Asserts/lib -lclangLex
-Lllvm/build/Release+Asserts/lib -lLLVMSupport -Lllvm/build/Release+Asserts/lib
-lclangSema -Lllvm/build/Release+Asserts/lib -lclangSerialization
-Lllvm/build/Release+Asserts/lib -lclangLex -Lllvm/build/Release+Asserts/lib
-lLLVMTarget -Lllvm/build/Release+Asserts/lib -lclangBasic -lpthread -ldl
llvm/build/Release+Asserts/lib/libclangBasic.a(Targets.o): In function
`(anonymous namespace)::DarwinTargetInfo<(anonymous
namespace)::PPC32TargetInfo>::isValidSectionSpecifier(llvm::StringRef) const':
Targets.cpp:(.text+0xb8f): undefined reference to
`llvm::MCSectionMachO::ParseSectionSpecifier(llvm::StringRef, llvm::StringRef&,
llvm::StringRef&, unsigned int&, bool&, unsigned int&)'
llvm/build/Release+Asserts/lib/libclangBasic.a(Targets.o): In function
`(anonymous namespace)::DarwinTargetInfo<(anonymous
namespace)::PPC64TargetInfo>::isValidSectionSpecifier(llvm::StringRef) const':
Targets.cpp:(.text+0xbff): undefined reference to
`llvm::MCSectionMachO::ParseSectionSpecifier(llvm::StringRef, llvm::StringRef&,
llvm::StringRef&, unsigned int&, bool&, unsigned int&)'
llvm/build/Release+Asserts/lib/libclangBasic.a(Targets.o): In function
`(anonymous namespace)::DarwinTargetInfo<(anonymous
namespace)::X86_32TargetInfo>::isValidSectionSpecifier(llvm::StringRef) const':
Targets.cpp:(.text+0xc6f): undefined reference to
`llvm::MCSectionMachO::ParseSectionSpecifier(llvm::StringRef, llvm::StringRef&,
llvm::StringRef&, unsigned int&, bool&, unsigned int&)'
llvm/build/Release+Asserts/lib/libclangBasic.a(Targets.o): In function
`(anonymous namespace)::DarwinTargetInfo<(anonymous
namespace)::X86_64TargetInfo>::isValidSectionSpecifier(llvm::StringRef) const':
Targets.cpp:(.text+0xcdf): undefined reference to
`llvm::MCSectionMachO::ParseSectionSpecifier(llvm::StringRef, llvm::StringRef&,
llvm::StringRef&, unsigned int&, bool&, unsigned int&)'
llvm/build/Release+Asserts/lib/libclangBasic.a(Targets.o): In function
`(anonymous namespace)::DarwinTargetInfo<(anonymous
namespace)::ARMTargetInfo>::isValidSectionSpecifier(llvm::StringRef) const':
Targets.cpp:(.text+0xd4f): undefined reference to
`llvm::MCSectionMachO::ParseSectionSpecifier(llvm::StringRef, llvm::StringRef&,
llvm::StringRef&, unsigned int&, bool&, unsigned int&)'
collect2: ld returned 1 exit status
make: *** [rewritersample] Error 1

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list