15460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===- MCLDAttribute.cpp --------------------------------------------------===// 25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// The MCLinker Project 45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file is distributed under the University of Illinois Open Source 65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// License. See LICENSE.TXT for details. 75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===// 937b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/MC/Attribute.h" 105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1137b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/MC/AttributeSet.h" 1237b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/Support/MsgHandling.h" 1337b74a387bb3993387029859c2d9d051c41c724eStephen Hines 1437b74a387bb3993387029859c2d9d051c41c724eStephen Hinesnamespace mcld { 155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//===----------------------------------------------------------------------===// 175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// AttrConstraint 1822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//===----------------------------------------------------------------------===// 1937b74a387bb3993387029859c2d9d051c41c724eStephen Hinesbool AttrConstraint::isLegal(const Attribute& pAttr) const { 205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao if (!isWholeArchive() && pAttr.isWholeArchive()) { 21affc150dc44fab1911775a49636d0ce85333b634Zonr Chang error(diag::err_unsupported_whole_archive); 225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return false; 235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao } 245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao if (!isAsNeeded() && pAttr.isAsNeeded()) { 25affc150dc44fab1911775a49636d0ce85333b634Zonr Chang error(diag::err_unsupported_as_needed); 265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return false; 275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao } 285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao if (!isAddNeeded() && pAttr.isAddNeeded()) { 29affc150dc44fab1911775a49636d0ce85333b634Zonr Chang error(diag::err_unsupported_add_needed); 305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return false; 315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao } 325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao if (isStaticSystem() && pAttr.isDynamic()) { 33affc150dc44fab1911775a49636d0ce85333b634Zonr Chang error(diag::err_unsupported_Bdynamic); 345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return false; 355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao } 365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao if (isStaticSystem() && pAttr.isAsNeeded()) { 37affc150dc44fab1911775a49636d0ce85333b634Zonr Chang warning(diag::err_enable_as_needed_on_static_system); 38affc150dc44fab1911775a49636d0ce85333b634Zonr Chang return true; 395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao } 405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao // FIXME: may be it's legal, but ignored by GNU ld. 415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao if (pAttr.isAsNeeded() && pAttr.isStatic()) { 42affc150dc44fab1911775a49636d0ce85333b634Zonr Chang warning(diag::err_mix_static_as_needed); 43affc150dc44fab1911775a49636d0ce85333b634Zonr Chang return true; 445460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao } 455460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return true; 465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 4822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//===----------------------------------------------------------------------===// 495460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// AttributeProxy 5022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//===----------------------------------------------------------------------===// 5122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei LiaoAttributeProxy::AttributeProxy(AttributeSet& pParent, 5222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao const Attribute& pBase, 5322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao const AttrConstraint& pConstraint) 5437b74a387bb3993387029859c2d9d051c41c724eStephen Hines : m_AttrPool(pParent), m_pBase(&pBase), m_Constraint(pConstraint) { 555460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 565460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 5737b74a387bb3993387029859c2d9d051c41c724eStephen HinesAttributeProxy::~AttributeProxy() { 585460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 595460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 6037b74a387bb3993387029859c2d9d051c41c724eStephen Hinesbool AttributeProxy::isWholeArchive() const { 6122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao if (m_Constraint.isWholeArchive()) 625460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return m_pBase->isWholeArchive(); 635460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao else 645460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return false; 655460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 665460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 6737b74a387bb3993387029859c2d9d051c41c724eStephen Hinesbool AttributeProxy::isAsNeeded() const { 6822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao if (m_Constraint.isAsNeeded()) 695460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return m_pBase->isAsNeeded(); 705460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao else 715460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return false; 725460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 735460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 7437b74a387bb3993387029859c2d9d051c41c724eStephen Hinesbool AttributeProxy::isAddNeeded() const { 7522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao if (m_Constraint.isAddNeeded()) 765460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return m_pBase->isAddNeeded(); 775460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao else 785460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return false; 795460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 805460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 8137b74a387bb3993387029859c2d9d051c41c724eStephen Hinesbool AttributeProxy::isStatic() const { 8222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao if (m_Constraint.isSharedSystem()) 835460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return m_pBase->isStatic(); 845460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao else 855460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return true; 865460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 875460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 8837b74a387bb3993387029859c2d9d051c41c724eStephen Hinesbool AttributeProxy::isDynamic() const { 8922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao if (m_Constraint.isSharedSystem()) 905460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return m_pBase->isDynamic(); 915460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao else 925460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return false; 935460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 945460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 9522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaostatic inline void ReplaceOrRecord(AttributeSet& pParent, 9637b74a387bb3993387029859c2d9d051c41c724eStephen Hines const Attribute*& pBase, 9737b74a387bb3993387029859c2d9d051c41c724eStephen Hines Attribute*& pCopy) { 9837b74a387bb3993387029859c2d9d051c41c724eStephen Hines Attribute* result = pParent.exists(*pCopy); 9937b74a387bb3993387029859c2d9d051c41c724eStephen Hines if (result == NULL) { // can not find 1005460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao pParent.record(*pCopy); 1015460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao pBase = pCopy; 10237b74a387bb3993387029859c2d9d051c41c724eStephen Hines } else { // find 1035460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao delete pCopy; 1045460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao pBase = result; 1055460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao } 1065460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 1075460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 10837b74a387bb3993387029859c2d9d051c41c724eStephen Hinesvoid AttributeProxy::setWholeArchive() { 10937b74a387bb3993387029859c2d9d051c41c724eStephen Hines Attribute* copy = new Attribute(*m_pBase); 1105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao copy->setWholeArchive(); 1115460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ReplaceOrRecord(m_AttrPool, m_pBase, copy); 1125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 1135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 11437b74a387bb3993387029859c2d9d051c41c724eStephen Hinesvoid AttributeProxy::unsetWholeArchive() { 11537b74a387bb3993387029859c2d9d051c41c724eStephen Hines Attribute* copy = new Attribute(*m_pBase); 1165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao copy->unsetWholeArchive(); 1175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ReplaceOrRecord(m_AttrPool, m_pBase, copy); 1185460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 1195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 12037b74a387bb3993387029859c2d9d051c41c724eStephen Hinesvoid AttributeProxy::setAsNeeded() { 12137b74a387bb3993387029859c2d9d051c41c724eStephen Hines Attribute* copy = new Attribute(*m_pBase); 1225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao copy->setAsNeeded(); 1235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ReplaceOrRecord(m_AttrPool, m_pBase, copy); 1245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 1255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 12637b74a387bb3993387029859c2d9d051c41c724eStephen Hinesvoid AttributeProxy::unsetAsNeeded() { 12737b74a387bb3993387029859c2d9d051c41c724eStephen Hines Attribute* copy = new Attribute(*m_pBase); 1285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao copy->unsetAsNeeded(); 1295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ReplaceOrRecord(m_AttrPool, m_pBase, copy); 1305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 1315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 13237b74a387bb3993387029859c2d9d051c41c724eStephen Hinesvoid AttributeProxy::setAddNeeded() { 13337b74a387bb3993387029859c2d9d051c41c724eStephen Hines Attribute* copy = new Attribute(*m_pBase); 1345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao copy->setAddNeeded(); 1355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ReplaceOrRecord(m_AttrPool, m_pBase, copy); 1365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 1375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 13837b74a387bb3993387029859c2d9d051c41c724eStephen Hinesvoid AttributeProxy::unsetAddNeeded() { 13937b74a387bb3993387029859c2d9d051c41c724eStephen Hines Attribute* copy = new Attribute(*m_pBase); 1405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao copy->unsetAddNeeded(); 1415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ReplaceOrRecord(m_AttrPool, m_pBase, copy); 1425460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 1435460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 14437b74a387bb3993387029859c2d9d051c41c724eStephen Hinesvoid AttributeProxy::setStatic() { 14537b74a387bb3993387029859c2d9d051c41c724eStephen Hines Attribute* copy = new Attribute(*m_pBase); 1465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao copy->setStatic(); 1475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ReplaceOrRecord(m_AttrPool, m_pBase, copy); 1485460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 1495460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 15037b74a387bb3993387029859c2d9d051c41c724eStephen Hinesvoid AttributeProxy::setDynamic() { 15137b74a387bb3993387029859c2d9d051c41c724eStephen Hines Attribute* copy = new Attribute(*m_pBase); 1525460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao copy->setDynamic(); 1535460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ReplaceOrRecord(m_AttrPool, m_pBase, copy); 1545460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 1555460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 15637b74a387bb3993387029859c2d9d051c41c724eStephen HinesAttributeProxy& AttributeProxy::assign(Attribute* pBase) { 15722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao m_pBase = pBase; 15822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao return *this; 1595460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 1605460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 16137b74a387bb3993387029859c2d9d051c41c724eStephen Hines} // namespace mcld 162