2013-01-09 09:17:12 +08:00
|
|
|
//===- DefinedAtom.cpp ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "lld/Core/DefinedAtom.h"
|
ELF: Don't use LayoutPass.
Previously we applied the LayoutPass to order atoms and then
apply elf::ArrayOrderPass to sort them again. The first pass is
basically supposed to sort atoms in the normal fashion (which
is to sort symbols in the same order as the input files).
The second pass sorts atoms in {init,fini}_array.<priority> by
priority.
The problem is that the LayoutPass is overkill. It analyzes
references between atoms to make a decision how to sort them.
It's slow, hard to understand, and above all, it doesn't seem
that we need its feature for ELF in the first place.
This patch remove the LayoutPass from ELF pass list. Now all
reordering is done in elf::OrderPass. That pass sorts atoms by
{init,fini}_array, and if they are not in the special section,
they are ordered as the same order as they appear in the command
line. The new code is far easier to understand, faster, and
still able to create valid executables.
Unlike the previous layout pass, elf::OrderPass doesn't count
any attributes of an atom (e.g. permissions) except its
position. It's OK because the writer takes care of them if we
have to.
This patch changes the order of final output, although that's
benign. Tests are updated.
http://reviews.llvm.org/D7278
llvm-svn: 227666
2015-01-31 10:05:01 +08:00
|
|
|
#include "lld/Core/File.h"
|
2013-01-09 09:17:12 +08:00
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
|
|
|
|
DefinedAtom::ContentPermissions DefinedAtom::permissions() const {
|
|
|
|
// By default base permissions on content type.
|
|
|
|
return permissions(this->contentType());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Utility function for deriving permissions from content type
|
|
|
|
DefinedAtom::ContentPermissions DefinedAtom::permissions(ContentType type) {
|
|
|
|
switch (type) {
|
|
|
|
case typeCode:
|
|
|
|
case typeResolver:
|
|
|
|
case typeBranchIsland:
|
|
|
|
case typeBranchShim:
|
|
|
|
case typeStub:
|
|
|
|
case typeStubHelper:
|
2014-11-13 06:21:56 +08:00
|
|
|
case typeMachHeader:
|
2013-01-09 09:17:12 +08:00
|
|
|
return permR_X;
|
2013-03-15 00:09:49 +08:00
|
|
|
|
2013-01-09 09:17:12 +08:00
|
|
|
case typeConstant:
|
|
|
|
case typeCString:
|
|
|
|
case typeUTF16String:
|
|
|
|
case typeCFI:
|
|
|
|
case typeLSDA:
|
|
|
|
case typeLiteral4:
|
|
|
|
case typeLiteral8:
|
|
|
|
case typeLiteral16:
|
|
|
|
case typeDTraceDOF:
|
|
|
|
case typeCompactUnwindInfo:
|
2014-10-01 05:29:54 +08:00
|
|
|
case typeProcessedUnwindInfo:
|
2016-01-20 05:54:21 +08:00
|
|
|
case typeObjCImageInfo:
|
2016-02-02 07:56:27 +08:00
|
|
|
case typeObjCMethodList:
|
2013-01-09 09:17:12 +08:00
|
|
|
return permR__;
|
|
|
|
|
|
|
|
case typeData:
|
2013-02-23 01:18:53 +08:00
|
|
|
case typeDataFast:
|
2013-01-09 09:17:12 +08:00
|
|
|
case typeZeroFill:
|
2013-02-24 11:09:10 +08:00
|
|
|
case typeZeroFillFast:
|
2013-01-09 09:17:12 +08:00
|
|
|
case typeObjC1Class:
|
|
|
|
case typeLazyPointer:
|
|
|
|
case typeLazyDylibPointer:
|
2016-02-10 04:11:17 +08:00
|
|
|
case typeNonLazyPointer:
|
2013-01-09 09:17:12 +08:00
|
|
|
case typeThunkTLV:
|
|
|
|
return permRW_;
|
|
|
|
|
|
|
|
case typeGOT:
|
|
|
|
case typeConstData:
|
|
|
|
case typeCFString:
|
|
|
|
case typeInitializerPtr:
|
|
|
|
case typeTerminatorPtr:
|
|
|
|
case typeCStringPtr:
|
|
|
|
case typeObjCClassPtr:
|
|
|
|
case typeObjC2CategoryList:
|
2014-11-06 09:09:13 +08:00
|
|
|
case typeInterposingTuples:
|
2013-01-09 09:17:12 +08:00
|
|
|
case typeTLVInitialData:
|
|
|
|
case typeTLVInitialZeroFill:
|
|
|
|
case typeTLVInitializerPtr:
|
|
|
|
return permRW_L;
|
2013-03-15 00:09:49 +08:00
|
|
|
|
2013-01-09 09:17:12 +08:00
|
|
|
case typeUnknown:
|
|
|
|
case typeTempLTO:
|
2015-10-24 16:20:51 +08:00
|
|
|
case typeSectCreate:
|
2016-02-03 05:37:15 +08:00
|
|
|
case typeDSOHandle:
|
2013-01-09 09:17:12 +08:00
|
|
|
return permUnknown;
|
|
|
|
}
|
|
|
|
llvm_unreachable("unknown content type");
|
|
|
|
}
|
|
|
|
|
ELF: Don't use LayoutPass.
Previously we applied the LayoutPass to order atoms and then
apply elf::ArrayOrderPass to sort them again. The first pass is
basically supposed to sort atoms in the normal fashion (which
is to sort symbols in the same order as the input files).
The second pass sorts atoms in {init,fini}_array.<priority> by
priority.
The problem is that the LayoutPass is overkill. It analyzes
references between atoms to make a decision how to sort them.
It's slow, hard to understand, and above all, it doesn't seem
that we need its feature for ELF in the first place.
This patch remove the LayoutPass from ELF pass list. Now all
reordering is done in elf::OrderPass. That pass sorts atoms by
{init,fini}_array, and if they are not in the special section,
they are ordered as the same order as they appear in the command
line. The new code is far easier to understand, faster, and
still able to create valid executables.
Unlike the previous layout pass, elf::OrderPass doesn't count
any attributes of an atom (e.g. permissions) except its
position. It's OK because the writer takes care of them if we
have to.
This patch changes the order of final output, although that's
benign. Tests are updated.
http://reviews.llvm.org/D7278
llvm-svn: 227666
2015-01-31 10:05:01 +08:00
|
|
|
bool DefinedAtom::compareByPosition(const DefinedAtom *lhs,
|
|
|
|
const DefinedAtom *rhs) {
|
2015-02-01 13:06:45 +08:00
|
|
|
if (lhs == rhs)
|
2015-02-01 13:27:01 +08:00
|
|
|
return false;
|
2015-02-04 08:44:52 +08:00
|
|
|
const File *lhsFile = &lhs->file();
|
|
|
|
const File *rhsFile = &rhs->file();
|
ELF: Don't use LayoutPass.
Previously we applied the LayoutPass to order atoms and then
apply elf::ArrayOrderPass to sort them again. The first pass is
basically supposed to sort atoms in the normal fashion (which
is to sort symbols in the same order as the input files).
The second pass sorts atoms in {init,fini}_array.<priority> by
priority.
The problem is that the LayoutPass is overkill. It analyzes
references between atoms to make a decision how to sort them.
It's slow, hard to understand, and above all, it doesn't seem
that we need its feature for ELF in the first place.
This patch remove the LayoutPass from ELF pass list. Now all
reordering is done in elf::OrderPass. That pass sorts atoms by
{init,fini}_array, and if they are not in the special section,
they are ordered as the same order as they appear in the command
line. The new code is far easier to understand, faster, and
still able to create valid executables.
Unlike the previous layout pass, elf::OrderPass doesn't count
any attributes of an atom (e.g. permissions) except its
position. It's OK because the writer takes care of them if we
have to.
This patch changes the order of final output, although that's
benign. Tests are updated.
http://reviews.llvm.org/D7278
llvm-svn: 227666
2015-01-31 10:05:01 +08:00
|
|
|
if (lhsFile->ordinal() != rhsFile->ordinal())
|
|
|
|
return lhsFile->ordinal() < rhsFile->ordinal();
|
|
|
|
assert(lhs->ordinal() != rhs->ordinal());
|
|
|
|
return lhs->ordinal() < rhs->ordinal();
|
|
|
|
}
|
2013-01-09 09:17:12 +08:00
|
|
|
|
|
|
|
} // namespace
|