Path: blob/main/contrib/llvm-project/llvm/lib/MC/MCSectionCOFF.cpp
35233 views
//===- lib/MC/MCSectionCOFF.cpp - COFF Code Section Representation --------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/MC/MCSectionCOFF.h"9#include "llvm/BinaryFormat/COFF.h"10#include "llvm/MC/MCSymbol.h"11#include "llvm/Support/raw_ostream.h"12#include <cassert>1314using namespace llvm;1516// shouldOmitSectionDirective - Decides whether a '.section' directive17// should be printed before the section name18bool MCSectionCOFF::shouldOmitSectionDirective(StringRef Name,19const MCAsmInfo &MAI) const {20if (COMDATSymbol)21return false;2223// FIXME: Does .section .bss/.data/.text work everywhere??24if (Name == ".text" || Name == ".data" || Name == ".bss")25return true;2627return false;28}2930void MCSectionCOFF::setSelection(int Selection) const {31assert(Selection != 0 && "invalid COMDAT selection type");32this->Selection = Selection;33Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;34}3536void MCSectionCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,37raw_ostream &OS,38uint32_t Subsection) const {39// standard sections don't require the '.section'40if (shouldOmitSectionDirective(getName(), MAI)) {41OS << '\t' << getName() << '\n';42return;43}4445OS << "\t.section\t" << getName() << ",\"";46if (getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)47OS << 'd';48if (getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)49OS << 'b';50if (getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE)51OS << 'x';52if (getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE)53OS << 'w';54else if (getCharacteristics() & COFF::IMAGE_SCN_MEM_READ)55OS << 'r';56else57OS << 'y';58if (getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE)59OS << 'n';60if (getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED)61OS << 's';62if ((getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) &&63!isImplicitlyDiscardable(getName()))64OS << 'D';65if (getCharacteristics() & COFF::IMAGE_SCN_LNK_INFO)66OS << 'i';67OS << '"';6869if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {70if (COMDATSymbol)71OS << ",";72else73OS << "\n\t.linkonce\t";74switch (Selection) {75case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES:76OS << "one_only";77break;78case COFF::IMAGE_COMDAT_SELECT_ANY:79OS << "discard";80break;81case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE:82OS << "same_size";83break;84case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH:85OS << "same_contents";86break;87case COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE:88OS << "associative";89break;90case COFF::IMAGE_COMDAT_SELECT_LARGEST:91OS << "largest";92break;93case COFF::IMAGE_COMDAT_SELECT_NEWEST:94OS << "newest";95break;96default:97assert(false && "unsupported COFF selection type");98break;99}100if (COMDATSymbol) {101OS << ",";102COMDATSymbol->print(OS, &MAI);103}104}105OS << '\n';106}107108bool MCSectionCOFF::useCodeAlign() const { return isText(); }109110StringRef MCSectionCOFF::getVirtualSectionKind() const {111return "IMAGE_SCN_CNT_UNINITIALIZED_DATA";112}113114115