当前位置: 首页>>代码示例>>C++>>正文


C++ Section::getRelocs方法代码示例

本文整理汇总了C++中Section::getRelocs方法的典型用法代码示例。如果您正苦于以下问题:C++ Section::getRelocs方法的具体用法?C++ Section::getRelocs怎么用?C++ Section::getRelocs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Section的用法示例。


在下文中一共展示了Section::getRelocs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

void
CoffSymbol::Write(Bytes& bytes,
                  const Symbol& sym,
                  DiagnosticsEngine& diags,
                  StringTable& strtab) const
{
    int vis = sym.getVisibility();

    IntNum value = 0;
    unsigned int scnum = 0xfffe;    // -2 = debugging symbol
    unsigned long scnlen = 0;   // for sect auxent
    unsigned long nreloc = 0;   // for sect auxent

    // Look at symrec for value/scnum/etc.
    Location loc;
    if (sym.getLabel(&loc))
    {
        Section* sect = 0;
        if (loc.bc)
            sect = loc.bc->getContainer()->getSection();
        // it's a label: get value and offset.
        // If there is not a section, leave as debugging symbol.
        if (sect)
        {
            CoffSection* coffsect = sect->getAssocData<CoffSection>();
            assert(coffsect != 0);

            scnum = coffsect->m_scnum;
            scnlen = coffsect->m_size;
            nreloc = sect->getRelocs().size();
            value = sect->getVMA();
            if (loc.bc)
                value += loc.getOffset();
        }
    }
    else if (const Expr* equ_expr_c = sym.getEqu())
    {
        Expr equ_expr = *equ_expr_c;
        if (!ExpandEqu(equ_expr))
        {
            diags.Report(sym.getDefSource(), diag::err_equ_circular_reference);
            return;
        }
        SimplifyCalcDist(equ_expr, diags);

        // trivial case: simple integer
        if (equ_expr.isIntNum())
        {
            scnum = 0xffff;     // -1 = absolute symbol
            value = equ_expr.getIntNum();
        }
        else
        {
            // otherwise might contain relocatable value (e.g. symbol alias)
            std::auto_ptr<Expr> equ_expr_p(new Expr);
            equ_expr_p->swap(equ_expr);
            Value val(64, equ_expr_p);
            val.setSource(sym.getDefSource());
            if (!val.Finalize(diags, diag::err_equ_too_complex))
                return;
            if (val.isComplexRelative())
            {
                diags.Report(sym.getDefSource(), diag::err_equ_too_complex);
                return;
            }

            // set section appropriately based on if value is relative
            if (val.isRelative())
            {
                SymbolRef rel = val.getRelative();
                Location loc;
                if (!rel->getLabel(&loc) || !loc.bc)
                {
                    // Referencing an undefined label?
                    // GNU as silently allows this... but doesn't gen the symbol?
                    // We make it an error instead.
                    diags.Report(sym.getDefSource(), diag::err_equ_too_complex);
                    return;
                }

                Section* sect = loc.bc->getContainer()->getSection();
                CoffSection* coffsect = sect->getAssocData<CoffSection>();
                assert(coffsect != 0);
                scnum = coffsect->m_scnum;
                value = sect->getVMA() + loc.getOffset();
            }
            else
            {
                scnum = 0xffff;     // -1 = absolute symbol
                value = 0;
            }

            // add in any remaining absolute portion
            if (Expr* abs = val.getAbs())
            {
                SimplifyCalcDist(*abs, diags);
                if (abs->isIntNum())
                    value += abs->getIntNum();
                else
                    diags.Report(sym.getDefSource(), diag::err_equ_not_integer);
//.........这里部分代码省略.........
开发者ID:8l,项目名称:yasm-nextgen,代码行数:101,代码来源:CoffSymbol.cpp

示例2: assert

void
XdfOutput::OutputSection(Section& sect)
{
    BytecodeOutput* outputter = this;

    XdfSection* xsect = sect.getAssocData<XdfSection>();
    assert(xsect != NULL);

    uint64_t pos;
    if (sect.isBSS())
    {
        // Don't output BSS sections.
        outputter = &m_no_output;
        pos = 0;    // position = 0 because it's not in the file
    }
    else
    {
        pos = m_os.tell();
        if (m_os.has_error())
        {
            Diag(SourceLocation(), diag::err_file_output_position);
            return;
        }
    }

    // Output bytecodes
    xsect->size = 0;
    for (Section::bc_iterator i=sect.bytecodes_begin(),
         end=sect.bytecodes_end(); i != end; ++i)
    {
        if (i->Output(*outputter))
            xsect->size += i->getTotalLen();
    }

    // Sanity check final section size
    assert(xsect->size == sect.bytecodes_back().getNextOffset());

    // Empty?  Go on to next section
    if (xsect->size == 0)
        return;

    sect.setFilePos(static_cast<unsigned long>(pos));

    // No relocations to output?  Go on to next section
    if (sect.getRelocs().size() == 0)
        return;

    pos = m_os.tell();
    if (m_os.has_error())
    {
        Diag(SourceLocation(), diag::err_file_output_position);
        return;
    }
    xsect->relptr = static_cast<unsigned long>(pos);

    for (Section::const_reloc_iterator i=sect.relocs_begin(),
         end=sect.relocs_end(); i != end; ++i)
    {
        const XdfReloc& reloc = static_cast<const XdfReloc&>(*i);
        Bytes& scratch = getScratch();
        reloc.Write(scratch);
        assert(scratch.size() == RELOC_SIZE);
        m_os << scratch;
    }
}
开发者ID:PeterJohnson,项目名称:yasm-nextgen,代码行数:65,代码来源:XdfObject.cpp


注:本文中的Section::getRelocs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。