summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-12-04 02:59:32 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-12-04 02:59:32 +0000
commit4c624745b7663cd7e5e077793994db19ea6a2178 (patch)
treea2a5b611b47a82624fe31dc457d12533a3aaaed6
parentdfd6c08c66b4b3d58fd28b5376478381e1a5647a (diff)
parent37b74a387bb3993387029859c2d9d051c41c724e (diff)
downloadmclinker-4c624745b7663cd7e5e077793994db19ea6a2178.tar.gz
Merge "Update mclinker for LLVM rebase to r222494."android-wear-5.0.0_r1lollipop-wear-release
-rw-r--r--Android.mk1
-rw-r--r--LICENSE.TXT8
-rw-r--r--include/mcld/ADT/BinTree.h421
-rw-r--r--include/mcld/ADT/Flags.h72
-rw-r--r--include/mcld/ADT/GraphLite/Digraph.h82
-rw-r--r--include/mcld/ADT/GraphLite/GraphBasicTypes.h29
-rw-r--r--include/mcld/ADT/GraphLite/ListDigraph.h89
-rw-r--r--include/mcld/ADT/HashBase.h71
-rw-r--r--include/mcld/ADT/HashBase.tcc135
-rw-r--r--include/mcld/ADT/HashEntry.h54
-rw-r--r--include/mcld/ADT/HashEntry.tcc23
-rw-r--r--include/mcld/ADT/HashEntryFactory.h30
-rw-r--r--include/mcld/ADT/HashIterator.h193
-rw-r--r--include/mcld/ADT/HashTable.h67
-rw-r--r--include/mcld/ADT/HashTable.tcc231
-rw-r--r--include/mcld/ADT/SizeTraits.h175
-rw-r--r--include/mcld/ADT/StringEntry.h122
-rw-r--r--include/mcld/ADT/StringEntry.tcc48
-rw-r--r--include/mcld/ADT/StringHash.h235
-rw-r--r--include/mcld/ADT/TreeAllocator.h34
-rw-r--r--include/mcld/ADT/TreeBase.h134
-rw-r--r--include/mcld/ADT/TypeTraits.h75
-rw-r--r--include/mcld/ADT/Uncopyable.h33
-rw-r--r--include/mcld/AttributeOption.h22
-rw-r--r--include/mcld/BitcodeOption.h46
-rw-r--r--include/mcld/CodeGen/MCLinker.h82
-rw-r--r--include/mcld/CodeGen/TargetMachine.h111
-rw-r--r--include/mcld/Config/Config.h.cmake621
-rw-r--r--include/mcld/Config/Config.h.in11
-rw-r--r--include/mcld/Config/Linkers.def.cmake28
-rw-r--r--include/mcld/Config/Targets.def.cmake28
-rw-r--r--include/mcld/Environment.h8
-rw-r--r--include/mcld/Fragment/AlignFragment.h34
-rw-r--r--include/mcld/Fragment/FillFragment.h31
-rw-r--r--include/mcld/Fragment/Fragment.h49
-rw-r--r--include/mcld/Fragment/FragmentRef.h43
-rw-r--r--include/mcld/Fragment/NullFragment.h26
-rw-r--r--include/mcld/Fragment/RegionFragment.h31
-rw-r--r--include/mcld/Fragment/Relocation.h54
-rw-r--r--include/mcld/Fragment/Stub.h72
-rw-r--r--include/mcld/Fragment/TargetFragment.h30
-rw-r--r--include/mcld/GeneralOptions.h442
-rw-r--r--include/mcld/IRBuilder.h217
-rw-r--r--include/mcld/InputTree.h245
-rw-r--r--include/mcld/LD/Archive.h128
-rw-r--r--include/mcld/LD/ArchiveReader.h21
-rw-r--r--include/mcld/LD/BSDArchiveReader.h23
-rw-r--r--include/mcld/LD/BinaryReader.h21
-rw-r--r--include/mcld/LD/BranchIsland.h97
-rw-r--r--include/mcld/LD/BranchIslandFactory.h24
-rw-r--r--include/mcld/LD/DWARFLineInfo.h19
-rw-r--r--include/mcld/LD/DebugString.h65
-rw-r--r--include/mcld/LD/DiagAttribute.inc88
-rw-r--r--include/mcld/LD/DiagCommonKinds.inc273
-rw-r--r--include/mcld/LD/DiagGOTPLT.inc25
-rw-r--r--include/mcld/LD/DiagLDScript.inc15
-rw-r--r--include/mcld/LD/DiagLayouts.inc42
-rw-r--r--include/mcld/LD/DiagReaders.inc20
-rw-r--r--include/mcld/LD/DiagRelocations.inc87
-rw-r--r--include/mcld/LD/DiagSymbolResolutions.inc55
-rw-r--r--include/mcld/LD/Diagnostic.h39
-rw-r--r--include/mcld/LD/DiagnosticEngine.h59
-rw-r--r--include/mcld/LD/DiagnosticInfos.h29
-rw-r--r--include/mcld/LD/DiagnosticLineInfo.h17
-rw-r--r--include/mcld/LD/DiagnosticPrinter.h27
-rw-r--r--include/mcld/LD/DynObjFileFormat.h17
-rw-r--r--include/mcld/LD/DynObjReader.h22
-rw-r--r--include/mcld/LD/ELFBinaryReader.h21
-rw-r--r--include/mcld/LD/ELFDynObjFileFormat.h14
-rw-r--r--include/mcld/LD/ELFDynObjReader.h28
-rw-r--r--include/mcld/LD/ELFExecFileFormat.h14
-rw-r--r--include/mcld/LD/ELFFileFormat.h510
-rw-r--r--include/mcld/LD/ELFObjectFileFormat.h14
-rw-r--r--include/mcld/LD/ELFObjectReader.h33
-rw-r--r--include/mcld/LD/ELFObjectWriter.h65
-rw-r--r--include/mcld/LD/ELFReader.h84
-rw-r--r--include/mcld/LD/ELFReaderIf.h42
-rw-r--r--include/mcld/LD/ELFSegment.h107
-rw-r--r--include/mcld/LD/ELFSegmentFactory.h39
-rw-r--r--include/mcld/LD/EhFrame.h153
-rw-r--r--include/mcld/LD/EhFrameHdr.h36
-rw-r--r--include/mcld/LD/EhFrameReader.h63
-rw-r--r--include/mcld/LD/GNUArchiveReader.h34
-rw-r--r--include/mcld/LD/GarbageCollection.h30
-rw-r--r--include/mcld/LD/Group.h16
-rw-r--r--include/mcld/LD/GroupReader.h29
-rw-r--r--include/mcld/LD/IdenticalCodeFolding.h35
-rw-r--r--include/mcld/LD/LDContext.h55
-rw-r--r--include/mcld/LD/LDFileFormat.h52
-rw-r--r--include/mcld/LD/LDReader.h35
-rw-r--r--include/mcld/LD/LDSection.h122
-rw-r--r--include/mcld/LD/LDSymbol.h83
-rw-r--r--include/mcld/LD/MergedStringTable.h62
-rw-r--r--include/mcld/LD/MsgHandler.h81
-rw-r--r--include/mcld/LD/NamePool.h94
-rw-r--r--include/mcld/LD/ObjectReader.h41
-rw-r--r--include/mcld/LD/ObjectWriter.h18
-rw-r--r--include/mcld/LD/RelocData.h77
-rw-r--r--include/mcld/LD/RelocationFactory.h31
-rw-r--r--include/mcld/LD/Relocator.h87
-rw-r--r--include/mcld/LD/ResolveInfo.h201
-rw-r--r--include/mcld/LD/Resolver.h47
-rw-r--r--include/mcld/LD/SectionData.h64
-rw-r--r--include/mcld/LD/SectionSymbolSet.h43
-rw-r--r--include/mcld/LD/StaticResolver.h120
-rw-r--r--include/mcld/LD/StubFactory.h28
-rw-r--r--include/mcld/LD/TextDiagnosticPrinter.h25
-rw-r--r--include/mcld/Linker.h31
-rw-r--r--include/mcld/LinkerConfig.h64
-rw-r--r--include/mcld/LinkerScript.h51
-rw-r--r--include/mcld/MC/Attribute.h143
-rw-r--r--include/mcld/MC/AttributeSet.h34
-rw-r--r--include/mcld/MC/CommandAction.h111
-rw-r--r--include/mcld/MC/ContextFactory.h24
-rw-r--r--include/mcld/MC/FileAction.h29
-rw-r--r--include/mcld/MC/Input.h91
-rw-r--r--include/mcld/MC/InputAction.h29
-rw-r--r--include/mcld/MC/InputBuilder.h67
-rw-r--r--include/mcld/MC/InputFactory.h31
-rw-r--r--include/mcld/MC/MCLDDirectory.h34
-rw-r--r--include/mcld/MC/SearchDirs.h48
-rw-r--r--include/mcld/MC/SymbolCategory.h84
-rw-r--r--include/mcld/MC/ZOption.h22
-rw-r--r--include/mcld/Module.h118
-rw-r--r--include/mcld/Object/ObjectBuilder.h49
-rw-r--r--include/mcld/Object/ObjectLinker.h83
-rw-r--r--include/mcld/Object/SectionMap.h131
-rw-r--r--include/mcld/Script/AssertCmd.h26
-rw-r--r--include/mcld/Script/Assignment.h50
-rw-r--r--include/mcld/Script/BinaryOp.h106
-rw-r--r--include/mcld/Script/EntryCmd.h27
-rw-r--r--include/mcld/Script/ExprToken.h35
-rw-r--r--include/mcld/Script/FileToken.h27
-rw-r--r--include/mcld/Script/FlexLexer.h219
-rw-r--r--include/mcld/Script/GroupCmd.h26
-rw-r--r--include/mcld/Script/InputCmd.h59
-rw-r--r--include/mcld/Script/InputSectDesc.h35
-rw-r--r--include/mcld/Script/InputToken.h33
-rw-r--r--include/mcld/Script/NameSpec.h27
-rw-r--r--include/mcld/Script/NullaryOp.h41
-rw-r--r--include/mcld/Script/Operand.h127
-rw-r--r--include/mcld/Script/Operator.h218
-rw-r--r--include/mcld/Script/OutputArchCmd.h27
-rw-r--r--include/mcld/Script/OutputCmd.h27
-rw-r--r--include/mcld/Script/OutputFormatCmd.h35
-rw-r--r--include/mcld/Script/OutputSectDesc.h57
-rw-r--r--include/mcld/Script/RpnEvaluator.h19
-rw-r--r--include/mcld/Script/RpnExpr.h36
-rw-r--r--include/mcld/Script/ScriptCommand.h37
-rw-r--r--include/mcld/Script/ScriptFile.h83
-rw-r--r--include/mcld/Script/ScriptReader.h39
-rw-r--r--include/mcld/Script/ScriptScanner.h32
-rw-r--r--include/mcld/Script/SearchDirCmd.h27
-rw-r--r--include/mcld/Script/SectionsCmd.h41
-rw-r--r--include/mcld/Script/StrToken.h40
-rw-r--r--include/mcld/Script/StringList.h42
-rw-r--r--include/mcld/Script/TernaryOp.h47
-rw-r--r--include/mcld/Script/UnaryOp.h68
-rw-r--r--include/mcld/Script/WildcardPattern.h32
-rw-r--r--include/mcld/Support/Allocators.h345
-rw-r--r--include/mcld/Support/CommandLine.h67
-rw-r--r--include/mcld/Support/Compiler.h30
-rw-r--r--include/mcld/Support/Demangle.h8
-rw-r--r--include/mcld/Support/Directory.h96
-rw-r--r--include/mcld/Support/ELF.h18
-rw-r--r--include/mcld/Support/FileHandle.h91
-rw-r--r--include/mcld/Support/FileOutputBuffer.h28
-rw-r--r--include/mcld/Support/FileSystem.h61
-rw-r--r--include/mcld/Support/GCFactory.h181
-rw-r--r--include/mcld/Support/GCFactoryListTraits.h47
-rw-r--r--include/mcld/Support/LEB128.h69
-rw-r--r--include/mcld/Support/MemoryArea.h21
-rw-r--r--include/mcld/Support/MemoryAreaFactory.h31
-rw-r--r--include/mcld/Support/MemoryRegion.h11
-rw-r--r--include/mcld/Support/MsgHandling.h32
-rw-r--r--include/mcld/Support/Path.h91
-rw-r--r--include/mcld/Support/PathCache.h37
-rw-r--r--include/mcld/Support/RealPath.h57
-rw-r--r--include/mcld/Support/SystemUtils.h17
-rw-r--r--include/mcld/Support/Target.h40
-rw-r--r--include/mcld/Support/TargetRegistry.h104
-rw-r--r--include/mcld/Support/TargetSelect.h125
-rw-r--r--include/mcld/Support/UniqueGCFactory.h39
-rw-r--r--include/mcld/Support/raw_ostream.h41
-rw-r--r--include/mcld/Target/DarwinLDBackend.h20
-rw-r--r--include/mcld/Target/ELFAttribute.h84
-rw-r--r--include/mcld/Target/ELFAttributeData.h68
-rw-r--r--include/mcld/Target/ELFAttributeValue.h91
-rw-r--r--include/mcld/Target/ELFDynamic.h110
-rw-r--r--include/mcld/Target/ELFDynamic.tcc25
-rw-r--r--include/mcld/Target/ELFEmulation.h9
-rw-r--r--include/mcld/Target/GNUInfo.h23
-rw-r--r--include/mcld/Target/GNULDBackend.h185
-rw-r--r--include/mcld/Target/GOT.h61
-rw-r--r--include/mcld/Target/KeyEntryMap.h109
-rw-r--r--include/mcld/Target/OutputRelocSection.h28
-rw-r--r--include/mcld/Target/PLT.h76
-rw-r--r--include/mcld/Target/TargetLDBackend.h75
-rw-r--r--include/mcld/TargetOptions.h31
-rw-r--r--lib/ADT/GraphLite/Digraph.cpp88
-rw-r--r--lib/ADT/GraphLite/ListDigraph.cpp178
-rw-r--r--lib/ADT/StringEntry.cpp34
-rw-r--r--lib/CodeGen/Android.mk29
-rw-r--r--lib/CodeGen/MCLDTargetMachine.cpp382
-rw-r--r--lib/CodeGen/MCLinker.cpp424
-rw-r--r--lib/Core/Android.mk7
-rw-r--r--lib/Core/AttributeOption.cpp12
-rw-r--r--lib/Core/BitcodeOption.cpp27
-rw-r--r--lib/Core/Environment.cpp11
-rw-r--r--lib/Core/GeneralOptions.cpp114
-rw-r--r--lib/Core/IRBuilder.cpp494
-rw-r--r--lib/Core/InputTree.cpp37
-rw-r--r--lib/Core/Linker.cpp211
-rw-r--r--lib/Core/LinkerConfig.cpp40
-rw-r--r--lib/Core/LinkerScript.cpp39
-rw-r--r--lib/Core/Module.cpp61
-rw-r--r--lib/Core/TargetOptions.cpp31
-rw-r--r--lib/Fragment/AlignFragment.cpp24
-rw-r--r--lib/Fragment/FillFragment.cpp15
-rw-r--r--lib/Fragment/Fragment.cpp25
-rw-r--r--lib/Fragment/FragmentRef.cpp72
-rw-r--r--lib/Fragment/NullFragment.cpp9
-rw-r--r--lib/Fragment/RegionFragment.cpp13
-rw-r--r--lib/Fragment/Relocation.cpp84
-rw-r--r--lib/Fragment/Stub.cpp27
-rw-r--r--lib/LD/Archive.cpp132
-rw-r--r--lib/LD/ArchiveReader.cpp10
-rw-r--r--lib/LD/BSDArchiveReader.cpp21
-rw-r--r--lib/LD/BinaryReader.cpp8
-rw-r--r--lib/LD/BranchIsland.cpp82
-rw-r--r--lib/LD/BranchIslandFactory.cpp45
-rw-r--r--lib/LD/DWARFLineInfo.cpp5
-rw-r--r--lib/LD/DebugString.cpp95
-rw-r--r--lib/LD/Diagnostic.cpp83
-rw-r--r--lib/LD/DiagnosticEngine.cpp45
-rw-r--r--lib/LD/DiagnosticInfos.cpp118
-rw-r--r--lib/LD/DiagnosticLineInfo.cpp5
-rw-r--r--lib/LD/DiagnosticPrinter.cpp14
-rw-r--r--lib/LD/DynObjReader.cpp7
-rw-r--r--lib/LD/ELFBinaryReader.cpp62
-rw-r--r--lib/LD/ELFDynObjFileFormat.cpp155
-rw-r--r--lib/LD/ELFDynObjReader.cpp56
-rw-r--r--lib/LD/ELFExecFileFormat.cpp156
-rw-r--r--lib/LD/ELFFileFormat.cpp417
-rw-r--r--lib/LD/ELFObjectReader.cpp138
-rw-r--r--lib/LD/ELFObjectWriter.cpp490
-rw-r--r--lib/LD/ELFReader.cpp579
-rw-r--r--lib/LD/ELFReaderIf.cpp99
-rw-r--r--lib/LD/ELFSegment.cpp82
-rw-r--r--lib/LD/ELFSegmentFactory.cpp48
-rw-r--r--lib/LD/EhFrame.cpp178
-rw-r--r--lib/LD/EhFrameHdr.cpp97
-rw-r--r--lib/LD/EhFrameReader.cpp122
-rw-r--r--lib/LD/GNUArchiveReader.cpp262
-rw-r--r--lib/LD/GarbageCollection.cpp134
-rw-r--r--lib/LD/GroupReader.cpp65
-rw-r--r--lib/LD/IdenticalCodeFolding.cpp119
-rw-r--r--lib/LD/LDContext.cpp46
-rw-r--r--lib/LD/LDFileFormat.cpp16
-rw-r--r--lib/LD/LDReader.cpp6
-rw-r--r--lib/LD/LDSection.cpp86
-rw-r--r--lib/LD/LDSymbol.cpp58
-rw-r--r--lib/LD/MergedStringTable.cpp42
-rw-r--r--lib/LD/MsgHandler.cpp26
-rw-r--r--lib/LD/NamePool.cpp80
-rw-r--r--lib/LD/ObjectWriter.cpp11
-rw-r--r--lib/LD/RelocData.cpp30
-rw-r--r--lib/LD/RelocationFactory.cpp39
-rw-r--r--lib/LD/Relocator.cpp57
-rw-r--r--lib/LD/ResolveInfo.cpp166
-rw-r--r--lib/LD/Resolver.cpp8
-rw-r--r--lib/LD/SectionData.cpp24
-rw-r--r--lib/LD/SectionSymbolSet.cpp54
-rw-r--r--lib/LD/StaticResolver.cpp124
-rw-r--r--lib/LD/StubFactory.cpp53
-rw-r--r--lib/LD/TextDiagnosticPrinter.cpp65
-rw-r--r--lib/MC/Attribute.cpp88
-rw-r--r--lib/MC/AttributeSet.cpp24
-rw-r--r--lib/MC/CommandAction.cpp150
-rw-r--r--lib/MC/ContextFactory.cpp26
-rw-r--r--lib/MC/FileAction.cpp37
-rw-r--r--lib/MC/Input.cpp99
-rw-r--r--lib/MC/InputAction.cpp11
-rw-r--r--lib/MC/InputBuilder.cpp106
-rw-r--r--lib/MC/InputFactory.cpp30
-rw-r--r--lib/MC/MCLDDirectory.cpp56
-rw-r--r--lib/MC/SearchDirs.cpp222
-rw-r--r--lib/MC/SymbolCategory.cpp263
-rw-r--r--lib/MC/ZOption.cpp15
-rw-r--r--lib/Object/ObjectBuilder.cpp101
-rw-r--r--lib/Object/ObjectLinker.cpp640
-rw-r--r--lib/Object/SectionMap.cpp151
-rw-r--r--lib/Script/AssertCmd.cpp34
-rw-r--r--lib/Script/Assignment.cpp228
-rw-r--r--lib/Script/BinaryOp.cpp167
-rw-r--r--lib/Script/CMakeLists.txt1
-rw-r--r--lib/Script/EntryCmd.cpp25
-rw-r--r--lib/Script/FileToken.cpp28
-rw-r--r--lib/Script/GroupCmd.cpp159
-rw-r--r--lib/Script/InputCmd.cpp213
-rw-r--r--lib/Script/InputSectDesc.cpp72
-rw-r--r--lib/Script/InputToken.cpp16
-rw-r--r--lib/Script/NameSpec.cpp28
-rw-r--r--lib/Script/NullaryOp.cpp38
-rw-r--r--lib/Script/Operand.cpp130
-rw-r--r--lib/Script/Operator.cpp319
-rw-r--r--lib/Script/OutputArchCmd.cpp20
-rw-r--r--lib/Script/OutputCmd.cpp24
-rw-r--r--lib/Script/OutputFormatCmd.cpp22
-rw-r--r--lib/Script/OutputSectDesc.cpp175
-rw-r--r--lib/Script/RpnEvaluator.cpp159
-rw-r--r--lib/Script/RpnExpr.cpp54
-rw-r--r--lib/Script/ScriptCommand.cpp8
-rw-r--r--lib/Script/ScriptFile.cpp170
-rw-r--r--lib/Script/ScriptParser.yy39
-rw-r--r--lib/Script/ScriptReader.cpp42
-rw-r--r--lib/Script/ScriptScanner.ll8
-rw-r--r--lib/Script/SearchDirCmd.cpp25
-rw-r--r--lib/Script/SectionsCmd.cpp94
-rw-r--r--lib/Script/StrToken.cpp29
-rw-r--r--lib/Script/StringList.cpp35
-rw-r--r--lib/Script/TernaryOp.cpp29
-rw-r--r--lib/Script/UnaryOp.cpp172
-rw-r--r--lib/Script/WildcardPattern.cpp38
-rw-r--r--lib/Support/Android.mk3
-rw-r--r--lib/Support/CommandLine.cpp160
-rw-r--r--lib/Support/Demangle.cpp23
-rw-r--r--lib/Support/Directory.cpp164
-rw-r--r--lib/Support/FileHandle.cpp119
-rw-r--r--lib/Support/FileOutputBuffer.cpp42
-rw-r--r--lib/Support/FileSystem.cpp12
-rw-r--r--lib/Support/LEB128.cpp78
-rw-r--r--lib/Support/MemoryArea.cpp35
-rw-r--r--lib/Support/MemoryAreaFactory.cpp30
-rw-r--r--lib/Support/MsgHandling.cpp40
-rw-r--r--lib/Support/Path.cpp152
-rw-r--r--lib/Support/RealPath.cpp31
-rw-r--r--lib/Support/SystemUtils.cpp4
-rw-r--r--lib/Support/Target.cpp68
-rw-r--r--lib/Support/TargetRegistry.cpp48
-rw-r--r--lib/Support/ToolOutputFile.cpp104
-rw-r--r--lib/Support/Unix/FileSystem.inc119
-rw-r--r--lib/Support/Unix/PathV3.inc160
-rw-r--r--lib/Support/Unix/System.inc47
-rw-r--r--lib/Support/Windows/FileSystem.inc83
-rw-r--r--lib/Support/Windows/PathV3.inc111
-rw-r--r--lib/Support/Windows/System.inc35
-rw-r--r--lib/Support/raw_ostream.cpp70
-rw-r--r--lib/Target/AArch64/AArch64.h13
-rw-r--r--lib/Target/AArch64/AArch64Diagnostic.cpp16
-rw-r--r--lib/Target/AArch64/AArch64ELFDynamic.cpp25
-rw-r--r--lib/Target/AArch64/AArch64ELFDynamic.h14
-rw-r--r--lib/Target/AArch64/AArch64ELFMCLinker.cpp25
-rw-r--r--lib/Target/AArch64/AArch64ELFMCLinker.h34
-rw-r--r--lib/Target/AArch64/AArch64Emulation.cpp18
-rw-r--r--lib/Target/AArch64/AArch64GNUInfo.h18
-rw-r--r--lib/Target/AArch64/AArch64GOT.cpp60
-rw-r--r--lib/Target/AArch64/AArch64GOT.h32
-rw-r--r--lib/Target/AArch64/AArch64LDBackend.cpp307
-rw-r--r--lib/Target/AArch64/AArch64LDBackend.h39
-rw-r--r--lib/Target/AArch64/AArch64MCLinker.cpp51
-rw-r--r--lib/Target/AArch64/AArch64PLT.cpp60
-rw-r--r--lib/Target/AArch64/AArch64PLT.h60
-rw-r--r--lib/Target/AArch64/AArch64RelocationFunctions.h203
-rw-r--r--lib/Target/AArch64/AArch64RelocationHelpers.h134
-rw-r--r--lib/Target/AArch64/AArch64Relocator.cpp268
-rw-r--r--lib/Target/AArch64/AArch64Relocator.h79
-rw-r--r--lib/Target/AArch64/AArch64TargetMachine.cpp30
-rw-r--r--lib/Target/AArch64/AArch64TargetMachine.h29
-rw-r--r--lib/Target/AArch64/Android.mk5
-rw-r--r--lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp7
-rw-r--r--lib/Target/ARM/ARM.h13
-rw-r--r--lib/Target/ARM/ARMDiagnostic.cpp18
-rw-r--r--lib/Target/ARM/ARMELFAttributeData.cpp335
-rw-r--r--lib/Target/ARM/ARMELFAttributeData.h195
-rw-r--r--lib/Target/ARM/ARMELFDynamic.cpp17
-rw-r--r--lib/Target/ARM/ARMELFDynamic.h14
-rw-r--r--lib/Target/ARM/ARMELFMCLinker.cpp22
-rw-r--r--lib/Target/ARM/ARMELFMCLinker.h34
-rw-r--r--lib/Target/ARM/ARMEmulation.cpp23
-rw-r--r--lib/Target/ARM/ARMGNUInfo.h18
-rw-r--r--lib/Target/ARM/ARMGOT.cpp56
-rw-r--r--lib/Target/ARM/ARMGOT.h32
-rw-r--r--lib/Target/ARM/ARMLDBackend.cpp549
-rw-r--r--lib/Target/ARM/ARMLDBackend.h64
-rw-r--r--lib/Target/ARM/ARMMCLinker.cpp50
-rw-r--r--lib/Target/ARM/ARMPLT.cpp56
-rw-r--r--lib/Target/ARM/ARMPLT.h52
-rw-r--r--lib/Target/ARM/ARMRelocationFunctions.h320
-rw-r--r--lib/Target/ARM/ARMRelocator.cpp576
-rw-r--r--lib/Target/ARM/ARMRelocator.h60
-rw-r--r--lib/Target/ARM/ARMTargetMachine.cpp31
-rw-r--r--lib/Target/ARM/ARMTargetMachine.h29
-rw-r--r--lib/Target/ARM/ARMToARMStub.cpp53
-rw-r--r--lib/Target/ARM/ARMToARMStub.h25
-rw-r--r--lib/Target/ARM/ARMToTHMStub.cpp55
-rw-r--r--lib/Target/ARM/ARMToTHMStub.h25
-rw-r--r--lib/Target/ARM/Android.mk3
-rw-r--r--lib/Target/ARM/THMToARMStub.cpp74
-rw-r--r--lib/Target/ARM/THMToARMStub.h23
-rw-r--r--lib/Target/ARM/THMToTHMStub.cpp88
-rw-r--r--lib/Target/ARM/THMToTHMStub.h23
-rw-r--r--lib/Target/ARM/TargetInfo/ARMTargetInfo.cpp7
-rw-r--r--lib/Target/Android.mk1
-rw-r--r--lib/Target/ELFAttribute.cpp138
-rw-r--r--lib/Target/ELFAttributeData.cpp27
-rw-r--r--lib/Target/ELFAttributeValue.cpp17
-rw-r--r--lib/Target/ELFDynamic.cpp237
-rw-r--r--lib/Target/ELFEmulation.cpp115
-rw-r--r--lib/Target/ELFMCLinker.cpp27
-rw-r--r--lib/Target/GNUInfo.cpp11
-rw-r--r--lib/Target/GNULDBackend.cpp1674
-rw-r--r--lib/Target/GOT.cpp22
-rw-r--r--lib/Target/Hexagon/Hexagon.h15
-rw-r--r--lib/Target/Hexagon/HexagonAbsoluteStub.cpp56
-rw-r--r--lib/Target/Hexagon/HexagonAbsoluteStub.h33
-rw-r--r--lib/Target/Hexagon/HexagonDiagnostic.cpp18
-rw-r--r--lib/Target/Hexagon/HexagonELFDynamic.cpp16
-rw-r--r--lib/Target/Hexagon/HexagonELFDynamic.h17
-rw-r--r--lib/Target/Hexagon/HexagonELFMCLinker.cpp22
-rw-r--r--lib/Target/Hexagon/HexagonELFMCLinker.h35
-rw-r--r--lib/Target/Hexagon/HexagonEmulation.cpp18
-rw-r--r--lib/Target/Hexagon/HexagonEncodings.h6
-rw-r--r--lib/Target/Hexagon/HexagonGNUInfo.cpp14
-rw-r--r--lib/Target/Hexagon/HexagonGNUInfo.h30
-rw-r--r--lib/Target/Hexagon/HexagonGOT.cpp17
-rw-r--r--lib/Target/Hexagon/HexagonGOT.h26
-rw-r--r--lib/Target/Hexagon/HexagonGOTPLT.cpp34
-rw-r--r--lib/Target/Hexagon/HexagonGOTPLT.h17
-rw-r--r--lib/Target/Hexagon/HexagonLDBackend.cpp705
-rw-r--r--lib/Target/Hexagon/HexagonLDBackend.h51
-rw-r--r--lib/Target/Hexagon/HexagonMCLinker.cpp53
-rw-r--r--lib/Target/Hexagon/HexagonPLT.cpp71
-rw-r--r--lib/Target/Hexagon/HexagonPLT.h72
-rw-r--r--lib/Target/Hexagon/HexagonRelocationFunctions.h205
-rw-r--r--lib/Target/Hexagon/HexagonRelocator.cpp986
-rw-r--r--lib/Target/Hexagon/HexagonRelocator.h68
-rw-r--r--lib/Target/Hexagon/HexagonTargetMachine.cpp29
-rw-r--r--lib/Target/Hexagon/HexagonTargetMachine.h27
-rw-r--r--lib/Target/Hexagon/TargetInfo/HexagonTargetInfo.cpp9
-rw-r--r--lib/Target/Mips/Android.mk5
-rw-r--r--lib/Target/Mips/Mips.h8
-rw-r--r--lib/Target/Mips/MipsDiagnostic.cpp9
-rw-r--r--lib/Target/Mips/MipsELFDynamic.cpp42
-rw-r--r--lib/Target/Mips/MipsELFDynamic.h19
-rw-r--r--lib/Target/Mips/MipsELFMCLinker.cpp22
-rw-r--r--lib/Target/Mips/MipsELFMCLinker.h34
-rw-r--r--lib/Target/Mips/MipsEmulation.cpp16
-rw-r--r--lib/Target/Mips/MipsGNUInfo.cpp35
-rw-r--r--lib/Target/Mips/MipsGNUInfo.h21
-rw-r--r--lib/Target/Mips/MipsGOT.cpp232
-rw-r--r--lib/Target/Mips/MipsGOT.h88
-rw-r--r--lib/Target/Mips/MipsGOTPLT.cpp37
-rw-r--r--lib/Target/Mips/MipsGOTPLT.h23
-rw-r--r--lib/Target/Mips/MipsLA25Stub.cpp53
-rw-r--r--lib/Target/Mips/MipsLA25Stub.h26
-rw-r--r--lib/Target/Mips/MipsLDBackend.cpp642
-rw-r--r--lib/Target/Mips/MipsLDBackend.h65
-rw-r--r--lib/Target/Mips/MipsMCLinker.cpp48
-rw-r--r--lib/Target/Mips/MipsPLT.cpp78
-rw-r--r--lib/Target/Mips/MipsPLT.h23
-rw-r--r--lib/Target/Mips/MipsRelocationFunctions.h564
-rw-r--r--lib/Target/Mips/MipsRelocator.cpp487
-rw-r--r--lib/Target/Mips/MipsRelocator.h69
-rw-r--r--lib/Target/Mips/MipsTargetMachine.cpp30
-rw-r--r--lib/Target/Mips/MipsTargetMachine.h27
-rw-r--r--lib/Target/Mips/TargetInfo/MipsTargetInfo.cpp13
-rw-r--r--lib/Target/OutputRelocSection.cpp53
-rw-r--r--lib/Target/PLT.cpp14
-rw-r--r--lib/Target/TargetLDBackend.cpp13
-rw-r--r--lib/Target/X86/Android.mk5
-rw-r--r--lib/Target/X86/TargetInfo/X86TargetInfo.cpp13
-rw-r--r--lib/Target/X86/X86.h13
-rw-r--r--lib/Target/X86/X86Diagnostic.cpp18
-rw-r--r--lib/Target/X86/X86ELFDynamic.cpp18
-rw-r--r--lib/Target/X86/X86ELFDynamic.h17
-rw-r--r--lib/Target/X86/X86ELFMCLinker.cpp22
-rw-r--r--lib/Target/X86/X86ELFMCLinker.h36
-rw-r--r--lib/Target/X86/X86Emulation.cpp28
-rw-r--r--lib/Target/X86/X86GNUInfo.h27
-rw-r--r--lib/Target/X86/X86GOT.cpp27
-rw-r--r--lib/Target/X86/X86GOT.h41
-rw-r--r--lib/Target/X86/X86GOTPLT.cpp54
-rw-r--r--lib/Target/X86/X86GOTPLT.h29
-rw-r--r--lib/Target/X86/X86LDBackend.cpp576
-rw-r--r--lib/Target/X86/X86LDBackend.h61
-rw-r--r--lib/Target/X86/X86MCLinker.cpp50
-rw-r--r--lib/Target/X86/X86PLT.cpp98
-rw-r--r--lib/Target/X86/X86PLT.h112
-rw-r--r--lib/Target/X86/X86RelocationFunctions.h231
-rw-r--r--lib/Target/X86/X86Relocator.cpp793
-rw-r--r--lib/Target/X86/X86Relocator.h111
-rw-r--r--lib/Target/X86/X86TargetMachine.cpp31
-rw-r--r--lib/Target/X86/X86TargetMachine.h28
-rw-r--r--tools/mcld/include/mcld/DynamicSectionOptions.h14
-rw-r--r--tools/mcld/include/mcld/OptimizationOptions.h10
-rw-r--r--tools/mcld/include/mcld/OutputFormatOptions.h10
-rw-r--r--tools/mcld/include/mcld/PositionalOptions.h15
-rw-r--r--tools/mcld/include/mcld/PreferenceOptions.h32
-rw-r--r--tools/mcld/include/mcld/ScriptOptions.h10
-rw-r--r--tools/mcld/include/mcld/SearchPathOptions.h27
-rw-r--r--tools/mcld/include/mcld/SymbolOptions.h10
-rw-r--r--tools/mcld/include/mcld/TargetControlOptions.h10
-rw-r--r--tools/mcld/include/mcld/TripleOptions.h18
-rw-r--r--tools/mcld/lib/DynamicSectionOptions.cpp146
-rw-r--r--tools/mcld/lib/OptimizationOptions.cpp178
-rw-r--r--tools/mcld/lib/OutputFormatOptions.cpp351
-rw-r--r--tools/mcld/lib/PositionalOptions.cpp280
-rw-r--r--tools/mcld/lib/PreferenceOptions.cpp190
-rw-r--r--tools/mcld/lib/ScriptOptions.cpp120
-rw-r--r--tools/mcld/lib/SearchPathOptions.cpp93
-rw-r--r--tools/mcld/lib/SymbolOptions.cpp58
-rw-r--r--tools/mcld/lib/TargetControlOptions.cpp69
-rw-r--r--tools/mcld/lib/TripleOptions.cpp120
-rw-r--r--tools/mcld/main.cpp86
-rw-r--r--unittests/BinTreeTest.cpp192
-rw-r--r--unittests/BinTreeTest.h39
-rw-r--r--unittests/DirIteratorTest.cpp25
-rw-r--r--unittests/DirIteratorTest.h40
-rw-r--r--unittests/ELFBinaryReaderTest.cpp32
-rw-r--r--unittests/ELFBinaryReaderTest.h10
-rw-r--r--unittests/ELFReaderTest.cpp101
-rw-r--r--unittests/ELFReaderTest.h32
-rw-r--r--unittests/FactoriesTest.cpp338
-rw-r--r--unittests/FactoriesTest.h48
-rw-r--r--unittests/FileHandleTest.cpp23
-rw-r--r--unittests/FileHandleTest.h18
-rw-r--r--unittests/FragmentRefTest.cpp45
-rw-r--r--unittests/FragmentRefTest.h16
-rw-r--r--unittests/FragmentTest.cpp35
-rw-r--r--unittests/FragmentTest.h18
-rw-r--r--unittests/GCFactoryListTraitsTest.cpp72
-rw-r--r--unittests/GCFactoryListTraitsTest.h76
-rw-r--r--unittests/GraphTest.cpp85
-rw-r--r--unittests/GraphTest.h11
-rw-r--r--unittests/HashTableTest.cpp183
-rw-r--r--unittests/HashTableTest.h27
-rw-r--r--unittests/InputTreeTest.cpp68
-rw-r--r--unittests/InputTreeTest.h16
-rw-r--r--unittests/LDSymbolTest.cpp18
-rw-r--r--unittests/LDSymbolTest.h17
-rw-r--r--unittests/LEB128Test.cpp66
-rw-r--r--unittests/LEB128Test.h27
-rw-r--r--unittests/LinearAllocatorTest.cpp182
-rw-r--r--unittests/LinearAllocatorTest.h86
-rw-r--r--unittests/LinkerTest.cpp234
-rw-r--r--unittests/LinkerTest.h10
-rw-r--r--unittests/MCRegionFragmentTest.cpp28
-rw-r--r--unittests/MCRegionFragmentTest.h36
-rw-r--r--unittests/NamePoolTest.cpp157
-rw-r--r--unittests/NamePoolTest.h36
-rw-r--r--unittests/PathSetTest.cpp22
-rw-r--r--unittests/PathSetTest.h36
-rw-r--r--unittests/PathTest.cpp60
-rw-r--r--unittests/PathTest.h31
-rw-r--r--unittests/RTLinearAllocatorTest.cpp178
-rw-r--r--unittests/RTLinearAllocatorTest.h78
-rw-r--r--unittests/SectionDataTest.cpp30
-rw-r--r--unittests/SectionDataTest.h13
-rw-r--r--unittests/StaticResolverTest.cpp414
-rw-r--r--unittests/StaticResolverTest.h17
-rw-r--r--unittests/StringTableTest.cpp15
-rw-r--r--unittests/StringTableTest.h18
-rw-r--r--unittests/SymbolCategoryTest.cpp19
-rw-r--r--unittests/SymbolCategoryTest.h18
-rw-r--r--unittests/SymbolTableTest.cpp15
-rw-r--r--unittests/SymbolTableTest.h21
-rw-r--r--unittests/SystemUtilsTest.cpp18
-rw-r--r--unittests/SystemUtilsTest.h10
-rw-r--r--unittests/TargetMachineTest.cpp18
-rw-r--r--unittests/TargetMachineTest.h27
-rw-r--r--unittests/UniqueGCFactoryBaseTest.cpp113
-rw-r--r--unittests/UniqueGCFactoryBaseTest.h19
573 files changed, 22011 insertions, 26100 deletions
diff --git a/Android.mk b/Android.mk
index 8e6d232..3f72fe5 100644
--- a/Android.mk
+++ b/Android.mk
@@ -9,7 +9,6 @@ include $(CLEAR_VARS)
# MCLinker Libraries
subdirs := \
lib/ADT \
- lib/CodeGen \
lib/Core \
lib/Fragment \
lib/LD \
diff --git a/LICENSE.TXT b/LICENSE.TXT
index 562a772..58ba014 100644
--- a/LICENSE.TXT
+++ b/LICENSE.TXT
@@ -4,7 +4,7 @@ MCLinker Release License
University of Illinois/NCSA
Open Source License
-Copyright (c) 2011-2013 MediaTek Inc.
+Copyright (c) 2011-2014 MediaTek Inc.
All rights reserved.
Developed by:
@@ -59,6 +59,6 @@ licenses, and/or restrictions:
Program Directory
------- ---------
-Google Test utils/gtest/
-Quake test/Android/Quake/
-Quake2 test/Android/Quake2/
+cpplint utils/cpplint
+Google Test utils/gtest
+zlib utils/zlib
diff --git a/include/mcld/ADT/BinTree.h b/include/mcld/ADT/BinTree.h
index a23bc7d..a9b50f4 100644
--- a/include/mcld/ADT/BinTree.h
+++ b/include/mcld/ADT/BinTree.h
@@ -6,12 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_BITREE_H
-#define MCLD_ADT_BITREE_H
+#ifndef MCLD_ADT_BINTREE_H_
+#define MCLD_ADT_BINTREE_H_
-#include <mcld/ADT/Uncopyable.h>
-#include <mcld/ADT/TreeBase.h>
-#include <mcld/ADT/TreeAllocator.h>
+#include "mcld/ADT/TreeAllocator.h"
+#include "mcld/ADT/TreeBase.h"
+#include "mcld/Support/Compiler.h"
#include <cstddef>
#include <iterator>
@@ -21,30 +21,25 @@
namespace mcld {
-template<class DataType>
+template <class DataType>
class BinaryTree;
-class DFSIterator : public TreeIteratorBase
-{
-public:
- DFSIterator()
- : TreeIteratorBase()
- { }
+class DFSIterator : public TreeIteratorBase {
+ public:
+ DFSIterator() : TreeIteratorBase() {}
- DFSIterator(NodeBase *X)
- : TreeIteratorBase(X) {
+ explicit DFSIterator(NodeBase* X) : TreeIteratorBase(X) {
if (hasRightChild())
m_Stack.push(m_pNode->right);
if (hasLeftChild())
m_Stack.push(m_pNode->left);
}
- virtual ~DFSIterator()
- { }
+ virtual ~DFSIterator() {}
void advance() {
- if (m_Stack.empty()) { // reach the end
- m_pNode = m_pNode->right; // should be root
+ if (m_Stack.empty()) { // reach the end
+ m_pNode = m_pNode->right; // should be root
return;
}
m_pNode = m_Stack.top();
@@ -55,31 +50,26 @@ public:
m_Stack.push(m_pNode->left);
}
-private:
- std::stack<NodeBase *> m_Stack;
+ private:
+ std::stack<NodeBase*> m_Stack;
};
-class BFSIterator : public TreeIteratorBase
-{
-public:
- BFSIterator()
- : TreeIteratorBase()
- { }
+class BFSIterator : public TreeIteratorBase {
+ public:
+ BFSIterator() : TreeIteratorBase() {}
- BFSIterator(NodeBase *X)
- : TreeIteratorBase(X) {
+ explicit BFSIterator(NodeBase* X) : TreeIteratorBase(X) {
if (hasRightChild())
m_Queue.push(m_pNode->right);
if (hasLeftChild())
m_Queue.push(m_pNode->left);
}
- virtual ~BFSIterator()
- { }
+ virtual ~BFSIterator() {}
void advance() {
- if (m_Queue.empty()) { // reach the end
- m_pNode = m_pNode->right; // should be root
+ if (m_Queue.empty()) { // reach the end
+ m_pNode = m_pNode->right; // should be root
return;
}
m_pNode = m_Queue.front();
@@ -90,71 +80,75 @@ public:
m_Queue.push(m_pNode->left);
}
-private:
- std::queue<NodeBase *> m_Queue;
+ private:
+ std::queue<NodeBase*> m_Queue;
};
-template<class DataType, class Traits, class IteratorType>
-class PolicyIteratorBase : public IteratorType
-{
-public:
- typedef DataType value_type;
- typedef Traits traits;
- typedef typename traits::pointer pointer;
- typedef typename traits::reference reference;
-
- typedef PolicyIteratorBase<value_type, Traits, IteratorType> Self;
- typedef Node<value_type> node_type;
- typedef typename traits::nonconst_traits nonconst_traits;
- typedef PolicyIteratorBase<value_type, nonconst_traits, IteratorType> iterator;
- typedef typename traits::const_traits const_traits;
- typedef PolicyIteratorBase<value_type, const_traits, IteratorType> const_iterator;
- typedef std::forward_iterator_tag iterator_category;
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
-
-public:
- PolicyIteratorBase()
- : IteratorType() {}
-
- PolicyIteratorBase(const iterator &X)
- : IteratorType(X.m_pNode) {}
-
- explicit PolicyIteratorBase(NodeBase* X)
- : IteratorType(X) {}
+template <class DataType, class Traits, class IteratorType>
+class PolicyIteratorBase : public IteratorType {
+ public:
+ typedef DataType value_type;
+ typedef Traits traits;
+ typedef typename traits::pointer pointer;
+ typedef typename traits::reference reference;
+
+ typedef PolicyIteratorBase<value_type, Traits, IteratorType> Self;
+ typedef Node<value_type> node_type;
+
+ typedef typename traits::nonconst_traits nonconst_traits;
+ typedef typename traits::const_traits const_traits;
+
+ typedef PolicyIteratorBase<value_type, nonconst_traits, IteratorType>
+ iterator;
+ typedef PolicyIteratorBase<value_type, const_traits, IteratorType>
+ const_iterator;
+
+ typedef std::forward_iterator_tag iterator_category;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+
+ public:
+ PolicyIteratorBase() : IteratorType() {}
+
+ PolicyIteratorBase(const iterator& X) : IteratorType(X.m_pNode) {}
+
+ explicit PolicyIteratorBase(NodeBase* X) : IteratorType(X) {}
virtual ~PolicyIteratorBase() {}
// ----- operators ----- //
- pointer operator*() const
- { return static_cast<node_type*>(IteratorType::m_pNode)->data; }
-
- reference operator->() const
- { return *static_cast<node_type*>(IteratorType::m_pNode)->data; }
+ pointer operator*() const {
+ return static_cast<node_type*>(IteratorType::m_pNode)->data;
+ }
- bool hasData() const
- { return (!IteratorType::isRoot() && (0 != static_cast<node_type*>(IteratorType::m_pNode)->data)); }
+ reference operator->() const {
+ return *static_cast<node_type*>(IteratorType::m_pNode)->data;
+ }
+ bool hasData() const {
+ return (!IteratorType::isRoot() &&
+ (0 != static_cast<node_type*>(IteratorType::m_pNode)->data));
+ }
};
-template<class DataType, class Traits, class IteratorType>
-class PolicyIterator : public PolicyIteratorBase<DataType, Traits, IteratorType>
-{
-public:
+template <class DataType, class Traits, class IteratorType>
+class PolicyIterator
+ : public PolicyIteratorBase<DataType, Traits, IteratorType> {
+ public:
typedef PolicyIterator<DataType, Traits, IteratorType> Self;
typedef PolicyIteratorBase<DataType, Traits, IteratorType> Base;
- typedef PolicyIterator<DataType, typename Traits::nonconst_traits, IteratorType> iterator;
- typedef PolicyIterator<DataType, typename Traits::const_traits, IteratorType> const_iterator;
+ typedef PolicyIterator<DataType,
+ typename Traits::nonconst_traits,
+ IteratorType> iterator;
+ typedef PolicyIterator<DataType, typename Traits::const_traits, IteratorType>
+ const_iterator;
-public:
- PolicyIterator()
- : Base() {}
+ public:
+ PolicyIterator() : Base() {}
- PolicyIterator(const iterator &X)
- : Base(X.m_pNode) {}
+ PolicyIterator(const iterator& X) : Base(X.m_pNode) {}
- explicit PolicyIterator(NodeBase* X)
- : Base(X) {}
+ explicit PolicyIterator(NodeBase* X) : Base(X) {}
virtual ~PolicyIterator() {}
@@ -170,7 +164,7 @@ public:
}
};
-template<class DataType>
+template <class DataType>
class BinaryTree;
/** \class TreeIterator
@@ -182,47 +176,44 @@ class BinaryTree;
*
* @see TreeIteratorBase
*/
-template<class DataType, class Traits>
-struct TreeIterator : public TreeIteratorBase
-{
-public:
- typedef DataType value_type;
- typedef Traits traits;
- typedef typename traits::pointer pointer;
- typedef typename traits::reference reference;
-
- typedef TreeIterator<value_type, Traits> Self;
- typedef Node<value_type> node_type;
-
- typedef typename traits::nonconst_traits nonconst_traits;
+template <class DataType, class Traits>
+struct TreeIterator : public TreeIteratorBase {
+ public:
+ typedef DataType value_type;
+ typedef Traits traits;
+ typedef typename traits::pointer pointer;
+ typedef typename traits::reference reference;
+
+ typedef TreeIterator<value_type, Traits> Self;
+ typedef Node<value_type> node_type;
+
+ typedef typename traits::nonconst_traits nonconst_traits;
typedef TreeIterator<value_type, nonconst_traits> iterator;
- typedef typename traits::const_traits const_traits;
- typedef TreeIterator<value_type, const_traits> const_iterator;
- typedef std::bidirectional_iterator_tag iterator_category;
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
+ typedef typename traits::const_traits const_traits;
+ typedef TreeIterator<value_type, const_traits> const_iterator;
+ typedef std::bidirectional_iterator_tag iterator_category;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
-public:
- TreeIterator()
- : TreeIteratorBase() {}
+ public:
+ TreeIterator() : TreeIteratorBase() {}
- TreeIterator(const iterator &X)
- : TreeIteratorBase(X.m_pNode) {}
+ TreeIterator(const iterator& X) : TreeIteratorBase(X.m_pNode) {}
~TreeIterator() {}
// ----- operators ----- //
- pointer operator*() const
- { return static_cast<node_type*>(m_pNode)->data; }
+ pointer operator*() const { return static_cast<node_type*>(m_pNode)->data; }
- reference operator->() const
- { return *static_cast<node_type*>(m_pNode)->data; }
+ reference operator->() const {
+ return *static_cast<node_type*>(m_pNode)->data;
+ }
- bool isRoot() const
- { return (m_pNode->right == m_pNode); }
+ bool isRoot() const { return (m_pNode->right == m_pNode); }
- bool hasData() const
- { return (!isRoot() && (0 != static_cast<node_type*>(m_pNode)->data)); }
+ bool hasData() const {
+ return (!isRoot() && (0 != static_cast<node_type*>(m_pNode)->data));
+ }
Self& operator++() {
this->move<TreeIteratorBase::Rightward>();
@@ -246,8 +237,7 @@ public:
return tmp;
}
- explicit TreeIterator(NodeBase* X)
- : TreeIteratorBase(X) {}
+ explicit TreeIterator(NodeBase* X) : TreeIteratorBase(X) {}
};
/** \class BinaryTreeBase
@@ -259,12 +249,12 @@ public:
*
* @see BinaryTree
*/
-template<class DataType>
-class BinaryTreeBase : private Uncopyable
-{
-public:
+template <class DataType>
+class BinaryTreeBase {
+ public:
typedef Node<DataType> NodeType;
-protected:
+
+ protected:
/// TreeImpl - TreeImpl records the root node and the number of nodes
//
// +---> Root(end) <---+
@@ -274,22 +264,17 @@ protected:
// | Left Right |
// +---/ \-----+
//
- class TreeImpl : public NodeFactory<DataType>
- {
- typedef typename NodeFactory<DataType>::iterator iterator;
+ class TreeImpl : public NodeFactory<DataType> {
+ typedef typename NodeFactory<DataType>::iterator iterator;
typedef typename NodeFactory<DataType>::const_iterator const_iterator;
- public:
+ public:
NodeBase node;
- public:
- TreeImpl()
- : NodeFactory<DataType>() {
- node.left = node.right = &node;
- }
+ public:
+ TreeImpl() : NodeFactory<DataType>() { node.left = node.right = &node; }
- ~TreeImpl()
- { }
+ ~TreeImpl() {}
/// summon - change the final edges of pClient to our root
void summon(TreeImpl& pClient) {
@@ -298,54 +283,48 @@ protected:
iterator data;
iterator dEnd = pClient.end();
- for (data = pClient.begin(); data!=dEnd; ++data ) {
+ for (data = pClient.begin(); data != dEnd; ++data) {
if ((*data).left == &pClient.node)
(*data).left = &node;
if ((*data).right == &pClient.node)
(*data).right = &node;
}
}
- }; // TreeImpl
+ }; // TreeImpl
-protected:
+ protected:
/// m_Root is a special object who responses:
// - the pointer of root
// - the simple factory of nodes.
TreeImpl m_Root;
-protected:
- NodeType *createNode() {
- NodeType *result = m_Root.produce();
+ protected:
+ NodeType* createNode() {
+ NodeType* result = m_Root.produce();
result->left = result->right = &m_Root.node;
return result;
}
- void destroyNode(NodeType *pNode) {
+ void destroyNode(NodeType* pNode) {
pNode->left = pNode->right = 0;
pNode->data = 0;
m_Root.deallocate(pNode);
}
-public:
- BinaryTreeBase()
- : m_Root()
- { }
+ public:
+ BinaryTreeBase() : m_Root() {}
- virtual ~BinaryTreeBase()
- { }
+ virtual ~BinaryTreeBase() {}
- size_t size() const {
- return m_Root.size();
- }
+ size_t size() const { return m_Root.size(); }
- bool empty() const {
- return m_Root.empty();
- }
+ bool empty() const { return m_Root.empty(); }
-protected:
- void clear() {
- m_Root.clear();
- }
+ protected:
+ void clear() { m_Root.clear(); }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BinaryTreeBase);
};
/** \class BinaryTree
@@ -353,81 +332,94 @@ protected:
*
* @see mcld::InputTree
*/
-template<class DataType>
-class BinaryTree : public BinaryTreeBase<DataType>
-{
-public:
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef DataType value_type;
- typedef value_type* pointer;
- typedef value_type& reference;
- typedef const value_type* const_pointer;
- typedef const value_type& const_reference;
-
- typedef BinaryTree<DataType> Self;
+template <class DataType>
+class BinaryTree : public BinaryTreeBase<DataType> {
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef DataType value_type;
+ typedef value_type* pointer;
+ typedef value_type& reference;
+ typedef const value_type* const_pointer;
+ typedef const value_type& const_reference;
+
+ typedef BinaryTree<DataType> Self;
typedef TreeIterator<value_type, NonConstTraits<value_type> > iterator;
- typedef TreeIterator<value_type, ConstTraits<value_type> > const_iterator;
+ typedef TreeIterator<value_type, ConstTraits<value_type> > const_iterator;
- typedef PolicyIterator<value_type, NonConstTraits<value_type>, DFSIterator> dfs_iterator;
- typedef PolicyIterator<value_type, ConstTraits<value_type>, DFSIterator> const_dfs_iterator;
- typedef PolicyIterator<value_type, NonConstTraits<value_type>, BFSIterator> bfs_iterator;
- typedef PolicyIterator<value_type, ConstTraits<value_type>, BFSIterator> const_bfs_iterator;
+ typedef PolicyIterator<value_type, NonConstTraits<value_type>, DFSIterator>
+ dfs_iterator;
+ typedef PolicyIterator<value_type, ConstTraits<value_type>, DFSIterator>
+ const_dfs_iterator;
-protected:
+ typedef PolicyIterator<value_type, NonConstTraits<value_type>, BFSIterator>
+ bfs_iterator;
+ typedef PolicyIterator<value_type, ConstTraits<value_type>, BFSIterator>
+ const_bfs_iterator;
+
+ protected:
typedef Node<value_type> node_type;
-public:
+ public:
// ----- constructors and destructor ----- //
- BinaryTree()
- : BinaryTreeBase<DataType>()
- { }
+ BinaryTree() : BinaryTreeBase<DataType>() {}
- ~BinaryTree() {
- }
+ ~BinaryTree() {}
// ----- iterators ----- //
- bfs_iterator bfs_begin()
- { return bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left); }
+ bfs_iterator bfs_begin() {
+ return bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left);
+ }
- bfs_iterator bfs_end()
- { return bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right); }
+ bfs_iterator bfs_end() {
+ return bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right);
+ }
- const_bfs_iterator bfs_begin() const
- { return const_bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left); }
+ const_bfs_iterator bfs_begin() const {
+ return const_bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left);
+ }
- const_bfs_iterator bfs_end() const
- { return const_bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right); }
+ const_bfs_iterator bfs_end() const {
+ return const_bfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right);
+ }
- dfs_iterator dfs_begin()
- { return dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left); }
+ dfs_iterator dfs_begin() {
+ return dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left);
+ }
- dfs_iterator dfs_end()
- { return dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right); }
+ dfs_iterator dfs_end() {
+ return dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right);
+ }
- const_dfs_iterator dfs_begin() const
- { return const_dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left); }
+ const_dfs_iterator dfs_begin() const {
+ return const_dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.left);
+ }
- const_dfs_iterator dfs_end() const
- { return const_dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right); }
+ const_dfs_iterator dfs_end() const {
+ return const_dfs_iterator(BinaryTreeBase<DataType>::m_Root.node.right);
+ }
- iterator root()
- { return iterator(&(BinaryTreeBase<DataType>::m_Root.node)); }
+ iterator root() { return iterator(&(BinaryTreeBase<DataType>::m_Root.node)); }
- const_iterator root() const
- { return const_iterator(&(BinaryTreeBase<DataType>::m_Root.node)); }
+ const_iterator root() const {
+ return const_iterator(&(BinaryTreeBase<DataType>::m_Root.node));
+ }
- iterator begin()
- { return iterator(BinaryTreeBase<DataType>::m_Root.node.left); }
+ iterator begin() {
+ return iterator(BinaryTreeBase<DataType>::m_Root.node.left);
+ }
- iterator end()
- { return iterator(BinaryTreeBase<DataType>::m_Root.node.right); }
+ iterator end() {
+ return iterator(BinaryTreeBase<DataType>::m_Root.node.right);
+ }
- const_iterator begin() const
- { return const_iterator(BinaryTreeBase<DataType>::m_Root.node.left); }
+ const_iterator begin() const {
+ return const_iterator(BinaryTreeBase<DataType>::m_Root.node.left);
+ }
- const_iterator end() const
- { return const_iterator(BinaryTreeBase<DataType>::m_Root.node.right); }
+ const_iterator end() const {
+ return const_iterator(BinaryTreeBase<DataType>::m_Root.node.right);
+ }
// ----- modifiers ----- //
/// join - create a leaf node and merge it in the tree.
@@ -435,9 +427,9 @@ public:
// @param DIRECT the direction of the connecting edge of the parent node.
// @param position the parent node
// @param value the value being pushed.
- template<size_t DIRECT>
+ template <size_t DIRECT>
BinaryTree& join(TreeIteratorBase& pPosition, const DataType& pValue) {
- node_type *node = BinaryTreeBase<DataType>::createNode();
+ node_type* node = BinaryTreeBase<DataType>::createNode();
node->data = const_cast<DataType*>(&pValue);
if (pPosition.isRoot())
@@ -453,7 +445,7 @@ public:
// @param position the parent node
// @param the tree being joined.
// @return the joined tree
- template<size_t DIRECT>
+ template <size_t DIRECT>
BinaryTree& merge(TreeIteratorBase& pPosition, BinaryTree& pTree) {
if (this == &pTree)
return *this;
@@ -461,7 +453,7 @@ public:
if (!pTree.empty()) {
pPosition.hook<DIRECT>(pTree.m_Root.node.left);
BinaryTreeBase<DataType>::m_Root.summon(
- pTree.BinaryTreeBase<DataType>::m_Root);
+ pTree.BinaryTreeBase<DataType>::m_Root);
BinaryTreeBase<DataType>::m_Root.delegate(pTree.m_Root);
pTree.m_Root.node.left = pTree.m_Root.node.right = &pTree.m_Root.node;
}
@@ -469,7 +461,6 @@ public:
}
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_ADT_BINTREE_H_
diff --git a/include/mcld/ADT/Flags.h b/include/mcld/ADT/Flags.h
index 0336770..e53ee09 100644
--- a/include/mcld/ADT/Flags.h
+++ b/include/mcld/ADT/Flags.h
@@ -6,44 +6,34 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_FLAGS_H
-#define MCLD_ADT_FLAGS_H
+#ifndef MCLD_ADT_FLAGS_H_
+#define MCLD_ADT_FLAGS_H_
-namespace mcld
-{
+namespace mcld {
-template<typename Enum>
-class Flags
-{
-public:
+template <typename Enum>
+class Flags {
+ public:
typedef Enum enum_type;
-public:
- Flags(const Flags& pOther)
- : m_Data(pOther.m_Data) {}
+ public:
+ Flags(const Flags& pOther) : m_Data(pOther.m_Data) {}
- Flags(Enum pFlag)
- : m_Data(pFlag) {}
+ explicit Flags(Enum pFlag) : m_Data(pFlag) {}
- Flags(unsigned int pFlag = 0x0)
- : m_Data(pFlag) {}
+ explicit Flags(unsigned int pFlag = 0x0) : m_Data(pFlag) {}
- operator unsigned int () const
- { return m_Data; }
+ operator unsigned int() const { return m_Data; }
- bool operator! () const
- { return (m_Data == 0x0); }
+ bool operator!() const { return (m_Data == 0x0); }
- Flags operator& (int pMask ) const
- { return Flags(m_Data & pMask); }
+ Flags operator&(int pMask) const { return Flags(m_Data & pMask); }
- Flags operator& (unsigned int pMask ) const
- { return Flags(m_Data & pMask); }
+ Flags operator&(unsigned int pMask) const { return Flags(m_Data & pMask); }
- Flags operator& (Enum pMask ) const
- { return Flags(m_Data & pMask); }
+ Flags operator&(Enum pMask) const { return Flags(m_Data & pMask); }
- Flags& operator&= (unsigned int pMask ) {
+ Flags& operator&=(unsigned int pMask) {
m_Data &= pMask;
return *this;
}
@@ -53,46 +43,40 @@ public:
return *this;
}
- Flags operator^ (Flags pOther) const
- { return Flags(m_Data^pOther.m_Data); }
+ Flags operator^(Flags pOther) const { return Flags(m_Data ^ pOther.m_Data); }
- Flags operator^ (Enum pOther) const
- { return Flags(m_Data^pOther); }
+ Flags operator^(Enum pOther) const { return Flags(m_Data ^ pOther); }
- Flags& operator^= (Flags pOther) {
+ Flags& operator^=(Flags pOther) {
m_Data ^= pOther.m_Data;
return *this;
}
- Flags& operator^= (Enum pOther) {
+ Flags& operator^=(Enum pOther) {
m_Data ^= pOther;
return *this;
}
- Flags operator| (Flags pOther) const
- { return Flags(m_Data | pOther.m_Data); }
+ Flags operator|(Flags pOther) const { return Flags(m_Data | pOther.m_Data); }
- Flags operator| (Enum pOther ) const
- { return Flags(m_Data | pOther); }
+ Flags operator|(Enum pOther) const { return Flags(m_Data | pOther); }
- Flags& operator|= (Flags pOther) {
+ Flags& operator|=(Flags pOther) {
m_Data |= pOther.m_Data;
return *this;
}
- Flags& operator|= (Enum pOther) {
+ Flags& operator|=(Enum pOther) {
m_Data |= pOther;
return *this;
}
- Flags operator~ () const
- { return Flags(~m_Data); }
+ Flags operator~() const { return Flags(~m_Data); }
-private:
+ private:
unsigned int m_Data;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_ADT_FLAGS_H_
diff --git a/include/mcld/ADT/GraphLite/Digraph.h b/include/mcld/ADT/GraphLite/Digraph.h
deleted file mode 100644
index 2e20c6c..0000000
--- a/include/mcld/ADT/GraphLite/Digraph.h
+++ /dev/null
@@ -1,82 +0,0 @@
-//===- Digraph.h ----------------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_GRAPHLITE_DIGRAPH_H
-#define MCLD_ADT_GRAPHLITE_DIGRAPH_H
-#include <mcld/ADT/Uncopyable.h>
-#include <mcld/ADT/GraphLite/GraphBasicTypes.h>
-#include <stdint.h>
-
-namespace mcld {
-namespace graph {
-
-/** \class Digraph
- * \brief Digraph provides the common interface of all directed graphs.
- */
-class Digraph : private Uncopyable
-{
-public:
- typedef DirectedTag direction_tag;
-
- class Node
- {
- friend class Digraph;
- public:
- Node() {}
-
- bool operator==(const Node& pOther) const { return m_ID == pOther.m_ID; }
- bool operator!=(const Node& pOther) const { return m_ID != pOther.m_ID; }
-
- protected:
- intptr_t m_ID;
- };
-
- class Arc
- {
- friend class Digraph;
- public:
- Arc();
-
- bool operator==(const Node& pOther) const;
- bool operator!=(const Node& pOther) const;
-
- Node source() const;
- Node target() const;
-
- protected:
- Arc(Digraph& pParent);
-
- protected:
- intptr_t m_ID;
- Digraph* m_Parent;
- };
-
-public:
- Digraph();
-
- Node addNode();
-
- Arc addArc(const Node& pSource, const Node& pTarget);
-
- void erase(const Node& pNode);
-
- void erase(const Arc& pArc);
-
- void clear();
-
- unsigned int numOfNodes() const;
-
- unsigned int numOfArcs() const;
-
-};
-
-} // namespace of graph
-} // namespace of mcld
-
-#endif
-
diff --git a/include/mcld/ADT/GraphLite/GraphBasicTypes.h b/include/mcld/ADT/GraphLite/GraphBasicTypes.h
deleted file mode 100644
index 5862bcb..0000000
--- a/include/mcld/ADT/GraphLite/GraphBasicTypes.h
+++ /dev/null
@@ -1,29 +0,0 @@
-//===- GraphBasicTypes.h --------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_GRAPHLITE_GRAPHBASICTYPES_H
-#define MCLD_ADT_GRAPHLITE_GRAPHBASICTYPES_H
-
-namespace mcld {
-namespace graph {
-
-/** \class UndirectedTag
- * \brief Undirected graph category.
- */
-struct UndirectedTag {};
-
-/** \class DirectedTag
- * \brief Directed graph category.
- */
-struct DirectedTag {};
-
-} // namespace of graph
-} // namespace of mcld
-
-#endif
-
diff --git a/include/mcld/ADT/GraphLite/ListDigraph.h b/include/mcld/ADT/GraphLite/ListDigraph.h
deleted file mode 100644
index b36dd67..0000000
--- a/include/mcld/ADT/GraphLite/ListDigraph.h
+++ /dev/null
@@ -1,89 +0,0 @@
-//===- ListDigraph.h ------------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_GRAPHLITE_LISTDIGRAPH_H
-#define MCLD_ADT_GRAPHLITE_LISTDIGRAPH_H
-#include <mcld/Support/GCFactory.h>
-
-namespace mcld {
-namespace graph {
-
-/** \class ListDigraph
- * \brief ListDigraph provides an linked-list inplementation of a graph.
- *
- * ListDigraph is designed to get well performance for most algorithms of
- * graph theory.
- *
- * Function | Complexity | Best Complexity
- * ----------------|------------|--------------------------
- * Storage | V + E |
- * Add node | O(1) |
- * Add arc | O(1) |
- * Remove node | O(E) | O(#(fan-in) + #(fan-out))
- * Remove edge | O(1) |
- * Query adjacency | O(E) | O(#(fan-in) + #(fan-out))
- *
- */
-class ListDigraph
-{
-public:
- struct Node;
- struct Arc;
-
- struct Node {
- public:
- Node();
-
- public:
- Node *prev, *next;
- Arc *first_in, *first_out;
- };
-
- struct Arc {
- public:
- Arc();
-
- public:
- Node *target, *source;
- Arc *prev_in, *next_in;
- Arc *prev_out, *next_out;
- };
-
-public:
- ListDigraph();
-
- Node* addNode();
-
- Arc* addArc(Node& pU, Node& pV);
-
- void erase(Node& pNode);
-
- void erase(Arc& pArc);
-
- void clear();
-
- void getHead(Node*& pNode) const { pNode = m_pNodeHead; }
-
-private:
- typedef GCFactory<Node, 0> NodeList;
- typedef GCFactory<Arc, 0> ArcList;
-
-private:
- Node* m_pNodeHead;
- Node* m_pFreeNodeHead;
- Arc* m_pFreeArcHead;
-
- NodeList m_NodeList;
- ArcList m_ArcList;
-};
-
-} // namespace of graph
-} // namespace of mcld
-
-#endif
-
diff --git a/include/mcld/ADT/HashBase.h b/include/mcld/ADT/HashBase.h
index d80333b..f3019bd 100644
--- a/include/mcld/ADT/HashBase.h
+++ b/include/mcld/ADT/HashBase.h
@@ -6,37 +6,37 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_HASHBASE_H
-#define MCLD_ADT_HASHBASE_H
+#ifndef MCLD_ADT_HASHBASE_H_
+#define MCLD_ADT_HASHBASE_H_
+
#include <llvm/ADT/StringRef.h>
+
#include <cstdlib>
namespace mcld {
/** forward declaration **/
-template<typename HashTableImplTy>
+template <typename HashTableImplTy>
class ChainIteratorBase;
-template<typename HashTableImplTy>
+template <typename HashTableImplTy>
class EntryIteratorBase;
/** \class HashBucket
* \brief HashBucket is an entry in the hash table.
*/
-template<typename HashEntryTy>
-class HashBucket
-{
-public:
+template <typename HashEntryTy>
+class HashBucket {
+ public:
typedef HashEntryTy entry_type;
-public:
+ public:
unsigned int FullHashValue;
- entry_type *Entry;
+ entry_type* Entry;
-public:
+ public:
static entry_type* getEmptyBucket();
static entry_type* getTombstone();
-
};
/** \class HashTableImpl
@@ -60,14 +60,12 @@ public:
* than static linkers. HashTableImpl also provides a template argument to
* change the hash functions.
*/
-template<typename HashEntryTy,
- typename HashFunctionTy>
-class HashTableImpl
-{
-private:
+template <typename HashEntryTy, typename HashFunctionTy>
+class HashTableImpl {
+ private:
static const unsigned int NumOfInitBuckets = 16;
-public:
+ public:
typedef size_t size_type;
typedef HashFunctionTy hasher;
typedef HashEntryTy entry_type;
@@ -75,8 +73,7 @@ public:
typedef HashBucket<HashEntryTy> bucket_type;
typedef HashTableImpl<HashEntryTy, HashFunctionTy> Self;
-
-public:
+ public:
HashTableImpl();
explicit HashTableImpl(unsigned int pInitSize);
virtual ~HashTableImpl();
@@ -84,19 +81,15 @@ public:
// ----- observers ----- //
bool empty() const;
- size_t numOfBuckets() const
- { return m_NumOfBuckets; }
+ size_t numOfBuckets() const { return m_NumOfBuckets; }
- size_t numOfEntries() const
- { return m_NumOfEntries; }
+ size_t numOfEntries() const { return m_NumOfEntries; }
- hasher& hash()
- { return m_Hasher; }
+ hasher& hash() { return m_Hasher; }
- const hasher& hash() const
- { return m_Hasher; }
+ const hasher& hash() const { return m_Hasher; }
-protected:
+ protected:
/// initialize the hash table.
void init(unsigned int pInitSize);
@@ -113,26 +106,26 @@ protected:
/// mayRehash - check the load_factor, compute the new size, and then doRehash
void mayRehash();
- /// doRehash - re-new the hash table, and rehash all elements into the new buckets
+ /// doRehash - re-new the hash table, and rehash all elements into the new
+ /// buckets
void doRehash(unsigned int pNewSize);
-friend class ChainIteratorBase<Self>;
-friend class ChainIteratorBase<const Self>;
-friend class EntryIteratorBase<Self>;
-friend class EntryIteratorBase<const Self>;
-protected:
+ friend class ChainIteratorBase<Self>;
+ friend class ChainIteratorBase<const Self>;
+ friend class EntryIteratorBase<Self>;
+ friend class EntryIteratorBase<const Self>;
+
+ protected:
// Array of Buckets
bucket_type* m_Buckets;
unsigned int m_NumOfBuckets;
unsigned int m_NumOfEntries;
unsigned int m_NumOfTombstones;
hasher m_Hasher;
-
};
#include "HashBase.tcc"
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_ADT_HASHBASE_H_
diff --git a/include/mcld/ADT/HashBase.tcc b/include/mcld/ADT/HashBase.tcc
index 50f6ac4..8b0a9be 100644
--- a/include/mcld/ADT/HashBase.tcc
+++ b/include/mcld/ADT/HashBase.tcc
@@ -10,13 +10,11 @@
//===----------------------------------------------------------------------===//
// internal non-member functions
//===----------------------------------------------------------------------===//
-inline static unsigned int compute_bucket_count(unsigned int pNumOfBuckets)
-{
- static const unsigned int bucket_size[] =
- {
- 1, 3, 17, 37, 67, 97, 197, 419, 977, 2593, 4099, 8209, 12289,
- 16411, 20483, 32771, 49157, 65537, 98317, 131101, 196613
- };
+inline static unsigned int compute_bucket_count(unsigned int pNumOfBuckets) {
+ static const unsigned int bucket_size[] = {
+ 1, 3, 17, 37, 67, 97, 197,
+ 419, 977, 2593, 4099, 8209, 12289, 16411,
+ 20483, 32771, 49157, 65537, 98317, 131101, 196613};
const unsigned int buckets_count =
sizeof(bucket_size) / sizeof(bucket_size[0]);
@@ -26,26 +24,24 @@ inline static unsigned int compute_bucket_count(unsigned int pNumOfBuckets)
return bucket_size[idx];
}
++idx;
- } while(idx < buckets_count);
+ } while (idx < buckets_count);
- return (pNumOfBuckets+131101); // rare case. increase constantly
+ return (pNumOfBuckets + 131101); // rare case. increase constantly
}
//===----------------------------------------------------------------------===//
// template implementation of HashBucket
//===----------------------------------------------------------------------===//
-template<typename DataType>
+template <typename DataType>
typename HashBucket<DataType>::entry_type*
-HashBucket<DataType>::getEmptyBucket()
-{
+HashBucket<DataType>::getEmptyBucket() {
static entry_type* empty_bucket = reinterpret_cast<entry_type*>(0x0);
return empty_bucket;
}
-template<typename DataType>
+template <typename DataType>
typename HashBucket<DataType>::entry_type*
-HashBucket<DataType>::getTombstone()
-{
+HashBucket<DataType>::getTombstone() {
static entry_type* tombstone = reinterpret_cast<entry_type*>(0x1);
return tombstone;
}
@@ -53,21 +49,19 @@ HashBucket<DataType>::getTombstone()
//===----------------------------------------------------------------------===//
// template implementation of HashTableImpl
//===----------------------------------------------------------------------===//
-template<typename HashEntryTy,
- typename HashFunctionTy>
+template <typename HashEntryTy, typename HashFunctionTy>
HashTableImpl<HashEntryTy, HashFunctionTy>::HashTableImpl()
- : m_Buckets(0),
- m_NumOfBuckets(0),
- m_NumOfEntries(0),
- m_NumOfTombstones(0),
- m_Hasher() {
+ : m_Buckets(0),
+ m_NumOfBuckets(0),
+ m_NumOfEntries(0),
+ m_NumOfTombstones(0),
+ m_Hasher() {
}
-template<typename HashEntryTy,
- typename HashFunctionTy>
+template <typename HashEntryTy, typename HashFunctionTy>
HashTableImpl<HashEntryTy, HashFunctionTy>::HashTableImpl(
- unsigned int pInitSize)
- : m_Hasher() {
+ unsigned int pInitSize)
+ : m_Hasher() {
if (pInitSize) {
init(pInitSize);
return;
@@ -79,27 +73,22 @@ HashTableImpl<HashEntryTy, HashFunctionTy>::HashTableImpl(
m_NumOfTombstones = 0;
}
-template<typename HashEntryTy,
- typename HashFunctionTy>
-HashTableImpl<HashEntryTy, HashFunctionTy>::~HashTableImpl()
-{
+template <typename HashEntryTy, typename HashFunctionTy>
+HashTableImpl<HashEntryTy, HashFunctionTy>::~HashTableImpl() {
clear();
}
/// empty - check if the hash table is empty
-template<typename HashEntryTy,
- typename HashFunctionTy>
-bool HashTableImpl<HashEntryTy, HashFunctionTy>::empty() const
-{
- return (0 == m_NumOfEntries);
+template <typename HashEntryTy, typename HashFunctionTy>
+bool HashTableImpl<HashEntryTy, HashFunctionTy>::empty() const {
+ return (m_NumOfEntries == 0);
}
/// init - initialize the hash table.
-template<typename HashEntryTy,
- typename HashFunctionTy>
-void HashTableImpl<HashEntryTy, HashFunctionTy>::init(unsigned int pInitSize)
-{
- m_NumOfBuckets = pInitSize? compute_bucket_count(pInitSize): NumOfInitBuckets;
+template <typename HashEntryTy, typename HashFunctionTy>
+void HashTableImpl<HashEntryTy, HashFunctionTy>::init(unsigned int pInitSize) {
+ m_NumOfBuckets =
+ pInitSize ? compute_bucket_count(pInitSize) : NumOfInitBuckets;
m_NumOfEntries = 0;
m_NumOfTombstones = 0;
@@ -109,10 +98,8 @@ void HashTableImpl<HashEntryTy, HashFunctionTy>::init(unsigned int pInitSize)
}
/// clear - clear the hash table.
-template<typename HashEntryTy,
- typename HashFunctionTy>
-void HashTableImpl<HashEntryTy, HashFunctionTy>::clear()
-{
+template <typename HashEntryTy, typename HashFunctionTy>
+void HashTableImpl<HashEntryTy, HashFunctionTy>::clear() {
free(m_Buckets);
m_Buckets = 0;
@@ -122,13 +109,10 @@ void HashTableImpl<HashEntryTy, HashFunctionTy>::clear()
}
/// lookUpBucketFor - look up the bucket whose key is pKey
-template<typename HashEntryTy,
- typename HashFunctionTy>
-unsigned int
-HashTableImpl<HashEntryTy, HashFunctionTy>::lookUpBucketFor(
- const typename HashTableImpl<HashEntryTy, HashFunctionTy>::key_type& pKey)
-{
- if (0 == m_NumOfBuckets) {
+template <typename HashEntryTy, typename HashFunctionTy>
+unsigned int HashTableImpl<HashEntryTy, HashFunctionTy>::lookUpBucketFor(
+ const typename HashTableImpl<HashEntryTy, HashFunctionTy>::key_type& pKey) {
+ if (m_NumOfBuckets == 0) {
// NumOfBuckets is changed after init(pInitSize)
init(NumOfInitBuckets);
}
@@ -140,11 +124,11 @@ HashTableImpl<HashEntryTy, HashFunctionTy>::lookUpBucketFor(
int firstTombstone = -1;
// linear probing
- while(true) {
+ while (true) {
bucket_type& bucket = m_Buckets[index];
// If we found an empty bucket, this key isn't in the table yet, return it.
if (bucket_type::getEmptyBucket() == bucket.Entry) {
- if (-1 != firstTombstone) {
+ if (firstTombstone != -1) {
m_Buckets[firstTombstone].FullHashValue = full_hash;
return firstTombstone;
}
@@ -154,11 +138,10 @@ HashTableImpl<HashEntryTy, HashFunctionTy>::lookUpBucketFor(
}
if (bucket_type::getTombstone() == bucket.Entry) {
- if (-1 == firstTombstone) {
+ if (firstTombstone == -1) {
firstTombstone = index;
}
- }
- else if (bucket.FullHashValue == full_hash) {
+ } else if (bucket.FullHashValue == full_hash) {
if (bucket.Entry->compare(pKey)) {
return index;
}
@@ -170,13 +153,11 @@ HashTableImpl<HashEntryTy, HashFunctionTy>::lookUpBucketFor(
}
}
-template<typename HashEntryTy,
- typename HashFunctionTy>
-int
-HashTableImpl<HashEntryTy, HashFunctionTy>::findKey(
- const typename HashTableImpl<HashEntryTy, HashFunctionTy>::key_type& pKey) const
-{
- if (0 == m_NumOfBuckets)
+template <typename HashEntryTy, typename HashFunctionTy>
+int HashTableImpl<HashEntryTy, HashFunctionTy>::findKey(
+ const typename HashTableImpl<HashEntryTy, HashFunctionTy>::key_type& pKey)
+ const {
+ if (m_NumOfBuckets == 0)
return -1;
unsigned int full_hash = m_Hasher(pKey);
@@ -185,15 +166,14 @@ HashTableImpl<HashEntryTy, HashFunctionTy>::findKey(
const unsigned int probe = 1;
// linear probing
while (true) {
- bucket_type &bucket = m_Buckets[index];
+ bucket_type& bucket = m_Buckets[index];
if (bucket_type::getEmptyBucket() == bucket.Entry)
return -1;
if (bucket_type::getTombstone() == bucket.Entry) {
// Ignore tombstones.
- }
- else if (full_hash == bucket.FullHashValue) {
+ } else if (full_hash == bucket.FullHashValue) {
// get string, compare, if match, return index
if (bucket.Entry->compare(pKey))
return index;
@@ -204,18 +184,16 @@ HashTableImpl<HashEntryTy, HashFunctionTy>::findKey(
}
}
-template<typename HashEntryTy,
- typename HashFunctionTy>
-void HashTableImpl<HashEntryTy, HashFunctionTy>::mayRehash()
-{
-
+template <typename HashEntryTy, typename HashFunctionTy>
+void HashTableImpl<HashEntryTy, HashFunctionTy>::mayRehash() {
unsigned int new_size;
// If the hash table is now more than 3/4 full, or if fewer than 1/8 of
// the buckets are empty (meaning that many are filled with tombstones),
// grow/rehash the table.
- if ((m_NumOfEntries<<2) > m_NumOfBuckets*3)
+ if ((m_NumOfEntries << 2) > m_NumOfBuckets * 3)
new_size = compute_bucket_count(m_NumOfBuckets);
- else if (((m_NumOfBuckets-(m_NumOfEntries+m_NumOfTombstones))<<3) < m_NumOfBuckets)
+ else if (((m_NumOfBuckets - (m_NumOfEntries + m_NumOfTombstones)) << 3) <
+ m_NumOfBuckets)
new_size = m_NumOfBuckets;
else
return;
@@ -223,15 +201,15 @@ void HashTableImpl<HashEntryTy, HashFunctionTy>::mayRehash()
doRehash(new_size);
}
-template<typename HashEntryTy,
- typename HashFunctionTy>
-void HashTableImpl<HashEntryTy, HashFunctionTy>::doRehash(unsigned int pNewSize)
-{
+template <typename HashEntryTy, typename HashFunctionTy>
+void HashTableImpl<HashEntryTy, HashFunctionTy>::doRehash(
+ unsigned int pNewSize) {
bucket_type* new_table = (bucket_type*)calloc(pNewSize, sizeof(bucket_type));
// Rehash all the items into their new buckets. Luckily :) we already have
// the hash values available, so we don't have to recall hash function again.
- for (bucket_type *IB = m_Buckets, *E = m_Buckets+m_NumOfBuckets; IB != E; ++IB) {
+ for (bucket_type* IB = m_Buckets, * E = m_Buckets + m_NumOfBuckets; IB != E;
+ ++IB) {
if (IB->Entry != bucket_type::getEmptyBucket() &&
IB->Entry != bucket_type::getTombstone()) {
// Fast case, bucket available.
@@ -263,4 +241,3 @@ void HashTableImpl<HashEntryTy, HashFunctionTy>::doRehash(unsigned int pNewSize)
m_NumOfBuckets = pNewSize;
m_NumOfTombstones = 0;
}
-
diff --git a/include/mcld/ADT/HashEntry.h b/include/mcld/ADT/HashEntry.h
index 3dc3ab7..fd450dd 100644
--- a/include/mcld/ADT/HashEntry.h
+++ b/include/mcld/ADT/HashEntry.h
@@ -1,4 +1,4 @@
-//===- HashEntry.h ---------------------------------------------------------===//
+//===- HashEntry.h --------------------------------------------------------===//
//
// The MCLinker Project
//
@@ -7,13 +7,13 @@
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_HASHENTRY_H
-#define MCLD_ADT_HASHENTRY_H
+#ifndef MCLD_ADT_HASHENTRY_H_
+#define MCLD_ADT_HASHENTRY_H_
namespace mcld {
/** forward declaration **/
-template<typename HashEntryTy>
+template <typename HashEntryTy>
class EntryFactory;
/** \class HashEntry
@@ -30,53 +30,46 @@ class EntryFactory;
* are doing when you let a new class inherit from mcld::HashEntry.
*/
template <typename KeyType, typename ValueType, typename KeyCompare>
-class HashEntry
-{
-public:
+class HashEntry {
+ public:
typedef KeyType key_type;
typedef ValueType value_type;
typedef KeyCompare key_compare;
-private:
+ private:
typedef HashEntry<KeyType, ValueType, KeyCompare> Self;
friend class EntryFactory<Self>;
-private:
- HashEntry(const KeyType& pKey);
+ private:
+ explicit HashEntry(const KeyType& pKey);
~HashEntry();
-public:
- KeyType& key()
- { return m_Key; }
+ public:
+ KeyType& key() { return m_Key; }
- const KeyType& key() const
- { return m_Key; }
+ const KeyType& key() const { return m_Key; }
- ValueType& value()
- { return m_Value; }
+ ValueType& value() { return m_Value; }
- const ValueType& value() const
- { return m_Value; }
+ const ValueType& value() const { return m_Value; }
- void setValue(const ValueType& pValue)
- { m_Value = pValue; }
+ void setValue(const ValueType& pValue) { m_Value = pValue; }
bool compare(const key_type& pKey);
-public:
+ public:
KeyType m_Key;
ValueType m_Value;
};
template <typename HashEntryTy>
-class EntryFactory
-{
-public:
- typedef HashEntryTy entry_type;
- typedef typename HashEntryTy::key_type key_type;
+class EntryFactory {
+ public:
+ typedef HashEntryTy entry_type;
+ typedef typename HashEntryTy::key_type key_type;
typedef typename HashEntryTy::value_type value_type;
-public:
+ public:
EntryFactory();
~EntryFactory();
@@ -86,7 +79,6 @@ public:
#include "HashEntry.tcc"
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_ADT_HASHENTRY_H_
diff --git a/include/mcld/ADT/HashEntry.tcc b/include/mcld/ADT/HashEntry.tcc
index fdd886b..3aa514e 100644
--- a/include/mcld/ADT/HashEntry.tcc
+++ b/include/mcld/ADT/HashEntry.tcc
@@ -11,17 +11,15 @@
// template implementation of HashEntry
template <typename KeyType, typename ValueType, typename KeyCompare>
HashEntry<KeyType, ValueType, KeyCompare>::HashEntry(const KeyType& pKey)
- : m_Key(pKey) {
+ : m_Key(pKey) {
}
template <typename KeyType, typename ValueType, typename KeyCompare>
-HashEntry<KeyType, ValueType, KeyCompare>::~HashEntry()
-{
+HashEntry<KeyType, ValueType, KeyCompare>::~HashEntry() {
}
template <typename KeyType, typename ValueType, typename KeyCompare>
-bool HashEntry<KeyType, ValueType, KeyCompare>::compare(const KeyType& pKey)
-{
+bool HashEntry<KeyType, ValueType, KeyCompare>::compare(const KeyType& pKey) {
static KeyCompare comparator;
return comparator(m_Key, pKey);
}
@@ -29,25 +27,20 @@ bool HashEntry<KeyType, ValueType, KeyCompare>::compare(const KeyType& pKey)
//===--------------------------------------------------------------------===//
// template implementation of EntryFactory
template <typename HashEntryTy>
-EntryFactory<HashEntryTy>::EntryFactory()
-{
+EntryFactory<HashEntryTy>::EntryFactory() {
}
template <typename HashEntryTy>
-EntryFactory<HashEntryTy>::~EntryFactory()
-{
+EntryFactory<HashEntryTy>::~EntryFactory() {
}
template <typename HashEntryTy>
-void EntryFactory<HashEntryTy>::destroy(HashEntryTy* pEntry)
-{
+void EntryFactory<HashEntryTy>::destroy(HashEntryTy* pEntry) {
delete pEntry;
}
template <typename HashEntryTy>
-HashEntryTy*
-EntryFactory<HashEntryTy>::produce(const typename EntryFactory<HashEntryTy>::key_type& pKey)
-{
+HashEntryTy* EntryFactory<HashEntryTy>::produce(
+ const typename EntryFactory<HashEntryTy>::key_type& pKey) {
return new HashEntryTy(pKey);
}
-
diff --git a/include/mcld/ADT/HashEntryFactory.h b/include/mcld/ADT/HashEntryFactory.h
index 91deab4..6c6114f 100644
--- a/include/mcld/ADT/HashEntryFactory.h
+++ b/include/mcld/ADT/HashEntryFactory.h
@@ -1,4 +1,4 @@
-//===- HashEntryFactory.h --------------------------------------------------===//
+//===- HashEntryFactory.h -------------------------------------------------===//
//
// The MCLinker Project
//
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_HASHENTRYFACTORY_H
-#define MCLD_ADT_HASHENTRYFACTORY_H
+#ifndef MCLD_ADT_HASHENTRYFACTORY_H_
+#define MCLD_ADT_HASHENTRYFACTORY_H_
namespace mcld {
@@ -15,22 +15,20 @@ namespace mcld {
* \brief HashEntryFactoy is a factory wrapper for those entries who have
* factory methods.
*/
-template<typename HashEntryTy>
-class HashEntryFactory
-{
-public:
- typedef HashEntryTy entry_type;
+template <typename HashEntryTy>
+class HashEntryFactory {
+ public:
+ typedef HashEntryTy entry_type;
typedef typename HashEntryTy::key_type key_type;
-public:
- entry_type* produce(const key_type& pKey)
- { return HashEntryTy::Create(pKey); }
+ public:
+ entry_type* produce(const key_type& pKey) {
+ return HashEntryTy::Create(pKey);
+ }
- void destroy(entry_type*& pEntry)
- { HashEntryTy::Destroy(pEntry); }
+ void destroy(entry_type*& pEntry) { HashEntryTy::Destroy(pEntry); }
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_ADT_HASHENTRYFACTORY_H_
diff --git a/include/mcld/ADT/HashIterator.h b/include/mcld/ADT/HashIterator.h
index adf593f..c7764a3 100644
--- a/include/mcld/ADT/HashIterator.h
+++ b/include/mcld/ADT/HashIterator.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_HASHITERATOR_H
-#define MCLD_ADT_HASHITERATOR_H
+#ifndef MCLD_ADT_HASHITERATOR_H_
+#define MCLD_ADT_HASHITERATOR_H_
#include <cstddef>
@@ -16,32 +16,28 @@ namespace mcld {
/** \class ChainIteratorBase
* \brief ChaintIteratorBase follows the HashEntryTy with the same hash value.
*/
-template<typename HashTableImplTy>
-class ChainIteratorBase
-{
-public:
+template <typename HashTableImplTy>
+class ChainIteratorBase {
+ public:
typedef HashTableImplTy hash_table;
typedef typename HashTableImplTy::key_type key_type;
typedef typename HashTableImplTy::entry_type entry_type;
typedef typename HashTableImplTy::bucket_type bucket_type;
-public:
+ public:
ChainIteratorBase()
- : m_pHashTable(0), m_Index(0), m_HashValue(0), m_EndIndex(0)
- { }
+ : m_pHashTable(NULL), m_Index(0), m_HashValue(0), m_EndIndex(0) {}
ChainIteratorBase(HashTableImplTy* pTable, const key_type& pKey)
- : m_pHashTable(pTable)
- {
+ : m_pHashTable(pTable) {
m_HashValue = pTable->hash()(pKey);
m_EndIndex = m_Index = m_HashValue % m_pHashTable->m_NumOfBuckets;
const unsigned int probe = 1;
- while(true) {
- bucket_type &bucket = m_pHashTable->m_Buckets[m_Index];
+ while (true) {
+ bucket_type& bucket = m_pHashTable->m_Buckets[m_Index];
if (bucket_type::getTombstone() == bucket.Entry) {
// Ignore tombstones.
- }
- else if (m_HashValue == bucket.FullHashValue) {
+ } else if (m_HashValue == bucket.FullHashValue) {
if (bucket.Entry->compare(pKey)) {
m_EndIndex = m_Index;
break;
@@ -59,11 +55,10 @@ public:
}
ChainIteratorBase(const ChainIteratorBase& pCopy)
- : m_pHashTable(pCopy.m_pHashTable),
- m_Index(pCopy.m_Index),
- m_HashValue(pCopy.m_HashValue),
- m_EndIndex(pCopy.m_EndIndex)
- { }
+ : m_pHashTable(pCopy.m_pHashTable),
+ m_Index(pCopy.m_Index),
+ m_HashValue(pCopy.m_HashValue),
+ m_EndIndex(pCopy.m_EndIndex) {}
ChainIteratorBase& assign(const ChainIteratorBase& pCopy) {
m_pHashTable = pCopy.m_pHashTable;
@@ -74,41 +69,41 @@ public:
}
inline bucket_type* getBucket() {
- if (0 == m_pHashTable)
- return 0;
+ if (m_pHashTable == NULL)
+ return NULL;
return &(m_pHashTable->m_Buckets[m_Index]);
}
inline const bucket_type* getBucket() const {
- if (0 == m_pHashTable)
- return 0;
+ if (m_pHashTable == NULL)
+ return NULL;
return &(m_pHashTable->m_Buckets[m_Index]);
}
inline entry_type* getEntry() {
- if (0 == m_pHashTable)
- return 0;
+ if (m_pHashTable == NULL)
+ return NULL;
return m_pHashTable->m_Buckets[m_Index].Entry;
}
inline const entry_type* getEntry() const {
- if (0 == m_pHashTable)
- return 0;
+ if (m_pHashTable == NULL)
+ return NULL;
return m_pHashTable->m_Buckets[m_Index].Entry;
}
inline void reset() {
- m_pHashTable = 0;
+ m_pHashTable = NULL;
m_Index = 0;
m_EndIndex = 0;
m_HashValue = 0;
}
inline void advance() {
- if (0 == m_pHashTable)
+ if (m_pHashTable == NULL)
return;
const unsigned int probe = 1;
- while(true) {
+ while (true) {
m_Index += probe;
if (m_Index == m_pHashTable->m_NumOfBuckets)
m_Index = 0;
@@ -118,13 +113,12 @@ public:
return;
}
- bucket_type &bucket = m_pHashTable->m_Buckets[m_Index];
+ bucket_type& bucket = m_pHashTable->m_Buckets[m_Index];
if (bucket_type::getTombstone() == bucket.Entry ||
bucket_type::getEmptyBucket() == bucket.Entry) {
// Ignore tombstones.
- }
- else if (m_HashValue == bucket.FullHashValue) {
+ } else if (m_HashValue == bucket.FullHashValue) {
return;
}
}
@@ -132,19 +126,19 @@ public:
bool operator==(const ChainIteratorBase& pCopy) const {
if (m_pHashTable == pCopy.m_pHashTable) {
- if (0 == m_pHashTable)
+ if (m_pHashTable == NULL)
return true;
return ((m_HashValue == pCopy.m_HashValue) &&
- (m_EndIndex == pCopy.m_EndIndex) &&
- (m_Index == pCopy.m_Index));
+ (m_EndIndex == pCopy.m_EndIndex) && (m_Index == pCopy.m_Index));
}
return false;
}
- bool operator!=(const ChainIteratorBase& pCopy) const
- { return !(*this == pCopy); }
+ bool operator!=(const ChainIteratorBase& pCopy) const {
+ return !(*this == pCopy);
+ }
-private:
+ private:
HashTableImplTy* m_pHashTable;
unsigned int m_Index;
unsigned int m_HashValue;
@@ -155,28 +149,22 @@ private:
* \brief EntryIteratorBase walks over hash table by the natural layout of the
* buckets
*/
-template<typename HashTableImplTy>
-class EntryIteratorBase
-{
-public:
+template <typename HashTableImplTy>
+class EntryIteratorBase {
+ public:
typedef HashTableImplTy hash_table;
typedef typename HashTableImplTy::key_type key_type;
typedef typename HashTableImplTy::entry_type entry_type;
typedef typename HashTableImplTy::bucket_type bucket_type;
-public:
- EntryIteratorBase()
- : m_pHashTable(0), m_Index(0)
- { }
+ public:
+ EntryIteratorBase() : m_pHashTable(NULL), m_Index(0) {}
- EntryIteratorBase(HashTableImplTy* pTable,
- unsigned int pIndex)
- : m_pHashTable(pTable), m_Index(pIndex)
- { }
+ EntryIteratorBase(HashTableImplTy* pTable, unsigned int pIndex)
+ : m_pHashTable(pTable), m_Index(pIndex) {}
EntryIteratorBase(const EntryIteratorBase& pCopy)
- : m_pHashTable(pCopy.m_pHashTable), m_Index(pCopy.m_Index)
- { }
+ : m_pHashTable(pCopy.m_pHashTable), m_Index(pCopy.m_Index) {}
EntryIteratorBase& assign(const EntryIteratorBase& pCopy) {
m_pHashTable = pCopy.m_pHashTable;
@@ -185,58 +173,60 @@ public:
}
inline bucket_type* getBucket() {
- if (0 == m_pHashTable)
- return 0;
+ if (m_pHashTable == NULL)
+ return NULL;
return &(m_pHashTable->m_Buckets[m_Index]);
}
inline const bucket_type* getBucket() const {
- if (0 == m_pHashTable)
- return 0;
+ if (m_pHashTable == NULL)
+ return NULL;
return &(m_pHashTable->m_Buckets[m_Index]);
}
inline entry_type* getEntry() {
- if (0 == m_pHashTable)
- return 0;
+ if (m_pHashTable == NULL)
+ return NULL;
return m_pHashTable->m_Buckets[m_Index].Entry;
}
inline const entry_type* getEntry() const {
- if (0 == m_pHashTable)
- return 0;
+ if (m_pHashTable == NULL)
+ return NULL;
return m_pHashTable->m_Buckets[m_Index].Entry;
}
inline void reset() {
- m_pHashTable = 0;
+ m_pHashTable = NULL;
m_Index = 0;
}
inline void advance() {
- if (0 == m_pHashTable)
+ if (m_pHashTable == NULL)
return;
do {
++m_Index;
- if (m_pHashTable->m_NumOfBuckets == m_Index) { // to the end
+ if (m_pHashTable->m_NumOfBuckets == m_Index) { // to the end
reset();
return;
}
- } while(bucket_type::getEmptyBucket() == m_pHashTable->m_Buckets[m_Index].Entry ||
- bucket_type::getTombstone() == m_pHashTable->m_Buckets[m_Index].Entry);
+ } while (bucket_type::getEmptyBucket() ==
+ m_pHashTable->m_Buckets[m_Index].Entry ||
+ bucket_type::getTombstone() ==
+ m_pHashTable->m_Buckets[m_Index].Entry);
}
- bool operator==(const EntryIteratorBase& pCopy) const
- { return ((m_pHashTable == pCopy.m_pHashTable) &&
- (m_Index == pCopy.m_Index)); }
+ bool operator==(const EntryIteratorBase& pCopy) const {
+ return ((m_pHashTable == pCopy.m_pHashTable) && (m_Index == pCopy.m_Index));
+ }
- bool operator!=(const EntryIteratorBase& pCopy) const
- { return !(*this == pCopy); }
+ bool operator!=(const EntryIteratorBase& pCopy) const {
+ return !(*this == pCopy);
+ }
-private:
+ private:
HashTableImplTy* m_pHashTable;
unsigned int m_Index;
-
};
/** \class HashIterator
@@ -250,53 +240,41 @@ private:
* behavior by change the template argument IteratorBase. HashTable defines
* above two iterators by defining HashIterators with different IteratorBase.
*/
-template<typename IteratorBase,
- typename Traits>
-class HashIterator : public IteratorBase
-{
-public:
- typedef Traits traits;
- typedef typename traits::pointer pointer;
+template <typename IteratorBase, typename Traits>
+class HashIterator : public IteratorBase {
+ public:
+ typedef Traits traits;
+ typedef typename traits::pointer pointer;
typedef typename traits::reference reference;
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef IteratorBase Base;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef IteratorBase Base;
- typedef HashIterator<IteratorBase,
- Traits> Self;
+ typedef HashIterator<IteratorBase, Traits> Self;
typedef typename traits::nonconst_traits nonconst_traits;
- typedef HashIterator<IteratorBase,
- nonconst_traits> iterator;
+ typedef HashIterator<IteratorBase, nonconst_traits> iterator;
- typedef typename traits::const_traits const_traits;
- typedef HashIterator<IteratorBase,
- const_traits> const_iterator;
- typedef std::forward_iterator_tag iterator_category;
+ typedef typename traits::const_traits const_traits;
+ typedef HashIterator<IteratorBase, const_traits> const_iterator;
+ typedef std::forward_iterator_tag iterator_category;
-public:
- HashIterator()
- : IteratorBase()
- { }
+ public:
+ HashIterator() : IteratorBase() {}
/// HashIterator - constructor for EntryIterator
HashIterator(typename IteratorBase::hash_table* pTable, unsigned int pIndex)
- : IteratorBase(pTable, pIndex)
- { }
+ : IteratorBase(pTable, pIndex) {}
/// HashIterator - constructor for ChainIterator
explicit HashIterator(typename IteratorBase::hash_table* pTable,
const typename IteratorBase::key_type& pKey,
int)
- : IteratorBase(pTable, pKey)
- { }
+ : IteratorBase(pTable, pKey) {}
- HashIterator(const HashIterator& pCopy)
- : IteratorBase(pCopy)
- { }
+ HashIterator(const HashIterator& pCopy) : IteratorBase(pCopy) {}
- ~HashIterator()
- { }
+ ~HashIterator() {}
HashIterator& operator=(const HashIterator& pCopy) {
IteratorBase::assign(pCopy);
@@ -316,7 +294,6 @@ public:
}
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_ADT_HASHITERATOR_H_
diff --git a/include/mcld/ADT/HashTable.h b/include/mcld/ADT/HashTable.h
index 83ff868..62b1bd3 100644
--- a/include/mcld/ADT/HashTable.h
+++ b/include/mcld/ADT/HashTable.h
@@ -1,4 +1,4 @@
-//===- HashTable.h ---------------------------------------------------------===//
+//===- HashTable.h --------------------------------------------------------===//
//
// The MCLinker Project
//
@@ -6,15 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_HASHTABLE_H
-#define MCLD_ADT_HASHTABLE_H
-
-#include <mcld/ADT/HashBase.h>
-#include <mcld/ADT/HashIterator.h>
-#include <mcld/ADT/HashEntryFactory.h>
-#include <mcld/ADT/Uncopyable.h>
-#include <mcld/ADT/TypeTraits.h>
-#include <mcld/Support/Allocators.h>
+#ifndef MCLD_ADT_HASHTABLE_H_
+#define MCLD_ADT_HASHTABLE_H_
+
+#include "mcld/ADT/HashBase.h"
+#include "mcld/ADT/HashEntryFactory.h"
+#include "mcld/ADT/HashIterator.h"
+#include "mcld/ADT/TypeTraits.h"
+#include "mcld/Support/Allocators.h"
+#include "mcld/Support/Compiler.h"
+
#include <utility>
namespace mcld {
@@ -27,42 +28,39 @@ namespace mcld {
* the memory space of the entries by itself. Instead, entries are allocated
* outside and then emplaced into the hash table.
*/
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy = HashEntryFactory<HashEntryTy> >
-class HashTable : public HashTableImpl<HashEntryTy, HashFunctionTy>,
- private Uncopyable
-{
-private:
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy = HashEntryFactory<HashEntryTy> >
+class HashTable : public HashTableImpl<HashEntryTy, HashFunctionTy> {
+ private:
typedef HashTableImpl<HashEntryTy, HashFunctionTy> BaseTy;
-public:
+ public:
typedef size_t size_type;
typedef HashFunctionTy hasher;
typedef HashEntryTy entry_type;
typedef typename BaseTy::bucket_type bucket_type;
typedef typename HashEntryTy::key_type key_type;
- typedef HashIterator<ChainIteratorBase<BaseTy>,
- NonConstTraits<HashEntryTy> > chain_iterator;
+ typedef HashIterator<ChainIteratorBase<BaseTy>, NonConstTraits<HashEntryTy> >
+ chain_iterator;
typedef HashIterator<ChainIteratorBase<const BaseTy>,
- ConstTraits<HashEntryTy> > const_chain_iterator;
+ ConstTraits<HashEntryTy> > const_chain_iterator;
- typedef HashIterator<EntryIteratorBase<BaseTy>,
- NonConstTraits<HashEntryTy> > entry_iterator;
+ typedef HashIterator<EntryIteratorBase<BaseTy>, NonConstTraits<HashEntryTy> >
+ entry_iterator;
typedef HashIterator<EntryIteratorBase<const BaseTy>,
- ConstTraits<HashEntryTy> > const_entry_iterator;
+ ConstTraits<HashEntryTy> > const_entry_iterator;
- typedef entry_iterator iterator;
- typedef const_entry_iterator const_iterator;
+ typedef entry_iterator iterator;
+ typedef const_entry_iterator const_iterator;
-public:
+ public:
// ----- constructor ----- //
- explicit HashTable(size_type pSize=3);
+ explicit HashTable(size_type pSize = 3);
~HashTable();
- EntryFactoryTy& getEntryFactory()
- { return m_EntryFactory; }
+ EntryFactoryTy& getEntryFactory() { return m_EntryFactory; }
// ----- modifiers ----- //
void clear();
@@ -109,14 +107,15 @@ public:
const_chain_iterator begin(const key_type& pKey) const;
const_chain_iterator end(const key_type& pKey) const;
-private:
+ private:
EntryFactoryTy m_EntryFactory;
+ private:
+ DISALLOW_COPY_AND_ASSIGN(HashTable);
};
#include "HashTable.tcc"
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_ADT_HASHTABLE_H_
diff --git a/include/mcld/ADT/HashTable.tcc b/include/mcld/ADT/HashTable.tcc
index d0040ae..4d5e8dc 100644
--- a/include/mcld/ADT/HashTable.tcc
+++ b/include/mcld/ADT/HashTable.tcc
@@ -1,4 +1,4 @@
-//===- HashTable.tcc ---------------------------------------------------------===//
+//===- HashTable.tcc ------------------------------------------------------===//
//
// The MCLinker Project
//
@@ -7,45 +7,43 @@
//
//===----------------------------------------------------------------------===//
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
// template implementation of HashTable
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
-HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::HashTable(size_type pSize)
- : HashTableImpl<HashEntryTy, HashFunctionTy>(pSize), m_EntryFactory()
-{
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
+HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::HashTable(
+ size_type pSize)
+ : HashTableImpl<HashEntryTy, HashFunctionTy>(pSize), m_EntryFactory() {
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
-HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::~HashTable()
-{
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
+HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::~HashTable() {
if (BaseTy::empty())
return;
/** clean up **/
- for (unsigned int i=0; i < BaseTy::m_NumOfBuckets; ++i) {
+ for (unsigned int i = 0; i < BaseTy::m_NumOfBuckets; ++i) {
if (bucket_type::getEmptyBucket() != BaseTy::m_Buckets[i].Entry &&
- bucket_type::getTombstone() != BaseTy::m_Buckets[i].Entry ) {
+ bucket_type::getTombstone() != BaseTy::m_Buckets[i].Entry) {
m_EntryFactory.destroy(BaseTy::m_Buckets[i].Entry);
}
}
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
-void HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::clear()
-{
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
+void HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::clear() {
if (BaseTy::empty())
return;
/** clean up **/
- for (unsigned int i=0; i < BaseTy::m_NumOfBuckets; ++i) {
- if (bucket_type::getEmptyBucket() != BaseTy::m_Buckets[i].Entry ) {
- if (bucket_type::getTombstone() != BaseTy::m_Buckets[i].Entry ) {
+ for (unsigned int i = 0; i < BaseTy::m_NumOfBuckets; ++i) {
+ if (bucket_type::getEmptyBucket() != BaseTy::m_Buckets[i].Entry) {
+ if (bucket_type::getTombstone() != BaseTy::m_Buckets[i].Entry) {
m_EntryFactory.destroy(BaseTy::m_Buckets[i].Entry);
}
BaseTy::m_Buckets[i].Entry = bucket_type::getEmptyBucket();
@@ -57,14 +55,15 @@ void HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::clear()
/// insert - insert a new element to the container. If the element already
// exist, return the element.
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::entry_type*
HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::insert(
- const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey,
- bool& pExist)
-{
+ const typename HashTable<HashEntryTy,
+ HashFunctionTy,
+ EntryFactoryTy>::key_type& pKey,
+ bool& pExist) {
unsigned int index = BaseTy::lookUpBucketFor(pKey);
bucket_type& bucket = BaseTy::m_Buckets[index];
entry_type* entry = bucket.Entry;
@@ -88,15 +87,16 @@ HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::insert(
/// erase - remove the elements with the pKey
// @return the number of removed elements.
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::size_type
HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::erase(
- const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey)
-{
+ const typename HashTable<HashEntryTy,
+ HashFunctionTy,
+ EntryFactoryTy>::key_type& pKey) {
int index;
- if (-1 == (index = BaseTy::findKey(pKey)))
+ if ((index = BaseTy::findKey(pKey)) == -1)
return 0;
bucket_type& bucket = BaseTy::m_Buckets[index];
@@ -109,39 +109,42 @@ HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::erase(
return 1;
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::iterator
HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::find(
- const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey)
-{
+ const typename HashTable<HashEntryTy,
+ HashFunctionTy,
+ EntryFactoryTy>::key_type& pKey) {
int index;
- if (-1 == (index = BaseTy::findKey(pKey)))
+ if ((index = BaseTy::findKey(pKey)) == -1)
return end();
return iterator(this, index);
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::const_iterator
HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::find(
- const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey) const
-{
+ const typename HashTable<HashEntryTy,
+ HashFunctionTy,
+ EntryFactoryTy>::key_type& pKey) const {
int index;
- if (-1 == (index = BaseTy::findKey(pKey)))
+ if ((index = BaseTy::findKey(pKey)) == -1)
return end();
return const_iterator(this, index);
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::size_type
HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::count(
- const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey) const
-{
+ const typename HashTable<HashEntryTy,
+ HashFunctionTy,
+ EntryFactoryTy>::key_type& pKey) const {
const_chain_iterator bucket, bEnd = end(pKey);
size_type count = 0;
for (bucket = begin(pKey); bucket != bEnd; ++bucket)
@@ -149,39 +152,35 @@ HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::count(
return count;
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
-float HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::load_factor() const
-{
- return ((float)BaseTy::m_NumOfEntries/(float)BaseTy::m_NumOfBuckets);
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
+float HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::load_factor()
+ const {
+ return ((float)BaseTy::m_NumOfEntries / (float)BaseTy::m_NumOfBuckets);
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
-void
-HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::rehash()
-{
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
+void HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::rehash() {
BaseTy::mayRehash();
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
-void
-HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::rehash(
- typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::size_type pCount)
-{
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
+void HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::rehash(
+ typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::size_type
+ pCount) {
BaseTy::doRehash(pCount);
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::iterator
-HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin()
-{
+HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin() {
if (BaseTy::empty())
return end();
unsigned int index = 0;
@@ -192,21 +191,19 @@ HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin()
return iterator(this, index);
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::iterator
-HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::end()
-{
+HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::end() {
return iterator(NULL, 0);
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::const_iterator
-HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin() const
-{
+HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin() const {
if (BaseTy::empty())
return end();
unsigned int index = 0;
@@ -217,52 +214,58 @@ HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin() const
return const_iterator(this, index);
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::const_iterator
-HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::end() const
-{
+HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::end() const {
return const_iterator(NULL, 0);
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::chain_iterator
HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin(
- const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey)
-{
+ const typename HashTable<HashEntryTy,
+ HashFunctionTy,
+ EntryFactoryTy>::key_type& pKey) {
return chain_iterator(this, pKey, 0x0);
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::chain_iterator
HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::end(
- const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey)
-{
+ const typename HashTable<HashEntryTy,
+ HashFunctionTy,
+ EntryFactoryTy>::key_type& pKey) {
return chain_iterator();
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
-typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::const_chain_iterator
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
+typename HashTable<HashEntryTy,
+ HashFunctionTy,
+ EntryFactoryTy>::const_chain_iterator
HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::begin(
- const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey) const
-{
+ const typename HashTable<HashEntryTy,
+ HashFunctionTy,
+ EntryFactoryTy>::key_type& pKey) const {
return const_chain_iterator(this, pKey, 0x0);
}
-template<typename HashEntryTy,
- typename HashFunctionTy,
- typename EntryFactoryTy>
-typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::const_chain_iterator
+template <typename HashEntryTy,
+ typename HashFunctionTy,
+ typename EntryFactoryTy>
+typename HashTable<HashEntryTy,
+ HashFunctionTy,
+ EntryFactoryTy>::const_chain_iterator
HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::end(
- const typename HashTable<HashEntryTy, HashFunctionTy, EntryFactoryTy>::key_type& pKey) const
-{
+ const typename HashTable<HashEntryTy,
+ HashFunctionTy,
+ EntryFactoryTy>::key_type& pKey) const {
return const_chain_iterator();
}
-
diff --git a/include/mcld/ADT/SizeTraits.h b/include/mcld/ADT/SizeTraits.h
index 53a6742..577fd69 100644
--- a/include/mcld/ADT/SizeTraits.h
+++ b/include/mcld/ADT/SizeTraits.h
@@ -6,80 +6,75 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_SIZETRAITS_H
-#define MCLD_ADT_SIZETRAITS_H
+#ifndef MCLD_ADT_SIZETRAITS_H_
+#define MCLD_ADT_SIZETRAITS_H_
#include <llvm/Support/DataTypes.h>
#include <llvm/Support/ELF.h>
-namespace mcld
-{
+namespace mcld {
-template<size_t SIZE>
+template <size_t SIZE>
class SizeTraits;
-template<>
-class SizeTraits<32>
-{
-public:
+template <>
+class SizeTraits<32> {
+ public:
typedef uint32_t Address;
typedef uint32_t Offset;
typedef uint32_t Word;
- typedef int32_t SWord;
+ typedef int32_t SWord;
};
-template<>
-class SizeTraits<64>
-{
-public:
+template <>
+class SizeTraits<64> {
+ public:
typedef uint64_t Address;
typedef uint64_t Offset;
typedef uint64_t Word;
- typedef int64_t SWord;
+ typedef int64_t SWord;
};
// FIXME: move this to mcld internal ELF header file?
-template<size_t SIZE>
+template <size_t SIZE>
class ELFSizeTraits;
-template<>
-class ELFSizeTraits<32>
-{
-public:
- typedef llvm::ELF::Elf32_Addr Addr; // Program address
- typedef llvm::ELF::Elf32_Off Off; // File offset
- typedef llvm::ELF::Elf32_Half Half;
- typedef llvm::ELF::Elf32_Word Word;
+template <>
+class ELFSizeTraits<32> {
+ public:
+ typedef llvm::ELF::Elf32_Addr Addr; // Program address
+ typedef llvm::ELF::Elf32_Off Off; // File offset
+ typedef llvm::ELF::Elf32_Half Half;
+ typedef llvm::ELF::Elf32_Word Word;
typedef llvm::ELF::Elf32_Sword Sword;
- typedef llvm::ELF::Elf32_Ehdr Ehdr;
- typedef llvm::ELF::Elf32_Shdr Shdr;
- typedef llvm::ELF::Elf32_Sym Sym;
- typedef llvm::ELF::Elf32_Rel Rel;
- typedef llvm::ELF::Elf32_Rela Rela;
- typedef llvm::ELF::Elf32_Phdr Phdr;
- typedef llvm::ELF::Elf32_Dyn Dyn;
+ typedef llvm::ELF::Elf32_Ehdr Ehdr;
+ typedef llvm::ELF::Elf32_Shdr Shdr;
+ typedef llvm::ELF::Elf32_Sym Sym;
+ typedef llvm::ELF::Elf32_Rel Rel;
+ typedef llvm::ELF::Elf32_Rela Rela;
+ typedef llvm::ELF::Elf32_Phdr Phdr;
+ typedef llvm::ELF::Elf32_Dyn Dyn;
};
-template<>
-class ELFSizeTraits<64>
-{
-public:
- typedef llvm::ELF::Elf64_Addr Addr;
- typedef llvm::ELF::Elf64_Off Off;
- typedef llvm::ELF::Elf64_Half Half;
- typedef llvm::ELF::Elf64_Word Word;
- typedef llvm::ELF::Elf64_Sword Sword;
- typedef llvm::ELF::Elf64_Xword Xword;
+template <>
+class ELFSizeTraits<64> {
+ public:
+ typedef llvm::ELF::Elf64_Addr Addr;
+ typedef llvm::ELF::Elf64_Off Off;
+ typedef llvm::ELF::Elf64_Half Half;
+ typedef llvm::ELF::Elf64_Word Word;
+ typedef llvm::ELF::Elf64_Sword Sword;
+ typedef llvm::ELF::Elf64_Xword Xword;
typedef llvm::ELF::Elf64_Sxword Sxword;
- typedef llvm::ELF::Elf64_Ehdr Ehdr;
- typedef llvm::ELF::Elf64_Shdr Shdr;
- typedef llvm::ELF::Elf64_Sym Sym;
- typedef llvm::ELF::Elf64_Rel Rel;
- typedef llvm::ELF::Elf64_Rela Rela;
- typedef llvm::ELF::Elf64_Phdr Phdr;
- typedef llvm::ELF::Elf64_Dyn Dyn;
+ typedef llvm::ELF::Elf64_Ehdr Ehdr;
+ typedef llvm::ELF::Elf64_Shdr Shdr;
+ typedef llvm::ELF::Elf64_Sym Sym;
+ typedef llvm::ELF::Elf64_Rel Rel;
+ typedef llvm::ELF::Elf64_Rela Rela;
+ typedef llvm::ELF::Elf64_Phdr Phdr;
+ typedef llvm::ELF::Elf64_Dyn Dyn;
};
/// alignAddress - helper function to align an address with given alignment
@@ -87,24 +82,21 @@ public:
///
/// @param pAddr - the address to be aligned
/// @param pAlignConstraint - the alignment used to align the given address
-inline void alignAddress(uint64_t& pAddr, uint64_t pAlignConstraint)
-{
+inline void alignAddress(uint64_t& pAddr, uint64_t pAlignConstraint) {
if (pAlignConstraint != 0)
- pAddr = (pAddr + pAlignConstraint - 1) &~ (pAlignConstraint - 1);
+ pAddr = (pAddr + pAlignConstraint - 1) & ~(pAlignConstraint - 1);
}
-template<size_t Constraint>
+template <size_t Constraint>
uint64_t Align(uint64_t pAddress);
-template<>
-inline uint64_t Align<32>(uint64_t pAddress)
-{
+template <>
+inline uint64_t Align<32>(uint64_t pAddress) {
return (pAddress + 0x1F) & (~0x1F);
}
-template<>
-inline uint64_t Align<64>(uint64_t pAddress)
-{
+template <>
+inline uint64_t Align<64>(uint64_t pAddress) {
return (pAddress + 0x3F) & (~0x3F);
}
@@ -120,54 +112,45 @@ inline uint64_t Align<64>(uint64_t pAddress)
/// bswap16 - byte swap 16-bit version
/// @ref binary utilities - elfcpp_swap
-inline uint16_t bswap16(uint16_t pData)
-{
- return ((pData >> 8) & 0xFF) | ((pData & 0xFF) << 8);
+inline uint16_t bswap16(uint16_t pData) {
+ return ((pData >> 8) & 0xFF) | ((pData & 0xFF) << 8);
}
/// bswap32 - byte swap 32-bit version
/// @ref elfcpp_swap
-inline uint32_t bswap32(uint32_t pData)
-{
- return (((pData & 0xFF000000) >> 24) |
- ((pData & 0x00FF0000) >> 8) |
- ((pData & 0x0000FF00) << 8) |
- ((pData & 0x000000FF) << 24));
-
+inline uint32_t bswap32(uint32_t pData) {
+ return (((pData & 0xFF000000) >> 24) | ((pData & 0x00FF0000) >> 8) |
+ ((pData & 0x0000FF00) << 8) | ((pData & 0x000000FF) << 24));
}
/// bswap64 - byte swap 64-bit version
/// @ref binary utilities - elfcpp_swap
-inline uint64_t bswap64(uint64_t pData)
-{
- return (((pData & 0xFF00000000000000ULL) >> 56) |
- ((pData & 0x00FF000000000000ULL) >> 40) |
- ((pData & 0x0000FF0000000000ULL) >> 24) |
- ((pData & 0x000000FF00000000ULL) >> 8) |
- ((pData & 0x00000000FF000000ULL) << 8) |
- ((pData & 0x0000000000FF0000ULL) << 24) |
- ((pData & 0x000000000000FF00ULL) << 40) |
- ((pData & 0x00000000000000FFULL) << 56));
+inline uint64_t bswap64(uint64_t pData) {
+ return (((pData & 0xFF00000000000000ULL) >> 56) |
+ ((pData & 0x00FF000000000000ULL) >> 40) |
+ ((pData & 0x0000FF0000000000ULL) >> 24) |
+ ((pData & 0x000000FF00000000ULL) >> 8) |
+ ((pData & 0x00000000FF000000ULL) << 8) |
+ ((pData & 0x0000000000FF0000ULL) << 24) |
+ ((pData & 0x000000000000FF00ULL) << 40) |
+ ((pData & 0x00000000000000FFULL) << 56));
}
-template<size_t SIZE>
+template <size_t SIZE>
typename SizeTraits<SIZE>::Word bswap(typename SizeTraits<SIZE>::Word pData);
-template<>
-inline SizeTraits<32>::Word bswap<32>(SizeTraits<32>::Word pData)
-{
+template <>
+inline SizeTraits<32>::Word bswap<32>(SizeTraits<32>::Word pData) {
return bswap32(pData);
}
-template<>
-inline SizeTraits<64>::Word bswap<64>(SizeTraits<64>::Word pData)
-{
+template <>
+inline SizeTraits<64>::Word bswap<64>(SizeTraits<64>::Word pData) {
return bswap64(pData);
}
template <size_t WIDTH>
-inline uint64_t signExtend(uint64_t pVal)
-{
+inline uint64_t signExtend(uint64_t pVal) {
uint64_t mask = (~((uint64_t)0)) >> (64 - WIDTH);
uint64_t sign_bit = 1 << (WIDTH - 1);
@@ -175,23 +158,21 @@ inline uint64_t signExtend(uint64_t pVal)
}
template <>
-inline uint64_t signExtend<64>(uint64_t pVal)
-{
+inline uint64_t signExtend<64>(uint64_t pVal) {
return pVal;
}
template <size_t SizeOfStr, typename FieldType>
-class StringSizerHelper
-{
-private:
+class StringSizerHelper {
+ private:
char FIELD_TOO_SMALL[SizeOfStr <= FieldType(~0U) ? 1 : -1];
-public:
+
+ public:
enum { Size = SizeOfStr };
};
-#define STR_SIZE(str, fieldTy) StringSizerHelper<sizeof(str)-1, fieldTy>::Size
-
-} // namespace of mcld
+#define STR_SIZE(str, fieldTy) StringSizerHelper<sizeof(str) - 1, fieldTy>::Size
-#endif
+} // namespace mcld
+#endif // MCLD_ADT_SIZETRAITS_H_
diff --git a/include/mcld/ADT/StringEntry.h b/include/mcld/ADT/StringEntry.h
index 4f57f10..99610cc 100644
--- a/include/mcld/ADT/StringEntry.h
+++ b/include/mcld/ADT/StringEntry.h
@@ -1,4 +1,4 @@
-//===- StringEntry.h -------------------------------------------------------===//
+//===- StringEntry.h ------------------------------------------------------===//
//
// The MCLinker Project
//
@@ -6,64 +6,55 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_STRINGENTRY_H
-#define MCLD_ADT_STRINGENTRY_H
+#ifndef MCLD_ADT_STRINGENTRY_H_
+#define MCLD_ADT_STRINGENTRY_H_
+
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/DataTypes.h>
+
+#include <cassert>
#include <cstdlib>
#include <cstring>
-#include <cassert>
-namespace mcld
-{
-template<typename DataType>
+namespace mcld {
+template <typename DataType>
class StringEntryFactory;
/** \class StringEntry
* \brief StringEntry is a pair of strings which is designed for high locality.
*/
-template<typename DataType>
-class StringEntry
-{
-public:
- typedef llvm::StringRef key_type;
+template <typename DataType>
+class StringEntry {
+ public:
+ typedef llvm::StringRef key_type;
typedef DataType value_type;
-public:
- key_type key()
- { return key_type(m_Key, m_KeyLen); }
+ public:
+ key_type key() { return key_type(m_Key, m_KeyLen); }
- const key_type key() const
- { return key_type(m_Key, m_KeyLen); }
+ const key_type key() const { return key_type(m_Key, m_KeyLen); }
- value_type& value()
- { return m_Value; }
+ value_type& value() { return m_Value; }
- const value_type& value() const
- { return m_Value; }
+ const value_type& value() const { return m_Value; }
- size_t getKeyLength() const
- { return m_KeyLen; }
+ size_t getKeyLength() const { return m_KeyLen; }
- size_t getValueLength() const
- { return m_Value.size(); }
+ size_t getValueLength() const { return m_Value.size(); }
- void setValue(const DataType& pVal)
- { m_Value = pVal; }
+ void setValue(const DataType& pVal) { m_Value = pVal; }
- bool compare(const llvm::StringRef& pX)
- { return (0 == key().compare(pX)); }
+ bool compare(const llvm::StringRef& pX) { return key().equals(pX); }
- bool compare(const llvm::StringRef& pX) const
- { return (0 == key().compare(pX)); }
+ bool compare(const llvm::StringRef& pX) const { return key().equals(pX); }
-private:
+ private:
StringEntry();
- StringEntry(const key_type& pKey);
+ explicit StringEntry(const key_type& pKey);
StringEntry(const StringEntry& pCopy);
~StringEntry();
-private:
+ private:
DataType m_Value;
uint16_t m_KeyLen;
char m_Key[];
@@ -71,53 +62,42 @@ private:
friend class StringEntryFactory<DataType>;
};
-
-template<>
-class StringEntry<llvm::StringRef>
-{
-public:
+template <>
+class StringEntry<llvm::StringRef> {
+ public:
typedef llvm::StringRef key_type;
typedef llvm::StringRef value_type;
-public:
- key_type key()
- { return key_type(m_Key, m_KeyLen); }
+ public:
+ key_type key() { return key_type(m_Key, m_KeyLen); }
- const key_type key() const
- { return key_type(m_Key, m_KeyLen); }
+ const key_type key() const { return key_type(m_Key, m_KeyLen); }
- value_type& value()
- { return m_Value; }
+ value_type& value() { return m_Value; }
- const value_type& value() const
- { return m_Value; }
+ const value_type& value() const { return m_Value; }
- size_t getKeyLength() const
- { return m_KeyLen; }
+ size_t getKeyLength() const { return m_KeyLen; }
- size_t getValueLength() const
- { return m_Value.size(); }
+ size_t getValueLength() const { return m_Value.size(); }
- void setValue(const std::string& pVal)
- { setValue(pVal.c_str()); }
+ void setValue(const std::string& pVal) { setValue(pVal.c_str()); }
void setValue(const char* pVal);
- void setValue(llvm::StringRef& pVal);
+ void setValue(llvm::StringRef pVal);
- bool compare(const llvm::StringRef& pX)
- { return (0 == key().compare(pX)); }
+ bool compare(const llvm::StringRef pX) { return key().equals(pX); }
- bool compare(const llvm::StringRef& pX) const
- { return (0 == key().compare(pX)); }
+ bool compare(const llvm::StringRef pX) const { return key().equals(pX); }
-private:
+ private:
StringEntry();
- StringEntry(const key_type& pKey);
+ explicit StringEntry(const key_type& pKey);
StringEntry(const StringEntry& pCopy);
~StringEntry();
-private:
+ private:
llvm::StringRef m_Value;
uint16_t m_KeyLen;
char m_Key[];
@@ -125,15 +105,14 @@ private:
friend class StringEntryFactory<llvm::StringRef>;
};
-template<typename DataType>
-class StringEntryFactory
-{
-public:
- typedef StringEntry<DataType> entry_type;
- typedef typename StringEntry<DataType>::key_type key_type;
+template <typename DataType>
+class StringEntryFactory {
+ public:
+ typedef StringEntry<DataType> entry_type;
+ typedef typename StringEntry<DataType>::key_type key_type;
typedef typename StringEntry<DataType>::value_type value_type;
-public:
+ public:
StringEntryFactory();
~StringEntryFactory();
@@ -143,7 +122,6 @@ public:
#include "StringEntry.tcc"
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_ADT_STRINGENTRY_H_
diff --git a/include/mcld/ADT/StringEntry.tcc b/include/mcld/ADT/StringEntry.tcc
index fa86f24..a9ed6b7 100644
--- a/include/mcld/ADT/StringEntry.tcc
+++ b/include/mcld/ADT/StringEntry.tcc
@@ -1,4 +1,4 @@
-//===- StringEntry.tcc -----------------------------------------------------===//
+//===- StringEntry.tcc ----------------------------------------------------===//
//
// The MCLinker Project
//
@@ -9,47 +9,43 @@
//===----------------------------------------------------------------------===//
// StringEntry
-template<typename DataType>
+template <typename DataType>
StringEntry<DataType>::StringEntry()
- : m_KeyLen(0) {
+ : m_KeyLen(0) {
}
-template<typename DataType>
+template <typename DataType>
StringEntry<DataType>::StringEntry(const StringEntry::key_type& pKey)
- : m_KeyLen(pKey.size()) {
+ : m_KeyLen(pKey.size()) {
}
-template<typename DataType>
+template <typename DataType>
StringEntry<DataType>::StringEntry(const StringEntry<DataType>& pCopy)
- : m_KeyLen(pCopy.m_KeyLen), m_Value(pCopy.m_Value) {
+ : m_KeyLen(pCopy.m_KeyLen), m_Value(pCopy.m_Value) {
assert("Copy constructor of StringEntry should not be called!");
}
-template<typename DataType>
-StringEntry<DataType>::~StringEntry()
-{
+template <typename DataType>
+StringEntry<DataType>::~StringEntry() {
}
//===----------------------------------------------------------------------===//
// StringEntryFactory
-template<typename DataType>
-StringEntryFactory<DataType>::StringEntryFactory()
-{
+template <typename DataType>
+StringEntryFactory<DataType>::StringEntryFactory() {
}
-template<typename DataType>
-StringEntryFactory<DataType>::~StringEntryFactory()
-{
+template <typename DataType>
+StringEntryFactory<DataType>::~StringEntryFactory() {
}
-template<typename DataType>
-StringEntry<DataType>*
-StringEntryFactory<DataType>::produce(const typename StringEntryFactory<DataType>::key_type& pKey)
-{
+template <typename DataType>
+StringEntry<DataType>* StringEntryFactory<DataType>::produce(
+ const typename StringEntryFactory<DataType>::key_type& pKey) {
StringEntry<DataType>* result = static_cast<StringEntry<DataType>*>(
- malloc(sizeof(StringEntry<DataType>) + pKey.size() + 1));
+ malloc(sizeof(StringEntry<DataType>) + pKey.size() + 1));
- if (NULL == result)
+ if (result == NULL)
return NULL;
size_t len = pKey.size();
@@ -60,12 +56,10 @@ StringEntryFactory<DataType>::produce(const typename StringEntryFactory<DataType
return result;
}
-template<typename DataType>
-void StringEntryFactory<DataType>::destroy(StringEntry<DataType>* pEntry)
-{
- if (NULL != pEntry) {
+template <typename DataType>
+void StringEntryFactory<DataType>::destroy(StringEntry<DataType>* pEntry) {
+ if (pEntry != NULL) {
pEntry->~StringEntry<DataType>();
free(pEntry);
}
}
-
diff --git a/include/mcld/ADT/StringHash.h b/include/mcld/ADT/StringHash.h
index ae9479b..f24bb6b 100644
--- a/include/mcld/ADT/StringHash.h
+++ b/include/mcld/ADT/StringHash.h
@@ -6,40 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_STRINGHASH_H
-#define MCLD_ADT_STRINGHASH_H
+#ifndef MCLD_ADT_STRINGHASH_H_
+#define MCLD_ADT_STRINGHASH_H_
+
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/DataTypes.h>
-#include <cctype>
+
#include <cassert>
+#include <cctype>
#include <functional>
namespace mcld {
namespace hash {
-enum Type {
- RS,
- JS,
- PJW,
- ELF,
- BKDR,
- SDBM,
- DJB,
- DEK,
- BP,
- FNV,
- AP,
- ES
-};
+enum Type { RS, JS, PJW, ELF, BKDR, SDBM, DJB, DEK, BP, FNV, AP, ES };
/** \class template<uint32_t TYPE> StringHash
* \brief the template StringHash class, for specification
*/
-template<uint32_t TYPE>
-struct StringHash : public std::unary_function<const llvm::StringRef&, uint32_t>
-{
- uint32_t operator()(const llvm::StringRef& pKey) const
- {
+template <uint32_t TYPE>
+struct StringHash
+ : public std::unary_function<const llvm::StringRef, uint32_t> {
+ uint32_t operator()(const llvm::StringRef pKey) const {
assert(false && "Undefined StringHash function.\n");
return 0;
}
@@ -48,16 +36,15 @@ struct StringHash : public std::unary_function<const llvm::StringRef&, uint32_t>
/** \class StringHash<RSHash>
* \brief RS StringHash funciton
*/
-template<>
-struct StringHash<RS> : public std::unary_function<const llvm::StringRef&, uint32_t>
-{
- uint32_t operator()(const llvm::StringRef& pKey) const
- {
+template <>
+struct StringHash<RS>
+ : public std::unary_function<const llvm::StringRef, uint32_t> {
+ uint32_t operator()(const llvm::StringRef pKey) const {
const unsigned int b = 378551;
uint32_t a = 63689;
uint32_t hash_val = 0;
- for(unsigned int i = 0; i < pKey.size(); ++i) {
+ for (unsigned int i = 0; i < pKey.size(); ++i) {
hash_val = hash_val * a + pKey[i];
a = a * b;
}
@@ -68,15 +55,14 @@ struct StringHash<RS> : public std::unary_function<const llvm::StringRef&, uint3
/** \class StringHash<JSHash>
* \brief JS hash funciton
*/
-template<>
-struct StringHash<JS> : public std::unary_function<const llvm::StringRef&, uint32_t>
-{
- uint32_t operator()(const llvm::StringRef& pKey) const
- {
+template <>
+struct StringHash<JS>
+ : public std::unary_function<const llvm::StringRef, uint32_t> {
+ uint32_t operator()(const llvm::StringRef pKey) const {
uint32_t hash_val = 1315423911;
- for(unsigned int i = 0; i < pKey.size(); ++i) {
- hash_val ^= ((hash_val << 5) + pKey[i] + (hash_val >> 2));
+ for (unsigned int i = 0; i < pKey.size(); ++i) {
+ hash_val ^= ((hash_val << 5) + pKey[i] + (hash_val >> 2));
}
return hash_val;
}
@@ -85,23 +71,25 @@ struct StringHash<JS> : public std::unary_function<const llvm::StringRef&, uint3
/** \class StringHash<PJW>
* \brief P.J. Weinberger hash function
*/
-template<>
-struct StringHash<PJW> : public std::unary_function<const llvm::StringRef&, uint32_t>
-{
- uint32_t operator()(const llvm::StringRef& pKey) const
- {
- const unsigned int BitsInUnsignedInt = (unsigned int)(sizeof(unsigned int) * 8);
- const unsigned int ThreeQuarters = (unsigned int)((BitsInUnsignedInt * 3) / 4);
- const unsigned int OneEighth = (unsigned int)(BitsInUnsignedInt / 8);
- const unsigned int HighBits = (unsigned int)(0xFFFFFFFF) << (BitsInUnsignedInt - OneEighth);
+template <>
+struct StringHash<PJW>
+ : public std::unary_function<const llvm::StringRef, uint32_t> {
+ uint32_t operator()(const llvm::StringRef pKey) const {
+ const unsigned int BitsInUnsignedInt =
+ (unsigned int)(sizeof(unsigned int) * 8);
+ const unsigned int ThreeQuarters =
+ (unsigned int)((BitsInUnsignedInt * 3) / 4);
+ const unsigned int OneEighth = (unsigned int)(BitsInUnsignedInt / 8);
+ const unsigned int HighBits = (unsigned int)(0xFFFFFFFF)
+ << (BitsInUnsignedInt - OneEighth);
uint32_t hash_val = 0;
uint32_t test = 0;
- for(unsigned int i = 0; i < pKey.size(); ++i) {
+ for (unsigned int i = 0; i < pKey.size(); ++i) {
hash_val = (hash_val << OneEighth) + pKey[i];
- if((test = hash_val & HighBits) != 0) {
- hash_val = (( hash_val ^ (test >> ThreeQuarters)) & (~HighBits));
+ if ((test = hash_val & HighBits) != 0) {
+ hash_val = ((hash_val ^ (test >> ThreeQuarters)) & (~HighBits));
}
}
return hash_val;
@@ -111,17 +99,16 @@ struct StringHash<PJW> : public std::unary_function<const llvm::StringRef&, uint
/** \class StringHash<ELF>
* \brief ELF hash function.
*/
-template<>
-struct StringHash<ELF> : public std::unary_function<const llvm::StringRef&, uint32_t>
-{
- uint32_t operator()(const llvm::StringRef& pKey) const
- {
+template <>
+struct StringHash<ELF>
+ : public std::unary_function<const llvm::StringRef, uint32_t> {
+ uint32_t operator()(const llvm::StringRef pKey) const {
uint32_t hash_val = 0;
uint32_t x = 0;
for (unsigned int i = 0; i < pKey.size(); ++i) {
hash_val = (hash_val << 4) + pKey[i];
- if((x = hash_val & 0xF0000000L) != 0)
+ if ((x = hash_val & 0xF0000000L) != 0)
hash_val ^= (x >> 24);
hash_val &= ~x;
}
@@ -132,33 +119,30 @@ struct StringHash<ELF> : public std::unary_function<const llvm::StringRef&, uint
/** \class StringHash<BKDR>
* \brief BKDR hash function
*/
-template<>
-struct StringHash<BKDR> : public std::unary_function<const llvm::StringRef&, uint32_t>
-{
- uint32_t operator()(const llvm::StringRef& pKey) const
- {
+template <>
+struct StringHash<BKDR>
+ : public std::unary_function<const llvm::StringRef, uint32_t> {
+ uint32_t operator()(const llvm::StringRef pKey) const {
const uint32_t seed = 131;
uint32_t hash_val = 0;
- for(uint32_t i = 0; i < pKey.size(); ++i)
+ for (uint32_t i = 0; i < pKey.size(); ++i)
hash_val = (hash_val * seed) + pKey[i];
return hash_val;
}
};
-
/** \class StringHash<SDBM>
* \brief SDBM hash function
* 0.049s in 100000 test
*/
-template<>
-struct StringHash<SDBM> : public std::unary_function<const llvm::StringRef&, uint32_t>
-{
- uint32_t operator()(const llvm::StringRef& pKey) const
- {
+template <>
+struct StringHash<SDBM>
+ : public std::unary_function<const llvm::StringRef, uint32_t> {
+ uint32_t operator()(const llvm::StringRef pKey) const {
uint32_t hash_val = 0;
- for(uint32_t i = 0; i < pKey.size(); ++i)
+ for (uint32_t i = 0; i < pKey.size(); ++i)
hash_val = pKey[i] + (hash_val << 6) + (hash_val << 16) - hash_val;
return hash_val;
}
@@ -168,14 +152,13 @@ struct StringHash<SDBM> : public std::unary_function<const llvm::StringRef&, uin
* \brief DJB hash function
* 0.057s in 100000 test
*/
-template<>
-struct StringHash<DJB> : public std::unary_function<const llvm::StringRef&, uint32_t>
-{
- uint32_t operator()(const llvm::StringRef& pKey) const
- {
+template <>
+struct StringHash<DJB>
+ : public std::unary_function<const llvm::StringRef, uint32_t> {
+ uint32_t operator()(const llvm::StringRef pKey) const {
uint32_t hash_val = 5381;
- for(uint32_t i = 0; i < pKey.size(); ++i)
+ for (uint32_t i = 0; i < pKey.size(); ++i)
hash_val = ((hash_val << 5) + hash_val) + pKey[i];
return hash_val;
@@ -186,14 +169,13 @@ struct StringHash<DJB> : public std::unary_function<const llvm::StringRef&, uint
* \brief DEK hash function
* 0.60s
*/
-template<>
-struct StringHash<DEK> : public std::unary_function<const llvm::StringRef&, uint32_t>
-{
- uint32_t operator()(const llvm::StringRef& pKey) const
- {
+template <>
+struct StringHash<DEK>
+ : public std::unary_function<const llvm::StringRef, uint32_t> {
+ uint32_t operator()(const llvm::StringRef pKey) const {
uint32_t hash_val = pKey.size();
- for(uint32_t i = 0; i < pKey.size(); ++i)
+ for (uint32_t i = 0; i < pKey.size(); ++i)
hash_val = ((hash_val << 5) ^ (hash_val >> 27)) ^ pKey[i];
return hash_val;
@@ -204,13 +186,12 @@ struct StringHash<DEK> : public std::unary_function<const llvm::StringRef&, uint
* \brief BP hash function
* 0.057s
*/
-template<>
-struct StringHash<BP> : public std::unary_function<const llvm::StringRef&, uint32_t>
-{
- uint32_t operator()(const llvm::StringRef& pKey) const
- {
+template <>
+struct StringHash<BP>
+ : public std::unary_function<const llvm::StringRef, uint32_t> {
+ uint32_t operator()(const llvm::StringRef pKey) const {
uint32_t hash_val = 0;
- for(uint32_t i = 0; i < pKey.size(); ++i)
+ for (uint32_t i = 0; i < pKey.size(); ++i)
hash_val = hash_val << 7 ^ pKey[i];
return hash_val;
@@ -221,14 +202,13 @@ struct StringHash<BP> : public std::unary_function<const llvm::StringRef&, uint3
* \brief FNV hash function
* 0.058s
*/
-template<>
-struct StringHash<FNV> : public std::unary_function<const llvm::StringRef&, uint32_t>
-{
- uint32_t operator()(const llvm::StringRef& pKey) const
- {
+template <>
+struct StringHash<FNV>
+ : public std::unary_function<const llvm::StringRef, uint32_t> {
+ uint32_t operator()(const llvm::StringRef pKey) const {
const uint32_t fnv_prime = 0x811C9DC5;
uint32_t hash_val = 0;
- for(uint32_t i = 0; i < pKey.size(); ++i) {
+ for (uint32_t i = 0; i < pKey.size(); ++i) {
hash_val *= fnv_prime;
hash_val ^= pKey[i];
}
@@ -241,17 +221,16 @@ struct StringHash<FNV> : public std::unary_function<const llvm::StringRef&, uint
* \brief AP hash function
* 0.060s
*/
-template<>
-struct StringHash<AP> : public std::unary_function<const llvm::StringRef&, uint32_t>
-{
- uint32_t operator()(const llvm::StringRef& pKey) const
- {
+template <>
+struct StringHash<AP>
+ : public std::unary_function<const llvm::StringRef, uint32_t> {
+ uint32_t operator()(const llvm::StringRef pKey) const {
unsigned int hash_val = 0xAAAAAAAA;
- for(uint32_t i = 0; i < pKey.size(); ++i) {
- hash_val ^= ((i & 1) == 0)?
- ((hash_val << 7) ^ pKey[i] * (hash_val >> 3)):
- (~((hash_val << 11) + (pKey[i] ^ (hash_val >> 5))));
+ for (uint32_t i = 0; i < pKey.size(); ++i) {
+ hash_val ^= ((i & 1) == 0)
+ ? ((hash_val << 7) ^ pKey[i] * (hash_val >> 3))
+ : (~((hash_val << 11) + (pKey[i] ^ (hash_val >> 5))));
}
return hash_val;
@@ -272,11 +251,10 @@ struct StringHash<AP> : public std::unary_function<const llvm::StringRef&, uint3
* bit 25~0 - Bit 25 is set only if the string contains a 'a' or 'A', and
* Bit 24 is set only if ... 'b' or 'B', ...
*/
-template<>
-struct StringHash<ES> : public std::unary_function<const llvm::StringRef&, uint32_t>
-{
- uint32_t operator()(const llvm::StringRef& pString) const
- {
+template <>
+struct StringHash<ES>
+ : public std::unary_function<const llvm::StringRef, uint32_t> {
+ uint32_t operator()(const llvm::StringRef pString) const {
uint32_t result = 0x0;
unsigned int dot = 0;
std::string::size_type idx;
@@ -312,21 +290,19 @@ struct StringHash<ES> : public std::unary_function<const llvm::StringRef&, uint3
return result;
}
-
/** \func may_include
* \brief is it possible that pRule is a sub-string of pInString
*/
- static bool may_include(uint32_t pRule, uint32_t pInString)
- {
+ static bool may_include(uint32_t pRule, uint32_t pInString) {
uint32_t in_c = pInString << 4;
- uint32_t r_c = pRule << 4;
+ uint32_t r_c = pRule << 4;
uint32_t res = (in_c ^ r_c) & r_c;
if (0 != res)
return false;
uint32_t in_dot = pInString >> 28;
- uint32_t r_dot = pRule >> 28;
+ uint32_t r_dot = pRule >> 28;
if (r_dot > in_dot)
return false;
@@ -337,29 +313,32 @@ struct StringHash<ES> : public std::unary_function<const llvm::StringRef&, uint3
/** \class template<uint32_t TYPE> StringCompare
* \brief the template StringCompare class, for specification
*/
-template<typename STRING_TYPE>
-struct StringCompare : public std::binary_function<const STRING_TYPE&, const STRING_TYPE&, bool>
-{
- bool operator()(const STRING_TYPE& X, const STRING_TYPE& Y) const
- { return X == Y; }
+template <typename STRING_TYPE>
+struct StringCompare : public std::binary_function<const STRING_TYPE&,
+ const STRING_TYPE&,
+ bool> {
+ bool operator()(const STRING_TYPE& X, const STRING_TYPE& Y) const {
+ return X == Y;
+ }
};
-template<>
-struct StringCompare<const char*> : public std::binary_function<const char*, const char*, bool>
-{
- bool operator()(const char* X, const char* Y) const
- { return (0 == std::strcmp(X, Y)); }
+template <>
+struct StringCompare<const char*>
+ : public std::binary_function<const char*, const char*, bool> {
+ bool operator()(const char* X, const char* Y) const {
+ return (std::strcmp(X, Y) == 0);
+ }
};
-template<>
-struct StringCompare<char*> : public std::binary_function<const char*, const char*, bool>
-{
- bool operator()(const char* X, const char* Y) const
- { return (0 == std::strcmp(X, Y)); }
+template <>
+struct StringCompare<char*>
+ : public std::binary_function<const char*, const char*, bool> {
+ bool operator()(const char* X, const char* Y) const {
+ return (std::strcmp(X, Y) == 0);
+ }
};
-} // namespace of hash
-} // namespace of mcld
-
-#endif
+} // namespace hash
+} // namespace mcld
+#endif // MCLD_ADT_STRINGHASH_H_
diff --git a/include/mcld/ADT/TreeAllocator.h b/include/mcld/ADT/TreeAllocator.h
index d7f47cc..b55a926 100644
--- a/include/mcld/ADT/TreeAllocator.h
+++ b/include/mcld/ADT/TreeAllocator.h
@@ -6,10 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_TREEALLOCATOR_H
-#define MCLD_ADT_TREEALLOCATOR_H
+#ifndef MCLD_ADT_TREEALLOCATOR_H_
+#define MCLD_ADT_TREEALLOCATOR_H_
+
+#include "mcld/ADT/TreeBase.h"
+#include "mcld/Support/GCFactory.h"
+
#include <set>
-#include <mcld/Support/GCFactory.h>
namespace mcld {
@@ -25,18 +28,17 @@ namespace mcld {
*
* @see LinearAllocator
*/
-template<typename DataType>
-class NodeFactory : public GCFactory<Node<DataType>, 64>
-{
-private:
+template <typename DataType>
+class NodeFactory : public GCFactory<Node<DataType>, 64> {
+ private:
typedef GCFactory<Node<DataType>, 64> Alloc;
-public:
- typedef Node<DataType> NodeType;
- typedef typename Alloc::iterator iterator;
+ public:
+ typedef Node<DataType> NodeType;
+ typedef typename Alloc::iterator iterator;
typedef typename Alloc::const_iterator const_iterator;
-public:
+ public:
/// produce - produce a node, add it under control
NodeType* produce() {
NodeType* result = Alloc::allocate();
@@ -65,10 +67,9 @@ public:
pClient.renounce();
}
-private:
+ private:
/// renounce - give up the control of all chunks
- void renounce()
- { Alloc::reset(); }
+ void renounce() { Alloc::reset(); }
/// replace - be the agent of client.
void replace(NodeFactory& pClient) {
@@ -87,7 +88,6 @@ private:
}
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_ADT_TREEALLOCATOR_H_
diff --git a/include/mcld/ADT/TreeBase.h b/include/mcld/ADT/TreeBase.h
index bca375f..5d0cd16 100644
--- a/include/mcld/ADT/TreeBase.h
+++ b/include/mcld/ADT/TreeBase.h
@@ -6,121 +6,109 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_TREEBASE_H
-#define MCLD_ADT_TREEBASE_H
-#include <mcld/ADT/TypeTraits.h>
+#ifndef MCLD_ADT_TREEBASE_H_
+#define MCLD_ADT_TREEBASE_H_
+
+#include "mcld/ADT/TypeTraits.h"
-#include <cstddef>
#include <cassert>
+#include <cstddef>
#include <iterator>
namespace mcld {
-class NodeBase
-{
-public:
- NodeBase *left;
- NodeBase *right;
+class NodeBase {
+ public:
+ NodeBase* left;
+ NodeBase* right;
-public:
- NodeBase()
- : left(0), right(0)
- { }
+ public:
+ NodeBase() : left(NULL), right(NULL) {}
};
-class TreeIteratorBase
-{
-public:
- enum Direct {
- Leftward,
- Rightward
- };
+class TreeIteratorBase {
+ public:
+ enum Direct { Leftward, Rightward };
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
typedef std::bidirectional_iterator_tag iterator_category;
-public:
+ public:
NodeBase* m_pNode;
-public:
- TreeIteratorBase()
- : m_pNode(0)
- { }
+ public:
+ TreeIteratorBase() : m_pNode(NULL) {}
- TreeIteratorBase(NodeBase *X)
- : m_pNode(X)
- { }
+ explicit TreeIteratorBase(NodeBase* X) : m_pNode(X) {}
virtual ~TreeIteratorBase(){};
- template<size_t DIRECT>
- void move() { assert(0 && "not allowed"); }
+ template <size_t DIRECT>
+ void move() {
+ assert(0 && "not allowed");
+ }
- template<size_t DIRECT>
- void hook(NodeBase* pNode) { assert(0 && "not allowed"); }
+ template <size_t DIRECT>
+ void hook(NodeBase* pNode) {
+ assert(0 && "not allowed");
+ }
- bool isRoot() const
- { return (m_pNode->right == m_pNode); }
+ bool isRoot() const { return (m_pNode->right == m_pNode); }
- bool hasRightChild() const
- { return ((m_pNode->right) != (m_pNode->right->right)); }
+ bool hasRightChild() const {
+ return ((m_pNode->right) != (m_pNode->right->right));
+ }
- bool hasLeftChild() const
- { return ((m_pNode->left) != (m_pNode->left->right)); }
+ bool hasLeftChild() const {
+ return ((m_pNode->left) != (m_pNode->left->right));
+ }
- bool operator==(const TreeIteratorBase& y) const
- { return this->m_pNode == y.m_pNode; }
+ bool operator==(const TreeIteratorBase& y) const {
+ return this->m_pNode == y.m_pNode;
+ }
- bool operator!=(const TreeIteratorBase& y) const
- { return this->m_pNode != y.m_pNode; }
+ bool operator!=(const TreeIteratorBase& y) const {
+ return this->m_pNode != y.m_pNode;
+ }
};
-template<> inline
-void TreeIteratorBase::move<TreeIteratorBase::Leftward>()
-{
+template <>
+inline void TreeIteratorBase::move<TreeIteratorBase::Leftward>() {
this->m_pNode = this->m_pNode->left;
}
-template<> inline
-void TreeIteratorBase::move<TreeIteratorBase::Rightward>()
-{
+template <>
+inline void TreeIteratorBase::move<TreeIteratorBase::Rightward>() {
this->m_pNode = this->m_pNode->right;
}
-template<> inline
-void TreeIteratorBase::hook<TreeIteratorBase::Leftward>(NodeBase* pOther)
-{
+template <>
+inline void TreeIteratorBase::hook<TreeIteratorBase::Leftward>(
+ NodeBase* pOther) {
this->m_pNode->left = pOther;
}
-template<> inline
-void TreeIteratorBase::hook<TreeIteratorBase::Rightward>(NodeBase* pOther)
-{
+template <>
+inline void TreeIteratorBase::hook<TreeIteratorBase::Rightward>(
+ NodeBase* pOther) {
this->m_pNode->right = pOther;
}
-template<typename DataType>
-class Node : public NodeBase
-{
-public:
- typedef DataType value_type;
+template <typename DataType>
+class Node : public NodeBase {
+ public:
+ typedef DataType value_type;
-public:
+ public:
value_type* data;
-public:
- Node()
- : NodeBase(), data(0)
- { }
-
- Node(const value_type& pValue)
- : NodeBase(), data(&pValue)
- { }
+ public:
+ Node() : NodeBase(), data(NULL) {}
+ explicit Node(const value_type& pValue) : NodeBase(), data(&pValue) {}
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_ADT_TREEBASE_H_
diff --git a/include/mcld/ADT/TypeTraits.h b/include/mcld/ADT/TypeTraits.h
index 11e9b69..1c13d76 100644
--- a/include/mcld/ADT/TypeTraits.h
+++ b/include/mcld/ADT/TypeTraits.h
@@ -6,63 +6,58 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_TYPETRAITS_H
-#define MCLD_ADT_TYPETRAITS_H
+#ifndef MCLD_ADT_TYPETRAITS_H_
+#define MCLD_ADT_TYPETRAITS_H_
#include <cstdlib>
namespace mcld {
-template<typename DataType>
+template <typename DataType>
struct NonConstTraits;
-template<typename DataType>
-struct ConstTraits
-{
- typedef DataType value_type;
- typedef const DataType* pointer;
- typedef const DataType& reference;
- typedef size_t size_type;
- typedef ConstTraits<DataType> const_traits;
+template <typename DataType>
+struct ConstTraits {
+ typedef DataType value_type;
+ typedef const DataType* pointer;
+ typedef const DataType& reference;
+ typedef size_t size_type;
+ typedef ConstTraits<DataType> const_traits;
typedef NonConstTraits<DataType> nonconst_traits;
};
-template<typename DataType>
-struct NonConstTraits
-{
- typedef DataType value_type;
- typedef DataType* pointer;
- typedef DataType& reference;
- typedef size_t size_type;
- typedef ConstTraits<DataType> const_traits;
+template <typename DataType>
+struct NonConstTraits {
+ typedef DataType value_type;
+ typedef DataType* pointer;
+ typedef DataType& reference;
+ typedef size_t size_type;
+ typedef ConstTraits<DataType> const_traits;
typedef NonConstTraits<DataType> nonconst_traits;
};
-template<typename DataType>
-struct ConstIteratorTraits
-{
- typedef DataType value_type;
- typedef const DataType* pointer;
- typedef const DataType& reference;
- typedef size_t size_type;
- typedef ConstTraits<DataType> const_traits;
- typedef NonConstTraits<DataType> nonconst_traits;
+template <typename DataType>
+struct ConstIteratorTraits {
+ typedef DataType value_type;
+ typedef const DataType* pointer;
+ typedef const DataType& reference;
+ typedef size_t size_type;
+ typedef ConstTraits<DataType> const_traits;
+ typedef NonConstTraits<DataType> nonconst_traits;
typedef typename DataType::const_iterator iterator;
};
-template<typename DataType>
-struct NonConstIteratorTraits
-{
- typedef DataType value_type;
- typedef DataType* pointer;
- typedef DataType& reference;
- typedef size_t size_type;
- typedef ConstTraits<DataType> const_traits;
- typedef NonConstTraits<DataType> nonconst_traits;
+template <typename DataType>
+struct NonConstIteratorTraits {
+ typedef DataType value_type;
+ typedef DataType* pointer;
+ typedef DataType& reference;
+ typedef size_t size_type;
+ typedef ConstTraits<DataType> const_traits;
+ typedef NonConstTraits<DataType> nonconst_traits;
typedef typename DataType::iterator iterator;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_ADT_TYPETRAITS_H_
diff --git a/include/mcld/ADT/Uncopyable.h b/include/mcld/ADT/Uncopyable.h
deleted file mode 100644
index 1ac89a9..0000000
--- a/include/mcld/ADT/Uncopyable.h
+++ /dev/null
@@ -1,33 +0,0 @@
-//===- Uncopyable.h -------------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef MCLD_ADT_UNCOPYABLE_H
-#define MCLD_ADT_UNCOPYABLE_H
-
-namespace mcld
-{
-
-/** \class Uncopyable
- * \brief Uncopyable provides the base class to forbit copy operations.
- *
- */
-class Uncopyable
-{
-protected:
- Uncopyable() { }
- ~Uncopyable() { }
-
-private:
- Uncopyable(const Uncopyable&); /// NOT TO IMPLEMENT
- Uncopyable& operator=(const Uncopyable&); /// NOT TO IMPLEMENT
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/include/mcld/AttributeOption.h b/include/mcld/AttributeOption.h
index a42f70b..40b2724 100644
--- a/include/mcld/AttributeOption.h
+++ b/include/mcld/AttributeOption.h
@@ -6,30 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ATTRIBUTEOPTION_H
-#define MCLD_ATTRIBUTEOPTION_H
-#include <mcld/MC/Attribute.h>
+#ifndef MCLD_ATTRIBUTEOPTION_H_
+#define MCLD_ATTRIBUTEOPTION_H_
+#include "mcld/MC/Attribute.h"
namespace mcld {
-class AttributeOption
-{
-public:
+class AttributeOption {
+ public:
AttributeOption();
~AttributeOption();
const Attribute& predefined() const { return m_Predefined; }
- Attribute& predefined() { return m_Predefined; }
+ Attribute& predefined() { return m_Predefined; }
const AttrConstraint& constraint() const { return m_Constraint; }
- AttrConstraint& constraint() { return m_Constraint; }
+ AttrConstraint& constraint() { return m_Constraint; }
-private:
+ private:
Attribute m_Predefined;
AttrConstraint m_Constraint;
};
-} // namespace mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_ATTRIBUTEOPTION_H_
diff --git a/include/mcld/BitcodeOption.h b/include/mcld/BitcodeOption.h
deleted file mode 100644
index 7236d6a..0000000
--- a/include/mcld/BitcodeOption.h
+++ /dev/null
@@ -1,46 +0,0 @@
-//===- BitcodeOption.h ----------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef MCLD_BITCODEOPTION_H
-#define MCLD_BITCODEOPTION_H
-
-#include <mcld/Support/Path.h>
-
-namespace mcld {
-
-/** \class BitcodeOption
- * \brief BitcodeOption represents the options of bitcode on the command line.
- */
-class BitcodeOption
-{
-public:
- BitcodeOption();
-
- ~BitcodeOption();
-
- void setPosition(unsigned int pPosition) { m_Position = pPosition; }
-
- unsigned int getPosition() const { return m_Position; }
-
- void setPath(const sys::fs::Path& pPath) { m_Path = pPath; }
-
- const sys::fs::Path& getPath() const { return m_Path; }
-
- bool hasDefined() const;
-
-private:
- int m_Position;
-
- sys::fs::Path m_Path;
-
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/include/mcld/CodeGen/MCLinker.h b/include/mcld/CodeGen/MCLinker.h
deleted file mode 100644
index 048ebb2..0000000
--- a/include/mcld/CodeGen/MCLinker.h
+++ /dev/null
@@ -1,82 +0,0 @@
-//===- MCLinker.h ---------------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// MCLinker is a base class inherited by target specific linker.
-// This class primarily handles common functionality used by all linkers.
-//
-//===----------------------------------------------------------------------===//
-#ifndef MCLD_CODEGEN_MCLINKER_H
-#define MCLD_CODEGEN_MCLINKER_H
-#include <llvm/CodeGen/MachineFunctionPass.h>
-
-namespace llvm {
-
-class Module;
-class MachineFunction;
-
-} // namespace of llvm
-
-namespace mcld {
-
-class Module;
-class IRBuilder;
-class LinkerConfig;
-class Linker;
-class FileHandle;
-
-/** \class MCLinker
-* \brief MCLinker provides a linking pass for standard compilation flow
-*
-* MCLinker is responded for
-* - provide an interface for target-specific linker
-* - set up environment for ObjectLinker
-* - perform linking
-*
-* @see MachineFunctionPass ObjectLinker
-*/
-class MCLinker : public llvm::MachineFunctionPass
-{
-protected:
- // Constructor. Although MCLinker has only two arguments,
- // TargetMCLinker should handle
- // - enabled attributes
- // - the default attribute
- // - the default link script
- // - the standard symbols
- MCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle);
-
-public:
- virtual ~MCLinker();
-
- virtual bool doInitialization(llvm::Module &pM);
-
- virtual bool doFinalization(llvm::Module &pM);
-
- virtual bool runOnMachineFunction(llvm::MachineFunction& pMFn);
-
-protected:
- void initializeInputTree(IRBuilder& pBuilder);
-
-protected:
- LinkerConfig& m_Config;
- mcld::Module& m_Module;
- FileHandle& m_FileHandle;
- IRBuilder* m_pBuilder;
- Linker* m_pLinker;
-
-private:
- static char m_ID;
-};
-
-} // namespace of MC Linker
-
-#endif
-
diff --git a/include/mcld/CodeGen/TargetMachine.h b/include/mcld/CodeGen/TargetMachine.h
deleted file mode 100644
index 6454d87..0000000
--- a/include/mcld/CodeGen/TargetMachine.h
+++ /dev/null
@@ -1,111 +0,0 @@
-//===- TargetMachine.h ----------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef MCLD_CODEGEN_TARGETMACHINE_H
-#define MCLD_CODEGEN_TARGETMACHINE_H
-#include <llvm/Support/CodeGen.h>
-#include <string>
-
-namespace llvm {
-
-class Target;
-class TargetData;
-class TargetMachine;
-class MCContext;
-class raw_ostream;
-class formatted_raw_ostream;
-namespace legacy {
-class PassManagerBase;
-} // namepsace legacy
-} // namespace llvm
-
-namespace mcld {
-
-class Module;
-class Target;
-class FileHandle;
-class LinkerConfig;
-class ToolOutputFile;
-
-enum CodeGenFileType {
- CGFT_ASMFile,
- CGFT_OBJFile,
- CGFT_DSOFile,
- CGFT_EXEFile,
- CGFT_PARTIAL,
- CGFT_BINARY,
- CGFT_NULLFile
-};
-
-
-/** \class mcld::MCLDTargetMachine
- * \brief mcld::MCLDTargetMachine is a object adapter of LLVMTargetMachine.
- */
-class MCLDTargetMachine
-{
-public:
- /// Adapter of llvm::TargetMachine
- ///
- MCLDTargetMachine(llvm::TargetMachine& pTM,
- const llvm::Target& pLLMVTarget,
- const mcld::Target& pMCLDTarget,
- const std::string& pTriple);
-
- virtual ~MCLDTargetMachine();
-
- /// getTarget - adapt llvm::TargetMachine::getTarget
- const mcld::Target& getTarget() const;
-
- /// getTM - return adapted the llvm::TargetMachine.
- const llvm::TargetMachine& getTM() const { return m_TM; }
- llvm::TargetMachine& getTM() { return m_TM; }
-
- /// appPassesToEmitFile - The target function which we has to modify as
- /// upstreaming.
- bool addPassesToEmitFile(llvm::legacy::PassManagerBase &,
- mcld::ToolOutputFile& pOutput,
- mcld::CodeGenFileType,
- llvm::CodeGenOpt::Level,
- mcld::Module& pModule,
- mcld::LinkerConfig& pConfig,
- bool DisableVerify = true);
-
-private:
- /// addCommonCodeGenPasses - Add standard LLVM codegen passes used for
- /// both emitting to assembly files or machine code output.
- bool addCommonCodeGenPasses(llvm::legacy::PassManagerBase &,
- mcld::CodeGenFileType,
- llvm::CodeGenOpt::Level,
- bool DisableVerify,
- llvm::MCContext *&OutCtx);
-
- bool addCompilerPasses(llvm::legacy::PassManagerBase &pPM,
- llvm::formatted_raw_ostream &pOutput,
- llvm::MCContext *&OutCtx);
-
- bool addAssemblerPasses(llvm::legacy::PassManagerBase &pPM,
- llvm::raw_ostream &pOutput,
- llvm::MCContext *&OutCtx);
-
- bool addLinkerPasses(llvm::legacy::PassManagerBase &pPM,
- mcld::LinkerConfig& pConfig,
- mcld::Module& pModule,
- mcld::FileHandle& pFileHandle,
- llvm::MCContext *&OutCtx);
-
-private:
- llvm::TargetMachine &m_TM;
- const llvm::Target *m_pLLVMTarget;
- const mcld::Target *m_pMCLDTarget;
- const std::string& m_Triple;
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/include/mcld/Config/Config.h.cmake b/include/mcld/Config/Config.h.cmake
new file mode 100644
index 0000000..482debd
--- /dev/null
+++ b/include/mcld/Config/Config.h.cmake
@@ -0,0 +1,621 @@
+/* include/llvm/Config/config.h.cmake corresponding to config.h.in. */
+//===- Config.h.in --------------------------------------------------------===//
+//
+// The MCLinker Project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#ifndef MCLD_CONFIG_CONFIG_H
+#define MCLD_CONFIG_CONFIG_H
+
+#define MCLD_REGION_CHUNK_SIZE 32
+#define MCLD_NUM_OF_INPUTS 32
+#define MCLD_SECTIONS_PER_INPUT 16
+#define MCLD_SYMBOLS_PER_INPUT 128
+#define MCLD_RELOCATIONS_PER_INPUT 1024
+
+#define MCLD_SEGMENTS_PER_OUTPUT 8
+
+#cmakedefine MCLD_VERSION "${MCLD_VERSION}"
+
+/* Target triple LLVM will generate code for by default */
+#cmakedefine MCLD_DEFAULT_TARGET_TRIPLE "${MCLD_DEFAULT_TARGET_TRIPLE}"
+
+#cmakedefine MCLD_ON_UNIX "${MCLD_ON_UNIX}"
+
+#cmakedefine MCLD_ON_WIN32 "${MCLD_ON_WIN32}"
+
+
+/* Define to 1 if you have the `arc4random' function. */
+#cmakedefine HAVE_ARC4RANDOM
+
+/* Define to 1 if you have the `argz_append' function. */
+#cmakedefine HAVE_ARGZ_APPEND ${HAVE_ARGZ_APPEND}
+
+/* Define to 1 if you have the `argz_create_sep' function. */
+#cmakedefine HAVE_ARGZ_CREATE_SEP ${HAVE_ARGZ_CREATE_SEP}
+
+/* Define to 1 if you have the <argz.h> header file. */
+#cmakedefine HAVE_ARGZ_H ${HAVE_ARGZ_H}
+
+/* Define to 1 if you have the `argz_insert' function. */
+#cmakedefine HAVE_ARGZ_INSERT ${HAVE_ARGZ_INSERT}
+
+/* Define to 1 if you have the `argz_next' function. */
+#cmakedefine HAVE_ARGZ_NEXT ${HAVE_ARGZ_NEXT}
+
+/* Define to 1 if you have the `argz_stringify' function. */
+#cmakedefine HAVE_ARGZ_STRINGIFY ${HAVE_ARGZ_STRINGIFY}
+
+/* Define to 1 if you have the <assert.h> header file. */
+#cmakedefine HAVE_ASSERT_H ${HAVE_ASSERT_H}
+
+/* Define to 1 if you have the `backtrace' function. */
+#cmakedefine HAVE_BACKTRACE ${HAVE_BACKTRACE}
+
+/* Define to 1 if you have the `bcopy' function. */
+#undef HAVE_BCOPY
+
+/* Define to 1 if you have the `ceilf' function. */
+#cmakedefine HAVE_CEILF ${HAVE_CEILF}
+
+/* Define if the neat program is available */
+#cmakedefine HAVE_CIRCO ${HAVE_CIRCO}
+
+/* Define to 1 if you have the `closedir' function. */
+#cmakedefine HAVE_CLOSEDIR ${HAVE_CLOSEDIR}
+
+/* Define to 1 if you have the <CrashReporterClient.h> header file. */
+#undef HAVE_CRASHREPORTERCLIENT_H
+
+/* can use __crashreporter_info__ */
+#undef HAVE_CRASHREPORTER_INFO
+
+/* Define to 1 if you have the <ctype.h> header file. */
+#cmakedefine HAVE_CTYPE_H ${HAVE_CTYPE_H}
+
+/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you
+ don't. */
+#cmakedefine01 HAVE_DECL_STRERROR_S
+
+/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
+ */
+#cmakedefine HAVE_DIRENT_H ${HAVE_DIRENT_H}
+
+/* Define if you have the GNU dld library. */
+#undef HAVE_DLD
+
+/* Define to 1 if you have the <dld.h> header file. */
+#cmakedefine HAVE_DLD_H ${HAVE_DLD_H}
+
+/* Define to 1 if you have the `dlerror' function. */
+#cmakedefine HAVE_DLERROR ${HAVE_DLERROR}
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H}
+
+/* Define if dlopen() is available on this platform. */
+#cmakedefine HAVE_DLOPEN ${HAVE_DLOPEN}
+
+/* Define to 1 if you have the <dl.h> header file. */
+#cmakedefine HAVE_DL_H ${HAVE_DL_H}
+
+/* Define if the dot program is available */
+#cmakedefine HAVE_DOT ${HAVE_DOT}
+
+/* Define if the dotty program is available */
+#cmakedefine HAVE_DOTTY ${HAVE_DOTTY}
+
+/* Define if you have the _dyld_func_lookup function. */
+#undef HAVE_DYLD
+
+/* Define to 1 if you have the <errno.h> header file. */
+#cmakedefine HAVE_ERRNO_H ${HAVE_ERRNO_H}
+
+/* Define to 1 if the system has the type `error_t'. */
+#cmakedefine HAVE_ERROR_T ${HAVE_ERROR_T}
+
+/* Define to 1 if you have the <execinfo.h> header file. */
+#cmakedefine HAVE_EXECINFO_H ${HAVE_EXECINFO_H}
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#cmakedefine HAVE_FCNTL_H ${HAVE_FCNTL_H}
+
+/* Define if the neat program is available */
+#cmakedefine HAVE_FDP ${HAVE_FDP}
+
+/* Define to 1 if you have the <fenv.h> header file. */
+#cmakedefine HAVE_FENV_H ${HAVE_FENV_H}
+
+/* Define if libffi is available on this platform. */
+#cmakedefine HAVE_FFI_CALL ${HAVE_FFI_CALL}
+
+/* Define to 1 if you have the <ffi/ffi.h> header file. */
+#cmakedefine HAVE_FFI_FFI_H ${HAVE_FFI_FFI_H}
+
+/* Define to 1 if you have the <ffi.h> header file. */
+#cmakedefine HAVE_FFI_H ${HAVE_FFI_H}
+
+/* Set to 1 if the finite function is found in <ieeefp.h> */
+#cmakedefine HAVE_FINITE_IN_IEEEFP_H ${HAVE_FINITE_IN_IEEEFP_H}
+
+/* Define to 1 if you have the `floorf' function. */
+#cmakedefine HAVE_FLOORF ${HAVE_FLOORF}
+
+/* Define to 1 if you have the `log' function. */
+#cmakedefine HAVE_LOG ${HAVE_LOG}
+
+/* Define to 1 if you have the `log2' function. */
+#cmakedefine HAVE_LOG2 ${HAVE_LOG2}
+
+/* Define to 1 if you have the `log10' function. */
+#cmakedefine HAVE_LOG10 ${HAVE_LOG10}
+
+/* Define to 1 if you have the `exp' function. */
+#cmakedefine HAVE_EXP ${HAVE_LOG}
+
+/* Define to 1 if you have the `exp2' function. */
+#cmakedefine HAVE_EXP2 ${HAVE_LOG2}
+
+/* Define to 1 if you have the `exp10' function. */
+#cmakedefine HAVE_EXP10 ${HAVE_LOG10}
+
+/* Define to 1 if you have the `fmodf' function. */
+#cmakedefine HAVE_FMODF ${HAVE_FMODF}
+
+/* Define to 1 if you have the `getcwd' function. */
+#cmakedefine HAVE_GETCWD ${HAVE_GETCWD}
+
+/* Define to 1 if you have the `getpagesize' function. */
+#cmakedefine HAVE_GETPAGESIZE ${HAVE_GETPAGESIZE}
+
+/* Define to 1 if you have the `getrlimit' function. */
+#cmakedefine HAVE_GETRLIMIT ${HAVE_GETRLIMIT}
+
+/* Define to 1 if you have the `getrusage' function. */
+#cmakedefine HAVE_GETRUSAGE ${HAVE_GETRUSAGE}
+
+/* Define to 1 if you have the `gettimeofday' function. */
+#cmakedefine HAVE_GETTIMEOFDAY ${HAVE_GETTIMEOFDAY}
+
+/* Define if the Graphviz program is available */
+#cmakedefine HAVE_GRAPHVIZ ${HAVE_GRAPHVIZ}
+
+/* Define if the gv program is available */
+#cmakedefine HAVE_GV ${HAVE_GV}
+
+/* Define to 1 if you have the `index' function. */
+#cmakedefine HAVE_INDEX ${HAVE_INDEX}
+
+/* Define to 1 if the system has the type `int64_t'. */
+#cmakedefine HAVE_INT64_T ${HAVE_INT64_T}
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#cmakedefine HAVE_INTTYPES_H ${HAVE_INTTYPES_H}
+
+/* Define to 1 if you have the `isatty' function. */
+#cmakedefine HAVE_ISATTY 1
+
+/* Set to 1 if the isinf function is found in <cmath> */
+#cmakedefine HAVE_ISINF_IN_CMATH ${HAVE_ISINF_IN_CMATH}
+
+/* Set to 1 if the isinf function is found in <math.h> */
+#cmakedefine HAVE_ISINF_IN_MATH_H ${HAVE_ISINF_IN_MATH_H}
+
+/* Set to 1 if the isnan function is found in <cmath> */
+#cmakedefine HAVE_ISNAN_IN_CMATH ${HAVE_ISNAN_IN_CMATH}
+
+/* Set to 1 if the isnan function is found in <math.h> */
+#cmakedefine HAVE_ISNAN_IN_MATH_H ${HAVE_ISNAN_IN_MATH_H}
+
+/* Define if you have the libdl library or equivalent. */
+#cmakedefine HAVE_LIBDL ${HAVE_LIBDL}
+
+/* Define to 1 if you have the `imagehlp' library (-limagehlp). */
+#cmakedefine HAVE_LIBIMAGEHLP ${HAVE_LIBIMAGEHLP}
+
+/* Define to 1 if you have the `m' library (-lm). */
+#undef HAVE_LIBM
+
+/* Define to 1 if you have the `psapi' library (-lpsapi). */
+#cmakedefine HAVE_LIBPSAPI ${HAVE_LIBPSAPI}
+
+/* Define to 1 if you have the `pthread' library (-lpthread). */
+#cmakedefine HAVE_LIBPTHREAD ${HAVE_LIBPTHREAD}
+
+/* Define to 1 if you have the `udis86' library (-ludis86). */
+#undef HAVE_LIBUDIS86
+
+/* Define to 1 if you have the <limits.h> header file. */
+#cmakedefine HAVE_LIMITS_H ${HAVE_LIMITS_H}
+
+/* Define if you can use -Wl,-export-dynamic. */
+#define HAVE_LINK_EXPORT_DYNAMIC 1
+
+/* Define to 1 if you have the <link.h> header file. */
+#cmakedefine HAVE_LINK_H ${HAVE_LINK_H}
+
+/* Define if you can use -Wl,-R. to pass -R. to the linker, in order to add
+ the current directory to the dynamic linker search path. */
+#undef HAVE_LINK_R
+
+/* Define to 1 if you have the `longjmp' function. */
+#cmakedefine HAVE_LONGJMP ${HAVE_LONGJMP}
+
+/* Define to 1 if you have the <mach/mach.h> header file. */
+#cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H}
+
+/* Define to 1 if you have the <mach-o/dyld.h> header file. */
+#cmakedefine HAVE_MACH_O_DYLD_H ${HAVE_MACH_O_DYLD_H}
+
+/* Define if mallinfo() is available on this platform. */
+#cmakedefine HAVE_MALLINFO ${HAVE_MALLINFO}
+
+/* Define to 1 if you have the <malloc.h> header file. */
+#cmakedefine HAVE_MALLOC_H ${HAVE_MALLOC_H}
+
+/* Define to 1 if you have the <malloc/malloc.h> header file. */
+#cmakedefine HAVE_MALLOC_MALLOC_H ${HAVE_MALLOC_MALLOC_H}
+
+/* Define to 1 if you have the `malloc_zone_statistics' function. */
+#cmakedefine HAVE_MALLOC_ZONE_STATISTICS ${HAVE_MALLOC_ZONE_STATISTICS}
+
+/* Define to 1 if you have the `memcpy' function. */
+#cmakedefine HAVE_MEMCPY ${HAVE_MEMCPY}
+
+/* Define to 1 if you have the `memmove' function. */
+#cmakedefine HAVE_MEMMOVE ${HAVE_MEMMOVE}
+
+/* Define to 1 if you have the <memory.h> header file. */
+#cmakedefine HAVE_MEMORY_H ${HAVE_MEMORY_H}
+
+/* Define to 1 if you have the `mkdtemp' function. */
+#cmakedefine HAVE_MKDTEMP ${HAVE_MKDTEMP}
+
+/* Define to 1 if you have the `mkstemp' function. */
+#cmakedefine HAVE_MKSTEMP ${HAVE_MKSTEMP}
+
+/* Define to 1 if you have the `mktemp' function. */
+#cmakedefine HAVE_MKTEMP ${HAVE_MKTEMP}
+
+/* Define to 1 if you have a working `mmap' system call. */
+#undef HAVE_MMAP
+
+/* Define if mmap() uses MAP_ANONYMOUS to map anonymous pages, or undefine if
+ it uses MAP_ANON */
+#undef HAVE_MMAP_ANONYMOUS
+
+/* Define if mmap() can map files into memory */
+#undef HAVE_MMAP_FILE
+
+/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
+#cmakedefine HAVE_NDIR_H ${HAVE_NDIR_H}
+
+/* Define to 1 if you have the `nearbyintf' function. */
+#cmakedefine HAVE_NEARBYINTF ${HAVE_NEARBYINTF}
+
+/* Define if the neat program is available */
+#cmakedefine HAVE_NEATO ${HAVE_NEATO}
+
+/* Define to 1 if you have the `opendir' function. */
+#cmakedefine HAVE_OPENDIR ${HAVE_OPENDIR}
+
+/* Define to 1 if you have the `posix_spawn' function. */
+#cmakedefine HAVE_POSIX_SPAWN ${HAVE_POSIX_SPAWN}
+
+/* Define to 1 if you have the `powf' function. */
+#cmakedefine HAVE_POWF ${HAVE_POWF}
+
+/* Define to 1 if you have the `pread' function. */
+#cmakedefine HAVE_PREAD ${HAVE_PREAD}
+
+/* Define if libtool can extract symbol lists from object files. */
+#undef HAVE_PRELOADED_SYMBOLS
+
+/* Define to have the %a format string */
+#undef HAVE_PRINTF_A
+
+/* Have pthread_getspecific */
+#cmakedefine HAVE_PTHREAD_GETSPECIFIC ${HAVE_PTHREAD_GETSPECIFIC}
+
+/* Define to 1 if you have the <pthread.h> header file. */
+#cmakedefine HAVE_PTHREAD_H ${HAVE_PTHREAD_H}
+
+/* Have pthread_mutex_lock */
+#cmakedefine HAVE_PTHREAD_MUTEX_LOCK ${HAVE_PTHREAD_MUTEX_LOCK}
+
+/* Have pthread_rwlock_init */
+#cmakedefine HAVE_PTHREAD_RWLOCK_INIT ${HAVE_PTHREAD_RWLOCK_INIT}
+
+/* Define to 1 if srand48/lrand48/drand48 exist in <stdlib.h> */
+#cmakedefine HAVE_RAND48 ${HAVE_RAND48}
+
+/* Define to 1 if you have the `readdir' function. */
+#cmakedefine HAVE_READDIR ${HAVE_READDIR}
+
+/* Define to 1 if you have the `realpath' function. */
+#undef HAVE_REALPATH
+
+/* Define to 1 if you have the `rindex' function. */
+#cmakedefine HAVE_RINDEX ${HAVE_RINDEX}
+
+/* Define to 1 if you have the `rintf' function. */
+#undef HAVE_RINTF
+
+/* Define to 1 if you have the `round' function. */
+#cmakedefine HAVE_ROUND ${HAVE_ROUND}
+
+/* Define to 1 if you have the `roundf' function. */
+#undef HAVE_ROUNDF
+
+/* Define to 1 if you have the `sbrk' function. */
+#cmakedefine HAVE_SBRK ${HAVE_SBRK}
+
+/* Define to 1 if you have the `setenv' function. */
+#cmakedefine HAVE_SETENV ${HAVE_SETENV}
+
+/* Define to 1 if you have the `setjmp' function. */
+#cmakedefine HAVE_SETJMP ${HAVE_SETJMP}
+
+/* Define to 1 if you have the <setjmp.h> header file. */
+#cmakedefine HAVE_SETJMP_H ${HAVE_SETJMP_H}
+
+/* Define to 1 if you have the `setrlimit' function. */
+#cmakedefine HAVE_SETRLIMIT ${HAVE_SETRLIMIT}
+
+/* Define if you have the shl_load function. */
+#undef HAVE_SHL_LOAD
+
+/* Define to 1 if you have the `siglongjmp' function. */
+#cmakedefine HAVE_SIGLONGJMP ${HAVE_SIGLONGJMP}
+
+/* Define to 1 if you have the <signal.h> header file. */
+#cmakedefine HAVE_SIGNAL_H ${HAVE_SIGNAL_H}
+
+/* Define to 1 if you have the `sigsetjmp' function. */
+#cmakedefine HAVE_SIGSETJMP ${HAVE_SIGSETJMP}
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#cmakedefine HAVE_STDINT_H ${HAVE_STDINT_H}
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#cmakedefine HAVE_STDIO_H ${HAVE_STDIO_H}
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#cmakedefine HAVE_STDLIB_H ${HAVE_STDLIB_H}
+
+/* Set to 1 if the std::isinf function is found in <cmath> */
+#undef HAVE_STD_ISINF_IN_CMATH
+
+/* Set to 1 if the std::isnan function is found in <cmath> */
+#undef HAVE_STD_ISNAN_IN_CMATH
+
+/* Define to 1 if you have the `strchr' function. */
+#cmakedefine HAVE_STRCHR ${HAVE_STRCHR}
+
+/* Define to 1 if you have the `strcmp' function. */
+#cmakedefine HAVE_STRCMP ${HAVE_STRCMP}
+
+/* Define to 1 if you have the `strdup' function. */
+#cmakedefine HAVE_STRDUP ${HAVE_STRDUP}
+
+/* Define to 1 if you have the `strerror' function. */
+#cmakedefine HAVE_STRERROR ${HAVE_STRERROR}
+
+/* Define to 1 if you have the `strerror_r' function. */
+#cmakedefine HAVE_STRERROR_R ${HAVE_STRERROR_R}
+
+/* Define to 1 if you have the <strings.h> header file. */
+#cmakedefine HAVE_STRINGS_H ${HAVE_STRINGS_H}
+
+/* Define to 1 if you have the <string.h> header file. */
+#cmakedefine HAVE_STRING_H ${HAVE_STRING_H}
+
+/* Define to 1 if you have the `strrchr' function. */
+#cmakedefine HAVE_STRRCHR ${HAVE_STRRCHR}
+
+/* Define to 1 if you have the `strtof' function. */
+#cmakedefine HAVE_STRTOF ${HAVE_STRTOF}
+
+/* Define to 1 if you have the `strtoll' function. */
+#cmakedefine HAVE_STRTOLL ${HAVE_STRTOLL}
+
+/* Define to 1 if you have the `strtoq' function. */
+#cmakedefine HAVE_STRTOQ ${HAVE_STRTOQ}
+
+/* Define to 1 if you have the `sysconf' function. */
+#undef HAVE_SYSCONF
+
+/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
+ */
+#cmakedefine HAVE_SYS_DIR_H ${HAVE_SYS_DIR_H}
+
+/* Define to 1 if you have the <sys/dl.h> header file. */
+#cmakedefine HAVE_SYS_DL_H ${HAVE_SYS_DL_H}
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#cmakedefine HAVE_SYS_IOCTL_H ${HAVE_SYS_IOCTL_H}
+
+/* Define to 1 if you have the <sys/mman.h> header file. */
+#cmakedefine HAVE_SYS_MMAN_H ${}
+
+/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
+ */
+#cmakedefine HAVE_SYS_NDIR_H ${HAVE_SYS_NDIR_H}
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#cmakedefine HAVE_SYS_PARAM_H ${HAVE_SYS_PARAM_H}
+
+/* Define to 1 if you have the <sys/resource.h> header file. */
+#cmakedefine HAVE_SYS_RESOURCE_H ${HAVE_SYS_RESOURCE_H}
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#cmakedefine HAVE_SYS_STAT_H ${HAVE_SYS_STAT_H}
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#cmakedefine HAVE_SYS_TIME_H ${HAVE_SYS_TIME_H}
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H}
+
+/* Define to 1 if you have the <sys/uio.h> header file. */
+#cmakedefine HAVE_SYS_UIO_H ${HAVE_SYS_UIO_H}
+
+/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
+#cmakedefine HAVE_SYS_WAIT_H ${HAVE_SYS_WAIT_H}
+
+/* Define to 1 if you have the <termios.h> header file. */
+#cmakedefine HAVE_TERMIOS_H ${HAVE_TERMIOS_H}
+
+/* Define if the neat program is available */
+#cmakedefine HAVE_TWOPI ${HAVE_TWOPI}
+
+/* Define to 1 if the system has the type `uint64_t'. */
+#cmakedefine HAVE_UINT64_T ${HAVE_UINT64_T}
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H}
+
+/* Define to 1 if you have the <utime.h> header file. */
+#cmakedefine HAVE_UTIME_H ${HAVE_UTIME_H}
+
+/* Define to 1 if the system has the type `u_int64_t'. */
+#cmakedefine HAVE_U_INT64_T ${HAVE_U_INT64_T}
+
+/* Define to 1 if you have the <valgrind/valgrind.h> header file. */
+#cmakedefine HAVE_VALGRIND_VALGRIND_H ${HAVE_VALGRIND_VALGRIND_H}
+
+/* Define to 1 if you have the <windows.h> header file. */
+#cmakedefine HAVE_WINDOWS_H ${HAVE_WINDOWS_H}
+
+/* Define to 1 if you have the `writev' function. */
+#cmakedefine HAVE_WRITEV ${HAVE_WRITEV}
+
+/* Define if the xdot.py program is available */
+#cmakedefine HAVE_XDOT_PY ${HAVE_XDOT_PY}
+
+/* Have host's _alloca */
+#cmakedefine HAVE__ALLOCA ${HAVE__ALLOCA}
+
+/* Have host's __alloca */
+#cmakedefine HAVE___ALLOCA ${HAVE___ALLOCA}
+
+/* Have host's __ashldi3 */
+#cmakedefine HAVE___ASHLDI3 ${HAVE___ASHLDI3}
+
+/* Have host's __ashrdi3 */
+#cmakedefine HAVE___ASHRDI3 ${HAVE___ASHRDI3}
+
+/* Have host's __chkstk */
+#cmakedefine HAVE___CHKSTK ${HAVE___CHKSTK}
+
+/* Have host's __cmpdi2 */
+#cmakedefine HAVE___CMPDI2 ${HAVE___CMPDI2}
+
+/* Have host's __divdi3 */
+#cmakedefine HAVE___DIVDI3 ${HAVE___DIVDI3}
+
+/* Define to 1 if you have the `__dso_handle' function. */
+#undef HAVE___DSO_HANDLE
+
+/* Have host's __fixdfdi */
+#cmakedefine HAVE___FIXDFDI ${HAVE___FIXDFDI}
+
+/* Have host's __fixsfdi */
+#cmakedefine HAVE___FIXSFDI ${HAVE___FIXSFDI}
+
+/* Have host's __floatdidf */
+#cmakedefine HAVE___FLOATDIDF ${HAVE___FLOATDIDF}
+
+/* Have host's __lshrdi3 */
+#cmakedefine HAVE___LSHRDI3 ${HAVE___LSHRDI3}
+
+/* Have host's __main */
+#cmakedefine HAVE___MAIN ${HAVE___MAIN}
+
+/* Have host's __moddi3 */
+#cmakedefine HAVE___MODDI3 ${HAVE___MODDI3}
+
+/* Have host's __udivdi3 */
+#cmakedefine HAVE___UDIVDI3 ${HAVE___UDIVDI3}
+
+/* Have host's __umoddi3 */
+#cmakedefine HAVE___UMODDI3 ${HAVE___UMODDI3}
+
+/* Have host's ___chkstk */
+#cmakedefine HAVE____CHKSTK ${HAVE____CHKSTK}
+
+/* Define if /dev/zero should be used when mapping RWX memory, or undefine if
+ its not necessary */
+#undef NEED_DEV_ZERO_FOR_MMAP
+
+/* Define if dlsym() requires a leading underscore in symbol names. */
+#undef NEED_USCORE
+
+/* Define to the address where bug reports for this package should be sent. */
+#cmakedefine PACKAGE_BUGREPORT "${PACKAGE_BUGREPORT}"
+
+/* Define to the full name of this package. */
+#cmakedefine PACKAGE_NAME "${PACKAGE_NAME}"
+
+/* Define to the full name and version of this package. */
+#cmakedefine PACKAGE_STRING "${PACKAGE_STRING}"
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the version of this package. */
+#cmakedefine PACKAGE_VERSION "${PACKAGE_VERSION}"
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#cmakedefine RETSIGTYPE ${RETSIGTYPE}
+
+/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
+#undef STAT_MACROS_BROKEN
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#undef TIME_WITH_SYS_TIME
+
+/* Define to 1 if your <sys/time.h> declares `struct tm'. */
+#undef TM_IN_SYS_TIME
+
+/* Define if use udis86 library */
+#undef USE_UDIS86
+
+/* Type of 1st arg on ELM Callback */
+#cmakedefine WIN32_ELMCB_PCSTR ${WIN32_ELMCB_PCSTR}
+
+/* Define to empty if `const' does not conform to ANSI C. */
+#undef const
+
+/* Define to a type to use for `error_t' if it is not otherwise available. */
+#cmakedefine error_t ${error_t}
+
+/* Define to `int' if <sys/types.h> does not define. */
+#undef pid_t
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+#undef size_t
+
+/* Define to a function replacing strtoll */
+#cmakedefine strtoll ${strtoll}
+
+/* Define to a function implementing strtoull */
+#cmakedefine strtoull ${strtoull}
+
+/* Define to a function implementing stricmp */
+#cmakedefine stricmp ${stricmp}
+
+/* Define to a function implementing strdup */
+#cmakedefine strdup ${strdup}
+
+/* Define to 1 if you have the `_chsize_s' function. */
+#cmakedefine HAVE__CHSIZE_S ${HAVE__CHSIZE_S}
+
+#endif
+
diff --git a/include/mcld/Config/Config.h.in b/include/mcld/Config/Config.h.in
index 4a38cbf..8afadca 100644
--- a/include/mcld/Config/Config.h.in
+++ b/include/mcld/Config/Config.h.in
@@ -13,6 +13,9 @@
#define MCLD_CONFIG_H
+/* Define to 1 if you have the <cxxabi.h> header file. */
+#undef HAVE_CXXABI_H
+
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
@@ -52,6 +55,9 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
+/* Define to 1 if you have the <zlib.h> header file. */
+#undef HAVE_ZLIB_H
+
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#undef LT_OBJDIR
@@ -102,12 +108,17 @@
/* Version number of package */
#undef VERSION
+/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
+ `char[]'. */
+#undef YYTEXT_POINTER
+
#define MCLD_REGION_CHUNK_SIZE 32
#define MCLD_NUM_OF_INPUTS 32
#define MCLD_SECTIONS_PER_INPUT 16
#define MCLD_SYMBOLS_PER_INPUT 128
#define MCLD_RELOCATIONS_PER_INPUT 1024
+
#define MCLD_SEGMENTS_PER_OUTPUT 8
#endif
diff --git a/include/mcld/Config/Linkers.def.cmake b/include/mcld/Config/Linkers.def.cmake
new file mode 100644
index 0000000..d03ead0
--- /dev/null
+++ b/include/mcld/Config/Linkers.def.cmake
@@ -0,0 +1,28 @@
+//===- llvm/Config/Linkers.def - MCLinkers ----------------------*- C++ -*-===//
+//
+// The MCLinker Project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file enumerates all of the linkers supported by this build of MCLinker.
+// Clients of this file should define the MCLD_LINKER macro to be a function-like
+// macro with a single parameter (the name of the target whose exe/dso can be
+// generated); including this file will then enumerate all of the targets with
+// linkers.
+//
+// The set of targets supported by MCLD is generated at configuration
+// time, at which point this header is generated. Do not modify this
+// header directly.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MCLD_LINKER
+# error Please define the macro MCLD_LINKER(TargetName)
+#endif
+
+${MCLD_ENUM_LINKERS}
+
+#undef MCLD_LINKER
diff --git a/include/mcld/Config/Targets.def.cmake b/include/mcld/Config/Targets.def.cmake
new file mode 100644
index 0000000..062a231
--- /dev/null
+++ b/include/mcld/Config/Targets.def.cmake
@@ -0,0 +1,28 @@
+/*===- llvm/Config/Targets.def - MCLD Target Architectures ------*- C++ -*-===*\
+|* *|
+|* The MCLinker Project *|
+|* *|
+|* This file is distributed under the University of Illinois Open Source *|
+|* License. See LICENSE.TXT for details. *|
+|* *|
+|*===----------------------------------------------------------------------===*|
+|* *|
+|* This file enumerates all of the target architectures supported by *|
+|* this build of MCLD. Clients of this file should define the *|
+|* MCLD_TARGET macro to be a function-like macro with a single *|
+|* parameter (the name of the target); including this file will then *|
+|* enumerate all of the targets. *|
+|* *|
+|* The set of targets supported by MCLD is generated at configuration *|
+|* time, at which point this header is generated. Do not modify this *|
+|* header directly. *|
+|* *|
+\*===----------------------------------------------------------------------===*/
+
+#ifndef MCLD_TARGET
+# error Please define the macro MCLD_TARGET(TargetName)
+#endif
+
+${MCLD_ENUM_TARGETS}
+
+#undef MCLD_TARGET
diff --git a/include/mcld/Environment.h b/include/mcld/Environment.h
index 20bcd8e..4f577da 100644
--- a/include/mcld/Environment.h
+++ b/include/mcld/Environment.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ENVIRONMENT_H
-#define MCLD_ENVIRONMENT_H
+#ifndef MCLD_ENVIRONMENT_H_
+#define MCLD_ENVIRONMENT_H_
namespace mcld {
@@ -15,6 +15,6 @@ void Initialize();
void Finalize();
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_ENVIRONMENT_H_
diff --git a/include/mcld/Fragment/AlignFragment.h b/include/mcld/Fragment/AlignFragment.h
index 5ca9b84..1680f9c 100644
--- a/include/mcld/Fragment/AlignFragment.h
+++ b/include/mcld/Fragment/AlignFragment.h
@@ -6,20 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_FRAGMENT_ALIGNFRAGMENT_H
-#define MCLD_FRAGMENT_ALIGNFRAGMENT_H
+#ifndef MCLD_FRAGMENT_ALIGNFRAGMENT_H_
+#define MCLD_FRAGMENT_ALIGNFRAGMENT_H_
-#include <mcld/Fragment/Fragment.h>
+#include "mcld/Fragment/Fragment.h"
namespace mcld {
class SectionData;
-class AlignFragment : public Fragment
-{
-public:
- AlignFragment(unsigned int pAlignment, int64_t pValue, unsigned int pValueSize,
- unsigned int pMaxBytesToEmit, SectionData *pSD = NULL);
+class AlignFragment : public Fragment {
+ public:
+ AlignFragment(unsigned int pAlignment,
+ int64_t pValue,
+ unsigned int pValueSize,
+ unsigned int pMaxBytesToEmit,
+ SectionData* pSD = NULL);
unsigned int getAlignment() const { return m_Alignment; }
@@ -33,13 +35,15 @@ public:
void setEmitNops(bool pValue) { m_bEmitNops = pValue; }
- static bool classof(const Fragment *F)
- { return F->getKind() == Fragment::Alignment; }
- static bool classof(const AlignFragment *) { return true; }
+ static bool classof(const Fragment* F) {
+ return F->getKind() == Fragment::Alignment;
+ }
+
+ static bool classof(const AlignFragment*) { return true; }
size_t size() const;
-private:
+ private:
/// Alignment - The alignment to ensure, in bytes.
unsigned int m_Alignment;
@@ -57,10 +61,8 @@ private:
/// of using the provided value. The exact interpretation of this flag is
/// target dependent.
bool m_bEmitNops : 1;
-
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_FRAGMENT_ALIGNFRAGMENT_H_
diff --git a/include/mcld/Fragment/FillFragment.h b/include/mcld/Fragment/FillFragment.h
index 96a17f6..3bb15db 100644
--- a/include/mcld/Fragment/FillFragment.h
+++ b/include/mcld/Fragment/FillFragment.h
@@ -6,35 +6,37 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_FRAGMENT_FILLFRAGMENT_H
-#define MCLD_FRAGMENT_FILLFRAGMENT_H
+#ifndef MCLD_FRAGMENT_FILLFRAGMENT_H_
+#define MCLD_FRAGMENT_FILLFRAGMENT_H_
-#include <llvm/Support/DataTypes.h>
+#include "mcld/Fragment/Fragment.h"
-#include <mcld/Fragment/Fragment.h>
+#include <llvm/Support/DataTypes.h>
namespace mcld {
class SectionData;
-class FillFragment : public Fragment
-{
-public:
- FillFragment(int64_t pValue, unsigned int pValueSize, uint64_t pSize,
+class FillFragment : public Fragment {
+ public:
+ FillFragment(int64_t pValue,
+ unsigned int pValueSize,
+ uint64_t pSize,
SectionData* pSD = NULL);
int64_t getValue() const { return m_Value; }
unsigned getValueSize() const { return m_ValueSize; }
- static bool classof(const Fragment *F)
- { return F->getKind() == Fragment::Fillment; }
+ static bool classof(const Fragment* F) {
+ return F->getKind() == Fragment::Fillment;
+ }
- static bool classof(const FillFragment *) { return true; }
+ static bool classof(const FillFragment*) { return true; }
size_t size() const { return m_Size; }
-private:
+ private:
/// m_Value - Value used for filling bytes
int64_t m_Value;
@@ -46,7 +48,6 @@ private:
uint64_t m_Size;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_FRAGMENT_FILLFRAGMENT_H_
diff --git a/include/mcld/Fragment/Fragment.h b/include/mcld/Fragment/Fragment.h
index 572ebde..76a5028 100644
--- a/include/mcld/Fragment/Fragment.h
+++ b/include/mcld/Fragment/Fragment.h
@@ -6,15 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_FRAGMENT_FRAGMENT_H
-#define MCLD_FRAGMENT_FRAGMENT_H
+#ifndef MCLD_FRAGMENT_FRAGMENT_H_
+#define MCLD_FRAGMENT_FRAGMENT_H_
-#include <llvm/ADT/ilist_node.h>
+#include "mcld/Support/Compiler.h"
+#include <llvm/ADT/ilist_node.h>
#include <llvm/Support/DataTypes.h>
-#include <cstddef>
#include <cassert>
+#include <cstddef>
namespace mcld {
@@ -23,31 +24,23 @@ class SectionData;
/** \class Fragment
* \brief Fragment is the minimun linking unit of MCLinker.
*/
-class Fragment : public llvm::ilist_node<Fragment>
-{
-public:
- enum Type {
- Alignment,
- Fillment,
- Region,
- Target,
- Stub,
- Null
- };
-
-public:
+class Fragment : public llvm::ilist_node<Fragment> {
+ public:
+ enum Type { Alignment, Fillment, Region, Target, Stub, Null };
+
+ public:
Fragment();
- Fragment(Type pKind, SectionData *pParent = NULL);
+ explicit Fragment(Type pKind, SectionData* pParent = NULL);
virtual ~Fragment();
Type getKind() const { return m_Kind; }
const SectionData* getParent() const { return m_pParent; }
- SectionData* getParent() { return m_pParent; }
+ SectionData* getParent() { return m_pParent; }
- void setParent(SectionData *pValue) { m_pParent = pValue; }
+ void setParent(SectionData* pValue) { m_pParent = pValue; }
uint64_t getOffset() const;
@@ -55,26 +48,24 @@ public:
bool hasOffset() const;
- static bool classof(const Fragment *O) { return true; }
+ static bool classof(const Fragment* O) { return true; }
virtual size_t size() const {
assert(false && "Can not call abstract Fragment::size()!");
return 0;
}
-private:
- Fragment(const Fragment& ); // DO NOT IMPLEMENT
- Fragment& operator=(const Fragment& ); // DO NOT IMPLEMENT
-
-private:
+ private:
Type m_Kind;
+
SectionData* m_pParent;
uint64_t m_Offset;
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Fragment);
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_FRAGMENT_FRAGMENT_H_
diff --git a/include/mcld/Fragment/FragmentRef.h b/include/mcld/Fragment/FragmentRef.h
index 768dab3..1db45a2 100644
--- a/include/mcld/Fragment/FragmentRef.h
+++ b/include/mcld/Fragment/FragmentRef.h
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_FRAGMENT_FRAGMENTREF_H
-#define MCLD_FRAGMENT_FRAGMENTREF_H
+#ifndef MCLD_FRAGMENT_FRAGMENTREF_H_
+#define MCLD_FRAGMENT_FRAGMENTREF_H_
-#include <mcld/Config/Config.h>
-#include <mcld/ADT/SizeTraits.h>
-#include <mcld/ADT/TypeTraits.h>
-#include <mcld/Support/Allocators.h>
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/ADT/TypeTraits.h"
+#include "mcld/Config/Config.h"
+#include "mcld/Support/Allocators.h"
namespace mcld {
@@ -24,14 +24,13 @@ class Layout;
* \brief FragmentRef is a reference of a Fragment's contetnt.
*
*/
-class FragmentRef
-{
-public:
- typedef uint64_t Offset; // FIXME: use SizeTraits<T>::Offset
+class FragmentRef {
+ public:
+ typedef uint64_t Offset; // FIXME: use SizeTraits<T>::Offset
typedef NonConstTraits<unsigned char>::pointer Address;
typedef ConstTraits<unsigned char>::pointer ConstAddress;
-public:
+ public:
/// Create - create a fragment reference for a given fragment.
///
/// @param pFrag - the given fragment
@@ -64,35 +63,31 @@ public:
// ----- observers ----- //
bool isNull() const { return (this == Null()); }
- Fragment* frag()
- { return m_pFragment; }
+ Fragment* frag() { return m_pFragment; }
- const Fragment* frag() const
- { return m_pFragment; }
+ const Fragment* frag() const { return m_pFragment; }
- Offset offset() const
- { return m_Offset; }
+ Offset offset() const { return m_Offset; }
Offset getOutputOffset() const;
-private:
+ private:
friend FragmentRef& NullFragmentRef();
friend class Chunk<FragmentRef, MCLD_SECTIONS_PER_INPUT>;
friend class Relocation;
FragmentRef();
- FragmentRef(Fragment& pFrag, Offset pOffset = 0);
+ explicit FragmentRef(Fragment& pFrag, Offset pOffset = 0);
-private:
+ private:
Fragment* m_pFragment;
+
Offset m_Offset;
static FragmentRef g_NullFragmentRef;
-
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_FRAGMENT_FRAGMENTREF_H_
diff --git a/include/mcld/Fragment/NullFragment.h b/include/mcld/Fragment/NullFragment.h
index cd3ba9f..1764b26 100644
--- a/include/mcld/Fragment/NullFragment.h
+++ b/include/mcld/Fragment/NullFragment.h
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_FRAGMENT_NULLFRAGMENT_H
-#define MCLD_FRAGMENT_NULLFRAGMENT_H
+#ifndef MCLD_FRAGMENT_NULLFRAGMENT_H_
+#define MCLD_FRAGMENT_NULLFRAGMENT_H_
-#include <mcld/Fragment/Fragment.h>
+#include "mcld/Fragment/Fragment.h"
namespace mcld {
@@ -19,22 +19,20 @@ class SectionData;
* \brief NullFragment is a kind of MCFragment that presents the "end fragment"
* referenced by some special symbols
*/
-class NullFragment : public Fragment
-{
-public:
- NullFragment(SectionData* pSD = NULL);
+class NullFragment : public Fragment {
+ public:
+ explicit NullFragment(SectionData* pSD = NULL);
/// size -
size_t size() const { return 0x0; }
- static bool classof(const Fragment *F)
- { return F->getKind() == Fragment::Null; }
+ static bool classof(const Fragment* F) {
+ return F->getKind() == Fragment::Null;
+ }
- static bool classof(const NullFragment *)
- { return true; }
+ static bool classof(const NullFragment*) { return true; }
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_FRAGMENT_NULLFRAGMENT_H_
diff --git a/include/mcld/Fragment/RegionFragment.h b/include/mcld/Fragment/RegionFragment.h
index 09d2db8..16ccea8 100644
--- a/include/mcld/Fragment/RegionFragment.h
+++ b/include/mcld/Fragment/RegionFragment.h
@@ -6,10 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_FRAGMENT_REGIONFRAGMENT_H
-#define MCLD_FRAGMENT_REGIONFRAGMENT_H
+#ifndef MCLD_FRAGMENT_REGIONFRAGMENT_H_
+#define MCLD_FRAGMENT_REGIONFRAGMENT_H_
+
+#include "mcld/Fragment/Fragment.h"
-#include <mcld/Fragment/Fragment.h>
#include <llvm/ADT/StringRef.h>
namespace mcld {
@@ -17,29 +18,27 @@ namespace mcld {
/** \class RegionFragment
* \brief RegionFragment is a kind of Fragment containing input memory region
*/
-class RegionFragment : public Fragment
-{
-public:
- RegionFragment(llvm::StringRef pRegion, SectionData* pSD = NULL);
+class RegionFragment : public Fragment {
+ public:
+ explicit RegionFragment(llvm::StringRef pRegion, SectionData* pSD = NULL);
~RegionFragment();
const llvm::StringRef getRegion() const { return m_Region; }
- llvm::StringRef getRegion() { return m_Region; }
+ llvm::StringRef getRegion() { return m_Region; }
- static bool classof(const Fragment *F)
- { return F->getKind() == Fragment::Region; }
+ static bool classof(const Fragment* F) {
+ return F->getKind() == Fragment::Region;
+ }
- static bool classof(const RegionFragment *)
- { return true; }
+ static bool classof(const RegionFragment*) { return true; }
size_t size() const;
-private:
+ private:
llvm::StringRef m_Region;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_FRAGMENT_REGIONFRAGMENT_H_
diff --git a/include/mcld/Fragment/Relocation.h b/include/mcld/Fragment/Relocation.h
index a8479b5..e6a4c76 100644
--- a/include/mcld/Fragment/Relocation.h
+++ b/include/mcld/Fragment/Relocation.h
@@ -6,11 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_FRAGMENT_RELOCATION_H
-#define MCLD_FRAGMENT_RELOCATION_H
-#include <mcld/Config/Config.h>
-#include <mcld/Fragment/FragmentRef.h>
-#include <mcld/Support/GCFactoryListTraits.h>
+#ifndef MCLD_FRAGMENT_RELOCATION_H_
+#define MCLD_FRAGMENT_RELOCATION_H_
+
+#include "mcld/Config/Config.h"
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/Support/GCFactoryListTraits.h"
#include <llvm/ADT/ilist_node.h>
#include <llvm/Support/DataTypes.h>
@@ -21,20 +22,19 @@ class ResolveInfo;
class Relocator;
class LinkerConfig;
-class Relocation : public llvm::ilist_node<Relocation>
-{
-friend class RelocationFactory;
-friend class GCFactoryListTraits<Relocation>;
-friend class Chunk<Relocation, MCLD_RELOCATIONS_PER_INPUT>;
+class Relocation : public llvm::ilist_node<Relocation> {
+ friend class RelocationFactory;
+ friend class GCFactoryListTraits<Relocation>;
+ friend class Chunk<Relocation, MCLD_RELOCATIONS_PER_INPUT>;
-public:
- typedef uint64_t Address; // FIXME: use SizeTrait<T>::Address instead
- typedef uint64_t DWord; // FIXME: use SizeTrait<T>::Word instead
- typedef int64_t SWord; // FIXME: use SizeTrait<T>::SWord instead
+ public:
+ typedef uint64_t Address; // FIXME: use SizeTrait<T>::Address instead
+ typedef uint64_t DWord; // FIXME: use SizeTrait<T>::Word instead
+ typedef int64_t SWord; // FIXME: use SizeTrait<T>::SWord instead
typedef uint32_t Type;
typedef uint32_t Size;
-private:
+ private:
Relocation();
Relocation(Type pType,
@@ -44,7 +44,7 @@ private:
~Relocation();
-public:
+ public:
/// Initialize - set up the relocation factory
static void SetUp(const LinkerConfig& pConfig);
@@ -58,22 +58,21 @@ public:
/// @param pType [in] the type of the relocation entry
/// @param pFragRef [in] the place to apply the relocation
/// @param pAddend [in] the addend of the relocation entry
- static Relocation* Create(Type pType, FragmentRef& pFragRef,
+ static Relocation* Create(Type pType,
+ FragmentRef& pFragRef,
Address pAddend = 0);
/// Destroy - destroy a relocation entry
static void Destroy(Relocation*& pRelocation);
/// type - relocation type
- Type type() const
- { return m_Type; }
+ Type type() const { return m_Type; }
/// symValue - S value - the symbol address
Address symValue() const;
/// addend - A value
- Address addend() const
- { return m_Addend; }
+ Address addend() const { return m_Addend; }
/// place - P value - address of the place being relocated
Address place() const;
@@ -83,15 +82,15 @@ public:
/// symbol info - binding, type
const ResolveInfo* symInfo() const { return m_pSymInfo; }
- ResolveInfo* symInfo() { return m_pSymInfo; }
+ ResolveInfo* symInfo() { return m_pSymInfo; }
/// target - the target data to relocate
const DWord& target() const { return m_TargetData; }
- DWord& target() { return m_TargetData; }
+ DWord& target() { return m_TargetData; }
/// targetRef - the reference of the target data
const FragmentRef& targetRef() const { return m_TargetAddress; }
- FragmentRef& targetRef() { return m_TargetAddress; }
+ FragmentRef& targetRef() { return m_TargetAddress; }
void apply(Relocator& pRelocator);
@@ -106,7 +105,7 @@ public:
void setSymInfo(ResolveInfo* pSym);
-private:
+ private:
/// m_Type - the type of the relocation entries
Type m_Type;
@@ -123,7 +122,6 @@ private:
Address m_Addend;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_FRAGMENT_RELOCATION_H_
diff --git a/include/mcld/Fragment/Stub.h b/include/mcld/Fragment/Stub.h
index f05aefe..94f58e9 100644
--- a/include/mcld/Fragment/Stub.h
+++ b/include/mcld/Fragment/Stub.h
@@ -7,56 +7,53 @@
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_FRAGMENT_STUB_H
-#define MCLD_FRAGMENT_STUB_H
+#ifndef MCLD_FRAGMENT_STUB_H_
+#define MCLD_FRAGMENT_STUB_H_
+
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/Fragment/Relocation.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Fragment/Fragment.h>
-#include <mcld/Fragment/Relocation.h>
-#include <vector>
+
#include <string>
+#include <vector>
-namespace mcld
-{
+namespace mcld {
class Relocation;
class ResolveInfo;
-class Stub: public Fragment
-{
-public:
+class Stub : public Fragment {
+ public:
typedef Relocation::DWord DWord;
typedef Relocation::SWord SWord;
- typedef Relocation::Type Type;
+ typedef Relocation::Type Type;
- class Fixup
- {
- public:
+ class Fixup {
+ public:
Fixup(DWord pOffset, SWord pAddend, Type pType)
- : m_Offset(pOffset), m_Addend(pAddend), m_Type(pType)
- { }
+ : m_Offset(pOffset), m_Addend(pAddend), m_Type(pType) {}
- ~Fixup()
- { }
+ ~Fixup() {}
DWord offset() const { return m_Offset; }
SWord addend() const { return m_Addend; }
- Type type() const { return m_Type; }
+ Type type() const { return m_Type; }
- private:
+ private:
DWord m_Offset;
SWord m_Addend;
- Type m_Type;
+ Type m_Type;
};
-public:
+ public:
typedef std::vector<Fixup*> FixupListType;
typedef FixupListType::iterator fixup_iterator;
typedef FixupListType::const_iterator const_fixup_iterator;
-public:
+ public:
Stub();
virtual ~Stub();
@@ -83,49 +80,48 @@ public:
virtual size_t alignment() const = 0;
/// symInfo - ResolveInfo of this Stub
- ResolveInfo* symInfo() { return m_pSymInfo; }
+ ResolveInfo* symInfo() { return m_pSymInfo; }
const ResolveInfo* symInfo() const { return m_pSymInfo; }
/// symValue - initial value for stub's symbol
- virtual uint64_t initSymValue() const { return 0x0; }
+ virtual uint64_t initSymValue() const { return 0x0; }
/// ----- Fixup ----- ///
- fixup_iterator fixup_begin() { return m_FixupList.begin(); }
+ fixup_iterator fixup_begin() { return m_FixupList.begin(); }
const_fixup_iterator fixup_begin() const { return m_FixupList.begin(); }
- fixup_iterator fixup_end() { return m_FixupList.end(); }
+ fixup_iterator fixup_end() { return m_FixupList.end(); }
- const_fixup_iterator fixup_end() const { return m_FixupList.end(); }
+ const_fixup_iterator fixup_end() const { return m_FixupList.end(); }
/// ----- modifiers ----- ///
void setSymInfo(ResolveInfo* pSymInfo);
// Stub is a kind of Fragment with type of Stub
- static bool classof(const Fragment *F)
- { return F->getKind() == Fragment::Stub; }
+ static bool classof(const Fragment* F) {
+ return F->getKind() == Fragment::Stub;
+ }
- static bool classof(const Stub *)
- { return true; }
+ static bool classof(const Stub*) { return true; }
-protected:
+ protected:
/// addFixup - add a fixup for this stub to build a relocation
void addFixup(DWord pOffset, SWord pAddend, Type pType);
/// addFixup - add a fixup from a existing fixup of the prototype
void addFixup(const Fixup& pFixup);
-private:
+ private:
/// doClone - when adding a backend stub, we should implement this function
virtual Stub* doClone() = 0;
-private:
+ private:
ResolveInfo* m_pSymInfo;
FixupListType m_FixupList;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_FRAGMENT_STUB_H_
diff --git a/include/mcld/Fragment/TargetFragment.h b/include/mcld/Fragment/TargetFragment.h
index aa404a0..e0c3051 100644
--- a/include/mcld/Fragment/TargetFragment.h
+++ b/include/mcld/Fragment/TargetFragment.h
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_FRAGMENT_TARGETFRAGMENT_H
-#define MCLD_FRAGMENT_TARGETFRAGMENT_H
+#ifndef MCLD_FRAGMENT_TARGETFRAGMENT_H_
+#define MCLD_FRAGMENT_TARGETFRAGMENT_H_
-#include <mcld/Fragment/Fragment.h>
+#include "mcld/Fragment/Fragment.h"
namespace mcld {
@@ -19,23 +19,21 @@ class SectionData;
* \brief TargetFragment is a kind of MCFragment inherited by
* target-depedent Fragment.
*/
-class TargetFragment : public Fragment
-{
-protected:
- TargetFragment(Fragment::Type pKind, SectionData* pSD = NULL)
- : Fragment(pKind, pSD) {}
+class TargetFragment : public Fragment {
+ protected:
+ explicit TargetFragment(Fragment::Type pKind, SectionData* pSD = NULL)
+ : Fragment(pKind, pSD) {}
-public:
+ public:
virtual ~TargetFragment() {}
- static bool classof(const Fragment *F)
- { return F->getKind() == Fragment::Target; }
+ static bool classof(const Fragment* F) {
+ return F->getKind() == Fragment::Target;
+ }
- static bool classof(const TargetFragment *)
- { return true; }
+ static bool classof(const TargetFragment*) { return true; }
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_FRAGMENT_TARGETFRAGMENT_H_
diff --git a/include/mcld/GeneralOptions.h b/include/mcld/GeneralOptions.h
index 1d6c9a3..58e4eb3 100644
--- a/include/mcld/GeneralOptions.h
+++ b/include/mcld/GeneralOptions.h
@@ -6,10 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_GENERALOPTIONS_H
-#define MCLD_GENERALOPTIONS_H
-#include <mcld/Support/RealPath.h>
-#include <mcld/Support/FileSystem.h>
+#ifndef MCLD_GENERALOPTIONS_H_
+#define MCLD_GENERALOPTIONS_H_
+#include "mcld/Config/Config.h"
+#include "mcld/Support/RealPath.h"
+#include "mcld/Support/FileSystem.h"
#include <string>
#include <vector>
#include <set>
@@ -24,9 +25,8 @@ class ZOption;
* - input files
* - attribute of input files
*/
-class GeneralOptions
-{
-public:
+class GeneralOptions {
+ public:
enum StripSymbolMode {
KeepAllSymbols,
StripTemporaries,
@@ -34,17 +34,9 @@ public:
StripAllSymbols
};
- enum HashStyle {
- SystemV = 0x1,
- GNU = 0x2,
- Both = 0x3
- };
+ enum HashStyle { SystemV = 0x1, GNU = 0x2, Both = 0x3 };
- enum ICF {
- ICF_None,
- ICF_All,
- ICF_Safe
- };
+ enum ICF { ICF_None, ICF_All, ICF_Safe };
typedef std::vector<std::string> RpathList;
typedef RpathList::iterator rpath_iterator;
@@ -64,404 +56,324 @@ public:
typedef std::set<std::string> ExcludeLIBS;
-public:
+ public:
GeneralOptions();
~GeneralOptions();
/// trace
- void setTrace(bool pEnableTrace = true)
- { m_bTrace = pEnableTrace; }
+ void setTrace(bool pEnableTrace = true) { m_bTrace = pEnableTrace; }
- bool trace() const
- { return m_bTrace; }
+ bool trace() const { return m_bTrace; }
- void setBsymbolic(bool pBsymbolic = true)
- { m_Bsymbolic = pBsymbolic; }
+ void setBsymbolic(bool pBsymbolic = true) { m_Bsymbolic = pBsymbolic; }
- bool Bsymbolic() const
- { return m_Bsymbolic; }
+ bool Bsymbolic() const { return m_Bsymbolic; }
- void setPIE(bool pPIE = true)
- { m_bPIE = pPIE; }
+ void setPIE(bool pPIE = true) { m_bPIE = pPIE; }
- bool isPIE() const
- { return m_bPIE; }
+ bool isPIE() const { return m_bPIE; }
- void setBgroup(bool pBgroup = true)
- { m_Bgroup = pBgroup; }
+ void setBgroup(bool pBgroup = true) { m_Bgroup = pBgroup; }
- bool Bgroup() const
- { return m_Bgroup; }
+ bool Bgroup() const { return m_Bgroup; }
- void setDyld(const std::string& pDyld)
- { m_Dyld = pDyld; }
+ void setDyld(const std::string& pDyld) { m_Dyld = pDyld; }
- const std::string& dyld() const
- { return m_Dyld; }
+ const std::string& dyld() const { return m_Dyld; }
- bool hasDyld() const
- { return !m_Dyld.empty(); }
+ bool hasDyld() const { return !m_Dyld.empty(); }
void setSOName(const std::string& pName);
- const std::string& soname() const
- { return m_SOName; }
+ const std::string& soname() const { return m_SOName; }
- void setVerbose(int8_t pVerbose = -1)
- { m_Verbose = pVerbose; }
+ void setVerbose(int8_t pVerbose = -1) { m_Verbose = pVerbose; }
- int8_t verbose() const
- { return m_Verbose; }
+ int8_t verbose() const { return m_Verbose; }
- void setMaxErrorNum(int16_t pNum)
- { m_MaxErrorNum = pNum; }
+ void setMaxErrorNum(int16_t pNum) { m_MaxErrorNum = pNum; }
- int16_t maxErrorNum() const
- { return m_MaxErrorNum; }
+ int16_t maxErrorNum() const { return m_MaxErrorNum; }
- void setMaxWarnNum(int16_t pNum)
- { m_MaxWarnNum = pNum; }
+ void setMaxWarnNum(int16_t pNum) { m_MaxWarnNum = pNum; }
- int16_t maxWarnNum() const
- { return m_MaxWarnNum; }
+ int16_t maxWarnNum() const { return m_MaxWarnNum; }
- void setColor(bool pEnabled = true)
- { m_bColor = pEnabled; }
+ void setColor(bool pEnabled = true) { m_bColor = pEnabled; }
- bool color() const
- { return m_bColor; }
+ bool color() const { return m_bColor; }
- void setNoUndefined(bool pEnable = true)
- { m_NoUndefined = (pEnable?YES:NO); }
+ void setNoUndefined(bool pEnable = true) {
+ m_NoUndefined = (pEnable ? YES : NO);
+ }
- void setMulDefs(bool pEnable = true)
- { m_MulDefs = (pEnable?YES:NO); }
+ void setMulDefs(bool pEnable = true) { m_MulDefs = (pEnable ? YES : NO); }
- void setEhFrameHdr(bool pEnable = true)
- { m_bCreateEhFrameHdr = pEnable; }
+ void setEhFrameHdr(bool pEnable = true) { m_bCreateEhFrameHdr = pEnable; }
/// ----- the -z options ----- ///
void addZOption(const mcld::ZOption& pOption);
- bool hasCombReloc() const
- { return m_bCombReloc; }
+ bool hasCombReloc() const { return m_bCombReloc; }
- bool hasNoUndefined() const
- { return (Unknown != m_NoUndefined); }
+ bool hasNoUndefined() const { return (Unknown != m_NoUndefined); }
- bool isNoUndefined() const
- { return (YES == m_NoUndefined); }
+ bool isNoUndefined() const { return (YES == m_NoUndefined); }
- bool hasStackSet() const
- { return (Unknown != m_ExecStack); }
+ bool hasStackSet() const { return (Unknown != m_ExecStack); }
- bool hasExecStack() const
- { return (YES == m_ExecStack); }
+ bool hasExecStack() const { return (YES == m_ExecStack); }
- bool hasInitFirst() const
- { return m_bInitFirst; }
+ bool hasInitFirst() const { return m_bInitFirst; }
- bool hasInterPose() const
- { return m_bInterPose; }
+ bool hasInterPose() const { return m_bInterPose; }
- bool hasLoadFltr() const
- { return m_bLoadFltr; }
+ bool hasLoadFltr() const { return m_bLoadFltr; }
- bool hasMulDefs() const
- { return (Unknown != m_MulDefs); }
+ bool hasMulDefs() const { return (Unknown != m_MulDefs); }
- bool isMulDefs() const
- { return (YES == m_MulDefs); }
+ bool isMulDefs() const { return (YES == m_MulDefs); }
- bool hasNoCopyReloc() const
- { return m_bNoCopyReloc; }
+ bool hasNoCopyReloc() const { return m_bNoCopyReloc; }
- bool hasNoDefaultLib() const
- { return m_bNoDefaultLib; }
+ bool hasNoDefaultLib() const { return m_bNoDefaultLib; }
- bool hasNoDelete() const
- { return m_bNoDelete; }
+ bool hasNoDelete() const { return m_bNoDelete; }
- bool hasNoDLOpen() const
- { return m_bNoDLOpen; }
+ bool hasNoDLOpen() const { return m_bNoDLOpen; }
- bool hasNoDump() const
- { return m_bNoDump; }
+ bool hasNoDump() const { return m_bNoDump; }
- bool hasRelro() const
- { return m_bRelro; }
+ bool hasRelro() const { return m_bRelro; }
- bool hasNow() const
- { return m_bNow; }
+ bool hasNow() const { return m_bNow; }
- bool hasOrigin() const
- { return m_bOrigin; }
+ bool hasOrigin() const { return m_bOrigin; }
- uint64_t commPageSize() const
- { return m_CommPageSize; }
+ uint64_t commPageSize() const { return m_CommPageSize; }
- uint64_t maxPageSize() const
- { return m_MaxPageSize; }
+ uint64_t maxPageSize() const { return m_MaxPageSize; }
- bool hasEhFrameHdr() const
- { return m_bCreateEhFrameHdr; }
+ bool hasEhFrameHdr() const { return m_bCreateEhFrameHdr; }
// -n, --nmagic
- void setNMagic(bool pMagic = true)
- { m_bNMagic = pMagic; }
+ void setNMagic(bool pMagic = true) { m_bNMagic = pMagic; }
- bool nmagic() const
- { return m_bNMagic; }
+ bool nmagic() const { return m_bNMagic; }
// -N, --omagic
- void setOMagic(bool pMagic = true)
- { m_bOMagic = pMagic; }
+ void setOMagic(bool pMagic = true) { m_bOMagic = pMagic; }
- bool omagic() const
- { return m_bOMagic; }
+ bool omagic() const { return m_bOMagic; }
// -S, --strip-debug
- void setStripDebug(bool pStripDebug = true)
- { m_bStripDebug = pStripDebug; }
+ void setStripDebug(bool pStripDebug = true) { m_bStripDebug = pStripDebug; }
- bool stripDebug() const
- { return m_bStripDebug; }
+ bool stripDebug() const { return m_bStripDebug; }
// -E, --export-dynamic
- void setExportDynamic(bool pExportDynamic = true)
- { m_bExportDynamic = pExportDynamic; }
+ void setExportDynamic(bool pExportDynamic = true) {
+ m_bExportDynamic = pExportDynamic;
+ }
- bool exportDynamic() const
- { return m_bExportDynamic; }
+ bool exportDynamic() const { return m_bExportDynamic; }
// --warn-shared-textrel
- void setWarnSharedTextrel(bool pWarnSharedTextrel = true)
- { m_bWarnSharedTextrel = pWarnSharedTextrel; }
+ void setWarnSharedTextrel(bool pWarnSharedTextrel = true) {
+ m_bWarnSharedTextrel = pWarnSharedTextrel;
+ }
- bool warnSharedTextrel() const
- { return m_bWarnSharedTextrel; }
+ bool warnSharedTextrel() const { return m_bWarnSharedTextrel; }
- void setBinaryInput(bool pBinaryInput = true)
- { m_bBinaryInput = pBinaryInput; }
+ void setBinaryInput(bool pBinaryInput = true) {
+ m_bBinaryInput = pBinaryInput;
+ }
- bool isBinaryInput() const
- { return m_bBinaryInput; }
+ bool isBinaryInput() const { return m_bBinaryInput; }
- void setDefineCommon(bool pEnable = true)
- { m_bDefineCommon = pEnable; }
+ void setDefineCommon(bool pEnable = true) { m_bDefineCommon = pEnable; }
- bool isDefineCommon() const
- { return m_bDefineCommon; }
+ bool isDefineCommon() const { return m_bDefineCommon; }
- void setFatalWarnings(bool pEnable = true)
- { m_bFatalWarnings = pEnable; }
+ void setFatalWarnings(bool pEnable = true) { m_bFatalWarnings = pEnable; }
- bool isFatalWarnings() const
- { return m_bFatalWarnings; }
+ bool isFatalWarnings() const { return m_bFatalWarnings; }
- StripSymbolMode getStripSymbolMode() const
- { return m_StripSymbols; }
+ StripSymbolMode getStripSymbolMode() const { return m_StripSymbols; }
- void setStripSymbols(StripSymbolMode pMode)
- { m_StripSymbols = pMode; }
+ void setStripSymbols(StripSymbolMode pMode) { m_StripSymbols = pMode; }
- void setNewDTags(bool pEnable = true)
- { m_bNewDTags = pEnable; }
+ void setNewDTags(bool pEnable = true) { m_bNewDTags = pEnable; }
- bool hasNewDTags() const
- { return m_bNewDTags; }
+ bool hasNewDTags() const { return m_bNewDTags; }
- void setNoStdlib(bool pEnable = true)
- { m_bNoStdlib = pEnable; }
+ void setNoStdlib(bool pEnable = true) { m_bNoStdlib = pEnable; }
- bool nostdlib() const
- { return m_bNoStdlib; }
+ bool nostdlib() const { return m_bNoStdlib; }
// -M, --print-map
- void setPrintMap(bool pEnable = true)
- { m_bPrintMap = pEnable; }
+ void setPrintMap(bool pEnable = true) { m_bPrintMap = pEnable; }
- bool printMap() const
- { return m_bPrintMap; }
+ bool printMap() const { return m_bPrintMap; }
- void setWarnMismatch(bool pEnable = true)
- { m_bWarnMismatch = pEnable; }
+ void setWarnMismatch(bool pEnable = true) { m_bWarnMismatch = pEnable; }
- bool warnMismatch() const
- { return m_bWarnMismatch; }
+ bool warnMismatch() const { return m_bWarnMismatch; }
// --gc-sections
- void setGCSections(bool pEnable = true)
- { m_bGCSections = pEnable; }
+ void setGCSections(bool pEnable = true) { m_bGCSections = pEnable; }
- bool GCSections() const
- { return m_bGCSections; }
+ bool GCSections() const { return m_bGCSections; }
// --print-gc-sections
- void setPrintGCSections(bool pEnable = true)
- { m_bPrintGCSections = pEnable; }
+ void setPrintGCSections(bool pEnable = true) { m_bPrintGCSections = pEnable; }
- bool getPrintGCSections() const
- { return m_bPrintGCSections; }
+ bool getPrintGCSections() const { return m_bPrintGCSections; }
// --ld-generated-unwind-info
- void setGenUnwindInfo(bool pEnable = true)
- { m_bGenUnwindInfo = pEnable; }
+ void setGenUnwindInfo(bool pEnable = true) { m_bGenUnwindInfo = pEnable; }
- bool genUnwindInfo() const
- { return m_bGenUnwindInfo; }
+ bool genUnwindInfo() const { return m_bGenUnwindInfo; }
// -G, max GP size option
- void setGPSize(int gpsize)
- { m_GPSize = gpsize; }
+ void setGPSize(int gpsize) { m_GPSize = gpsize; }
- int getGPSize() const
- { return m_GPSize; }
+ int getGPSize() const { return m_GPSize; }
unsigned int getHashStyle() const { return m_HashStyle; }
- void setHashStyle(unsigned int pStyle)
- { m_HashStyle = pStyle; }
+ void setHashStyle(unsigned int pStyle) { m_HashStyle = pStyle; }
ICF getICFMode() const { return m_ICF; }
- void setICFMode(ICF pMode)
- { m_ICF = pMode; }
+ void setICFMode(ICF pMode) { m_ICF = pMode; }
size_t getICFIterations() const { return m_ICFIterations; }
- void setICFIterations(size_t pNum)
- { m_ICFIterations = pNum; }
+ void setICFIterations(size_t pNum) { m_ICFIterations = pNum; }
bool printICFSections() const { return m_bPrintICFSections; }
- void setPrintICFSections(bool pPrintICFSections)
- { m_bPrintICFSections = pPrintICFSections; }
+ void setPrintICFSections(bool pPrintICFSections) {
+ m_bPrintICFSections = pPrintICFSections;
+ }
// ----- link-in rpath ----- //
const RpathList& getRpathList() const { return m_RpathList; }
- RpathList& getRpathList() { return m_RpathList; }
+ RpathList& getRpathList() { return m_RpathList; }
const_rpath_iterator rpath_begin() const { return m_RpathList.begin(); }
- rpath_iterator rpath_begin() { return m_RpathList.begin(); }
- const_rpath_iterator rpath_end () const { return m_RpathList.end(); }
- rpath_iterator rpath_end () { return m_RpathList.end(); }
+ rpath_iterator rpath_begin() { return m_RpathList.begin(); }
+ const_rpath_iterator rpath_end() const { return m_RpathList.end(); }
+ rpath_iterator rpath_end() { return m_RpathList.end(); }
// ----- link-in script ----- //
const ScriptList& getScriptList() const { return m_ScriptList; }
- ScriptList& getScriptList() { return m_ScriptList; }
+ ScriptList& getScriptList() { return m_ScriptList; }
const_script_iterator script_begin() const { return m_ScriptList.begin(); }
- script_iterator script_begin() { return m_ScriptList.begin(); }
- const_script_iterator script_end () const { return m_ScriptList.end(); }
- script_iterator script_end () { return m_ScriptList.end(); }
+ script_iterator script_begin() { return m_ScriptList.begin(); }
+ const_script_iterator script_end() const { return m_ScriptList.end(); }
+ script_iterator script_end() { return m_ScriptList.end(); }
// ----- -u/--undefined, undefined symbols ----- //
const UndefSymList& getUndefSymList() const { return m_UndefSymList; }
- UndefSymList& getUndefSymList() { return m_UndefSymList; }
+ UndefSymList& getUndefSymList() { return m_UndefSymList; }
- const_undef_sym_iterator undef_sym_begin() const
- { return m_UndefSymList.begin(); }
- undef_sym_iterator undef_sym_begin()
- { return m_UndefSymList.begin(); }
+ const_undef_sym_iterator undef_sym_begin() const {
+ return m_UndefSymList.begin();
+ }
+ undef_sym_iterator undef_sym_begin() { return m_UndefSymList.begin(); }
- const_undef_sym_iterator undef_sym_end() const
- { return m_UndefSymList.end(); }
- undef_sym_iterator undef_sym_end()
- { return m_UndefSymList.end(); }
+ const_undef_sym_iterator undef_sym_end() const {
+ return m_UndefSymList.end();
+ }
+ undef_sym_iterator undef_sym_end() { return m_UndefSymList.end(); }
// ----- filter and auxiliary filter ----- //
- void setFilter(const std::string& pFilter)
- { m_Filter = pFilter; }
+ void setFilter(const std::string& pFilter) { m_Filter = pFilter; }
- const std::string& filter() const
- { return m_Filter; }
+ const std::string& filter() const { return m_Filter; }
- bool hasFilter() const
- { return !m_Filter.empty(); }
+ bool hasFilter() const { return !m_Filter.empty(); }
const AuxiliaryList& getAuxiliaryList() const { return m_AuxiliaryList; }
- AuxiliaryList& getAuxiliaryList() { return m_AuxiliaryList; }
+ AuxiliaryList& getAuxiliaryList() { return m_AuxiliaryList; }
const_aux_iterator aux_begin() const { return m_AuxiliaryList.begin(); }
- aux_iterator aux_begin() { return m_AuxiliaryList.begin(); }
- const_aux_iterator aux_end () const { return m_AuxiliaryList.end(); }
- aux_iterator aux_end () { return m_AuxiliaryList.end(); }
+ aux_iterator aux_begin() { return m_AuxiliaryList.begin(); }
+ const_aux_iterator aux_end() const { return m_AuxiliaryList.end(); }
+ aux_iterator aux_end() { return m_AuxiliaryList.end(); }
// ----- exclude libs ----- //
- ExcludeLIBS& excludeLIBS()
- { return m_ExcludeLIBS; }
+ ExcludeLIBS& excludeLIBS() { return m_ExcludeLIBS; }
bool isInExcludeLIBS(const Input& pInput) const;
+ const char* getVersionString() const { return PACKAGE_NAME " " MCLD_VERSION; }
-private:
- enum status {
- YES,
- NO,
- Unknown
- };
+ private:
+ enum status { YES, NO, Unknown };
-private:
+ private:
std::string m_DefaultLDScript;
std::string m_Dyld;
std::string m_SOName;
- int8_t m_Verbose; // --verbose[=0,1,2]
- uint16_t m_MaxErrorNum; // --error-limit=N
- uint16_t m_MaxWarnNum; // --warning-limit=N
- status m_ExecStack; // execstack, noexecstack
- status m_NoUndefined; // defs, --no-undefined
- status m_MulDefs; // muldefs, --allow-multiple-definition
- uint64_t m_CommPageSize; // common-page-size=value
- uint64_t m_MaxPageSize; // max-page-size=value
- bool m_bCombReloc : 1; // combreloc, nocombreloc
- bool m_bInitFirst : 1; // initfirst
- bool m_bInterPose : 1; // interpose
- bool m_bLoadFltr : 1; // loadfltr
- bool m_bNoCopyReloc : 1; // nocopyreloc
- bool m_bNoDefaultLib : 1; // nodefaultlib
- bool m_bNoDelete : 1; // nodelete
- bool m_bNoDLOpen : 1; // nodlopen
- bool m_bNoDump : 1; // nodump
- bool m_bRelro : 1; // relro, norelro
- bool m_bNow : 1; // lazy, now
- bool m_bOrigin : 1; // origin
- bool m_bTrace : 1; // --trace
- bool m_Bsymbolic : 1; // --Bsymbolic
- bool m_Bgroup : 1;
- bool m_bPIE : 1;
- bool m_bColor : 1; // --color[=true,false,auto]
- bool m_bCreateEhFrameHdr : 1; // --eh-frame-hdr
- bool m_bNMagic : 1; // -n, --nmagic
- bool m_bOMagic : 1; // -N, --omagic
- bool m_bStripDebug : 1; // -S, --strip-debug
- bool m_bExportDynamic :1; //-E, --export-dynamic
- bool m_bWarnSharedTextrel : 1; // --warn-shared-textrel
- bool m_bBinaryInput : 1; // -b [input-format], --format=[input-format]
- bool m_bDefineCommon : 1; // -d, -dc, -dp
- bool m_bFatalWarnings : 1; // --fatal-warnings
- bool m_bNewDTags: 1; // --enable-new-dtags
- bool m_bNoStdlib: 1; // -nostdlib
- bool m_bPrintMap: 1; // --print-map
- bool m_bWarnMismatch: 1; // --no-warn-mismatch
- bool m_bGCSections: 1; // --gc-sections
- bool m_bPrintGCSections:1; // --print-gc-sections
- bool m_bGenUnwindInfo: 1; // --ld-generated-unwind-info
- bool m_bPrintICFSections: 1; // --print-icf-sections
+ int8_t m_Verbose; // --verbose[=0,1,2]
+ uint16_t m_MaxErrorNum; // --error-limit=N
+ uint16_t m_MaxWarnNum; // --warning-limit=N
+ status m_ExecStack; // execstack, noexecstack
+ status m_NoUndefined; // defs, --no-undefined
+ status m_MulDefs; // muldefs, --allow-multiple-definition
+ uint64_t m_CommPageSize; // common-page-size=value
+ uint64_t m_MaxPageSize; // max-page-size=value
+ bool m_bCombReloc : 1; // combreloc, nocombreloc
+ bool m_bInitFirst : 1; // initfirst
+ bool m_bInterPose : 1; // interpose
+ bool m_bLoadFltr : 1; // loadfltr
+ bool m_bNoCopyReloc : 1; // nocopyreloc
+ bool m_bNoDefaultLib : 1; // nodefaultlib
+ bool m_bNoDelete : 1; // nodelete
+ bool m_bNoDLOpen : 1; // nodlopen
+ bool m_bNoDump : 1; // nodump
+ bool m_bRelro : 1; // relro, norelro
+ bool m_bNow : 1; // lazy, now
+ bool m_bOrigin : 1; // origin
+ bool m_bTrace : 1; // --trace
+ bool m_Bsymbolic : 1; // --Bsymbolic
+ bool m_Bgroup : 1;
+ bool m_bPIE : 1;
+ bool m_bColor : 1; // --color[=true,false,auto]
+ bool m_bCreateEhFrameHdr : 1; // --eh-frame-hdr
+ bool m_bNMagic : 1; // -n, --nmagic
+ bool m_bOMagic : 1; // -N, --omagic
+ bool m_bStripDebug : 1; // -S, --strip-debug
+ bool m_bExportDynamic : 1; // -E, --export-dynamic
+ bool m_bWarnSharedTextrel : 1; // --warn-shared-textrel
+ bool m_bBinaryInput : 1; // -b [input-format], --format=[input-format]
+ bool m_bDefineCommon : 1; // -d, -dc, -dp
+ bool m_bFatalWarnings : 1; // --fatal-warnings
+ bool m_bNewDTags : 1; // --enable-new-dtags
+ bool m_bNoStdlib : 1; // -nostdlib
+ bool m_bPrintMap : 1; // --print-map
+ bool m_bWarnMismatch : 1; // --no-warn-mismatch
+ bool m_bGCSections : 1; // --gc-sections
+ bool m_bPrintGCSections : 1; // --print-gc-sections
+ bool m_bGenUnwindInfo : 1; // --ld-generated-unwind-info
+ bool m_bPrintICFSections : 1; // --print-icf-sections
ICF m_ICF;
size_t m_ICFIterations;
- uint32_t m_GPSize; // -G, --gpsize
+ uint32_t m_GPSize; // -G, --gpsize
StripSymbolMode m_StripSymbols;
RpathList m_RpathList;
ScriptList m_ScriptList;
- UndefSymList m_UndefSymList; // -u [symbol], --undefined [symbol]
+ UndefSymList m_UndefSymList; // -u [symbol], --undefined [symbol]
unsigned int m_HashStyle;
std::string m_Filter;
AuxiliaryList m_AuxiliaryList;
ExcludeLIBS m_ExcludeLIBS;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_GENERALOPTIONS_H_
diff --git a/include/mcld/IRBuilder.h b/include/mcld/IRBuilder.h
index 7cacb36..b68b8fa 100644
--- a/include/mcld/IRBuilder.h
+++ b/include/mcld/IRBuilder.h
@@ -11,30 +11,27 @@
// with a consistent and simplified interface.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_IRBUILDER_H
-#define MCLD_IRBUILDER_H
-
-#include <mcld/MC/Input.h>
-#include <mcld/MC/InputBuilder.h>
-
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/LDSymbol.h>
-
-#include <mcld/Fragment/Fragment.h>
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/Fragment/FragmentRef.h>
-
-#include <mcld/Support/Path.h>
-#include <mcld/Support/FileHandle.h>
+#ifndef MCLD_IRBUILDER_H_
+#define MCLD_IRBUILDER_H_
+
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/MC/Input.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/Path.h"
namespace mcld {
-class Module;
-class LinkerConfig;
class InputTree;
+class LinkerConfig;
+class Module;
/** \class IRBuilder
* \brief IRBuilder provides an uniform API for creating sections and
@@ -44,38 +41,27 @@ class InputTree;
* language into a system-dependent binary. IRBuilder helps such kind of VMs
* to emit binaries in native object format, such as ELF or MachO.
*/
-class IRBuilder
-{
-public:
- enum ObjectFormat {
- ELF,
- MachO,
- COFF
- };
-
- enum SymbolDefinePolicy {
- Force,
- AsReferred
- };
-
- enum SymbolResolvePolicy {
- Unresolve,
- Resolve
- };
-
-public:
+class IRBuilder {
+ public:
+ enum ObjectFormat { ELF, MachO, COFF };
+
+ enum SymbolDefinePolicy { Force, AsReferred };
+
+ enum SymbolResolvePolicy { Unresolve, Resolve };
+
+ public:
IRBuilder(Module& pModule, const LinkerConfig& pConfig);
~IRBuilder();
const InputBuilder& getInputBuilder() const { return m_InputBuilder; }
- InputBuilder& getInputBuilder() { return m_InputBuilder; }
+ InputBuilder& getInputBuilder() { return m_InputBuilder; }
const Module& getModule() const { return m_Module; }
- Module& getModule() { return m_Module; }
+ Module& getModule() { return m_Module; }
-/// @}
-/// @name Input Files On The Command Line
-/// @{
+ /// @}
+ /// @name Input Files On The Command Line
+ /// @{
/// CreateInput - To create an input file and append it to the input tree.
/// This function is like to add an input file in the command line.
@@ -159,9 +145,9 @@ public:
/// MCLinker to stop adding following archives in the created group.
bool EndGroup();
-/// @}
-/// @name Positional Options On The Command Line
-/// @{
+ /// @}
+ /// @name Positional Options On The Command Line
+ /// @{
/// WholeArchive - Append a --whole-archive option on the command line
///
@@ -217,9 +203,9 @@ public:
/// search archives before shared objects for the following namespec.
void AgainstStatic();
-/// @}
-/// @name Input Methods
-/// @{
+ /// @}
+ /// @name Input Methods
+ /// @{
/// CreateELFHeader - To create and append a section header in the input file
///
@@ -255,7 +241,7 @@ public:
/// @return The created relocation data. If the pSection already has
/// relocation data, or if the pSection's type is not
/// LDFileFormat::Relocation, then an assertion occurs.
- static RelocData* CreateRelocData(LDSection &pSection);
+ static RelocData* CreateRelocData(LDSection& pSection);
/// CreateEhFrame - To create a eh_frame for given pSection
/// @param [in, out] pSection The given LDSection. It can be in either an
@@ -266,6 +252,13 @@ public:
/// assertion occurs.
static EhFrame* CreateEhFrame(LDSection& pSection);
+ /// CreateDebugString - To create a debug_str for given pSection
+ /// @param pSection The given LDSection. It should be the output
+ /// .debug_str section
+ /// pSection.getDebugString() is set to a valid eh_frame.
+ /// @return The created DebugString
+ static DebugString* CreateDebugString(LDSection& pSection);
+
/// CreateBSS - To create a bss section for given pSection
/// @param [in, out] pSection The given LDSection. It can be in either an
/// input or the output.
@@ -432,19 +425,21 @@ public:
/// { Global, Weak, Local, Absolute }
///
/// @return The symbol kept in mcld::Module.
- template<SymbolDefinePolicy POLICY, SymbolResolvePolicy RESOLVE>
- LDSymbol* AddSymbol(const llvm::StringRef& pName,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize = 0,
- LDSymbol::ValueType pValue = 0x0,
- FragmentRef* pFragmentRef = FragmentRef::Null(),
- ResolveInfo::Visibility pVisibility = ResolveInfo::Default);
+ template <SymbolDefinePolicy POLICY, SymbolResolvePolicy RESOLVE>
+ LDSymbol* AddSymbol(
+ const llvm::StringRef& pName,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize = 0,
+ LDSymbol::ValueType pValue = 0x0,
+ FragmentRef * pFragmentRef = FragmentRef::Null(),
+ ResolveInfo::Visibility pVisibility = ResolveInfo::Default);
/// AddRelocation - To add a relocation entry
///
- /// @param [in] pSection The relocation section. pSection's link should point to
+ /// @param [in] pSection The relocation section. pSection's link should point
+ /// to
/// the target section.
/// @param [in] pType The type of the relocation (target dependent)
/// @param [in] pSym The symbol should be the symbol in the input file.
@@ -460,7 +455,7 @@ public:
/// symbols should be force to local symbols
bool shouldForceLocal(const ResolveInfo& pInfo, const LinkerConfig& pConfig);
-private:
+ private:
LDSymbol* addSymbolFromObject(const std::string& pName,
ResolveInfo::Type pType,
ResolveInfo::Desc pDesc,
@@ -479,57 +474,57 @@ private:
LDSymbol::ValueType pValue,
ResolveInfo::Visibility pVisibility);
-private:
+ private:
Module& m_Module;
const LinkerConfig& m_Config;
InputBuilder m_InputBuilder;
};
-template<> LDSymbol*
-IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- const llvm::StringRef& pName,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility);
-
-template<> LDSymbol*
-IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>(
- const llvm::StringRef& pName,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility);
-
-template<> LDSymbol*
-IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- const llvm::StringRef& pName,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility);
-
-template<> LDSymbol*
-IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- const llvm::StringRef& pName,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility);
-
-} // end of namespace mcld
-
-#endif
+template <>
+LDSymbol* IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
+ const llvm::StringRef& pName,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ FragmentRef* pFragmentRef,
+ ResolveInfo::Visibility pVisibility);
+
+template <>
+LDSymbol* IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>(
+ const llvm::StringRef& pName,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ FragmentRef* pFragmentRef,
+ ResolveInfo::Visibility pVisibility);
+
+template <>
+LDSymbol* IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
+ const llvm::StringRef& pName,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ FragmentRef* pFragmentRef,
+ ResolveInfo::Visibility pVisibility);
+
+template <>
+LDSymbol* IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ const llvm::StringRef& pName,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ FragmentRef* pFragmentRef,
+ ResolveInfo::Visibility pVisibility);
+
+} // end of namespace mcld
+
+#endif // MCLD_IRBUILDER_H_
diff --git a/include/mcld/InputTree.h b/include/mcld/InputTree.h
index 687c805..88ad34a 100644
--- a/include/mcld/InputTree.h
+++ b/include/mcld/InputTree.h
@@ -6,45 +6,43 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_INPUTTREE_H
-#define MCLD_INPUTTREE_H
+#ifndef MCLD_INPUTTREE_H_
+#define MCLD_INPUTTREE_H_
-#include <mcld/ADT/BinTree.h>
-#include <mcld/ADT/TypeTraits.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Support/Path.h>
+#include "mcld/ADT/BinTree.h"
+#include "mcld/ADT/TypeTraits.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Support/Path.h"
#include <string>
-
namespace mcld {
-/** \class template<typename Traits, typename Iterator> PolicyIterator<mcld::Input>
+/** \class template<typename Traits, typename Iterator>
+ * PolicyIterator<mcld::Input>
* \brief PolicyIterator<mcld::Input> is a partially specific PolicyIterator
*/
-template<typename Traits, typename IteratorType>
-class PolicyIterator<mcld::Input, Traits, IteratorType> : public PolicyIteratorBase<Input, Traits, IteratorType>
-{
-public:
+template <typename Traits, typename IteratorType>
+class PolicyIterator<mcld::Input, Traits, IteratorType>
+ : public PolicyIteratorBase<Input, Traits, IteratorType> {
+ public:
typedef PolicyIterator<Input, Traits, IteratorType> Self;
typedef PolicyIteratorBase<Input, Traits, IteratorType> Base;
- typedef PolicyIterator<Input, typename Traits::nonconst_traits, IteratorType> iterator;
- typedef PolicyIterator<Input, typename Traits::const_traits, IteratorType> const_iterator;
+ typedef PolicyIterator<Input, typename Traits::nonconst_traits, IteratorType>
+ iterator;
+ typedef PolicyIterator<Input, typename Traits::const_traits, IteratorType>
+ const_iterator;
-public:
- PolicyIterator()
- : Base() {}
+ public:
+ PolicyIterator() : Base() {}
- PolicyIterator(const iterator &X)
- : Base(X.m_pNode) {}
+ PolicyIterator(const iterator& X) : Base(X.m_pNode) {}
- explicit PolicyIterator(NodeBase* X)
- : Base(X) {}
+ explicit PolicyIterator(NodeBase* X) : Base(X) {}
virtual ~PolicyIterator() {}
- bool isGroup() const
- { return !Base::hasData() && !Base::isRoot(); }
+ bool isGroup() const { return !Base::hasData() && !Base::isRoot(); }
Self& operator++() {
IteratorType::advance();
@@ -64,114 +62,109 @@ public:
}
};
-template<>
-class BinaryTree<Input> : public BinaryTreeBase<Input>
-{
-public:
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef Input value_type;
- typedef value_type* pointer;
- typedef value_type& reference;
- typedef const value_type* const_pointer;
- typedef const value_type& const_reference;
-
- typedef BinaryTree<Input> Self;
+template <>
+class BinaryTree<Input> : public BinaryTreeBase<Input> {
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef Input value_type;
+ typedef value_type* pointer;
+ typedef value_type& reference;
+ typedef const value_type* const_pointer;
+ typedef const value_type& const_reference;
+
+ typedef BinaryTree<Input> Self;
typedef TreeIterator<value_type, NonConstTraits<value_type> > iterator;
- typedef TreeIterator<value_type, ConstTraits<value_type> > const_iterator;
-
- typedef PolicyIterator<value_type, NonConstTraits<value_type>, DFSIterator> dfs_iterator;
- typedef PolicyIterator<value_type, ConstTraits<value_type>, DFSIterator> const_dfs_iterator;
- typedef PolicyIterator<value_type, NonConstTraits<value_type>, BFSIterator> bfs_iterator;
- typedef PolicyIterator<value_type, ConstTraits<value_type>, BFSIterator> const_bfs_iterator;
-
-protected:
+ typedef TreeIterator<value_type, ConstTraits<value_type> > const_iterator;
+
+ typedef PolicyIterator<value_type, NonConstTraits<value_type>, DFSIterator>
+ dfs_iterator;
+ typedef PolicyIterator<value_type, ConstTraits<value_type>, DFSIterator>
+ const_dfs_iterator;
+ typedef PolicyIterator<value_type, NonConstTraits<value_type>, BFSIterator>
+ bfs_iterator;
+ typedef PolicyIterator<value_type, ConstTraits<value_type>, BFSIterator>
+ const_bfs_iterator;
+
+ protected:
typedef Node<value_type> node_type;
-public:
+ public:
// ----- constructors and destructor ----- //
- BinaryTree()
- : BinaryTreeBase<Input>()
- { }
+ BinaryTree() : BinaryTreeBase<Input>() {}
- ~BinaryTree() {
- }
+ ~BinaryTree() {}
// ----- iterators ----- //
- bfs_iterator bfs_begin()
- {
- bfs_iterator it = bfs_iterator(BinaryTreeBase<Input>::m_Root.node.left);
- if (it.isGroup())
- ++it;
- return it;
+ bfs_iterator bfs_begin() {
+ bfs_iterator it = bfs_iterator(BinaryTreeBase<Input>::m_Root.node.left);
+ if (it.isGroup())
+ ++it;
+ return it;
}
- bfs_iterator bfs_end()
- { return bfs_iterator(BinaryTreeBase<Input>::m_Root.node.right); }
+ bfs_iterator bfs_end() {
+ return bfs_iterator(BinaryTreeBase<Input>::m_Root.node.right);
+ }
- const_bfs_iterator bfs_begin() const
- {
- const_bfs_iterator it =
- const_bfs_iterator(BinaryTreeBase<Input>::m_Root.node.left);
- if (it.isGroup())
- ++it;
- return it;
+ const_bfs_iterator bfs_begin() const {
+ const_bfs_iterator it =
+ const_bfs_iterator(BinaryTreeBase<Input>::m_Root.node.left);
+ if (it.isGroup())
+ ++it;
+ return it;
}
- const_bfs_iterator bfs_end() const
- { return const_bfs_iterator(BinaryTreeBase<Input>::m_Root.node.right); }
+ const_bfs_iterator bfs_end() const {
+ return const_bfs_iterator(BinaryTreeBase<Input>::m_Root.node.right);
+ }
- dfs_iterator dfs_begin()
- {
+ dfs_iterator dfs_begin() {
dfs_iterator it = dfs_iterator(BinaryTreeBase<Input>::m_Root.node.left);
if (it.isGroup())
++it;
return it;
}
- dfs_iterator dfs_end()
- { return dfs_iterator(BinaryTreeBase<Input>::m_Root.node.right); }
+ dfs_iterator dfs_end() {
+ return dfs_iterator(BinaryTreeBase<Input>::m_Root.node.right);
+ }
- const_dfs_iterator dfs_begin() const
- {
+ const_dfs_iterator dfs_begin() const {
const_dfs_iterator it =
- const_dfs_iterator(BinaryTreeBase<Input>::m_Root.node.left);
+ const_dfs_iterator(BinaryTreeBase<Input>::m_Root.node.left);
if (it.isGroup())
++it;
return it;
}
- const_dfs_iterator dfs_end() const
- { return const_dfs_iterator(BinaryTreeBase<Input>::m_Root.node.right); }
+ const_dfs_iterator dfs_end() const {
+ return const_dfs_iterator(BinaryTreeBase<Input>::m_Root.node.right);
+ }
- iterator root()
- { return iterator(&(BinaryTreeBase<Input>::m_Root.node)); }
+ iterator root() { return iterator(&(BinaryTreeBase<Input>::m_Root.node)); }
- const_iterator root() const
- {
+ const_iterator root() const {
// FIXME: provide the iterater constructors for constant NodeBase instead of
// using const_cast
return const_iterator(
- const_cast<NodeBase*>(&BinaryTreeBase<Input>::m_Root.node));
+ const_cast<NodeBase*>(&BinaryTreeBase<Input>::m_Root.node));
}
- iterator begin()
- {
+ iterator begin() {
iterator it = iterator(BinaryTreeBase<Input>::m_Root.node.left);
return it;
}
- iterator end()
- { return iterator(BinaryTreeBase<Input>::m_Root.node.right); }
+ iterator end() { return iterator(BinaryTreeBase<Input>::m_Root.node.right); }
- const_iterator begin() const
- {
- const_iterator it = const_iterator(BinaryTreeBase<Input>::m_Root.node.left);
- return it;
+ const_iterator begin() const {
+ return const_iterator(BinaryTreeBase<Input>::m_Root.node.left);
}
- const_iterator end() const
- { return const_iterator(BinaryTreeBase<Input>::m_Root.node.right); }
+ const_iterator end() const {
+ return const_iterator(BinaryTreeBase<Input>::m_Root.node.right);
+ }
// ----- modifiers ----- //
/// join - create a leaf node and merge it in the tree.
@@ -179,9 +172,9 @@ public:
// @param DIRECT the direction of the connecting edge of the parent node.
// @param position the parent node
// @param value the value being pushed.
- template<size_t DIRECT>
+ template <size_t DIRECT>
BinaryTree& join(TreeIteratorBase& pPosition, const Input& value) {
- node_type *node = BinaryTreeBase<Input>::createNode();
+ node_type* node = BinaryTreeBase<Input>::createNode();
node->data = const_cast<Input*>(&value);
if (pPosition.isRoot())
@@ -197,15 +190,14 @@ public:
// @param position the parent node
// @param the tree being joined.
// @return the joined tree
- template<size_t DIRECT>
+ template <size_t DIRECT>
BinaryTree& merge(TreeIteratorBase& pPosition, BinaryTree& pTree) {
if (this == &pTree)
return *this;
if (!pTree.empty()) {
pPosition.hook<DIRECT>(pTree.m_Root.node.left);
- BinaryTreeBase<Input>::m_Root.summon(
- pTree.BinaryTreeBase<Input>::m_Root);
+ BinaryTreeBase<Input>::m_Root.summon(pTree.BinaryTreeBase<Input>::m_Root);
BinaryTreeBase<Input>::m_Root.delegate(pTree.m_Root);
pTree.m_Root.node.left = pTree.m_Root.node.right = &pTree.m_Root.node;
}
@@ -221,21 +213,20 @@ public:
*
* @see Input
*/
-class InputTree : public BinaryTree<Input>
-{
-private:
+class InputTree : public BinaryTree<Input> {
+ private:
typedef BinaryTree<Input> BinTreeTy;
-public:
+ public:
enum Direction {
- Inclusive = TreeIteratorBase::Leftward,
+ Inclusive = TreeIteratorBase::Leftward,
Positional = TreeIteratorBase::Rightward
};
- typedef BinaryTree<Input>::iterator iterator;
+ typedef BinaryTree<Input>::iterator iterator;
typedef BinaryTree<Input>::const_iterator const_iterator;
-public:
+ public:
/** \class Mover
* \brief Mover provides the interface for moving iterator forward.
*
@@ -246,7 +237,7 @@ public:
struct Mover {
virtual void connect(TreeIteratorBase& pFrom, NodeBase* pTo) const = 0;
virtual void move(TreeIteratorBase& pNode) const = 0;
- virtual ~Mover() { }
+ virtual ~Mover() {}
};
/** \class Succeeder
@@ -257,9 +248,7 @@ public:
pFrom.hook<Positional>(pTo);
}
- void move(TreeIteratorBase& pNode) const {
- pNode.move<Positional>();
- }
+ void move(TreeIteratorBase& pNode) const { pNode.move<Positional>(); }
};
/** \class Includer
@@ -270,38 +259,30 @@ public:
pFrom.hook<Inclusive>(pTo);
}
- void move(TreeIteratorBase& pNode) const {
- pNode.move<Inclusive>();
- }
+ void move(TreeIteratorBase& pNode) const { pNode.move<Inclusive>(); }
};
-public:
+ public:
static Succeeder Afterward;
- static Includer Downward;
-
-public:
+ static Includer Downward;
+ public:
using BinTreeTy::merge;
// ----- modify ----- //
- template<size_t DIRECT>
+ template <size_t DIRECT>
InputTree& enterGroup(TreeIteratorBase pRoot);
- template<size_t DIRECT>
- InputTree& insert(TreeIteratorBase pRoot,
- Input& pInput);
+ template <size_t DIRECT>
+ InputTree& insert(TreeIteratorBase pRoot, Input& pInput);
InputTree& merge(TreeIteratorBase pRoot,
const Mover& pMover,
InputTree& pTree);
- InputTree& insert(TreeIteratorBase pRoot,
- const Mover& pMover,
- Input& pInput);
-
- InputTree& enterGroup(TreeIteratorBase pRoot,
- const Mover& pMover);
+ InputTree& insert(TreeIteratorBase pRoot, const Mover& pMover, Input& pInput);
+ InputTree& enterGroup(TreeIteratorBase pRoot, const Mover& pMover);
};
bool isGroup(const InputTree::iterator& pos);
@@ -311,15 +292,13 @@ bool isGroup(const InputTree::const_dfs_iterator& pos);
bool isGroup(const InputTree::bfs_iterator& pos);
bool isGroup(const InputTree::const_bfs_iterator& pos);
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// template member functions
//===----------------------------------------------------------------------===//
-template<size_t DIRECT>
-mcld::InputTree&
-mcld::InputTree::enterGroup(mcld::TreeIteratorBase pRoot)
-{
+template <size_t DIRECT>
+mcld::InputTree& mcld::InputTree::enterGroup(mcld::TreeIteratorBase pRoot) {
BinTreeTy::node_type* node = createNode();
if (pRoot.isRoot())
@@ -330,10 +309,9 @@ mcld::InputTree::enterGroup(mcld::TreeIteratorBase pRoot)
return *this;
}
-template<size_t DIRECT>
+template <size_t DIRECT>
mcld::InputTree& mcld::InputTree::insert(mcld::TreeIteratorBase pRoot,
- mcld::Input& pInput)
-{
+ mcld::Input& pInput) {
BinTreeTy::node_type* node = createNode();
node->data = &pInput;
@@ -345,5 +323,4 @@ mcld::InputTree& mcld::InputTree::insert(mcld::TreeIteratorBase pRoot,
return *this;
}
-#endif
-
+#endif // MCLD_INPUTTREE_H_
diff --git a/include/mcld/LD/Archive.h b/include/mcld/LD/Archive.h
index 34fc9cf..db333cb 100644
--- a/include/mcld/LD/Archive.h
+++ b/include/mcld/LD/Archive.h
@@ -6,41 +6,39 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_ARCHIVE_H
-#define MCLD_LD_ARCHIVE_H
+#ifndef MCLD_LD_ARCHIVE_H_
+#define MCLD_LD_ARCHIVE_H_
-#include <mcld/InputTree.h>
-#include <mcld/ADT/HashEntry.h>
-#include <mcld/ADT/HashTable.h>
-#include <mcld/ADT/StringHash.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/InputTree.h"
+#include "mcld/ADT/HashEntry.h"
+#include "mcld/ADT/HashTable.h"
+#include "mcld/ADT/StringHash.h"
+#include "mcld/Support/GCFactory.h"
-#include <vector>
#include <string>
+#include <vector>
namespace mcld {
class Input;
-class InputFactory;
class InputBuilder;
+class InputFactory;
/** \class Archive
* \brief This class define the interfacee to Archive files
*/
-class Archive
-{
-public:
- static const char MAGIC[]; ///< magic string
- static const char THIN_MAGIC[]; ///< magic of thin archive
- static const size_t MAGIC_LEN; ///< length of magic string
- static const char SVR4_SYMTAB_NAME[]; ///< SVR4 symtab entry name
- static const char IRIX6_SYMTAB_NAME[]; ///< Irix6 symtab entry name
- static const char STRTAB_NAME[]; ///< Name of string table
- static const char PAD[]; ///< inter-file align padding
- static const char MEMBER_MAGIC[]; ///< fmag field magic #
-
- struct MemberHeader
- {
+class Archive {
+ public:
+ static const char MAGIC[]; ///< magic string
+ static const char THIN_MAGIC[]; ///< magic of thin archive
+ static const size_t MAGIC_LEN; ///< length of magic string
+ static const char SVR4_SYMTAB_NAME[]; ///< SVR4 symtab entry name
+ static const char IRIX6_SYMTAB_NAME[]; ///< Irix6 symtab entry name
+ static const char STRTAB_NAME[]; ///< Name of string table
+ static const char PAD[]; ///< inter-file align padding
+ static const char MEMBER_MAGIC[]; ///< fmag field magic #
+
+ struct MemberHeader {
char name[16]; ///< Name of the file member.
char date[12]; ///< File date, decimal seconds since Epoch
char uid[6]; ///< user id in ASCII decimal
@@ -50,18 +48,14 @@ public:
char fmag[2]; ///< Always contains ARFILE_MAGIC_TERMINATOR
};
-private:
- template<typename OFFSET_TYPE>
- struct OffsetCompare
- {
- bool operator()(OFFSET_TYPE X, OFFSET_TYPE Y) const
- { return (X == Y); }
+ private:
+ template <typename OFFSET_TYPE>
+ struct OffsetCompare {
+ bool operator()(OFFSET_TYPE X, OFFSET_TYPE Y) const { return (X == Y); }
};
- struct MurmurHash3
- {
- size_t operator()(uint32_t pKey) const
- {
+ struct MurmurHash3 {
+ size_t operator()(uint32_t pKey) const {
pKey ^= pKey >> 16;
pKey *= 0x85ebca6b;
pKey ^= pKey >> 13;
@@ -71,51 +65,41 @@ private:
}
};
- typedef HashEntry<uint32_t,
- InputTree::iterator,
- OffsetCompare<uint32_t> > ObjectMemberEntryType;
-public:
+ typedef HashEntry<uint32_t, InputTree::iterator, OffsetCompare<uint32_t> >
+ ObjectMemberEntryType;
+
+ public:
typedef HashTable<ObjectMemberEntryType,
MurmurHash3,
EntryFactory<ObjectMemberEntryType> > ObjectMemberMapType;
- struct ArchiveMember
- {
+ struct ArchiveMember {
Input* file;
InputTree::iterator lastPos;
InputTree::Mover* move;
};
-private:
+ private:
typedef HashEntry<const llvm::StringRef,
ArchiveMember,
- hash::StringCompare<llvm::StringRef> > ArchiveMemberEntryType;
+ hash::StringCompare<llvm::StringRef> >
+ ArchiveMemberEntryType;
-public:
+ public:
typedef HashTable<ArchiveMemberEntryType,
hash::StringHash<hash::DJB>,
EntryFactory<ArchiveMemberEntryType> > ArchiveMemberMapType;
- struct Symbol
- {
- public:
- enum Status
- {
- Include,
- Exclude,
- Unknown
- };
-
- Symbol(const char* pName,
- uint32_t pOffset,
- enum Status pStatus)
- : name(pName), fileOffset(pOffset), status(pStatus)
- {}
-
- ~Symbol()
- {}
-
- public:
+ struct Symbol {
+ public:
+ enum Status { Include, Exclude, Unknown };
+
+ Symbol(const char* pName, uint32_t pOffset, enum Status pStatus)
+ : name(pName), fileOffset(pOffset), status(pStatus) {}
+
+ ~Symbol() {}
+
+ public:
std::string name;
uint32_t fileOffset;
enum Status status;
@@ -123,7 +107,7 @@ public:
typedef std::vector<Symbol*> SymTabType;
-public:
+ public:
Archive(Input& pInputFile, InputBuilder& pBuilder);
~Archive();
@@ -198,10 +182,9 @@ public:
/// addSymbol - add a symtab entry to symtab
/// @param pName - symbol name
/// @param pFileOffset - file offset in symtab represents a object file
- void
- addSymbol(const char* pName,
- uint32_t pFileOffset,
- enum Symbol::Status pStatus = Archive::Symbol::Unknown);
+ void addSymbol(const char* pName,
+ uint32_t pFileOffset,
+ enum Symbol::Status pStatus = Archive::Symbol::Unknown);
/// getSymbolName - get the symbol name with the given index
const std::string& getSymbolName(size_t pSymIdx) const;
@@ -236,12 +219,12 @@ public:
const sys::fs::Path& pPath,
off_t pFileOffset = 0);
-private:
+ private:
typedef GCFactory<Symbol, 0> SymbolFactory;
-private:
+ private:
Input& m_ArchiveFile;
- InputTree *m_pInputTree;
+ InputTree* m_pInputTree;
ObjectMemberMapType m_ObjectMemberMap;
ArchiveMemberMapType m_ArchiveMemberMap;
SymbolFactory m_SymbolFactory;
@@ -251,7 +234,6 @@ private:
InputBuilder& m_Builder;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ARCHIVE_H_
diff --git a/include/mcld/LD/ArchiveReader.h b/include/mcld/LD/ArchiveReader.h
index 6f2ce12..6e15872 100644
--- a/include/mcld/LD/ArchiveReader.h
+++ b/include/mcld/LD/ArchiveReader.h
@@ -6,15 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_ARCHIVEREADER_H
-#define MCLD_LD_ARCHIVEREADER_H
-#include <mcld/LD/LDReader.h>
+#ifndef MCLD_LD_ARCHIVEREADER_H_
+#define MCLD_LD_ARCHIVEREADER_H_
+#include "mcld/LD/LDReader.h"
-namespace mcld
-{
+namespace mcld {
-class LinkerConfig;
class Archive;
+class LinkerConfig;
/** \class ArchiveReader
* \brief ArchiveReader provides an common interface for all archive readers.
@@ -26,16 +25,14 @@ class Archive;
* 3. All archive headers are the same size.
*/
-class ArchiveReader : public LDReader
-{
-public:
+class ArchiveReader : public LDReader {
+ public:
ArchiveReader();
virtual ~ArchiveReader();
virtual bool readArchive(const LinkerConfig& pConfig, Archive& pArchive) = 0;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ARCHIVEREADER_H_
diff --git a/include/mcld/LD/BSDArchiveReader.h b/include/mcld/LD/BSDArchiveReader.h
index 8ba12cf..3b28bde 100644
--- a/include/mcld/LD/BSDArchiveReader.h
+++ b/include/mcld/LD/BSDArchiveReader.h
@@ -6,32 +6,29 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_BSDARCHIVEREADER_H
-#define MCLD_LD_BSDARCHIVEREADER_H
-#include <mcld/LD/ArchiveReader.h>
+#ifndef MCLD_LD_BSDARCHIVEREADER_H_
+#define MCLD_LD_BSDARCHIVEREADER_H_
+#include "mcld/LD/ArchiveReader.h"
-namespace mcld
-{
+namespace mcld {
-class Input;
class Archive;
+class Input;
class LinkerConfig;
/** \class BSDArchiveReader
* \brief BSDArchiveReader reads BSD-variant archive files.
*
*/
-class BSDArchiveReader : public ArchiveReader
-{
-public:
+class BSDArchiveReader : public ArchiveReader {
+ public:
BSDArchiveReader();
~BSDArchiveReader();
bool readArchive(const LinkerConfig& pConfig, Archive& pArchive);
- bool isMyFormat(Input& pInput, bool &pContinue) const;
+ bool isMyFormat(Input& pInput, bool& pContinue) const;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_BSDARCHIVEREADER_H_
diff --git a/include/mcld/LD/BinaryReader.h b/include/mcld/LD/BinaryReader.h
index 26dab6f..09e5b27 100644
--- a/include/mcld/LD/BinaryReader.h
+++ b/include/mcld/LD/BinaryReader.h
@@ -6,31 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_BINARYREADER_H
-#define MCLD_LD_BINARYREADER_H
+#ifndef MCLD_LD_BINARYREADER_H_
+#define MCLD_LD_BINARYREADER_H_
#include "mcld/LD/LDReader.h"
namespace mcld {
-class Module;
class Input;
/** \class BinaryReader
* \brief BinaryReader provides an common interface for different Binary
* formats.
*/
-class BinaryReader : public LDReader
-{
-public:
+class BinaryReader : public LDReader {
+ public:
virtual ~BinaryReader() = 0;
- virtual bool isMyFormat(Input& pInput, bool &pContinue) const
- { pContinue = true; return false; }
+ virtual bool isMyFormat(Input& pInput, bool& pContinue) const {
+ pContinue = true;
+ return false;
+ }
virtual bool readBinary(Input& pFile) = 0;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_BINARYREADER_H_
diff --git a/include/mcld/LD/BranchIsland.h b/include/mcld/LD/BranchIsland.h
index 8733ddb..c57e5fb 100644
--- a/include/mcld/LD/BranchIsland.h
+++ b/include/mcld/LD/BranchIsland.h
@@ -6,32 +6,33 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_BRANCHISLAND_H
-#define MCLD_LD_BRANCHISLAND_H
-
-#include <mcld/ADT/HashEntry.h>
-#include <mcld/ADT/HashTable.h>
-#include <mcld/ADT/StringHash.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Fragment/FragmentRef.h>
-#include <mcld/Fragment/Stub.h>
+#ifndef MCLD_LD_BRANCHISLAND_H_
+#define MCLD_LD_BRANCHISLAND_H_
+
+#include "mcld/ADT/HashEntry.h"
+#include "mcld/ADT/HashTable.h"
+#include "mcld/ADT/StringHash.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/LDSymbol.h"
+
#include <llvm/Support/DataTypes.h>
#include <llvm/ADT/StringRef.h>
+
#include <string>
namespace mcld {
-class Stub;
class Relocation;
+class Stub;
/** \class BranchIsland
* \brief BranchIsland is a collection of stubs
*
*/
-class BranchIsland
-{
-public:
+class BranchIsland {
+ public:
typedef SectionData::iterator iterator;
typedef SectionData::const_iterator const_iterator;
@@ -39,7 +40,7 @@ public:
typedef RelocationListType::iterator reloc_iterator;
typedef RelocationListType::const_iterator const_reloc_iterator;
-public:
+ public:
/*
* ----------
* --- Entry -> | Island | -> Exit ---
@@ -64,17 +65,13 @@ public:
const_iterator end() const;
/// relocation iterators of the island
- reloc_iterator reloc_begin()
- { return m_Relocations.begin(); }
+ reloc_iterator reloc_begin() { return m_Relocations.begin(); }
- const_reloc_iterator reloc_begin() const
- { return m_Relocations.begin(); }
+ const_reloc_iterator reloc_begin() const { return m_Relocations.begin(); }
- reloc_iterator reloc_end()
- { return m_Relocations.end(); }
+ reloc_iterator reloc_end() { return m_Relocations.end(); }
- const_reloc_iterator reloc_end() const
- { return m_Relocations.end(); }
+ const_reloc_iterator reloc_end() const { return m_Relocations.end(); }
/// observers
uint64_t offset() const;
@@ -97,47 +94,38 @@ public:
/// addRelocation - add a relocation into island
bool addRelocation(Relocation& pReloc);
-private:
+ private:
/** \class Key
* \brief Key to recognize a stub in the island.
*
*/
- class Key
- {
- public:
+ class Key {
+ public:
Key(const Stub* pPrototype, const LDSymbol* pSymbol, Stub::SWord pAddend)
- : m_pPrototype(pPrototype), m_pSymbol(pSymbol), m_Addend(pAddend)
- { }
+ : m_pPrototype(pPrototype), m_pSymbol(pSymbol), m_Addend(pAddend) {}
- ~Key()
- { }
+ ~Key() {}
- const Stub* prototype() const { return m_pPrototype; }
+ const Stub* prototype() const { return m_pPrototype; }
const LDSymbol* symbol() const { return m_pSymbol; }
- Stub::SWord addend() const { return m_Addend; }
+ Stub::SWord addend() const { return m_Addend; }
- struct Hash
- {
- size_t operator() (const Key& KEY) const
- {
+ struct Hash {
+ size_t operator()(const Key& KEY) const {
llvm::StringRef sym_name(KEY.symbol()->name());
hash::StringHash<hash::DJB> str_hasher;
- return (size_t((uintptr_t)KEY.prototype())) ^
- str_hasher(sym_name) ^
+ return (size_t((uintptr_t)KEY.prototype())) ^ str_hasher(sym_name) ^
KEY.addend();
}
};
- struct Compare
- {
- bool operator() (const Key& KEY1, const Key& KEY2) const
- {
+ struct Compare {
+ bool operator()(const Key& KEY1, const Key& KEY2) const {
bool res = false;
if ((KEY1.prototype() == KEY2.prototype()) &&
(KEY1.addend() == KEY2.addend())) {
-
if (KEY1.symbol() == KEY2.symbol()) {
res = true;
} else {
@@ -156,7 +144,7 @@ private:
}
};
- private:
+ private:
const Stub* m_pPrototype;
const LDSymbol* m_pSymbol;
Stub::SWord m_Addend;
@@ -164,13 +152,13 @@ private:
typedef HashEntry<Key, Stub*, Key::Compare> StubEntryType;
- typedef HashTable<StubEntryType,
- Key::Hash,
- EntryFactory<StubEntryType> > StubMapType;
-private:
- Fragment& m_Entry; // entry fragment of the island
- Fragment* m_pExit; // exit fragment of the island
- Fragment* m_pRear; // rear fragment of the island
+ typedef HashTable<StubEntryType, Key::Hash, EntryFactory<StubEntryType> >
+ StubMapType;
+
+ private:
+ Fragment& m_Entry; // entry fragment of the island
+ Fragment* m_pExit; // exit fragment of the island
+ Fragment* m_pRear; // rear fragment of the island
size_t m_MaxSize;
std::string m_Name;
StubMapType m_StubMap;
@@ -178,7 +166,6 @@ private:
RelocationListType m_Relocations;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_BRANCHISLAND_H_
diff --git a/include/mcld/LD/BranchIslandFactory.h b/include/mcld/LD/BranchIslandFactory.h
index 61a13ad..575d40f 100644
--- a/include/mcld/LD/BranchIslandFactory.h
+++ b/include/mcld/LD/BranchIslandFactory.h
@@ -6,15 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_BRANCHISLANDFACTORY_H
-#define MCLD_LD_BRANCHISLANDFACTORY_H
+#ifndef MCLD_LD_BRANCHISLANDFACTORY_H_
+#define MCLD_LD_BRANCHISLANDFACTORY_H_
+
+#include "mcld/LD/BranchIsland.h"
+#include "mcld/Support/GCFactory.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Support/GCFactory.h>
-#include <mcld/LD/BranchIsland.h>
-namespace mcld
-{
+namespace mcld {
class Fragment;
class Module;
@@ -23,9 +23,8 @@ class Module;
* \brief
*
*/
-class BranchIslandFactory : public GCFactory<BranchIsland, 0>
-{
-public:
+class BranchIslandFactory : public GCFactory<BranchIsland, 0> {
+ public:
/// ctor
/// @param pMaxFwdBranchRange - the max forward branch range of the target
/// @param pMaxBwdBranchRange - the max backward branch range of the target
@@ -50,13 +49,12 @@ public:
/// @return - return the pair of <fwd island, bwd island>
std::pair<BranchIsland*, BranchIsland*> getIslands(const Fragment& pFragment);
-private:
+ private:
int64_t m_MaxFwdBranchRange;
int64_t m_MaxBwdBranchRange;
size_t m_MaxIslandSize;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_BRANCHISLANDFACTORY_H_
diff --git a/include/mcld/LD/DWARFLineInfo.h b/include/mcld/LD/DWARFLineInfo.h
index 6152437..21f3345 100644
--- a/include/mcld/LD/DWARFLineInfo.h
+++ b/include/mcld/LD/DWARFLineInfo.h
@@ -6,23 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_DWARFLINEINFO_H
-#define MCLD_LD_DWARFLINEINFO_H
-#include <mcld/LD/DiagnosticLineInfo.h>
+#ifndef MCLD_LD_DWARFLINEINFO_H_
+#define MCLD_LD_DWARFLINEINFO_H_
+#include "mcld/LD/DiagnosticLineInfo.h"
-namespace mcld
-{
+namespace mcld {
/** \class DWARFLineInfo
* \brief DWARFLineInfo provides the conversion from address to line of code
* by DWARF format.
*/
-class DWARFLineInfo : public DiagnosticLineInfo
-{
+class DWARFLineInfo : public DiagnosticLineInfo {};
-};
-
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_DWARFLINEINFO_H_
diff --git a/include/mcld/LD/DebugString.h b/include/mcld/LD/DebugString.h
new file mode 100644
index 0000000..ada8975
--- /dev/null
+++ b/include/mcld/LD/DebugString.h
@@ -0,0 +1,65 @@
+//===- DebugString.h ------------------------------------------------------===//
+//
+// The MCLinker Project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#ifndef MCLD_LD_DEBUGSTRING_H_
+#define MCLD_LD_DEBUGSTRING_H_
+
+#include "mcld/LD/MergedStringTable.h"
+
+#include <vector>
+
+namespace mcld {
+
+class LDSection;
+class Relocation;
+class TargetLDBackend;
+
+/** \class DebugString
+ * \brief DebugString represents the output debug section .debug_str
+ */
+class DebugString {
+ public:
+ DebugString()
+ : m_pSection(NULL) {}
+
+ static DebugString* Create(LDSection& pSection);
+
+ /// merge - process the strings in the given input .debug_str section and add
+ /// those strings into merged string map
+ void merge(LDSection& pSection);
+
+ /// computeOffsetSize - set up the output offset of each strings and the
+ /// section size
+ /// @return string table size
+ size_t computeOffsetSize();
+
+ /// applyOffset - apply the relocation which refer to debug string. This
+ /// should be called after finalizeStringsOffset()
+ void applyOffset(Relocation& pReloc, TargetLDBackend& pBackend);
+
+ /// emit - emit the section .debug_str
+ void emit(MemoryRegion& pRegion);
+
+ void setOutputSection(LDSection& pSection)
+ { m_pSection = &pSection; }
+
+ /// ---- observers ----- ///
+ const LDSection* getSection() const { return m_pSection; }
+ LDSection* getSection() { return m_pSection; }
+
+ private:
+ /// m_Section - the output LDSection of this .debug_str
+ LDSection* m_pSection;
+
+ MergedStringTable m_StringTable;
+};
+
+} // namespace mcld
+
+#endif // MCLD_LD_DEBUGSTRING_H_
+
diff --git a/include/mcld/LD/DiagAttribute.inc b/include/mcld/LD/DiagAttribute.inc
index 453ae65..b6ce546 100644
--- a/include/mcld/LD/DiagAttribute.inc
+++ b/include/mcld/LD/DiagAttribute.inc
@@ -1,19 +1,75 @@
// General
-DIAG(warn_unsupported_attribute_section_format, DiagnosticEngine::Warning, "unsupported format of attribute section in input %0 (version=%1).", "unsupported format of attribute section in input %0 (version=%1).")
-DIAG(warn_unrecognized_vendor_subsection, DiagnosticEngine::Warning, "skip unrecognized private vendor subsection with name '%0' in %1.", "skip unrecognized private vendor subsection with name '%0' in %1.")
+DIAG(warn_unsupported_attribute_section_format,
+ DiagnosticEngine::Warning,
+ "unsupported format of attribute section in input %0 (version=%1).",
+ "unsupported format of attribute section in input %0 (version=%1).")
+DIAG(warn_unrecognized_vendor_subsection,
+ DiagnosticEngine::Warning,
+ "skip unrecognized private vendor subsection with name '%0' in %1.",
+ "skip unrecognized private vendor subsection with name '%0' in %1.")
// ARM attributes
-DIAG(error_unknown_cpu_arch, DiagnosticEngine::Error, "input %0 has unknown CPU architecture profile.", "input %0 has unknown CPU architecture profile.")
-DIAG(warn_mismatch_cpu_arch_profile, DiagnosticEngine::Warning, "conflicting architecture profiles %0 in %1.", "conflicting architecture profiles %0 in %1.")
-DIAG(error_mismatch_mpextension_use, DiagnosticEngine::Error, "conflicting values from Tag_MPextension_use and Tag_MPextension_use_legacy in %0", "conflicting values from Tag_MPextension_use and Tag_MPextension_use_legacy in %0")
-DIAG(warn_mismatch_enum_size, DiagnosticEngine::Warning, "the size of enumerated data item in input %0 (value=%1) is not compatible with the output (value=%2).", "the size of enumerated data item in input %0 (value=%1) is not compatible with the output (value=%2).")
-DIAG(warn_mismatch_fp16_format, DiagnosticEngine::Warning, "conflicting 16-bit FP number format in %0", "conflicting 16-bit FP number format in %0")
-DIAG(warn_unrecognized_virtualization_use, DiagnosticEngine::Warning, "value of Tag_Virtualization_use cannot be recognized in %0 (value=%1).", "value of Tag_Virtualization_use cannot be recognized in %0 (value=%1).")
-DIAG(warn_mismatch_abi_wmmx_args, DiagnosticEngine::Warning, "%0 uses different way to pass WMMX parameters and results.", "%0 uses different way to pass WMMX parameters and results.")
-DIAG(warn_mismatch_pcs_config, DiagnosticEngine::Warning, "conflicting procedure call standard config in input %0.", "conflicting procedure call standard config in input %0.")
-DIAG(warn_mismatch_r9_use, DiagnosticEngine::Warning, "conflicting way to use R9 in input %0.", "conflicting way to use R9 in input %0.")
-DIAG(warn_conflict_rw_data_and_r9, DiagnosticEngine::Warning, "RW static data addressing (SB-relative) conflicts the use of R9 (Tag_ABI_PCS_R9_use) in input %0.", "RW static data addressing (SB-relative) conflicts the use of R9 (Tag_ABI_PCS_R9_use) in input %0.")
-DIAG(warn_mismatch_wchar_size, DiagnosticEngine::Warning, "incompatible size of wchar_t in input %0 (value=%1) with the output (value=%2).", "incompatible size of wchar_t in input %0 (value=%1) with the output (value=%2).")
-DIAG(warn_unknown_mandatory_attribute, DiagnosticEngine::Warning, "unknown mandatory attribute with tag %0 was ignored in %1.", "unknown mandatory attribute with tag %0 was ignored in %1.")
-DIAG(warn_unknown_attribute, DiagnosticEngine::Warning, "unknown attribute with tag %0 was ignored in %1.", "unknown attribute with tag %0 was ignored in %1.")
-DIAG(warn_mismatch_vfp_args, DiagnosticEngine::Warning, "%0 uses different way to pass the floating point parameter and results.", "%0 uses different way to pass the floating point parameter and results.")
+DIAG(error_unknown_cpu_arch,
+ DiagnosticEngine::Error,
+ "input %0 has unknown CPU architecture profile.",
+ "input %0 has unknown CPU architecture profile.")
+DIAG(warn_mismatch_cpu_arch_profile,
+ DiagnosticEngine::Warning,
+ "conflicting architecture profiles %0 in %1.",
+ "conflicting architecture profiles %0 in %1.")
+DIAG(error_mismatch_mpextension_use,
+ DiagnosticEngine::Error,
+ "conflicting values from Tag_MPextension_use and "
+ "Tag_MPextension_use_legacy in %0",
+ "conflicting values from Tag_MPextension_use and "
+ "Tag_MPextension_use_legacy in %0")
+DIAG(warn_mismatch_enum_size,
+ DiagnosticEngine::Warning,
+ "the size of enumerated data item in input %0 (value=%1) is not "
+ "compatible with the output (value=%2).",
+ "the size of enumerated data item in input %0 (value=%1) is not "
+ "compatible with the output (value=%2).")
+DIAG(warn_mismatch_fp16_format,
+ DiagnosticEngine::Warning,
+ "conflicting 16-bit FP number format in %0",
+ "conflicting 16-bit FP number format in %0")
+DIAG(warn_unrecognized_virtualization_use,
+ DiagnosticEngine::Warning,
+ "value of Tag_Virtualization_use cannot be recognized in %0 (value=%1).",
+ "value of Tag_Virtualization_use cannot be recognized in %0 (value=%1).")
+DIAG(warn_mismatch_abi_wmmx_args,
+ DiagnosticEngine::Warning,
+ "%0 uses different way to pass WMMX parameters and results.",
+ "%0 uses different way to pass WMMX parameters and results.")
+DIAG(warn_mismatch_pcs_config,
+ DiagnosticEngine::Warning,
+ "conflicting procedure call standard config in input %0.",
+ "conflicting procedure call standard config in input %0.")
+DIAG(warn_mismatch_r9_use,
+ DiagnosticEngine::Warning,
+ "conflicting way to use R9 in input %0.",
+ "conflicting way to use R9 in input %0.")
+DIAG(warn_conflict_rw_data_and_r9,
+ DiagnosticEngine::Warning,
+ "RW static data addressing (SB-relative) conflicts the use of R9 "
+ "(Tag_ABI_PCS_R9_use) in input %0.",
+ "RW static data addressing (SB-relative) conflicts the use of R9 "
+ "(Tag_ABI_PCS_R9_use) in input %0.")
+DIAG(warn_mismatch_wchar_size,
+ DiagnosticEngine::Warning,
+ "incompatible size of wchar_t in input %0 (value=%1) with the output "
+ "(value=%2).",
+ "incompatible size of wchar_t in input %0 (value=%1) with the output "
+ "(value=%2).")
+DIAG(warn_unknown_mandatory_attribute,
+ DiagnosticEngine::Warning,
+ "unknown mandatory attribute with tag %0 was ignored in %1.",
+ "unknown mandatory attribute with tag %0 was ignored in %1.")
+DIAG(warn_unknown_attribute,
+ DiagnosticEngine::Warning,
+ "unknown attribute with tag %0 was ignored in %1.",
+ "unknown attribute with tag %0 was ignored in %1.")
+DIAG(warn_mismatch_vfp_args,
+ DiagnosticEngine::Warning,
+ "%0 uses different way to pass the floating point parameter and results.",
+ "%0 uses different way to pass the floating point parameter and results.")
diff --git a/include/mcld/LD/DiagCommonKinds.inc b/include/mcld/LD/DiagCommonKinds.inc
index 6bb1461..f673c78 100644
--- a/include/mcld/LD/DiagCommonKinds.inc
+++ b/include/mcld/LD/DiagCommonKinds.inc
@@ -1,54 +1,221 @@
-DIAG(err_cannot_open_input, DiagnosticEngine::Error, "can not open input file `%0': %1", "can not open input file `%0' : %1")
-DIAG(err_cannot_open_output_file, DiagnosticEngine::Fatal, "cannot open output file `%0': %1", "cannot open output file `%0': %1")
-DIAG(warn_cannot_open_search_dir, DiagnosticEngine::Warning, "can not open search directory `-L%0'", "can not open search directory `-L%0'")
+DIAG(err_cannot_open_input,
+ DiagnosticEngine::Error,
+ "can not open input file `%0': %1",
+ "can not open input file `%0' : %1")
+DIAG(err_cannot_open_output_file,
+ DiagnosticEngine::Fatal,
+ "cannot open output file `%0': %1",
+ "cannot open output file `%0': %1")
+DIAG(warn_cannot_open_search_dir,
+ DiagnosticEngine::Warning,
+ "can not open search directory `-L%0'",
+ "can not open search directory `-L%0'")
DIAG(err_no_inputs, DiagnosticEngine::Error, "no inputs", "no inputs")
-DIAG(err_empty_input, DiagnosticEngine::Error, "Empty input file `%0' : %1", "Empty input file `%0' : %1")
-DIAG(warn_unrecognized_input_file, DiagnosticEngine::Warning, "cannot recognize the format of file `%0'.\n object format or given target machine (%1) is incompatible.","cannot recognize the format of file `%0'.\n object format or given target machine (%1) is incompatible.")
-DIAG(err_cannot_find_namespec, DiagnosticEngine::Fatal, "cannot recognize namespec -l%0", "cannot recognize namespec -l%0")
-DIAG(err_cannot_identify_option, DiagnosticEngine::Fatal, "unknown command line argument `%0' at %1", "unknown command line argument `%0' at %1")
-DIAG(err_mixed_shared_static_objects, DiagnosticEngine::Error, "cannot link shared objects with -static option.\nShared object `%0': %1", "cannot link shared objects with -static option.\nShared object `%0': %1")
-DIAG(unrecognized_output_file, DiagnosticEngine::Unreachable, "unsupported output file format: `%0'", "unsupported output file format: `%0'")
-DIAG(unrecognized_output_sectoin, DiagnosticEngine::Unreachable, "Unable to emit section `%0'\nPlease report to `%1'", "Unable to emit section `%0'\nPlease report to `%1'")
-DIAG(duplicated_wrap, DiagnosticEngine::Warning, "wrapped symbol `%0' had been claimed", "wrapped symbol `%0' had been claimed")
-DIAG(rewrap, DiagnosticEngine::Warning, "There are duplicated --wrap `%0' on the command line\nsymbol `%1' had been claimed", "There are duplicated --wrap `%0' on the command line]\nsymbol `%1' had been claimed.")
-DIAG(err_cannot_read_symbol, DiagnosticEngine::Fatal, "can not read symbol[%0] in file %1", "can not read symbol[%0] in file %1")
-DIAG(err_cannot_read_section, DiagnosticEngine::Fatal, "can not read section `%0'.", "can not read section `%0'.")
-DIAG(err_cannot_read_target_section, DiagnosticEngine::Fatal, "can not read target-dependent section `%0'.", "can not read target-dependent section `%0'.")
-DIAG(err_cannot_read_relocated_section, DiagnosticEngine::Fatal, "can not read the section being relocated in file %0.\ninvalid sh_info: %1\nrelocation section: %2", "can not read the section being relocated in file %0.\ninvalid sh_info: %1\nrelocation section: %2")
-DIAG(err_unsupported_section, DiagnosticEngine::Fatal, "unsupported section `%0' (type %1)", "unsupported section `%0' (type %1)")
-DIAG(unreachable_invalid_section_idx, DiagnosticEngine::Unreachable, "section[%0] is invalid in file %1", "section[%0] is invalid in file %1")
-DIAG(err_unsupported_whole_archive, DiagnosticEngine::Error, "Target does not support --whole-archive", "Target does not support --whole-archive")
-DIAG(err_unsupported_as_needed, DiagnosticEngine::Error, "Target does not support --as-needed", "Target does not support --as-needed")
-DIAG(err_unsupported_add_needed, DiagnosticEngine::Error, "Target doest not support --add-needed", "Target does not support --add-needed")
-DIAG(err_unsupported_Bdynamic, DiagnosticEngine::Error, "Target does not support --Bdynamic", "Target does not support --Bdynamic")
-DIAG(err_enable_as_needed_on_static_system, DiagnosticEngine::Warning, "can not enable --as-needed on the target which does not support shared objects", "can not enable --as-needed on the target which does not support shared objects")
-DIAG(err_mix_static_as_needed, DiagnosticEngine::Warning, "cannot mix --static with --as-needed", "cannot mix --static with --as-needed")
-DIAG(err_cannot_change_file_size, DiagnosticEngine::Error, "cannot truncate file `%0' to size %1", "cannot truncate ffile `%0' to size %1")
-DIAG(err_cannot_open_file, DiagnosticEngine::Error, "cannot open file `%0': %1.", "cannot open file `%0': %1.")
-DIAG(err_cannot_close_file, DiagnosticEngine::Error, "cannot close file `%0': %1.", "cannot close file `%0': %1.")
-DIAG(err_cannot_read_file, DiagnosticEngine::Error, "cannot read file %0 from offset %1 to length %2.", "cannot read file %0 from offset %1 to length %2.")
-DIAG(err_cannot_read_small_file, DiagnosticEngine::Fatal, "file %0 is too small to read.\n file size is %1.\n read from %2.", "file %0 is too small to read.\n file size is %1.\n read from %2.")
-DIAG(err_cannot_mmap_file, DiagnosticEngine::Error, "cannot open memory mapped file %0 from offset %1 to length %2.", "cannot open memoory mpped file %0 from offset %1 to length %2.")
-DIAG(err_cannot_munmap_file, DiagnosticEngine::Error, "cannot remove the mapped memory of file %0.", "cannot remove the mapped memory of file %0.")
-DIAG(err_cannot_write_file, DiagnosticEngine::Error, "cannot write file %0 from offset %1 to length %2.", "cannot write file %0 from offset %1 to length %2.")
-DIAG(warn_illegal_input_section, DiagnosticEngine::Warning, "section `%0' should not appear in input file `%1': %2", "section `%0' should not appear in input file `%1': %2")
-DIAG(err_cannot_trace_file, DiagnosticEngine::Unreachable, "cannot identify the type (%0) of input file `%1'.\n %2", "cannot identify the type (%0) of input file `%1'.\n %2")
-DIAG(err_out_of_range_region, DiagnosticEngine::Unreachable, "requested memory region [%0, %1] is out of range.", "requested memory region [%0, %1] is out of range.")
-DIAG(debug_eh_unsupport, DiagnosticEngine::Debug, "unsupported .eh_frame section in input: %0", "unsupported .eh_frame section in input: %0")
-DIAG(note_eh_cie, DiagnosticEngine::Note, "CIE length: %0, aug_string: %1, fde_encodeing: %2", "CIE length: %0, aug_string: %1, fde_encodeing: %2")
-DIAG(note_eh_fde, DiagnosticEngine::Note, "FDE length: %0, offset of PC Begin: %1", "FDE length: %0, offset of PC Begin: %1")
-DIAG(fatal_cannot_init_target, DiagnosticEngine::Fatal, "Cannot initialize mcld::Target for given triple '%0'.\n(Detail: %1)", "Cannot initialize mcld::Target for given triple '%0'.\n(Detail: %1)")
-DIAG(fatal_cannot_init_lineinfo, DiagnosticEngine::Fatal, "Cannot initialize mcld::DiagnosticLineInfo for given triple '%0'", "Cannot initialize mcld::DiagnosticLineInfo for given triple '%0'")
-DIAG(fatal_cannot_init_backend, DiagnosticEngine::Fatal, "Cannot initialize mcld::TargetLDBackend for given triple '%0'.", "Cannot initialize mcld::TargetLDBackend for given triple '%0'.")
-DIAG(fatal_forbid_nest_group, DiagnosticEngine::Fatal, "not matched --start-group and --end-group", "not matched --start-group and --end-group")
-DIAG(fatal_unwritable_output, DiagnosticEngine::Fatal, "unable to write output file %0", "unable to write output file %0")
-DIAG(warn_unsupported_option, DiagnosticEngine::Warning, "Option `%0' is not implemented yet!", "Option `%0' is not implemented yet!")
-DIAG(warn_shared_textrel, DiagnosticEngine::Warning, "Add DT_TEXTREL in a shared object!", "Add DT_TEXTREL in a shared object.")
-DIAG(fatal_illegal_codegen_type, DiagnosticEngine::Fatal, "illegal output format of output %0", "illegal output format of output %0")
-DIAG(err_nmagic_not_static, DiagnosticEngine::Error, "cannot mix -nmagic option with -shared", "cannot mix -nmagic option with -shared")
-DIAG(err_omagic_not_static, DiagnosticEngine::Error, "cannot mix -omagic option with -shared", "cannot mix -omagic option with -shared")
-DIAG(err_invalid_emulation, DiagnosticEngine::Error, "Invalid target emulation: `%0'.", "Invalid target emulation: `%0'.")
-DIAG(err_cannot_find_scriptfile, DiagnosticEngine::Fatal, "cannot open %0 file %1", "cannot open %0 file %1")
-DIAG(err_unsupported_archive, DiagnosticEngine::Error, "Unsupported archive type.", "Unsupported archive type.")
-DIAG(unexpected_frag_type, DiagnosticEngine::Unreachable, "Unexpected fragment type `%0' when constructing FG", "Unexpected fragment type `%0' when constructing FG")
-DIAG(debug_print_gc_sections, DiagnosticEngine::Debug, "removing unused section from '%0' in file '%1'", "removing unused section from '%0' in file '%1'")
+DIAG(err_empty_input,
+ DiagnosticEngine::Error,
+ "Empty input file `%0' : %1",
+ "Empty input file `%0' : %1")
+DIAG(warn_unrecognized_input_file,
+ DiagnosticEngine::Warning,
+ "cannot recognize the format of file `%0'.\n object format or given "
+ "target machine (%1) is incompatible.",
+ "cannot recognize the format of file `%0'.\n object format or given "
+ "target machine (%1) is incompatible.")
+DIAG(err_cannot_find_namespec,
+ DiagnosticEngine::Fatal,
+ "cannot recognize namespec -l%0",
+ "cannot recognize namespec -l%0")
+DIAG(err_cannot_identify_option,
+ DiagnosticEngine::Fatal,
+ "unknown command line argument `%0' at %1",
+ "unknown command line argument `%0' at %1")
+DIAG(err_mixed_shared_static_objects,
+ DiagnosticEngine::Error,
+ "cannot link shared objects with -static option.\nShared object `%0': %1",
+ "cannot link shared objects with -static option.\nShared object `%0': %1")
+DIAG(unrecognized_output_file,
+ DiagnosticEngine::Unreachable,
+ "unsupported output file format: `%0'",
+ "unsupported output file format: `%0'")
+DIAG(unrecognized_output_sectoin,
+ DiagnosticEngine::Unreachable,
+ "Unable to emit section `%0'\nPlease report to `%1'",
+ "Unable to emit section `%0'\nPlease report to `%1'")
+DIAG(duplicated_wrap,
+ DiagnosticEngine::Warning,
+ "wrapped symbol `%0' had been claimed",
+ "wrapped symbol `%0' had been claimed")
+DIAG(rewrap,
+ DiagnosticEngine::Warning,
+ "There are duplicated --wrap `%0' on the command line\nsymbol `%1' had "
+ "been claimed",
+ "There are duplicated --wrap `%0' on the command line]\nsymbol `%1' had "
+ "been claimed.")
+DIAG(err_cannot_read_symbol,
+ DiagnosticEngine::Fatal,
+ "can not read symbol[%0] in file %1",
+ "can not read symbol[%0] in file %1")
+DIAG(err_cannot_read_section,
+ DiagnosticEngine::Fatal,
+ "can not read section `%0'.",
+ "can not read section `%0'.")
+DIAG(err_cannot_read_target_section,
+ DiagnosticEngine::Fatal,
+ "can not read target-dependent section `%0'.",
+ "can not read target-dependent section `%0'.")
+DIAG(err_cannot_read_relocated_section,
+ DiagnosticEngine::Fatal,
+ "can not read the section being relocated in file %0.\ninvalid sh_info: "
+ "%1\nrelocation section: %2",
+ "can not read the section being relocated in file %0.\ninvalid sh_info: "
+ "%1\nrelocation section: %2")
+DIAG(err_unsupported_section,
+ DiagnosticEngine::Fatal,
+ "unsupported section `%0' (type %1)",
+ "unsupported section `%0' (type %1)")
+DIAG(unreachable_invalid_section_idx,
+ DiagnosticEngine::Unreachable,
+ "section[%0] is invalid in file %1",
+ "section[%0] is invalid in file %1")
+DIAG(err_unsupported_whole_archive,
+ DiagnosticEngine::Error,
+ "Target does not support --whole-archive",
+ "Target does not support --whole-archive")
+DIAG(err_unsupported_as_needed,
+ DiagnosticEngine::Error,
+ "Target does not support --as-needed",
+ "Target does not support --as-needed")
+DIAG(err_unsupported_add_needed,
+ DiagnosticEngine::Error,
+ "Target doest not support --add-needed",
+ "Target does not support --add-needed")
+DIAG(err_unsupported_Bdynamic,
+ DiagnosticEngine::Error,
+ "Target does not support --Bdynamic",
+ "Target does not support --Bdynamic")
+DIAG(err_enable_as_needed_on_static_system,
+ DiagnosticEngine::Warning,
+ "can not enable --as-needed on the target which does not support shared "
+ "objects",
+ "can not enable --as-needed on the target which does not support shared "
+ "objects")
+DIAG(err_mix_static_as_needed,
+ DiagnosticEngine::Warning,
+ "cannot mix --static with --as-needed",
+ "cannot mix --static with --as-needed")
+DIAG(err_cannot_change_file_size,
+ DiagnosticEngine::Error,
+ "cannot truncate file `%0' to size %1",
+ "cannot truncate ffile `%0' to size %1")
+DIAG(err_cannot_open_file,
+ DiagnosticEngine::Error,
+ "cannot open file `%0': %1.",
+ "cannot open file `%0': %1.")
+DIAG(err_cannot_close_file,
+ DiagnosticEngine::Error,
+ "cannot close file `%0': %1.",
+ "cannot close file `%0': %1.")
+DIAG(err_cannot_read_file,
+ DiagnosticEngine::Error,
+ "cannot read file %0 from offset %1 to length %2.",
+ "cannot read file %0 from offset %1 to length %2.")
+DIAG(err_cannot_read_small_file,
+ DiagnosticEngine::Fatal,
+ "file %0 is too small to read.\n file size is %1.\n read from %2.",
+ "file %0 is too small to read.\n file size is %1.\n read from %2.")
+DIAG(err_cannot_mmap_file,
+ DiagnosticEngine::Error,
+ "cannot open memory mapped file %0 from offset %1 to length %2.",
+ "cannot open memoory mpped file %0 from offset %1 to length %2.")
+DIAG(err_cannot_munmap_file,
+ DiagnosticEngine::Error,
+ "cannot remove the mapped memory of file %0.",
+ "cannot remove the mapped memory of file %0.")
+DIAG(err_cannot_write_file,
+ DiagnosticEngine::Error,
+ "cannot write file %0 from offset %1 to length %2.",
+ "cannot write file %0 from offset %1 to length %2.")
+DIAG(warn_illegal_input_section,
+ DiagnosticEngine::Warning,
+ "section `%0' should not appear in input file `%1': %2",
+ "section `%0' should not appear in input file `%1': %2")
+DIAG(err_cannot_trace_file,
+ DiagnosticEngine::Unreachable,
+ "cannot identify the type (%0) of input file `%1'.\n %2",
+ "cannot identify the type (%0) of input file `%1'.\n %2")
+DIAG(err_out_of_range_region,
+ DiagnosticEngine::Unreachable,
+ "requested memory region [%0, %1] is out of range.",
+ "requested memory region [%0, %1] is out of range.")
+DIAG(debug_eh_unsupport,
+ DiagnosticEngine::Debug,
+ "unsupported .eh_frame section in input: %0",
+ "unsupported .eh_frame section in input: %0")
+DIAG(note_eh_cie,
+ DiagnosticEngine::Note,
+ "CIE length: %0, aug_string: %1, fde_encodeing: %2",
+ "CIE length: %0, aug_string: %1, fde_encodeing: %2")
+DIAG(note_eh_fde,
+ DiagnosticEngine::Note,
+ "FDE length: %0, offset of PC Begin: %1",
+ "FDE length: %0, offset of PC Begin: %1")
+DIAG(fatal_cannot_init_target,
+ DiagnosticEngine::Fatal,
+ "Cannot initialize mcld::Target for given triple '%0'.\n(Detail: %1)",
+ "Cannot initialize mcld::Target for given triple '%0'.\n(Detail: %1)")
+DIAG(fatal_cannot_init_lineinfo,
+ DiagnosticEngine::Fatal,
+ "Cannot initialize mcld::DiagnosticLineInfo for given triple '%0'",
+ "Cannot initialize mcld::DiagnosticLineInfo for given triple '%0'")
+DIAG(fatal_cannot_init_backend,
+ DiagnosticEngine::Fatal,
+ "Cannot initialize mcld::TargetLDBackend for given triple '%0'.",
+ "Cannot initialize mcld::TargetLDBackend for given triple '%0'.")
+DIAG(fatal_forbid_nest_group,
+ DiagnosticEngine::Fatal,
+ "not matched --start-group and --end-group",
+ "not matched --start-group and --end-group")
+DIAG(fatal_unwritable_output,
+ DiagnosticEngine::Fatal,
+ "unable to write output file %0",
+ "unable to write output file %0")
+DIAG(warn_unsupported_option,
+ DiagnosticEngine::Warning,
+ "Option `%0' is not implemented yet!",
+ "Option `%0' is not implemented yet!")
+DIAG(warn_shared_textrel,
+ DiagnosticEngine::Warning,
+ "Add DT_TEXTREL in a shared object!",
+ "Add DT_TEXTREL in a shared object.")
+DIAG(fatal_illegal_codegen_type,
+ DiagnosticEngine::Fatal,
+ "illegal output format of output %0",
+ "illegal output format of output %0")
+DIAG(err_nmagic_not_static,
+ DiagnosticEngine::Error,
+ "cannot mix -nmagic option with -shared",
+ "cannot mix -nmagic option with -shared")
+DIAG(err_omagic_not_static,
+ DiagnosticEngine::Error,
+ "cannot mix -omagic option with -shared",
+ "cannot mix -omagic option with -shared")
+DIAG(err_invalid_emulation,
+ DiagnosticEngine::Error,
+ "Invalid target emulation: `%0'.",
+ "Invalid target emulation: `%0'.")
+DIAG(err_cannot_find_scriptfile,
+ DiagnosticEngine::Fatal,
+ "cannot open %0 file %1",
+ "cannot open %0 file %1")
+DIAG(err_unsupported_archive,
+ DiagnosticEngine::Error,
+ "Unsupported archive type.",
+ "Unsupported archive type.")
+DIAG(unexpected_frag_type,
+ DiagnosticEngine::Unreachable,
+ "Unexpected fragment type `%0' when constructing FG",
+ "Unexpected fragment type `%0' when constructing FG")
+DIAG(debug_print_gc_sections,
+ DiagnosticEngine::Debug,
+ "removing unused section from '%0' in file '%1'",
+ "removing unused section from '%0' in file '%1'")
diff --git a/include/mcld/LD/DiagGOTPLT.inc b/include/mcld/LD/DiagGOTPLT.inc
index 172bceb..3de335a 100644
--- a/include/mcld/LD/DiagGOTPLT.inc
+++ b/include/mcld/LD/DiagGOTPLT.inc
@@ -1,5 +1,20 @@
-DIAG(mips_got_symbol, DiagnosticEngine::Unreachable, "%0 is not a dynamic symbol, do not put it in global got", "%0 is not a dynamic symbol, do not put it in global got")
-DIAG(fail_allocate_memory_got, DiagnosticEngine::Fatal, "fial to allocate memory for GOT", "fial to allocate memory for GOT")
-DIAG(fail_allocate_memory_plt, DiagnosticEngine::Fatal, "fial to allocate memory for PLT", "fial to allocate memory for PLT")
-DIAG(reserve_entry_number_mismatch_got, DiagnosticEngine::Unreachable, "The number of reserved entries for GOT is inconsist", "The number of reserved entries for GOT is inconsist")
-DIAG(reserve_entry_number_mismatch_plt, DiagnosticEngine::Unreachable, "The number of reserved entries for PLT is inconsist", "The number of reserved entries for PLT is inconsist")
+DIAG(mips_got_symbol,
+ DiagnosticEngine::Unreachable,
+ "%0 is not a dynamic symbol, do not put it in global got",
+ "%0 is not a dynamic symbol, do not put it in global got")
+DIAG(fail_allocate_memory_got,
+ DiagnosticEngine::Fatal,
+ "fial to allocate memory for GOT",
+ "fial to allocate memory for GOT")
+DIAG(fail_allocate_memory_plt,
+ DiagnosticEngine::Fatal,
+ "fial to allocate memory for PLT",
+ "fial to allocate memory for PLT")
+DIAG(reserve_entry_number_mismatch_got,
+ DiagnosticEngine::Unreachable,
+ "The number of reserved entries for GOT is inconsist",
+ "The number of reserved entries for GOT is inconsist")
+DIAG(reserve_entry_number_mismatch_plt,
+ DiagnosticEngine::Unreachable,
+ "The number of reserved entries for PLT is inconsist",
+ "The number of reserved entries for PLT is inconsist")
diff --git a/include/mcld/LD/DiagLDScript.inc b/include/mcld/LD/DiagLDScript.inc
index c752773..1699bb9 100644
--- a/include/mcld/LD/DiagLDScript.inc
+++ b/include/mcld/LD/DiagLDScript.inc
@@ -1,3 +1,12 @@
-DIAG(err_unterminated_comment, DiagnosticEngine::Error, "%0:%1:%2: error: unterminated comment\n", "%0:%1:%2: error: unterminated comment\n")
-DIAG(err_syntax_error, DiagnosticEngine::Error, "%0:%1:%2: error: %3\n", "%0:%1:%2: error: %3\n")
-DIAG(err_assert_failed, DiagnosticEngine::Error,"Assertion failed: %0\n", "Assertion failed: %0\n")
+DIAG(err_unterminated_comment,
+ DiagnosticEngine::Error,
+ "%0:%1:%2: error: unterminated comment\n",
+ "%0:%1:%2: error: unterminated comment\n")
+DIAG(err_syntax_error,
+ DiagnosticEngine::Error,
+ "%0:%1:%2: error: %3\n",
+ "%0:%1:%2: error: %3\n")
+DIAG(err_assert_failed,
+ DiagnosticEngine::Error,
+ "Assertion failed: %0\n",
+ "Assertion failed: %0\n")
diff --git a/include/mcld/LD/DiagLayouts.inc b/include/mcld/LD/DiagLayouts.inc
index 513ee33..c41b775 100644
--- a/include/mcld/LD/DiagLayouts.inc
+++ b/include/mcld/LD/DiagLayouts.inc
@@ -1,8 +1,34 @@
-DIAG(warn_unsupported_exception, DiagnosticEngine::Warning, "Exception handling has not been fully supported yet.\nsection `%0'.", "Exception handling has not been fully supported yet.\nsection `%0'.")
-DIAG(warn_unsupported_symbolic_versioning, DiagnosticEngine::Warning, "Symbolic versioning has not been fully supported yet.\nsection `%0'.", "Symbolic versioning has not been fully supported yet.\nsection `%0'")
-DIAG(err_section_not_laid_out, DiagnosticEngine::Unreachable, "section %0 has not been laid out. Developers may use an output LDSection in Layout::getFragmentRef", "section %0 has not been laid out. Developers may use an output LDSection in Layout::getFragmentRef")
-DIAG(warn_duplicate_std_sectmap, DiagnosticEngine::Warning, "Duplicated definition of section map \"from %0 to %0\".", "Duplicated definition of section map \"from %0 to %0\".")
-DIAG(warn_rules_check_failed, DiagnosticEngine::Warning, "Illegal section mapping rule: %0 -> %1. (conflict with %2 -> %3)", "Illegal section mapping rule: %0 -> %1. (conflict with %2 -> %3)")
-DIAG(err_cannot_merge_section, DiagnosticEngine::Error, "Cannot merge section %0 of %1", "Cannot merge section %0 of %1")
-DIAG(debug_icf_iterations, DiagnosticEngine::Debug, "ICF converged after `%0' iteration(s).", "ICF converged after `%0' iteration(s).")
-DIAG(debug_icf_folded_section, DiagnosticEngine::Debug, "ICF folding section `%0' of `%1' into `%2' of `%3'", "ICF folding section `%0' of `%1' into `%2' of `%3'")
+DIAG(warn_unsupported_exception,
+ DiagnosticEngine::Warning,
+ "Exception handling has not been fully supported yet.\nsection `%0'.",
+ "Exception handling has not been fully supported yet.\nsection `%0'.")
+DIAG(warn_unsupported_symbolic_versioning,
+ DiagnosticEngine::Warning,
+ "Symbolic versioning has not been fully supported yet.\nsection `%0'.",
+ "Symbolic versioning has not been fully supported yet.\nsection `%0'")
+DIAG(err_section_not_laid_out,
+ DiagnosticEngine::Unreachable,
+ "section %0 has not been laid out. Developers may use an output LDSection "
+ "in Layout::getFragmentRef",
+ "section %0 has not been laid out. Developers may use an output LDSection "
+ "in Layout::getFragmentRef")
+DIAG(warn_duplicate_std_sectmap,
+ DiagnosticEngine::Warning,
+ "Duplicated definition of section map \"from %0 to %0\".",
+ "Duplicated definition of section map \"from %0 to %0\".")
+DIAG(warn_rules_check_failed,
+ DiagnosticEngine::Warning,
+ "Illegal section mapping rule: %0 -> %1. (conflict with %2 -> %3)",
+ "Illegal section mapping rule: %0 -> %1. (conflict with %2 -> %3)")
+DIAG(err_cannot_merge_section,
+ DiagnosticEngine::Error,
+ "Cannot merge section %0 of %1",
+ "Cannot merge section %0 of %1")
+DIAG(debug_icf_iterations,
+ DiagnosticEngine::Debug,
+ "ICF converged after `%0' iteration(s).",
+ "ICF converged after `%0' iteration(s).")
+DIAG(debug_icf_folded_section,
+ DiagnosticEngine::Debug,
+ "ICF folding section `%0' of `%1' into `%2' of `%3'",
+ "ICF folding section `%0' of `%1' into `%2' of `%3'")
diff --git a/include/mcld/LD/DiagReaders.inc b/include/mcld/LD/DiagReaders.inc
index 3f08a21..2409946 100644
--- a/include/mcld/LD/DiagReaders.inc
+++ b/include/mcld/LD/DiagReaders.inc
@@ -1,4 +1,16 @@
-DIAG(archive_magic_mismatch, DiagnosticEngine::Error, "magic number is mismatched in `%0'", "magic number is mismatched in `%0'")
-DIAG(debug_cannot_parse_eh, DiagnosticEngine::Debug, "cannot parse .eh_frame section in input %0", "cannot parse .eh_frame section in input %0.")
-DIAG(debug_cannot_scan_eh, DiagnosticEngine::Debug, "cannot scan .eh_frame section in input %0", "cannot scan .eh_frame section in input %0.")
-DIAG(fatal_cannot_read_input, DiagnosticEngine::Fatal, "cannot read input input %0", "cannot read input %0")
+DIAG(archive_magic_mismatch,
+ DiagnosticEngine::Error,
+ "magic number is mismatched in `%0'",
+ "magic number is mismatched in `%0'")
+DIAG(debug_cannot_parse_eh,
+ DiagnosticEngine::Debug,
+ "cannot parse .eh_frame section in input %0",
+ "cannot parse .eh_frame section in input %0.")
+DIAG(debug_cannot_scan_eh,
+ DiagnosticEngine::Debug,
+ "cannot scan .eh_frame section in input %0",
+ "cannot scan .eh_frame section in input %0.")
+DIAG(fatal_cannot_read_input,
+ DiagnosticEngine::Fatal,
+ "cannot read input input %0",
+ "cannot read input %0")
diff --git a/include/mcld/LD/DiagRelocations.inc b/include/mcld/LD/DiagRelocations.inc
index bacae6e..8b2021b 100644
--- a/include/mcld/LD/DiagRelocations.inc
+++ b/include/mcld/LD/DiagRelocations.inc
@@ -1,15 +1,72 @@
-DIAG(reloc_factory_has_not_config, DiagnosticEngine::Fatal, "Please call mcld::Linker::config before creating relocations", "Please call mcld::Linker::config before creating relocations")
-DIAG(unsupported_bitclass, DiagnosticEngine::Fatal, "Only supports 32 and 64 bits targets. (Target: %0, bitclass:%1)", "Only supports 32 and 64 bits targets. (Target: %0, bitclass:%1)")
-DIAG(undefined_reference, DiagnosticEngine::Fatal, "%1(%2+%3): undefined reference to `%0'", "%1(%2+%3): undefined reference to `%0'")
-DIAG(undefined_reference_text, DiagnosticEngine::Fatal, "%1:%2:function %3: undefined reference to `%0'", "%1:%2: undefined reference to `%0'")
-DIAG(non_pic_relocation, DiagnosticEngine::Error, "attempt to generate unsupported relocation type `%0' for symbol `%1', recompile with -fPIC", "attempt to generate unsupported relocation type `%0' for symbol `%1, recompile with -fPIC")
-DIAG(base_relocation, DiagnosticEngine::Fatal, "relocation type `%0' is not supported for symbol `%1'\nPlease report to %2", "relocation type `%0' is not supported for symbol `%1'\nPlease report to %2")
-DIAG(dynamic_relocation, DiagnosticEngine::Fatal, "unexpected relocation type `%0' in object file", "unexpected relocation type `%0' in object file")
-DIAG(unsupported_relocation, DiagnosticEngine::Unreachable, "encounter unsupported relocation type `%0'\nPlease report to %1", "encounter unsupported relocation type `%0'\nPlease report to %1")
-DIAG(unknown_relocation, DiagnosticEngine::Fatal, "encounter unknown relocation type `%0' for symbol `%1'", "encounter unknown relocation type `%0' for symbol `%1'")
-DIAG(invalid_global_relocation, DiagnosticEngine::Unreachable, "relocation type `%0' is invalid for global symbol `%1'", "relocation type `%0' is invalid for global symbol `%1'")
-DIAG(result_overflow, DiagnosticEngine::Error, "applying relocation `%0' causes overflow on symbol `%1'","applying relocation `%0' causes overflow on symbol `%1'")
-DIAG(result_badreloc, DiagnosticEngine::Error, "applying relocation `%0' encounters unexpected opcode on symbol `%1'","applying relocation `%0' encounters unexpected opcode on symbol `%1'")
-DIAG(invalid_tls, DiagnosticEngine::Error, "TLS relocation against invalid symbol `%0' in section `%1'", "TLS relocation against invalid symbol `%0' in section `%1'")
-DIAG(unknown_reloc_section_type, DiagnosticEngine::Unreachable, "unknown relocation section type: `%0' in section `%1'", "unknown relocation section type: `%0' in section `%1'")
-DIAG(unsupport_cond_branch_reloc, DiagnosticEngine::Error, "applying relocation `%0', conditional branch to PLT in THUMB-2 not supported yet", "applying relocation `%0', conditional branch to PLT in THUMB-2 not supported yet")
+DIAG(reloc_factory_has_not_config,
+ DiagnosticEngine::Fatal,
+ "Please call mcld::Linker::config before creating relocations",
+ "Please call mcld::Linker::config before creating relocations")
+DIAG(unsupported_bitclass,
+ DiagnosticEngine::Fatal,
+ "Only supports 32 and 64 bits targets. (Target: %0, bitclass:%1)",
+ "Only supports 32 and 64 bits targets. (Target: %0, bitclass:%1)")
+DIAG(undefined_reference,
+ DiagnosticEngine::Fatal,
+ "%1(%2+%3): undefined reference to `%0'",
+ "%1(%2+%3): undefined reference to `%0'")
+DIAG(undefined_reference_text,
+ DiagnosticEngine::Fatal,
+ "%1:%2:function %3: undefined reference to `%0'",
+ "%1:%2: undefined reference to `%0'")
+DIAG(non_pic_relocation,
+ DiagnosticEngine::Error,
+ "attempt to generate unsupported relocation `%0' for symbol `%1', "
+ "recompile with -fPIC",
+ "attempt to generate unsupported relocation `%0' for symbol `%1, "
+ "recompile with -fPIC")
+DIAG(base_relocation,
+ DiagnosticEngine::Fatal,
+ "relocation type `%0' is not supported for symbol `%1'\nPlease report to "
+ "%2",
+ "relocation type `%0' is not supported for symbol `%1'\nPlease report to "
+ "%2")
+DIAG(dynamic_relocation,
+ DiagnosticEngine::Fatal,
+ "unexpected relocation type `%0' in object file",
+ "unexpected relocation type `%0' in object file")
+DIAG(unsupported_relocation,
+ DiagnosticEngine::Unreachable,
+ "encounter unsupported relocation type `%0'\nPlease report to %1",
+ "encounter unsupported relocation type `%0'\nPlease report to %1")
+DIAG(unknown_relocation,
+ DiagnosticEngine::Fatal,
+ "encounter unknown relocation type `%0' for symbol `%1'",
+ "encounter unknown relocation type `%0' for symbol `%1'")
+DIAG(invalid_global_relocation,
+ DiagnosticEngine::Unreachable,
+ "relocation type `%0' is invalid for global symbol `%1'",
+ "relocation type `%0' is invalid for global symbol `%1'")
+DIAG(result_overflow,
+ DiagnosticEngine::Error,
+ "applying relocation `%0' causes overflow on symbol `%1'",
+ "applying relocation `%0' causes overflow on symbol `%1'")
+DIAG(result_badreloc,
+ DiagnosticEngine::Error,
+ "applying relocation `%0' encounters unexpected opcode on symbol `%1'",
+ "applying relocation `%0' encounters unexpected opcode on symbol `%1'")
+DIAG(invalid_tls,
+ DiagnosticEngine::Error,
+ "TLS relocation against invalid symbol `%0' in section `%1'",
+ "TLS relocation against invalid symbol `%0' in section `%1'")
+DIAG(unknown_reloc_section_type,
+ DiagnosticEngine::Unreachable,
+ "unknown relocation section type: `%0' in section `%1'",
+ "unknown relocation section type: `%0' in section `%1'")
+DIAG(unsupported_cond_branch_reloc,
+ DiagnosticEngine::Error,
+ "applying relocation `%0', conditional branch to PLT in THUMB-2 not "
+ "supported yet",
+ "applying relocation `%0', conditional branch to PLT in THUMB-2 not "
+ "supported yet")
+DIAG(unsupport_reloc_for_debug_string,
+ DiagnosticEngine::Error,
+ "applying relocation `%0' for .debug_str is not supported. "
+ "Please report to %1",
+ "applying relocation `%0' for .debug_str is not supported. "
+ "Please report to %1")
diff --git a/include/mcld/LD/DiagSymbolResolutions.inc b/include/mcld/LD/DiagSymbolResolutions.inc
index 04113dc..b640334 100644
--- a/include/mcld/LD/DiagSymbolResolutions.inc
+++ b/include/mcld/LD/DiagSymbolResolutions.inc
@@ -1,11 +1,44 @@
-DIAG(note_has_no_symtab, DiagnosticEngine::Note, "input file `%0' has no symbol table `%2'\n path of input file: %1", "input file `%0' has no symbol table `%2'\n path of input file: %1")
-DIAG(fatal_cannot_read_strtab, DiagnosticEngine::Fatal, "cannot read strtab for %2 in file `%0': %1", "cannot read strtab for %2 in file `%0': %1")
-DIAG(fail_sym_resolution, DiagnosticEngine::Unreachable, "Fails to resolve symbols [%0:%1]\nPlease reports to `%2'", "Fails to resolve symbols [%0:%1]\nPlease reports to `%2'")
-DIAG(mark_dynamic_defined, DiagnosticEngine::Ignore, "refer to dynamic symbol %0", "call a external function %0")
-DIAG(comm_refer_to_define, DiagnosticEngine::Ignore, "common symbol %0 is overridden by previous definition", "common symbol %0 is overridden by previous definition")
-DIAG(redefine_common, DiagnosticEngine::Ignore, "common symbol %0 is overridden by definition", "common symbol %0 is overriden by definition")
-DIAG(indirect_refer_to_common, DiagnosticEngine::Ignore, "indirect symbol %0 points to a common symbol", "indirect symbol %0 points to a common symbol")
-DIAG(indirect_refer_to_inexist, DiagnosticEngine::Fatal, "indirect symbol %0 points to a undefined symbol", "variable %0 is undefined")
-DIAG(multiple_definitions, DiagnosticEngine::Error, "multiple definition of symbol `%0'", "you define variable %0 twice")
-DIAG(undefined_situation, DiagnosticEngine::Unreachable, "reach undefined situation, action: %0, old(%1) -> new(%2)", "reach undefined situation, action: %0, old(%1) -> new(%2)")
-DIAG(multiple_absolute_definitions, DiagnosticEngine::Error, "inconsistent definitions of absolute symbol `%0': old(%1) -> new(%2)", "you defined an absolute symbol with different values")
+DIAG(note_has_no_symtab,
+ DiagnosticEngine::Note,
+ "input file `%0' has no symbol table `%2'\n path of input file: %1",
+ "input file `%0' has no symbol table `%2'\n path of input file: %1")
+DIAG(fatal_cannot_read_strtab,
+ DiagnosticEngine::Fatal,
+ "cannot read strtab for %2 in file `%0': %1",
+ "cannot read strtab for %2 in file `%0': %1")
+DIAG(fail_sym_resolution,
+ DiagnosticEngine::Unreachable,
+ "Fails to resolve symbols [%0:%1]\nPlease reports to `%2'",
+ "Fails to resolve symbols [%0:%1]\nPlease reports to `%2'")
+DIAG(mark_dynamic_defined,
+ DiagnosticEngine::Ignore,
+ "refer to dynamic symbol %0",
+ "call a external function %0")
+DIAG(comm_refer_to_define,
+ DiagnosticEngine::Ignore,
+ "common symbol %0 is overridden by previous definition",
+ "common symbol %0 is overridden by previous definition")
+DIAG(redefine_common,
+ DiagnosticEngine::Ignore,
+ "common symbol %0 is overridden by definition",
+ "common symbol %0 is overriden by definition")
+DIAG(indirect_refer_to_common,
+ DiagnosticEngine::Ignore,
+ "indirect symbol %0 points to a common symbol",
+ "indirect symbol %0 points to a common symbol")
+DIAG(indirect_refer_to_inexist,
+ DiagnosticEngine::Fatal,
+ "indirect symbol %0 points to a undefined symbol",
+ "variable %0 is undefined")
+DIAG(multiple_definitions,
+ DiagnosticEngine::Error,
+ "multiple definition of symbol `%0'",
+ "you define variable %0 twice")
+DIAG(undefined_situation,
+ DiagnosticEngine::Unreachable,
+ "reach undefined situation, action: %0, old(%1) -> new(%2)",
+ "reach undefined situation, action: %0, old(%1) -> new(%2)")
+DIAG(multiple_absolute_definitions,
+ DiagnosticEngine::Error,
+ "inconsistent definitions of absolute symbol `%0': old(%1) -> new(%2)",
+ "you defined an absolute symbol with different values")
diff --git a/include/mcld/LD/Diagnostic.h b/include/mcld/LD/Diagnostic.h
index 615c99d..6183947 100644
--- a/include/mcld/LD/Diagnostic.h
+++ b/include/mcld/LD/Diagnostic.h
@@ -6,37 +6,35 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_DIAGNOSTIC_H
-#define MCLD_LD_DIAGNOSTIC_H
+#ifndef MCLD_LD_DIAGNOSTIC_H_
+#define MCLD_LD_DIAGNOSTIC_H_
+
+#include "mcld/LD/DiagnosticEngine.h"
-#include <string>
#include <cassert>
-#include <mcld/LD/DiagnosticEngine.h>
+#include <string>
namespace mcld {
/** \class Diagnostic
* \brief Diagnostic provides current status to DiagnosticPrinters.
*/
-class Diagnostic
-{
-public:
- Diagnostic(DiagnosticEngine& pEngine);
+class Diagnostic {
+ public:
+ explicit Diagnostic(DiagnosticEngine& pEngine);
~Diagnostic();
- unsigned int getID() const
- { return m_Engine.state().ID; }
+ unsigned int getID() const { return m_Engine.state().ID; }
- unsigned int getNumArgs() const
- { return m_Engine.state().numArgs; }
+ unsigned int getNumArgs() const { return m_Engine.state().numArgs; }
DiagnosticEngine::ArgumentKind getArgKind(unsigned int pIdx) const {
assert(pIdx < getNumArgs() && "Argument index is out of range!");
return (DiagnosticEngine::ArgumentKind)m_Engine.state().ArgumentKinds[pIdx];
}
- const std::string &getArgStdStr(unsigned int pIdx) const {
+ const std::string& getArgStdStr(unsigned int pIdx) const {
assert(getArgKind(pIdx) == DiagnosticEngine::ak_std_string &&
"Invalid argument accessor!");
return m_Engine.state().ArgumentStrs[pIdx];
@@ -51,7 +49,7 @@ public:
int getArgSInt(unsigned int pIdx) const {
assert(getArgKind(pIdx) == DiagnosticEngine::ak_sint &&
"Invalid argument accessor!");
- return (int)m_Engine.state().ArgumentVals[pIdx];
+ return static_cast<int>(m_Engine.state().ArgumentVals[pIdx]);
}
unsigned int getArgUInt(unsigned int pIdx) const {
@@ -69,7 +67,7 @@ public:
bool getArgBool(unsigned int pIdx) const {
assert(getArgKind(pIdx) == DiagnosticEngine::ak_bool &&
"Invalid argument accessor!");
- return (bool)m_Engine.state().ArgumentVals[pIdx];
+ return static_cast<bool>(m_Engine.state().ArgumentVals[pIdx]);
}
intptr_t getRawVals(unsigned int pIdx) const {
@@ -86,14 +84,13 @@ public:
// arguments. The result is appended at on the pOutStr.
void format(const char* pBegin, const char* pEnd, std::string& pOutStr) const;
-private:
- const char* findMatch(char pVal, const char* pBegin, const char* pEnd ) const;
+ private:
+ const char* findMatch(char pVal, const char* pBegin, const char* pEnd) const;
-private:
+ private:
DiagnosticEngine& m_Engine;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_DIAGNOSTIC_H_
diff --git a/include/mcld/LD/DiagnosticEngine.h b/include/mcld/LD/DiagnosticEngine.h
index 460e4b7..ef73def 100644
--- a/include/mcld/LD/DiagnosticEngine.h
+++ b/include/mcld/LD/DiagnosticEngine.h
@@ -6,19 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_DIAGNOSTICENGINE_H
-#define MCLD_LD_DIAGNOSTICENGINE_H
-#include <string>
+#ifndef MCLD_LD_DIAGNOSTICENGINE_H_
+#define MCLD_LD_DIAGNOSTICENGINE_H_
+#include "mcld/LD/DiagnosticInfos.h"
+
#include <llvm/Support/DataTypes.h>
-#include <mcld/LD/DiagnosticInfos.h>
+
+#include <string>
namespace mcld {
+class DiagnosticLineInfo;
+class DiagnosticPrinter;
class Input;
class LinkerConfig;
class MsgHandler;
-class DiagnosticPrinter;
-class DiagnosticLineInfo;
/** \class DiagnosticEngine
* \brief DiagnosticEngine is used to report problems and issues.
@@ -31,9 +33,8 @@ class DiagnosticLineInfo;
* - remember the argument string for MsgHandler
* - choice the severity of a message by options
*/
-class DiagnosticEngine
-{
-public:
+class DiagnosticEngine {
+ public:
enum Severity {
Unreachable,
Fatal,
@@ -54,7 +55,7 @@ public:
ak_bool // bool
};
-public:
+ public:
DiagnosticEngine();
~DiagnosticEngine();
@@ -66,16 +67,14 @@ public:
void setPrinter(DiagnosticPrinter& pPrinter, bool pShouldOwnPrinter = true);
const DiagnosticPrinter* getPrinter() const { return m_pPrinter; }
- DiagnosticPrinter* getPrinter() { return m_pPrinter; }
-
+ DiagnosticPrinter* getPrinter() { return m_pPrinter; }
DiagnosticPrinter* takePrinter() {
m_OwnPrinter = false;
return m_pPrinter;
}
- bool ownPrinter() const
- { return m_OwnPrinter; }
+ bool ownPrinter() const { return m_OwnPrinter; }
// ----- emission ----- //
// emit - process the message to printer
@@ -84,7 +83,7 @@ public:
// report - issue the message to the printer
MsgHandler report(uint16_t pID, Severity pSeverity);
-private:
+ private:
friend class MsgHandler;
friend class Diagnostic;
@@ -94,11 +93,10 @@ private:
MaxArguments = 10
};
- struct State
- {
- public:
- State() : numArgs(0), ID(-1), severity(None), file(NULL) { }
- ~State() { }
+ struct State {
+ public:
+ State() : numArgs(0), ID(-1), severity(None), file(NULL) {}
+ ~State() {}
void reset() {
numArgs = 0;
@@ -107,7 +105,7 @@ private:
file = NULL;
}
- public:
+ public:
std::string ArgumentStrs[MaxArguments];
intptr_t ArgumentVals[MaxArguments];
uint8_t ArgumentKinds[MaxArguments];
@@ -117,24 +115,22 @@ private:
Input* file;
};
-private:
- State& state()
- { return m_State; }
+ private:
+ State& state() { return m_State; }
- const State& state() const
- { return m_State; }
+ const State& state() const { return m_State; }
DiagnosticInfos& infoMap() {
- assert(NULL != m_pInfoMap && "DiagnosticEngine was not initialized!");
+ assert(m_pInfoMap != NULL && "DiagnosticEngine was not initialized!");
return *m_pInfoMap;
}
const DiagnosticInfos& infoMap() const {
- assert(NULL != m_pInfoMap && "DiagnosticEngine was not initialized!");
+ assert(m_pInfoMap != NULL && "DiagnosticEngine was not initialized!");
return *m_pInfoMap;
}
-private:
+ private:
const LinkerConfig* m_pConfig;
DiagnosticLineInfo* m_pLineInfo;
DiagnosticPrinter* m_pPrinter;
@@ -144,7 +140,6 @@ private:
State m_State;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_DIAGNOSTICENGINE_H_
diff --git a/include/mcld/LD/DiagnosticInfos.h b/include/mcld/LD/DiagnosticInfos.h
index 543b754..804394e 100644
--- a/include/mcld/LD/DiagnosticInfos.h
+++ b/include/mcld/LD/DiagnosticInfos.h
@@ -6,14 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_DIAGNOSTICINFORMATION_H
-#define MCLD_LD_DIAGNOSTICINFORMATION_H
+#ifndef MCLD_LD_DIAGNOSTICINFOS_H_
+#define MCLD_LD_DIAGNOSTICINFOS_H_
+
#include <llvm/ADT/StringRef.h>
namespace mcld {
namespace diag {
- enum ID {
+enum ID {
#define DIAG(ENUM, CLASS, ADDRMSG, LINEMSG) ENUM,
#include "mcld/LD/DiagAttribute.inc"
#include "mcld/LD/DiagCommonKinds.inc"
@@ -24,20 +25,19 @@ namespace diag {
#include "mcld/LD/DiagGOTPLT.inc"
#include "mcld/LD/DiagLDScript.inc"
#undef DIAG
- NUM_OF_BUILDIN_DIAGNOSTIC_INFO
- };
-} // namespace of diag
+ NUM_OF_BUILDIN_DIAGNOSTIC_INFO
+};
+} // namespace diag
-class LinkerConfig;
class DiagnosticEngine;
+class LinkerConfig;
/** \class DiagnosticInfos
* \brief DiagnosticInfos caches run-time information of DiagnosticInfo.
*/
-class DiagnosticInfos
-{
-public:
- DiagnosticInfos(const LinkerConfig& pConfig);
+class DiagnosticInfos {
+ public:
+ explicit DiagnosticInfos(const LinkerConfig& pConfig);
~DiagnosticInfos();
@@ -45,11 +45,10 @@ public:
bool process(DiagnosticEngine& pEngine) const;
-private:
+ private:
const LinkerConfig& m_Config;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_DIAGNOSTICINFOS_H_
diff --git a/include/mcld/LD/DiagnosticLineInfo.h b/include/mcld/LD/DiagnosticLineInfo.h
index a13aef6..852eaa5 100644
--- a/include/mcld/LD/DiagnosticLineInfo.h
+++ b/include/mcld/LD/DiagnosticLineInfo.h
@@ -6,21 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_DIAGNOSTICLINEINFO_H
-#define MCLD_LD_DIAGNOSTICLINEINFO_H
+#ifndef MCLD_LD_DIAGNOSTICLINEINFO_H_
+#define MCLD_LD_DIAGNOSTICLINEINFO_H_
-namespace mcld
-{
+namespace mcld {
/** \class DiagnosticLineInfo
* \brief Map the address to the line of code.
*/
-class DiagnosticLineInfo
-{
+class DiagnosticLineInfo {};
-};
-
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_DIAGNOSTICLINEINFO_H_
diff --git a/include/mcld/LD/DiagnosticPrinter.h b/include/mcld/LD/DiagnosticPrinter.h
index d03b9a9..68cc484 100644
--- a/include/mcld/LD/DiagnosticPrinter.h
+++ b/include/mcld/LD/DiagnosticPrinter.h
@@ -6,21 +6,20 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_DIAGNOSTICPRINTER_H
-#define MCLD_LD_DIAGNOSTICPRINTER_H
-#include <mcld/LD/DiagnosticEngine.h>
-#include <mcld/LD/Diagnostic.h>
+#ifndef MCLD_LD_DIAGNOSTICPRINTER_H_
+#define MCLD_LD_DIAGNOSTICPRINTER_H_
-namespace mcld
-{
+#include "mcld/LD/Diagnostic.h"
+#include "mcld/LD/DiagnosticEngine.h"
+
+namespace mcld {
/** \class DiagnosticPrinter
* \brief DiagnosticPrinter provides the interface to customize diagnostic
* messages and output.
*/
-class DiagnosticPrinter
-{
-public:
+class DiagnosticPrinter {
+ public:
DiagnosticPrinter();
virtual ~DiagnosticPrinter();
@@ -31,8 +30,7 @@ public:
virtual void finish() {}
- virtual void clear()
- { m_NumErrors = m_NumWarnings = 0; }
+ virtual void clear() { m_NumErrors = m_NumWarnings = 0; }
/// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
/// capturing it to a log as needed.
@@ -42,12 +40,11 @@ public:
unsigned int getNumErrors() const { return m_NumErrors; }
unsigned int getNumWarnings() const { return m_NumWarnings; }
-protected:
+ protected:
unsigned int m_NumErrors;
unsigned int m_NumWarnings;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_DIAGNOSTICPRINTER_H_
diff --git a/include/mcld/LD/DynObjFileFormat.h b/include/mcld/LD/DynObjFileFormat.h
index dbacdd0..bb1c252 100644
--- a/include/mcld/LD/DynObjFileFormat.h
+++ b/include/mcld/LD/DynObjFileFormat.h
@@ -6,21 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_DYNOBJFILEFORMAT_H
-#define MCLD_LD_DYNOBJFILEFORMAT_H
+#ifndef MCLD_LD_DYNOBJFILEFORMAT_H_
+#define MCLD_LD_DYNOBJFILEFORMAT_H_
-namespace mcld
-{
+namespace mcld {
/** \class DynObjFormat
* \brief DynObjFormat describes the file format for dynamic objects.
*/
-class DynObjFormat : public LDFileFormat
-{
+class DynObjFormat : public LDFileFormat {};
-};
-
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_DYNOBJFILEFORMAT_H_
diff --git a/include/mcld/LD/DynObjReader.h b/include/mcld/LD/DynObjReader.h
index 1817c4a..d313bf4 100644
--- a/include/mcld/LD/DynObjReader.h
+++ b/include/mcld/LD/DynObjReader.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_DYNOBJREADER_H
-#define MCLD_LD_DYNOBJREADER_H
+#ifndef MCLD_LD_DYNOBJREADER_H_
+#define MCLD_LD_DYNOBJREADER_H_
#include "mcld/LD/LDReader.h"
namespace mcld {
@@ -19,22 +19,18 @@ class Input;
* \brief DynObjReader provides an common interface for different object
* formats.
*/
-class DynObjReader : public LDReader
-{
-protected:
- DynObjReader()
- { }
+class DynObjReader : public LDReader {
+ protected:
+ DynObjReader() {}
-public:
- virtual ~DynObjReader() { }
+ public:
+ virtual ~DynObjReader() {}
virtual bool readHeader(Input& pFile) = 0;
virtual bool readSymbols(Input& pFile) = 0;
-
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_DYNOBJREADER_H_
diff --git a/include/mcld/LD/ELFBinaryReader.h b/include/mcld/LD/ELFBinaryReader.h
index 117807e..f6fdfd4 100644
--- a/include/mcld/LD/ELFBinaryReader.h
+++ b/include/mcld/LD/ELFBinaryReader.h
@@ -6,14 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_ELFBINARYREADER_H
-#define MCLD_LD_ELFBINARYREADER_H
+#ifndef MCLD_LD_ELFBINARYREADER_H_
+#define MCLD_LD_ELFBINARYREADER_H_
-#include <mcld/LD/BinaryReader.h>
+#include "mcld/LD/BinaryReader.h"
namespace mcld {
-class Module;
class Input;
class IRBuilder;
class LinkerConfig;
@@ -21,23 +20,21 @@ class LinkerConfig;
/** \lclass ELFBinaryReader
* \brief ELFBinaryReader reads target-independent parts of Binary file
*/
-class ELFBinaryReader : public BinaryReader
-{
-public:
+class ELFBinaryReader : public BinaryReader {
+ public:
ELFBinaryReader(IRBuilder& pBuilder, const LinkerConfig& pConfig);
~ELFBinaryReader();
- bool isMyFormat(Input& pInput, bool &pContinue) const;
+ bool isMyFormat(Input& pInput, bool& pContinue) const;
bool readBinary(Input& pInput);
-private:
+ private:
IRBuilder& m_Builder;
const LinkerConfig& m_Config;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ELFBINARYREADER_H_
diff --git a/include/mcld/LD/ELFDynObjFileFormat.h b/include/mcld/LD/ELFDynObjFileFormat.h
index 8a18376..c239ca8 100644
--- a/include/mcld/LD/ELFDynObjFileFormat.h
+++ b/include/mcld/LD/ELFDynObjFileFormat.h
@@ -6,9 +6,9 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_ELFDYNOBJFILEFROMAT_H
-#define MCLD_LD_ELFDYNOBJFILEFROMAT_H
-#include <mcld/LD/ELFFileFormat.h>
+#ifndef MCLD_LD_ELFDYNOBJFILEFORMAT_H_
+#define MCLD_LD_ELFDYNOBJFILEFORMAT_H_
+#include "mcld/LD/ELFFileFormat.h"
namespace mcld {
@@ -17,14 +17,12 @@ class ObjectBuilder;
/** \class ELFDynObjFileFormat
* \brief ELFDynObjFileFormat describes the format for ELF dynamic objects.
*/
-class ELFDynObjFileFormat : public ELFFileFormat
-{
+class ELFDynObjFileFormat : public ELFFileFormat {
/// initObjectFormat - initialize sections that are dependent on shared
/// objects.
void initObjectFormat(ObjectBuilder& pBuilder, unsigned int pBitClass);
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ELFDYNOBJFILEFORMAT_H_
diff --git a/include/mcld/LD/ELFDynObjReader.h b/include/mcld/LD/ELFDynObjReader.h
index 0beeecd..fdf9608 100644
--- a/include/mcld/LD/ELFDynObjReader.h
+++ b/include/mcld/LD/ELFDynObjReader.h
@@ -6,44 +6,42 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_ELFDYNOBJREADER_H
-#define MCLD_LD_ELFDYNOBJREADER_H
-#include <mcld/LD/DynObjReader.h>
+#ifndef MCLD_LD_ELFDYNOBJREADER_H_
+#define MCLD_LD_ELFDYNOBJREADER_H_
+#include "mcld/LD/DynObjReader.h"
namespace mcld {
+class ELFReaderIF;
+class GNULDBackend;
class Input;
-class LinkerConfig;
class IRBuilder;
-class GNULDBackend;
-class ELFReaderIF;
+class LinkerConfig;
/** \class ELFDynObjReader
* \brief ELFDynObjReader reads ELF dynamic shared objects.
*
*/
-class ELFDynObjReader : public DynObjReader
-{
-public:
+class ELFDynObjReader : public DynObjReader {
+ public:
ELFDynObjReader(GNULDBackend& pBackend,
IRBuilder& pBuilder,
const LinkerConfig& pConfig);
~ELFDynObjReader();
// ----- observers ----- //
- bool isMyFormat(Input &pFile, bool &pContinue) const;
+ bool isMyFormat(Input& pFile, bool& pContinue) const;
// ----- readers ----- //
bool readHeader(Input& pFile);
bool readSymbols(Input& pInput);
-private:
- ELFReaderIF *m_pELFReader;
+ private:
+ ELFReaderIF* m_pELFReader;
IRBuilder& m_Builder;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ELFDYNOBJREADER_H_
diff --git a/include/mcld/LD/ELFExecFileFormat.h b/include/mcld/LD/ELFExecFileFormat.h
index 9279069..a37bac9 100644
--- a/include/mcld/LD/ELFExecFileFormat.h
+++ b/include/mcld/LD/ELFExecFileFormat.h
@@ -6,9 +6,9 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ELF_EXEC_FILE_FORMAT_H
-#define MCLD_ELF_EXEC_FILE_FORMAT_H
-#include <mcld/LD/ELFFileFormat.h>
+#ifndef MCLD_LD_ELFEXECFILEFORMAT_H_
+#define MCLD_LD_ELFEXECFILEFORMAT_H_
+#include "mcld/LD/ELFFileFormat.h"
namespace mcld {
@@ -17,14 +17,12 @@ class ObjectBuilder;
/** \class ELFExecFileFormat
* \brief ELFExecFileFormat describes the format for ELF dynamic objects.
*/
-class ELFExecFileFormat : public ELFFileFormat
-{
+class ELFExecFileFormat : public ELFFileFormat {
/// initObjectFormat - initialize sections that are dependent on executable
/// objects.
void initObjectFormat(ObjectBuilder& pBuilder, unsigned int pBitClass);
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ELFEXECFILEFORMAT_H_
diff --git a/include/mcld/LD/ELFFileFormat.h b/include/mcld/LD/ELFFileFormat.h
index 360ff5a..5bb664c 100644
--- a/include/mcld/LD/ELFFileFormat.h
+++ b/include/mcld/LD/ELFFileFormat.h
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ELF_FILE_FORMAT_H
-#define MCLD_ELF_FILE_FORMAT_H
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/LD/LDSection.h>
+#ifndef MCLD_LD_ELFFILEFORMAT_H_
+#define MCLD_LD_ELFFILEFORMAT_H_
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/LD/LDSection.h"
namespace mcld {
@@ -25,683 +25,707 @@ class ObjectBuilder;
* @ref "Object Format," Ch. 10, in ISO/IEC 23360 Part 1:2010(E), Linux
* Standard Base Core Specification 4.1.
*/
-class ELFFileFormat : public LDFileFormat
-{
-private:
+class ELFFileFormat : public LDFileFormat {
+ private:
/// initObjectFormat - initialize sections that are dependent on object
/// formats. (executable, shared objects or relocatable objects).
- virtual void
- initObjectFormat(ObjectBuilder& pBuilder, unsigned int pBitClass) = 0;
+ virtual void initObjectFormat(ObjectBuilder& pBuilder,
+ unsigned int pBitClass) = 0;
-public:
+ public:
ELFFileFormat();
void initStdSections(ObjectBuilder& pBuilder, unsigned int pBitClass);
// ----- capacity ----- //
/// @ref Special Sections, Ch. 4.17, System V ABI, 4th edition.
- bool hasNULLSection() const
- { return (NULL != f_pNULLSection) && (0 != f_pNULLSection->size()); }
+ bool hasNULLSection() const {
+ return (f_pNULLSection != NULL) && (f_pNULLSection->size() != 0);
+ }
- bool hasGOT() const
- { return (NULL != f_pGOT) && (0 != f_pGOT->size()); }
+ bool hasGOT() const { return (f_pGOT != NULL) && (f_pGOT->size() != 0); }
- bool hasPLT() const
- { return (NULL != f_pPLT) && (0 != f_pPLT->size()); }
+ bool hasPLT() const { return (f_pPLT != NULL) && (f_pPLT->size() != 0); }
- bool hasRelDyn() const
- { return (NULL != f_pRelDyn) && (0 != f_pRelDyn->size()); }
+ bool hasRelDyn() const {
+ return (f_pRelDyn != NULL) && (f_pRelDyn->size() != 0);
+ }
- bool hasRelPlt() const
- { return (NULL != f_pRelPlt) && (0 != f_pRelPlt->size()); }
+ bool hasRelPlt() const {
+ return (f_pRelPlt != NULL) && (f_pRelPlt->size() != 0);
+ }
- bool hasRelaDyn() const
- { return (NULL != f_pRelaDyn) && (0 != f_pRelaDyn->size()); }
+ bool hasRelaDyn() const {
+ return (f_pRelaDyn != NULL) && (f_pRelaDyn->size() != 0);
+ }
- bool hasRelaPlt() const
- { return (NULL != f_pRelaPlt) && (0 != f_pRelaPlt->size()); }
+ bool hasRelaPlt() const {
+ return (f_pRelaPlt != NULL) && (f_pRelaPlt->size() != 0);
+ }
/// @ref 10.3.1.1, ISO/IEC 23360, Part 1:2010(E), p. 21.
- bool hasComment() const
- { return (NULL != f_pComment) && (0 != f_pComment->size()); }
+ bool hasComment() const {
+ return (f_pComment != NULL) && (f_pComment->size() != 0);
+ }
- bool hasData1() const
- { return (NULL != f_pData1) && (0 != f_pData1->size()); }
+ bool hasData1() const {
+ return (f_pData1 != NULL) && (f_pData1->size() != 0);
+ }
- bool hasDebug() const
- { return (NULL != f_pDebug) && (0 != f_pDebug->size()); }
+ bool hasDebug() const {
+ return (f_pDebug != NULL) && (f_pDebug->size() != 0);
+ }
- bool hasDynamic() const
- { return (NULL != f_pDynamic) && (0 != f_pDynamic->size()); }
+ bool hasDynamic() const {
+ return (f_pDynamic != NULL) && (f_pDynamic->size() != 0);
+ }
- bool hasDynStrTab() const
- { return (NULL != f_pDynStrTab) && (0 != f_pDynStrTab->size()); }
+ bool hasDynStrTab() const {
+ return (f_pDynStrTab != NULL) && (f_pDynStrTab->size() != 0);
+ }
- bool hasDynSymTab() const
- { return (NULL != f_pDynSymTab) && (0 != f_pDynSymTab->size()); }
+ bool hasDynSymTab() const {
+ return (f_pDynSymTab != NULL) && (f_pDynSymTab->size() != 0);
+ }
- bool hasFini() const
- { return (NULL != f_pFini) && (0 != f_pFini->size()); }
+ bool hasFini() const { return (f_pFini != NULL) && (f_pFini->size() != 0); }
- bool hasFiniArray() const
- { return (NULL != f_pFiniArray) && (0 != f_pFiniArray->size()); }
+ bool hasFiniArray() const {
+ return (f_pFiniArray != NULL) && (f_pFiniArray->size() != 0);
+ }
- bool hasHashTab() const
- { return (NULL != f_pHashTab) && (0 != f_pHashTab->size()); }
+ bool hasHashTab() const {
+ return (f_pHashTab != NULL) && (f_pHashTab->size() != 0);
+ }
- bool hasInit() const
- { return (NULL != f_pInit) && (0 != f_pInit->size()); }
+ bool hasInit() const { return (f_pInit != NULL) && (f_pInit->size() != 0); }
- bool hasInitArray() const
- { return (NULL != f_pInitArray) && (0 != f_pInitArray->size()); }
+ bool hasInitArray() const {
+ return (f_pInitArray != NULL) && (f_pInitArray->size() != 0);
+ }
- bool hasInterp() const
- { return (NULL != f_pInterp) && (0 != f_pInterp->size()); }
+ bool hasInterp() const {
+ return (f_pInterp != NULL) && (f_pInterp->size() != 0);
+ }
- bool hasLine() const
- { return (NULL != f_pLine) && (0 != f_pLine->size()); }
+ bool hasLine() const { return (f_pLine != NULL) && (f_pLine->size() != 0); }
- bool hasNote() const
- { return (NULL != f_pNote) && (0 != f_pNote->size()); }
+ bool hasNote() const { return (f_pNote != NULL) && (f_pNote->size() != 0); }
- bool hasPreInitArray() const
- { return (NULL != f_pPreInitArray) && (0 != f_pPreInitArray->size()); }
+ bool hasPreInitArray() const {
+ return (f_pPreInitArray != NULL) && (f_pPreInitArray->size() != 0);
+ }
- bool hasROData1() const
- { return (NULL != f_pROData1) && (0 != f_pROData1->size()); }
+ bool hasROData1() const {
+ return (f_pROData1 != NULL) && (f_pROData1->size() != 0);
+ }
- bool hasShStrTab() const
- { return (NULL != f_pShStrTab) && (0 != f_pShStrTab->size()); }
+ bool hasShStrTab() const {
+ return (f_pShStrTab != NULL) && (f_pShStrTab->size() != 0);
+ }
- bool hasStrTab() const
- { return (NULL != f_pStrTab) && (0 != f_pStrTab->size()); }
+ bool hasStrTab() const {
+ return (f_pStrTab != NULL) && (f_pStrTab->size() != 0);
+ }
- bool hasSymTab() const
- { return (NULL != f_pSymTab) && (0 != f_pSymTab->size()); }
+ bool hasSymTab() const {
+ return (f_pSymTab != NULL) && (f_pSymTab->size() != 0);
+ }
- bool hasTBSS() const
- { return (NULL != f_pTBSS) && (0 != f_pTBSS->size()); }
+ bool hasTBSS() const { return (f_pTBSS != NULL) && (f_pTBSS->size() != 0); }
- bool hasTData() const
- { return (NULL != f_pTData) && (0 != f_pTData->size()); }
+ bool hasTData() const {
+ return (f_pTData != NULL) && (f_pTData->size() != 0);
+ }
/// @ref 10.3.1.2, ISO/IEC 23360, Part 1:2010(E), p. 24.
- bool hasCtors() const
- { return (NULL != f_pCtors) && (0 != f_pCtors->size()); }
+ bool hasCtors() const {
+ return (f_pCtors != NULL) && (f_pCtors->size() != 0);
+ }
- bool hasDataRelRo() const
- { return (NULL != f_pDataRelRo) && (0 != f_pDataRelRo->size()); }
+ bool hasDataRelRo() const {
+ return (f_pDataRelRo != NULL) && (f_pDataRelRo->size() != 0);
+ }
- bool hasDtors() const
- { return (NULL != f_pDtors) && (0 != f_pDtors->size()); }
+ bool hasDtors() const {
+ return (f_pDtors != NULL) && (f_pDtors->size() != 0);
+ }
- bool hasEhFrame() const
- { return (NULL != f_pEhFrame) && (0 != f_pEhFrame->size()); }
+ bool hasEhFrame() const {
+ return (f_pEhFrame != NULL) && (f_pEhFrame->size() != 0);
+ }
- bool hasEhFrameHdr() const
- { return (NULL != f_pEhFrameHdr) && (0 != f_pEhFrameHdr->size()); }
+ bool hasEhFrameHdr() const {
+ return (f_pEhFrameHdr != NULL) && (f_pEhFrameHdr->size() != 0);
+ }
- bool hasGCCExceptTable() const
- { return (NULL != f_pGCCExceptTable) && (0 != f_pGCCExceptTable->size()); }
+ bool hasGCCExceptTable() const {
+ return (f_pGCCExceptTable != NULL) && (f_pGCCExceptTable->size() != 0);
+ }
- bool hasGNUVersion() const
- { return (NULL != f_pGNUVersion) && (0 != f_pGNUVersion->size()); }
+ bool hasGNUVersion() const {
+ return (f_pGNUVersion != NULL) && (f_pGNUVersion->size() != 0);
+ }
- bool hasGNUVersionD() const
- { return (NULL != f_pGNUVersionD) && (0 != f_pGNUVersionD->size()); }
+ bool hasGNUVersionD() const {
+ return (f_pGNUVersionD != NULL) && (f_pGNUVersionD->size() != 0);
+ }
- bool hasGNUVersionR() const
- { return (NULL != f_pGNUVersionR) && (0 != f_pGNUVersionR->size()); }
+ bool hasGNUVersionR() const {
+ return (f_pGNUVersionR != NULL) && (f_pGNUVersionR->size() != 0);
+ }
- bool hasGOTPLT() const
- { return (NULL != f_pGOTPLT) && (0 != f_pGOTPLT->size()); }
+ bool hasGOTPLT() const {
+ return (f_pGOTPLT != NULL) && (f_pGOTPLT->size() != 0);
+ }
- bool hasJCR() const
- { return (NULL != f_pJCR) && (0 != f_pJCR->size()); }
+ bool hasJCR() const { return (f_pJCR != NULL) && (f_pJCR->size() != 0); }
- bool hasNoteABITag() const
- { return (NULL != f_pNoteABITag) && (0 != f_pNoteABITag->size()); }
+ bool hasNoteABITag() const {
+ return (f_pNoteABITag != NULL) && (f_pNoteABITag->size() != 0);
+ }
- bool hasStab() const
- { return (NULL != f_pStab) && (0 != f_pStab->size()); }
+ bool hasStab() const { return (f_pStab != NULL) && (f_pStab->size() != 0); }
- bool hasStabStr() const
- { return (NULL != f_pStabStr) && (0 != f_pStabStr->size()); }
+ bool hasStabStr() const {
+ return (f_pStabStr != NULL) && (f_pStabStr->size() != 0);
+ }
- bool hasStack() const
- { return (NULL != f_pStack) && (0 != f_pStack->size()); }
+ bool hasStack() const {
+ return (f_pStack != NULL) && (f_pStack->size() != 0);
+ }
- bool hasStackNote() const
- { return (NULL != f_pStackNote); }
+ bool hasStackNote() const { return (f_pStackNote != NULL); }
- bool hasDataRelRoLocal() const
- { return (NULL != f_pDataRelRoLocal) && (0 != f_pDataRelRoLocal->size()); }
+ bool hasDataRelRoLocal() const {
+ return (f_pDataRelRoLocal != NULL) && (f_pDataRelRoLocal->size() != 0);
+ }
- bool hasGNUHashTab() const
- { return (NULL != f_pGNUHashTab) && (0 != f_pGNUHashTab->size()); }
+ bool hasGNUHashTab() const {
+ return (f_pGNUHashTab != NULL) && (f_pGNUHashTab->size() != 0);
+ }
// ----- access functions ----- //
/// @ref Special Sections, Ch. 4.17, System V ABI, 4th edition.
LDSection& getNULLSection() {
- assert(NULL != f_pNULLSection);
+ assert(f_pNULLSection != NULL);
return *f_pNULLSection;
}
const LDSection& getNULLSection() const {
- assert(NULL != f_pNULLSection);
+ assert(f_pNULLSection != NULL);
return *f_pNULLSection;
}
LDSection& getGOT() {
- assert(NULL != f_pGOT);
+ assert(f_pGOT != NULL);
return *f_pGOT;
}
const LDSection& getGOT() const {
- assert(NULL != f_pGOT);
+ assert(f_pGOT != NULL);
return *f_pGOT;
}
LDSection& getPLT() {
- assert(NULL != f_pPLT);
+ assert(f_pPLT != NULL);
return *f_pPLT;
}
const LDSection& getPLT() const {
- assert(NULL != f_pPLT);
+ assert(f_pPLT != NULL);
return *f_pPLT;
}
LDSection& getRelDyn() {
- assert(NULL != f_pRelDyn);
+ assert(f_pRelDyn != NULL);
return *f_pRelDyn;
}
const LDSection& getRelDyn() const {
- assert(NULL != f_pRelDyn);
+ assert(f_pRelDyn != NULL);
return *f_pRelDyn;
}
LDSection& getRelPlt() {
- assert(NULL != f_pRelPlt);
+ assert(f_pRelPlt != NULL);
return *f_pRelPlt;
}
const LDSection& getRelPlt() const {
- assert(NULL != f_pRelPlt);
+ assert(f_pRelPlt != NULL);
return *f_pRelPlt;
}
LDSection& getRelaDyn() {
- assert(NULL != f_pRelaDyn);
+ assert(f_pRelaDyn != NULL);
return *f_pRelaDyn;
}
const LDSection& getRelaDyn() const {
- assert(NULL != f_pRelaDyn);
+ assert(f_pRelaDyn != NULL);
return *f_pRelaDyn;
}
LDSection& getRelaPlt() {
- assert(NULL != f_pRelaPlt);
+ assert(f_pRelaPlt != NULL);
return *f_pRelaPlt;
}
const LDSection& getRelaPlt() const {
- assert(NULL != f_pRelaPlt);
+ assert(f_pRelaPlt != NULL);
return *f_pRelaPlt;
}
LDSection& getComment() {
- assert(NULL != f_pComment);
+ assert(f_pComment != NULL);
return *f_pComment;
}
/// @ref 10.3.1.1, ISO/IEC 23360, Part 1:2010(E), p. 21.
const LDSection& getComment() const {
- assert(NULL != f_pComment);
+ assert(f_pComment != NULL);
return *f_pComment;
}
LDSection& getData1() {
- assert(NULL != f_pData1);
+ assert(f_pData1 != NULL);
return *f_pData1;
}
const LDSection& getData1() const {
- assert(NULL != f_pData1);
+ assert(f_pData1 != NULL);
return *f_pData1;
}
LDSection& getDebug() {
- assert(NULL != f_pDebug);
+ assert(f_pDebug != NULL);
return *f_pDebug;
}
const LDSection& getDebug() const {
- assert(NULL != f_pDebug);
+ assert(f_pDebug != NULL);
return *f_pDebug;
}
LDSection& getDynamic() {
- assert(NULL != f_pDynamic);
+ assert(f_pDynamic != NULL);
return *f_pDynamic;
}
const LDSection& getDynamic() const {
- assert(NULL != f_pDynamic);
+ assert(f_pDynamic != NULL);
return *f_pDynamic;
}
LDSection& getDynStrTab() {
- assert(NULL != f_pDynStrTab);
+ assert(f_pDynStrTab != NULL);
return *f_pDynStrTab;
}
const LDSection& getDynStrTab() const {
- assert(NULL != f_pDynStrTab);
+ assert(f_pDynStrTab != NULL);
return *f_pDynStrTab;
}
LDSection& getDynSymTab() {
- assert(NULL != f_pDynSymTab);
+ assert(f_pDynSymTab != NULL);
return *f_pDynSymTab;
}
const LDSection& getDynSymTab() const {
- assert(NULL != f_pDynSymTab);
+ assert(f_pDynSymTab != NULL);
return *f_pDynSymTab;
}
LDSection& getFini() {
- assert(NULL != f_pFini);
+ assert(f_pFini != NULL);
return *f_pFini;
}
const LDSection& getFini() const {
- assert(NULL != f_pFini);
+ assert(f_pFini != NULL);
return *f_pFini;
}
LDSection& getFiniArray() {
- assert(NULL != f_pFiniArray);
+ assert(f_pFiniArray != NULL);
return *f_pFiniArray;
}
const LDSection& getFiniArray() const {
- assert(NULL != f_pFiniArray);
+ assert(f_pFiniArray != NULL);
return *f_pFiniArray;
}
LDSection& getHashTab() {
- assert(NULL != f_pHashTab);
+ assert(f_pHashTab != NULL);
return *f_pHashTab;
}
const LDSection& getHashTab() const {
- assert(NULL != f_pHashTab);
+ assert(f_pHashTab != NULL);
return *f_pHashTab;
}
LDSection& getInit() {
- assert(NULL != f_pInit);
+ assert(f_pInit != NULL);
return *f_pInit;
}
const LDSection& getInit() const {
- assert(NULL != f_pInit);
+ assert(f_pInit != NULL);
return *f_pInit;
}
LDSection& getInitArray() {
- assert(NULL != f_pInitArray);
+ assert(f_pInitArray != NULL);
return *f_pInitArray;
}
const LDSection& getInitArray() const {
- assert(NULL != f_pInitArray);
+ assert(f_pInitArray != NULL);
return *f_pInitArray;
}
LDSection& getInterp() {
- assert(NULL != f_pInterp);
+ assert(f_pInterp != NULL);
return *f_pInterp;
}
const LDSection& getInterp() const {
- assert(NULL != f_pInterp);
+ assert(f_pInterp != NULL);
return *f_pInterp;
}
LDSection& getLine() {
- assert(NULL != f_pLine);
+ assert(f_pLine != NULL);
return *f_pLine;
}
const LDSection& getLine() const {
- assert(NULL != f_pLine);
+ assert(f_pLine != NULL);
return *f_pLine;
}
LDSection& getNote() {
- assert(NULL != f_pNote);
+ assert(f_pNote != NULL);
return *f_pNote;
}
const LDSection& getNote() const {
- assert(NULL != f_pNote);
+ assert(f_pNote != NULL);
return *f_pNote;
}
LDSection& getPreInitArray() {
- assert(NULL != f_pPreInitArray);
+ assert(f_pPreInitArray != NULL);
return *f_pPreInitArray;
}
const LDSection& getPreInitArray() const {
- assert(NULL != f_pPreInitArray);
+ assert(f_pPreInitArray != NULL);
return *f_pPreInitArray;
}
LDSection& getROData1() {
- assert(NULL != f_pROData1);
+ assert(f_pROData1 != NULL);
return *f_pROData1;
}
const LDSection& getROData1() const {
- assert(NULL != f_pROData1);
+ assert(f_pROData1 != NULL);
return *f_pROData1;
}
LDSection& getShStrTab() {
- assert(NULL != f_pShStrTab);
+ assert(f_pShStrTab != NULL);
return *f_pShStrTab;
}
const LDSection& getShStrTab() const {
- assert(NULL != f_pShStrTab);
+ assert(f_pShStrTab != NULL);
return *f_pShStrTab;
}
LDSection& getStrTab() {
- assert(NULL != f_pStrTab);
+ assert(f_pStrTab != NULL);
return *f_pStrTab;
}
const LDSection& getStrTab() const {
- assert(NULL != f_pStrTab);
+ assert(f_pStrTab != NULL);
return *f_pStrTab;
}
LDSection& getSymTab() {
- assert(NULL != f_pSymTab);
+ assert(f_pSymTab != NULL);
return *f_pSymTab;
}
const LDSection& getSymTab() const {
- assert(NULL != f_pSymTab);
+ assert(f_pSymTab != NULL);
return *f_pSymTab;
}
LDSection& getTBSS() {
- assert(NULL != f_pTBSS);
+ assert(f_pTBSS != NULL);
return *f_pTBSS;
}
const LDSection& getTBSS() const {
- assert(NULL != f_pTBSS);
+ assert(f_pTBSS != NULL);
return *f_pTBSS;
}
LDSection& getTData() {
- assert(NULL != f_pTData);
+ assert(f_pTData != NULL);
return *f_pTData;
}
const LDSection& getTData() const {
- assert(NULL != f_pTData);
+ assert(f_pTData != NULL);
return *f_pTData;
}
/// @ref 10.3.1.2, ISO/IEC 23360, Part 1:2010(E), p. 24.
LDSection& getCtors() {
- assert(NULL != f_pCtors);
+ assert(f_pCtors != NULL);
return *f_pCtors;
}
const LDSection& getCtors() const {
- assert(NULL != f_pCtors);
+ assert(f_pCtors != NULL);
return *f_pCtors;
}
LDSection& getDataRelRo() {
- assert(NULL != f_pDataRelRo);
+ assert(f_pDataRelRo != NULL);
return *f_pDataRelRo;
}
const LDSection& getDataRelRo() const {
- assert(NULL != f_pDataRelRo);
+ assert(f_pDataRelRo != NULL);
return *f_pDataRelRo;
}
LDSection& getDtors() {
- assert(NULL != f_pDtors);
+ assert(f_pDtors != NULL);
return *f_pDtors;
}
const LDSection& getDtors() const {
- assert(NULL != f_pDtors);
+ assert(f_pDtors != NULL);
return *f_pDtors;
}
LDSection& getEhFrame() {
- assert(NULL != f_pEhFrame);
+ assert(f_pEhFrame != NULL);
return *f_pEhFrame;
}
const LDSection& getEhFrame() const {
- assert(NULL != f_pEhFrame);
+ assert(f_pEhFrame != NULL);
return *f_pEhFrame;
}
LDSection& getEhFrameHdr() {
- assert(NULL != f_pEhFrameHdr);
+ assert(f_pEhFrameHdr != NULL);
return *f_pEhFrameHdr;
}
const LDSection& getEhFrameHdr() const {
- assert(NULL != f_pEhFrameHdr);
+ assert(f_pEhFrameHdr != NULL);
return *f_pEhFrameHdr;
}
LDSection& getGCCExceptTable() {
- assert(NULL != f_pGCCExceptTable);
+ assert(f_pGCCExceptTable != NULL);
return *f_pGCCExceptTable;
}
const LDSection& getGCCExceptTable() const {
- assert(NULL != f_pGCCExceptTable);
+ assert(f_pGCCExceptTable != NULL);
return *f_pGCCExceptTable;
}
LDSection& getGNUVersion() {
- assert(NULL != f_pGNUVersion);
+ assert(f_pGNUVersion != NULL);
return *f_pGNUVersion;
}
const LDSection& getGNUVersion() const {
- assert(NULL != f_pGNUVersion);
+ assert(f_pGNUVersion != NULL);
return *f_pGNUVersion;
}
LDSection& getGNUVersionD() {
- assert(NULL != f_pGNUVersionD);
+ assert(f_pGNUVersionD != NULL);
return *f_pGNUVersionD;
}
const LDSection& getGNUVersionD() const {
- assert(NULL != f_pGNUVersionD);
+ assert(f_pGNUVersionD != NULL);
return *f_pGNUVersionD;
}
LDSection& getGNUVersionR() {
- assert(NULL != f_pGNUVersionR);
+ assert(f_pGNUVersionR != NULL);
return *f_pGNUVersionR;
}
const LDSection& getGNUVersionR() const {
- assert(NULL != f_pGNUVersionR);
+ assert(f_pGNUVersionR != NULL);
return *f_pGNUVersionR;
}
LDSection& getGOTPLT() {
- assert(NULL != f_pGOTPLT);
+ assert(f_pGOTPLT != NULL);
return *f_pGOTPLT;
}
const LDSection& getGOTPLT() const {
- assert(NULL != f_pGOTPLT);
+ assert(f_pGOTPLT != NULL);
return *f_pGOTPLT;
}
LDSection& getJCR() {
- assert(NULL != f_pJCR);
+ assert(f_pJCR != NULL);
return *f_pJCR;
}
const LDSection& getJCR() const {
- assert(NULL != f_pJCR);
+ assert(f_pJCR != NULL);
return *f_pJCR;
}
LDSection& getNoteABITag() {
- assert(NULL != f_pNoteABITag);
+ assert(f_pNoteABITag != NULL);
return *f_pNoteABITag;
}
const LDSection& getNoteABITag() const {
- assert(NULL != f_pNoteABITag);
+ assert(f_pNoteABITag != NULL);
return *f_pNoteABITag;
}
LDSection& getStab() {
- assert(NULL != f_pStab);
+ assert(f_pStab != NULL);
return *f_pStab;
}
const LDSection& getStab() const {
- assert(NULL != f_pStab);
+ assert(f_pStab != NULL);
return *f_pStab;
}
LDSection& getStabStr() {
- assert(NULL != f_pStabStr);
+ assert(f_pStabStr != NULL);
return *f_pStabStr;
}
const LDSection& getStabStr() const {
- assert(NULL != f_pStabStr);
+ assert(f_pStabStr != NULL);
return *f_pStabStr;
}
LDSection& getStack() {
- assert(NULL != f_pStack);
+ assert(f_pStack != NULL);
return *f_pStack;
}
const LDSection& getStack() const {
- assert(NULL != f_pStack);
+ assert(f_pStack != NULL);
return *f_pStack;
}
LDSection& getStackNote() {
- assert(NULL != f_pStackNote);
+ assert(f_pStackNote != NULL);
return *f_pStackNote;
}
const LDSection& getStackNote() const {
- assert(NULL != f_pStackNote);
+ assert(f_pStackNote != NULL);
return *f_pStackNote;
}
LDSection& getDataRelRoLocal() {
- assert(NULL != f_pDataRelRoLocal);
+ assert(f_pDataRelRoLocal != NULL);
return *f_pDataRelRoLocal;
}
const LDSection& getDataRelRoLocal() const {
- assert(NULL != f_pDataRelRoLocal);
+ assert(f_pDataRelRoLocal != NULL);
return *f_pDataRelRoLocal;
}
LDSection& getGNUHashTab() {
- assert(NULL != f_pGNUHashTab);
+ assert(f_pGNUHashTab != NULL);
return *f_pGNUHashTab;
}
const LDSection& getGNUHashTab() const {
- assert(NULL != f_pGNUHashTab);
+ assert(f_pGNUHashTab != NULL);
return *f_pGNUHashTab;
}
-protected:
+ protected:
// variable name : ELF
/// @ref Special Sections, Ch. 4.17, System V ABI, 4th edition.
LDSection* f_pNULLSection;
- LDSection* f_pGOT; // .got
- LDSection* f_pPLT; // .plt
- LDSection* f_pRelDyn; // .rel.dyn
- LDSection* f_pRelPlt; // .rel.plt
- LDSection* f_pRelaDyn; // .rela.dyn
- LDSection* f_pRelaPlt; // .rela.plt
+ LDSection* f_pGOT; // .got
+ LDSection* f_pPLT; // .plt
+ LDSection* f_pRelDyn; // .rel.dyn
+ LDSection* f_pRelPlt; // .rel.plt
+ LDSection* f_pRelaDyn; // .rela.dyn
+ LDSection* f_pRelaPlt; // .rela.plt
/// @ref 10.3.1.1, ISO/IEC 23360, Part 1:2010(E), p. 21.
- LDSection* f_pComment; // .comment
- LDSection* f_pData1; // .data1
- LDSection* f_pDebug; // .debug
- LDSection* f_pDynamic; // .dynamic
- LDSection* f_pDynStrTab; // .dynstr
- LDSection* f_pDynSymTab; // .dynsym
- LDSection* f_pFini; // .fini
- LDSection* f_pFiniArray; // .fini_array
- LDSection* f_pHashTab; // .hash
- LDSection* f_pInit; // .init
- LDSection* f_pInitArray; // .init_array
- LDSection* f_pInterp; // .interp
- LDSection* f_pLine; // .line
- LDSection* f_pNote; // .note
- LDSection* f_pPreInitArray; // .preinit_array
- LDSection* f_pROData1; // .rodata1
- LDSection* f_pShStrTab; // .shstrtab
- LDSection* f_pStrTab; // .strtab
- LDSection* f_pSymTab; // .symtab
- LDSection* f_pTBSS; // .tbss
- LDSection* f_pTData; // .tdata
+ LDSection* f_pComment; // .comment
+ LDSection* f_pData1; // .data1
+ LDSection* f_pDebug; // .debug
+ LDSection* f_pDynamic; // .dynamic
+ LDSection* f_pDynStrTab; // .dynstr
+ LDSection* f_pDynSymTab; // .dynsym
+ LDSection* f_pFini; // .fini
+ LDSection* f_pFiniArray; // .fini_array
+ LDSection* f_pHashTab; // .hash
+ LDSection* f_pInit; // .init
+ LDSection* f_pInitArray; // .init_array
+ LDSection* f_pInterp; // .interp
+ LDSection* f_pLine; // .line
+ LDSection* f_pNote; // .note
+ LDSection* f_pPreInitArray; // .preinit_array
+ LDSection* f_pROData1; // .rodata1
+ LDSection* f_pShStrTab; // .shstrtab
+ LDSection* f_pStrTab; // .strtab
+ LDSection* f_pSymTab; // .symtab
+ LDSection* f_pTBSS; // .tbss
+ LDSection* f_pTData; // .tdata
/// @ref 10.3.1.2, ISO/IEC 23360, Part 1:2010(E), p. 24.
- LDSection* f_pCtors; // .ctors
- LDSection* f_pDataRelRo; // .data.rel.ro
- LDSection* f_pDtors; // .dtors
- LDSection* f_pEhFrame; // .eh_frame
- LDSection* f_pEhFrameHdr; // .eh_frame_hdr
- LDSection* f_pGCCExceptTable; // .gcc_except_table
- LDSection* f_pGNUVersion; // .gnu.version
- LDSection* f_pGNUVersionD; // .gnu.version_d
- LDSection* f_pGNUVersionR; // .gnu.version_r
- LDSection* f_pGOTPLT; // .got.plt
- LDSection* f_pJCR; // .jcr
- LDSection* f_pNoteABITag; // .note.ABI-tag
- LDSection* f_pStab; // .stab
- LDSection* f_pStabStr; // .stabstr
+ LDSection* f_pCtors; // .ctors
+ LDSection* f_pDataRelRo; // .data.rel.ro
+ LDSection* f_pDtors; // .dtors
+ LDSection* f_pEhFrame; // .eh_frame
+ LDSection* f_pEhFrameHdr; // .eh_frame_hdr
+ LDSection* f_pGCCExceptTable; // .gcc_except_table
+ LDSection* f_pGNUVersion; // .gnu.version
+ LDSection* f_pGNUVersionD; // .gnu.version_d
+ LDSection* f_pGNUVersionR; // .gnu.version_r
+ LDSection* f_pGOTPLT; // .got.plt
+ LDSection* f_pJCR; // .jcr
+ LDSection* f_pNoteABITag; // .note.ABI-tag
+ LDSection* f_pStab; // .stab
+ LDSection* f_pStabStr; // .stabstr
/// practical
- LDSection* f_pStack; // .stack
- LDSection* f_pStackNote; // .note.GNU-stack
- LDSection* f_pDataRelRoLocal; // .data.rel.ro.local
- LDSection* f_pGNUHashTab; // .gnu.hash
+ LDSection* f_pStack; // .stack
+ LDSection* f_pStackNote; // .note.GNU-stack
+ LDSection* f_pDataRelRoLocal; // .data.rel.ro.local
+ LDSection* f_pGNUHashTab; // .gnu.hash
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ELFFILEFORMAT_H_
diff --git a/include/mcld/LD/ELFObjectFileFormat.h b/include/mcld/LD/ELFObjectFileFormat.h
index 45e3ca2..9ca7713 100644
--- a/include/mcld/LD/ELFObjectFileFormat.h
+++ b/include/mcld/LD/ELFObjectFileFormat.h
@@ -6,9 +6,9 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ELF_OBJECT_FILE_FROMAT_H
-#define MCLD_ELF_OBJECT_FILE_FROMAT_H
-#include <mcld/LD/ELFFileFormat.h>
+#ifndef MCLD_LD_ELFOBJECTFILEFORMAT_H_
+#define MCLD_LD_ELFOBJECTFILEFORMAT_H_
+#include "mcld/LD/ELFFileFormat.h"
namespace mcld {
@@ -17,15 +17,13 @@ class ObjectBuilder;
/** \class ELFObjectFileFormat
* \brief ELFObjectFileFormat describes the format for ELF dynamic objects.
*/
-class ELFObjectFileFormat : public ELFFileFormat
-{
+class ELFObjectFileFormat : public ELFFileFormat {
void initObjectFormat(ObjectBuilder& pBuilder, unsigned int pBitClass) {
// do nothing
return;
}
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ELFOBJECTFILEFORMAT_H_
diff --git a/include/mcld/LD/ELFObjectReader.h b/include/mcld/LD/ELFObjectReader.h
index 4449234..a892e02 100644
--- a/include/mcld/LD/ELFObjectReader.h
+++ b/include/mcld/LD/ELFObjectReader.h
@@ -6,36 +6,34 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_ELF_OBJECT_READER_H
-#define MCLD_ELF_OBJECT_READER_H
+#ifndef MCLD_LD_ELFOBJECTREADER_H_
+#define MCLD_LD_ELFOBJECTREADER_H_
-#include <mcld/LD/ObjectReader.h>
-#include <mcld/ADT/Flags.h>
+#include "mcld/ADT/Flags.h"
+#include "mcld/LD/ObjectReader.h"
namespace mcld {
-class Module;
+class EhFrameReader;
+class ELFReaderIF;
class Input;
class IRBuilder;
class GNULDBackend;
-class ELFReaderIF;
-class EhFrameReader;
class LinkerConfig;
/** \lclass ELFObjectReader
* \brief ELFObjectReader reads target-independent parts of ELF object file
*/
-class ELFObjectReader : public ObjectReader
-{
-public:
+class ELFObjectReader : public ObjectReader {
+ public:
enum ReadFlagType {
- ParseEhFrame = 0x1, ///< parse .eh_frame section if the bit is set.
- NumOfReadFlags = 1
+ ParseEhFrame = 0x1, ///< parse .eh_frame section if the bit is set.
+ NumOfReadFlags = 1
};
typedef Flags<ReadFlagType> ReadFlag;
-public:
+ public:
ELFObjectReader(GNULDBackend& pBackend,
IRBuilder& pBuilder,
const LinkerConfig& pConfig);
@@ -43,7 +41,7 @@ public:
~ELFObjectReader();
// ----- observers ----- //
- bool isMyFormat(Input &pFile, bool &pContinue) const;
+ bool isMyFormat(Input& pFile, bool& pContinue) const;
// ----- readers ----- //
bool readHeader(Input& pFile);
@@ -57,7 +55,7 @@ public:
/// This function should be called after symbol resolution.
virtual bool readRelocations(Input& pFile);
-private:
+ private:
ELFReaderIF* m_pELFReader;
EhFrameReader* m_pEhFrameReader;
IRBuilder& m_Builder;
@@ -66,7 +64,6 @@ private:
const LinkerConfig& m_Config;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ELFOBJECTREADER_H_
diff --git a/include/mcld/LD/ELFObjectWriter.h b/include/mcld/LD/ELFObjectWriter.h
index b83fb01..8181b9f 100644
--- a/include/mcld/LD/ELFObjectWriter.h
+++ b/include/mcld/LD/ELFObjectWriter.h
@@ -6,34 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_ELFOBJWRITER_H
-#define MCLD_LD_ELFOBJWRITER_H
-#include <mcld/LD/ObjectWriter.h>
-#include <cassert>
+#ifndef MCLD_LD_ELFOBJECTWRITER_H_
+#define MCLD_LD_ELFOBJECTWRITER_H_
+#include "mcld/LD/ObjectWriter.h"
+#include "mcld/Support/FileOutputBuffer.h"
-#include <mcld/Support/FileOutputBuffer.h>
+#include <cassert>
namespace mcld {
class EhFrame;
-class Module;
-class LinkerConfig;
class GNULDBackend;
-class FragmentLinker;
-class Relocation;
class LDSection;
-class SectionData;
+class LinkerConfig;
+class Module;
class RelocData;
-class Output;
+class SectionData;
/** \class ELFObjectWriter
* \brief ELFObjectWriter writes the target-independent parts of object files.
* ELFObjectWriter reads a MCLDFile and writes into raw_ostream
*
*/
-class ELFObjectWriter : public ObjectWriter
-{
-public:
+class ELFObjectWriter : public ObjectWriter {
+ public:
ELFObjectWriter(GNULDBackend& pBackend, const LinkerConfig& pConfig);
~ELFObjectWriter();
@@ -42,16 +38,16 @@ public:
size_t getOutputSize(const Module& pModule) const;
-private:
+ private:
void writeSection(Module& pModule,
- FileOutputBuffer& pOutput, LDSection *section);
+ FileOutputBuffer& pOutput,
+ LDSection* section);
- GNULDBackend& target() { return m_Backend; }
-
- const GNULDBackend& target() const { return m_Backend; }
+ const GNULDBackend& target() const { return m_Backend; }
+ GNULDBackend& target() { return m_Backend; }
// writeELFHeader - emit ElfXX_Ehdr
- template<size_t SIZE>
+ template <size_t SIZE>
void writeELFHeader(const LinkerConfig& pConfig,
const Module& pModule,
FileOutputBuffer& pOutput) const;
@@ -60,13 +56,13 @@ private:
const Module& pModule) const;
// emitSectionHeader - emit ElfXX_Shdr
- template<size_t SIZE>
+ template <size_t SIZE>
void emitSectionHeader(const Module& pModule,
const LinkerConfig& pConfig,
FileOutputBuffer& pOutput) const;
// emitProgramHeader - emit ElfXX_Phdr
- template<size_t SIZE>
+ template <size_t SIZE>
void emitProgramHeader(FileOutputBuffer& pOutput) const;
// emitShStrTab - emit .shstrtab
@@ -77,26 +73,27 @@ private:
void emitSectionData(const LDSection& pSection, MemoryRegion& pRegion) const;
void emitEhFrame(Module& pModule,
- EhFrame& pFrame, MemoryRegion& pRegion) const;
+ EhFrame& pFrame,
+ MemoryRegion& pRegion) const;
void emitRelocation(const LinkerConfig& pConfig,
const LDSection& pSection,
MemoryRegion& pRegion) const;
// emitRel - emit ElfXX_Rel
- template<size_t SIZE>
+ template <size_t SIZE>
void emitRel(const LinkerConfig& pConfig,
const RelocData& pRelocData,
MemoryRegion& pRegion) const;
// emitRela - emit ElfXX_Rela
- template<size_t SIZE>
+ template <size_t SIZE>
void emitRela(const LinkerConfig& pConfig,
const RelocData& pRelocData,
MemoryRegion& pRegion) const;
// getSectEntrySize - compute ElfXX_Shdr::sh_entsize
- template<size_t SIZE>
+ template <size_t SIZE>
uint64_t getSectEntrySize(const LDSection& pSection) const;
// getSectLink - compute ElfXX_Shdr::sh_link
@@ -106,28 +103,26 @@ private:
// getSectInfo - compute ElfXX_Shdr::sh_info
uint64_t getSectInfo(const LDSection& pSection) const;
- template<size_t SIZE>
- uint64_t getLastStartOffset(const Module& pModule) const
- {
+ template <size_t SIZE>
+ uint64_t getLastStartOffset(const Module& pModule) const {
assert(0 && "Call invalid ELFObjectWriter::getLastStartOffset");
return 0;
}
void emitSectionData(const SectionData& pSD, MemoryRegion& pRegion) const;
-private:
+ private:
GNULDBackend& m_Backend;
const LinkerConfig& m_Config;
};
-template<>
+template <>
uint64_t ELFObjectWriter::getLastStartOffset<32>(const Module& pModule) const;
-template<>
+template <>
uint64_t ELFObjectWriter::getLastStartOffset<64>(const Module& pModule) const;
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ELFOBJECTWRITER_H_
diff --git a/include/mcld/LD/ELFReader.h b/include/mcld/LD/ELFReader.h
index afdb0b0..7cd91a5 100644
--- a/include/mcld/LD/ELFReader.h
+++ b/include/mcld/LD/ELFReader.h
@@ -6,53 +6,49 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_ELFREADER_H
-#define MCLD_LD_ELFREADER_H
+#ifndef MCLD_LD_ELFREADER_H_
+#define MCLD_LD_ELFREADER_H_
+
+#include "mcld/LD/ELFReaderIf.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/ELF.h>
#include <llvm/Support/Host.h>
-#include <mcld/LD/ELFReaderIf.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Target/GNULDBackend.h>
-
namespace mcld {
-//class Module;
class IRBuilder;
-class SectionData;
class LDSection;
+class SectionData;
/** \class ELFReader
* \brief ELFReader is a template scaffolding for partial specification.
*/
-template<size_t BIT, bool LITTLEENDIAN>
-class ELFReader
-{ };
+template <size_t BIT, bool LITTLEENDIAN>
+class ELFReader {};
/** \class ELFReader<32, true>
* \brief ELFReader<32, true> is a 32-bit, little endian ELFReader.
*/
-template<>
-class ELFReader<32, true> : public ELFReaderIF
-{
-public:
+template <>
+class ELFReader<32, true> : public ELFReaderIF {
+ public:
typedef llvm::ELF::Elf32_Ehdr ELFHeader;
typedef llvm::ELF::Elf32_Shdr SectionHeader;
- typedef llvm::ELF::Elf32_Sym Symbol;
- typedef llvm::ELF::Elf32_Rel Rel;
+ typedef llvm::ELF::Elf32_Sym Symbol;
+ typedef llvm::ELF::Elf32_Rel Rel;
typedef llvm::ELF::Elf32_Rela Rela;
-public:
- ELFReader(GNULDBackend& pBackend);
+ public:
+ explicit ELFReader(GNULDBackend& pBackend);
~ELFReader();
/// ELFHeaderSize - return the size of the ELFHeader
- size_t getELFHeaderSize() const
- { return sizeof(ELFHeader); }
+ size_t getELFHeaderSize() const { return sizeof(ELFHeader); }
/// isELF - is this a ELF file
bool isELF(const void* pELFHeader) const;
@@ -97,52 +93,47 @@ public:
/// readDynamic - read ELF .dynamic in input dynobj
bool readDynamic(Input& pInput) const;
-private:
+ private:
struct AliasInfo {
- LDSymbol* pt_alias; ///potential alias
+ LDSymbol* pt_alias; /// potential alias
uint64_t ld_value;
ResolveInfo::Binding ld_binding;
};
/// comparison function to sort symbols for analyzing weak alias.
/// sort symbols by symbol value and then weak before strong.
- /// ref. to gold symtabl.cc 1595
static bool less(AliasInfo p1, AliasInfo p2) {
if (p1.ld_value != p2.ld_value)
return (p1.ld_value < p2.ld_value);
if (p1.ld_binding != p2.ld_binding) {
- if (ResolveInfo::Weak==p1.ld_binding)
+ if (ResolveInfo::Weak == p1.ld_binding)
return true;
- else if (ResolveInfo::Weak==p2.ld_binding)
+ else if (ResolveInfo::Weak == p2.ld_binding)
return false;
}
return p1.pt_alias->str() < p2.pt_alias->str();
}
-
};
-
/** \class ELFReader<64, true>
* \brief ELFReader<64, true> is a 64-bit, little endian ELFReader.
*/
-template<>
-class ELFReader<64, true> : public ELFReaderIF
-{
-public:
+template <>
+class ELFReader<64, true> : public ELFReaderIF {
+ public:
typedef llvm::ELF::Elf64_Ehdr ELFHeader;
typedef llvm::ELF::Elf64_Shdr SectionHeader;
- typedef llvm::ELF::Elf64_Sym Symbol;
- typedef llvm::ELF::Elf64_Rel Rel;
+ typedef llvm::ELF::Elf64_Sym Symbol;
+ typedef llvm::ELF::Elf64_Rel Rel;
typedef llvm::ELF::Elf64_Rela Rela;
-public:
- ELFReader(GNULDBackend& pBackend);
+ public:
+ explicit ELFReader(GNULDBackend& pBackend);
~ELFReader();
/// ELFHeaderSize - return the size of the ELFHeader
- size_t getELFHeaderSize() const
- { return sizeof(ELFHeader); }
+ size_t getELFHeaderSize() const { return sizeof(ELFHeader); }
/// isELF - is this a ELF file
bool isELF(const void* pELFHeader) const;
@@ -187,31 +178,28 @@ public:
/// readDynamic - read ELF .dynamic in input dynobj
bool readDynamic(Input& pInput) const;
-private:
+ private:
struct AliasInfo {
- LDSymbol* pt_alias; ///potential alias
+ LDSymbol* pt_alias; /// potential alias
uint64_t ld_value;
ResolveInfo::Binding ld_binding;
};
/// comparison function to sort symbols for analyzing weak alias.
/// sort symbols by symbol value and then weak before strong.
- /// ref. to gold symtabl.cc 1595
static bool less(AliasInfo p1, AliasInfo p2) {
if (p1.ld_value != p2.ld_value)
return (p1.ld_value < p2.ld_value);
if (p1.ld_binding != p2.ld_binding) {
- if (ResolveInfo::Weak==p1.ld_binding)
+ if (ResolveInfo::Weak == p1.ld_binding)
return true;
- else if (ResolveInfo::Weak==p2.ld_binding)
+ else if (ResolveInfo::Weak == p2.ld_binding)
return false;
}
return p1.pt_alias->str() < p2.pt_alias->str();
}
-
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ELFREADER_H_
diff --git a/include/mcld/LD/ELFReaderIf.h b/include/mcld/LD/ELFReaderIf.h
index 9fae24f..b359da1 100644
--- a/include/mcld/LD/ELFReaderIf.h
+++ b/include/mcld/LD/ELFReaderIf.h
@@ -6,38 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_ELFREADERIF_H
-#define MCLD_LD_ELFREADERIF_H
+#ifndef MCLD_LD_ELFREADERIF_H_
+#define MCLD_LD_ELFREADERIF_H_
+
+#include "mcld/LinkerConfig.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/ELF.h>
#include <llvm/Support/Host.h>
-#include <mcld/Module.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Support/MsgHandling.h>
-
namespace mcld {
-class Module;
class IRBuilder;
class FragmentRef;
-class SectionData;
class LDSection;
+class SectionData;
/** \class ELFReaderIF
* \brief ELFReaderIF provides common interface for all kind of ELF readers.
*/
-class ELFReaderIF
-{
-public:
- ELFReaderIF(GNULDBackend& pBackend)
- : m_Backend(pBackend)
- { }
+class ELFReaderIF {
+ public:
+ explicit ELFReaderIF(GNULDBackend& pBackend) : m_Backend(pBackend) {}
- virtual ~ELFReaderIF() { }
+ virtual ~ELFReaderIF() {}
/// ELFHeaderSize - return the size of the ELFHeader
virtual size_t getELFHeaderSize() const = 0;
@@ -56,8 +50,7 @@ public:
/// target - the target backend
const GNULDBackend& target() const { return m_Backend; }
- GNULDBackend& target() { return m_Backend; }
-
+ GNULDBackend& target() { return m_Backend; }
/// readSectionHeaders - read ELF section header table and create LDSections
virtual bool readSectionHeaders(Input& pInput,
@@ -91,7 +84,7 @@ public:
/// readDynamic - read ELF .dynamic in input dynobj
virtual bool readDynamic(Input& pInput) const = 0;
-protected:
+ protected:
/// LinkInfo - some section needs sh_link and sh_info, remember them.
struct LinkInfo {
LDSection* section;
@@ -101,7 +94,7 @@ protected:
typedef std::vector<LinkInfo> LinkInfoList;
-protected:
+ protected:
ResolveInfo::Type getSymType(uint8_t pInfo, uint16_t pShndx) const;
ResolveInfo::Desc getSymDesc(uint16_t pShndx, const Input& pInput) const;
@@ -120,11 +113,10 @@ protected:
ResolveInfo::Visibility getSymVisibility(uint8_t pVis) const;
-protected:
+ protected:
GNULDBackend& m_Backend;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ELFREADERIF_H_
diff --git a/include/mcld/LD/ELFSegment.h b/include/mcld/LD/ELFSegment.h
index cd86ecc..09fb612 100644
--- a/include/mcld/LD/ELFSegment.h
+++ b/include/mcld/LD/ELFSegment.h
@@ -6,100 +6,92 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_ELFSEGMENT_H
-#define MCLD_LD_ELFSEGMENT_H
-#include <mcld/Support/Allocators.h>
-#include <mcld/Config/Config.h>
-#include <llvm/Support/ELF.h>
+#ifndef MCLD_LD_ELFSEGMENT_H_
+#define MCLD_LD_ELFSEGMENT_H_
+#include "mcld/Config/Config.h"
+#include "mcld/Support/Allocators.h"
+
#include <llvm/Support/DataTypes.h>
+#include <llvm/Support/ELF.h>
+
#include <vector>
-namespace mcld
-{
+namespace mcld {
class LDSection;
/** \class ELFSegment
* \brief decribe the program header for ELF executable or shared object
*/
-class ELFSegment
-{
-public:
+class ELFSegment {
+ public:
typedef std::vector<LDSection*> SectionList;
typedef SectionList::iterator iterator;
typedef SectionList::const_iterator const_iterator;
typedef SectionList::reverse_iterator reverse_iterator;
typedef SectionList::const_reverse_iterator const_reverse_iterator;
-private:
+ private:
friend class Chunk<ELFSegment, MCLD_SEGMENTS_PER_OUTPUT>;
ELFSegment();
- ELFSegment(uint32_t pType, uint32_t pFlag = llvm::ELF::PF_R);
+ explicit ELFSegment(uint32_t pType, uint32_t pFlag = llvm::ELF::PF_R);
-public:
+ public:
~ELFSegment();
/// ----- iterators ----- ///
- iterator begin() { return m_SectionList.begin(); }
+ iterator begin() { return m_SectionList.begin(); }
const_iterator begin() const { return m_SectionList.begin(); }
- iterator end() { return m_SectionList.end(); }
- const_iterator end() const { return m_SectionList.end(); }
+ iterator end() { return m_SectionList.end(); }
+ const_iterator end() const { return m_SectionList.end(); }
- reverse_iterator rbegin() { return m_SectionList.rbegin(); }
+ reverse_iterator rbegin() { return m_SectionList.rbegin(); }
const_reverse_iterator rbegin() const { return m_SectionList.rbegin(); }
- reverse_iterator rend() { return m_SectionList.rend(); }
- const_reverse_iterator rend() const { return m_SectionList.rend(); }
+ reverse_iterator rend() { return m_SectionList.rend(); }
+ const_reverse_iterator rend() const { return m_SectionList.rend(); }
- LDSection* front() { return m_SectionList.front(); }
+ LDSection* front() { return m_SectionList.front(); }
const LDSection* front() const { return m_SectionList.front(); }
- LDSection* back() { return m_SectionList.back(); }
- const LDSection* back() const { return m_SectionList.back(); }
+ LDSection* back() { return m_SectionList.back(); }
+ const LDSection* back() const { return m_SectionList.back(); }
/// ----- observers ----- ///
- uint32_t type() const { return m_Type; }
+ uint32_t type() const { return m_Type; }
uint64_t offset() const { return m_Offset; }
- uint64_t vaddr() const { return m_Vaddr; }
- uint64_t paddr() const { return m_Paddr; }
+ uint64_t vaddr() const { return m_Vaddr; }
+ uint64_t paddr() const { return m_Paddr; }
uint64_t filesz() const { return m_Filesz; }
- uint64_t memsz() const { return m_Memsz; }
- uint32_t flag() const { return m_Flag; }
- uint64_t align() const { return std::max(m_Align, m_MaxSectionAlign); }
+ uint64_t memsz() const { return m_Memsz; }
+ uint32_t flag() const { return m_Flag; }
+ uint64_t align() const { return std::max(m_Align, m_MaxSectionAlign); }
size_t size() const { return m_SectionList.size(); }
- bool empty() const { return m_SectionList.empty(); }
+ bool empty() const { return m_SectionList.empty(); }
bool isLoadSegment() const;
bool isDataSegment() const;
bool isBssSegment() const;
/// ----- modifiers ----- ///
- void setOffset(uint64_t pOffset)
- { m_Offset = pOffset; }
+ void setOffset(uint64_t pOffset) { m_Offset = pOffset; }
- void setVaddr(uint64_t pVaddr)
- { m_Vaddr = pVaddr; }
+ void setVaddr(uint64_t pVaddr) { m_Vaddr = pVaddr; }
- void setPaddr(uint64_t pPaddr)
- { m_Paddr = pPaddr; }
+ void setPaddr(uint64_t pPaddr) { m_Paddr = pPaddr; }
- void setFilesz(uint64_t pFilesz)
- { m_Filesz = pFilesz; }
+ void setFilesz(uint64_t pFilesz) { m_Filesz = pFilesz; }
- void setMemsz(uint64_t pMemsz)
- { m_Memsz = pMemsz; }
+ void setMemsz(uint64_t pMemsz) { m_Memsz = pMemsz; }
- void setFlag(uint32_t pFlag)
- { m_Flag = pFlag; }
+ void setFlag(uint32_t pFlag) { m_Flag = pFlag; }
- void updateFlag(uint32_t pFlag)
- {
+ void updateFlag(uint32_t pFlag) {
// PT_TLS segment should be PF_R
if (llvm::ELF::PT_TLS != m_Type)
m_Flag |= pFlag;
}
- void setAlign(uint64_t pAlign)
- { m_Align = pAlign; }
+ void setAlign(uint64_t pAlign) { m_Align = pAlign; }
iterator insert(iterator pPos, LDSection* pSection);
@@ -110,20 +102,19 @@ public:
static void Destroy(ELFSegment*& pSegment);
static void Clear();
-private:
- uint32_t m_Type; // Type of segment
- uint32_t m_Flag; // Segment flags
- uint64_t m_Offset; // File offset where segment is located, in bytes
- uint64_t m_Vaddr; // Virtual address of the segment
- uint64_t m_Paddr; // Physical address of the segment (OS-specific)
- uint64_t m_Filesz; // # of bytes in file image of segment (may be 0)
- uint64_t m_Memsz; // # of bytes in mem image of segment (may be 0)
- uint64_t m_Align; // alignment constraint
- uint64_t m_MaxSectionAlign; // max alignment of the sections in this segment
+ private:
+ uint32_t m_Type; // Type of segment
+ uint32_t m_Flag; // Segment flags
+ uint64_t m_Offset; // File offset where segment is located, in bytes
+ uint64_t m_Vaddr; // Virtual address of the segment
+ uint64_t m_Paddr; // Physical address of the segment (OS-specific)
+ uint64_t m_Filesz; // # of bytes in file image of segment (may be 0)
+ uint64_t m_Memsz; // # of bytes in mem image of segment (may be 0)
+ uint64_t m_Align; // alignment constraint
+ uint64_t m_MaxSectionAlign; // max alignment of the sections in this segment
SectionList m_SectionList;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ELFSEGMENT_H_
diff --git a/include/mcld/LD/ELFSegmentFactory.h b/include/mcld/LD/ELFSegmentFactory.h
index 9bd6148..12a5831 100644
--- a/include/mcld/LD/ELFSegmentFactory.h
+++ b/include/mcld/LD/ELFSegmentFactory.h
@@ -6,15 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_ELFSEGMENTFACTORY_H
-#define MCLD_LD_ELFSEGMENTFACTORY_H
+#ifndef MCLD_LD_ELFSEGMENTFACTORY_H_
+#define MCLD_LD_ELFSEGMENTFACTORY_H_
#include <llvm/Support/DataTypes.h>
#include <llvm/Support/ELF.h>
+
#include <vector>
-namespace mcld
-{
+namespace mcld {
class ELFSegment;
class LDSection;
@@ -22,22 +22,21 @@ class LDSection;
/** \class ELFSegmentFactory
* \brief provide the interface to create and delete an ELFSegment
*/
-class ELFSegmentFactory
-{
-public:
+class ELFSegmentFactory {
+ public:
typedef std::vector<ELFSegment*> Segments;
typedef Segments::const_iterator const_iterator;
typedef Segments::iterator iterator;
const_iterator begin() const { return m_Segments.begin(); }
- iterator begin() { return m_Segments.begin(); }
- const_iterator end() const { return m_Segments.end(); }
- iterator end() { return m_Segments.end(); }
+ iterator begin() { return m_Segments.begin(); }
+ const_iterator end() const { return m_Segments.end(); }
+ iterator end() { return m_Segments.end(); }
const ELFSegment* front() const { return m_Segments.front(); }
- ELFSegment* front() { return m_Segments.front(); }
- const ELFSegment* back() const { return m_Segments.back(); }
- ELFSegment* back() { return m_Segments.back(); }
+ ELFSegment* front() { return m_Segments.front(); }
+ const ELFSegment* back() const { return m_Segments.back(); }
+ ELFSegment* back() { return m_Segments.back(); }
size_t size() const { return m_Segments.size(); }
@@ -45,10 +44,11 @@ public:
iterator find(uint32_t pType, uint32_t pFlagSet, uint32_t pFlagClear);
- const_iterator
- find(uint32_t pType, uint32_t pFlagSet, uint32_t pFlagClear) const;
+ const_iterator find(uint32_t pType,
+ uint32_t pFlagSet,
+ uint32_t pFlagClear) const;
- iterator find(uint32_t pType, const LDSection* pSection);
+ iterator find(uint32_t pType, const LDSection* pSection);
const_iterator find(uint32_t pType, const LDSection* pSection) const;
@@ -59,11 +59,10 @@ public:
void erase(iterator pSegment);
-private:
+ private:
Segments m_Segments;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_ELFSEGMENTFACTORY_H_
diff --git a/include/mcld/LD/EhFrame.h b/include/mcld/LD/EhFrame.h
index eed80bc..ef6446d 100644
--- a/include/mcld/LD/EhFrame.h
+++ b/include/mcld/LD/EhFrame.h
@@ -6,34 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_EHFRAME_H
-#define MCLD_LD_EHFRAME_H
+#ifndef MCLD_LD_EHFRAME_H_
+#define MCLD_LD_EHFRAME_H_
-#include <mcld/Config/Config.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Support/Allocators.h>
+#include "mcld/Config/Config.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Support/Allocators.h"
+#include "mcld/Support/Compiler.h"
#include <llvm/ADT/StringRef.h>
+
#include <list>
#include <map>
-#include <set>
#include <vector>
namespace mcld {
class Input;
-class Module;
class LDSection;
-class ObjectLinker;
class Relocation;
/** \class EhFrame
* \brief EhFrame represents .eh_frame section
*/
-class EhFrame
-{
-private:
+class EhFrame {
+ private:
friend class Chunk<EhFrame, MCLD_SECTIONS_PER_INPUT>;
EhFrame();
@@ -41,15 +39,8 @@ private:
~EhFrame();
- EhFrame(const EhFrame&); // DO NOT IMPLEMENT
- EhFrame& operator=(const EhFrame&); // DO NOT IMPLEMENT
-
-public:
- enum RecordType {
- RECORD_UNKNOWN,
- RECORD_INPUT,
- RECORD_GENERATED
- };
+ public:
+ enum RecordType { RECORD_UNKNOWN, RECORD_INPUT, RECORD_GENERATED };
class CIE;
class FDE;
@@ -62,32 +53,32 @@ public:
typedef FDEList::iterator fde_iterator;
typedef FDEList::const_iterator const_fde_iterator;
- typedef std::map</*offset*/size_t, CIE*> CIEMap;
+ typedef std::map</*offset*/ size_t, CIE*> CIEMap;
// A super class of CIE and FDE, containing the same part
- class Record : public RegionFragment
- {
- public:
- Record(llvm::StringRef pRegion);
+ class Record : public RegionFragment {
+ public:
+ explicit Record(llvm::StringRef pRegion);
virtual ~Record();
- const llvm::StringRef getRegion() const { return RegionFragment::getRegion(); }
- llvm::StringRef getRegion() { return RegionFragment::getRegion(); }
+ const llvm::StringRef getRegion() const {
+ return RegionFragment::getRegion();
+ }
+ llvm::StringRef getRegion() { return RegionFragment::getRegion(); }
virtual RecordType getRecordType() const { return RECORD_UNKNOWN; }
- private:
- Record(const Record&); // DO NOT IMPLEMENT
- Record& operator=(const Record&); // DO NOT IMPLEMENT
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Record);
};
/** \class CIE
* \brief Common Information Entry.
- * The CIE structure refers to LSB Core Spec 4.1, chap.10.6. Exception Frames.
+ * The CIE structure refers to LSB Core Spec 4.1, chap.10.6. Exception
+ * Frames.
*/
- class CIE : public Record
- {
- public:
- CIE(llvm::StringRef pRegion);
+ class CIE : public Record {
+ public:
+ explicit CIE(llvm::StringRef pRegion);
~CIE();
virtual RecordType getRecordType() const { return RECORD_INPUT; }
@@ -101,14 +92,22 @@ public:
void setRelocation(const Relocation& pReloc) { m_pReloc = &pReloc; }
const Relocation* getRelocation() const { return m_pReloc; }
- void setPersonalityOffset(uint64_t pOffset) { m_PersonalityOffset = pOffset; }
+ void setPersonalityOffset(uint64_t pOffset) {
+ m_PersonalityOffset = pOffset;
+ }
uint64_t getPersonalityOffset() const { return m_PersonalityOffset; }
- void setPersonalityName(const std::string& pStr) { m_PersonalityName = pStr; }
+ void setPersonalityName(const std::string& pStr) {
+ m_PersonalityName = pStr;
+ }
const std::string& getPersonalityName() const { return m_PersonalityName; }
- void setAugmentationData(const std::string& pStr) { m_AugmentationData = pStr; }
- const std::string& getAugmentationData() const { return m_AugmentationData; }
+ void setAugmentationData(const std::string& pStr) {
+ m_AugmentationData = pStr;
+ }
+ const std::string& getAugmentationData() const {
+ return m_AugmentationData;
+ }
void add(FDE& pFDE) { m_FDEs.push_back(&pFDE); }
void remove(FDE& pFDE) { m_FDEs.remove(&pFDE); }
@@ -116,11 +115,11 @@ public:
size_t numOfFDEs() const { return m_FDEs.size(); }
const_fde_iterator begin() const { return m_FDEs.begin(); }
- fde_iterator begin() { return m_FDEs.begin(); }
+ fde_iterator begin() { return m_FDEs.begin(); }
const_fde_iterator end() const { return m_FDEs.end(); }
- fde_iterator end() { return m_FDEs.end(); }
+ fde_iterator end() { return m_FDEs.end(); }
- private:
+ private:
uint8_t m_FDEEncode;
bool m_Mergeable;
const Relocation* m_pReloc;
@@ -132,43 +131,41 @@ public:
/** \class FDE
* \brief Frame Description Entry
- * The FDE structure refers to LSB Core Spec 4.1, chap.10.6. Exception Frames.
+ * The FDE structure refers to LSB Core Spec 4.1, chap.10.6. Exception
+ * Frames.
*/
- class FDE : public Record
- {
- public:
+ class FDE : public Record {
+ public:
FDE(llvm::StringRef pRegion, CIE& pCIE);
~FDE();
void setCIE(CIE& pCIE);
const CIE& getCIE() const { return *m_pCIE; }
- CIE& getCIE() { return *m_pCIE; }
+ CIE& getCIE() { return *m_pCIE; }
- private:
+ private:
CIE* m_pCIE; // Referenced CIE may change when merging.
};
// These are created for PLT
- class GeneratedCIE : public CIE
- {
- public:
- GeneratedCIE(llvm::StringRef pRegion);
+ class GeneratedCIE : public CIE {
+ public:
+ explicit GeneratedCIE(llvm::StringRef pRegion);
~GeneratedCIE();
virtual RecordType getRecordType() const { return RECORD_GENERATED; }
virtual bool getMergeable() const { return true; }
};
- class GeneratedFDE : public FDE
- {
- public:
+ class GeneratedFDE : public FDE {
+ public:
GeneratedFDE(llvm::StringRef pRegion, CIE& pCIE);
~GeneratedFDE();
virtual RecordType getRecordType() const { return RECORD_GENERATED; }
};
-public:
+ public:
static EhFrame* Create(LDSection& pSection);
static void Destroy(EhFrame*& pSection);
@@ -179,10 +176,10 @@ public:
EhFrame& merge(const Input& pInput, EhFrame& pInFrame);
const LDSection& getSection() const;
- LDSection& getSection();
+ LDSection& getSection();
const SectionData* getSectionData() const { return m_pSectionData; }
- SectionData* getSectionData() { return m_pSectionData; }
+ SectionData* getSectionData() { return m_pSectionData; }
// ----- fragment ----- //
void addFragment(Fragment& pFrag);
@@ -195,32 +192,34 @@ public:
// ----- CIE ----- //
const_cie_iterator cie_begin() const { return m_CIEs.begin(); }
- cie_iterator cie_begin() { return m_CIEs.begin(); }
- const_cie_iterator cie_end () const { return m_CIEs.end(); }
- cie_iterator cie_end () { return m_CIEs.end(); }
+ cie_iterator cie_begin() { return m_CIEs.begin(); }
+ const_cie_iterator cie_end() const { return m_CIEs.end(); }
+ cie_iterator cie_end() { return m_CIEs.end(); }
const CIE& cie_front() const { return *m_CIEs.front(); }
- CIE& cie_front() { return *m_CIEs.front(); }
- const CIE& cie_back () const { return *m_CIEs.back(); }
- CIE& cie_back () { return *m_CIEs.back(); }
+ CIE& cie_front() { return *m_CIEs.front(); }
+ const CIE& cie_back() const { return *m_CIEs.back(); }
+ CIE& cie_back() { return *m_CIEs.back(); }
bool emptyCIEs() const { return m_CIEs.empty(); }
size_t numOfCIEs() const { return m_CIEs.size(); }
size_t numOfFDEs() const;
const CIEMap& getCIEMap() const { return m_FoundCIEs; }
- CIEMap& getCIEMap() { return m_FoundCIEs; }
+ CIEMap& getCIEMap() { return m_FoundCIEs; }
-public:
+ public:
size_t computeOffsetSize();
/// getDataStartOffset - Get the offset after length and ID field.
/// The offset is 8byte for 32b, and 16byte for 64b.
/// We can just use "BITCLASS/4" to represent offset.
template <size_t BITCLASS>
- static size_t getDataStartOffset() { return BITCLASS / 4; }
+ static size_t getDataStartOffset() {
+ return BITCLASS / 4;
+ }
-private:
+ private:
// We needs to check if it is mergeable and check personality name
// before merging them. The important note is we must do this after
// ALL readSections done, that is the reason why we don't check this
@@ -228,13 +227,15 @@ private:
void setupAttributes(const LDSection* reloc_sect);
void removeDiscardedFDE(CIE& pCIE, const LDSection* pRelocEhFrameSect);
-private:
- void removeAndUpdateCIEForFDE(EhFrame& pInFrame, CIE& pInCIE, CIE& pOutCIE,
+ private:
+ void removeAndUpdateCIEForFDE(EhFrame& pInFrame,
+ CIE& pInCIE,
+ CIE& pOutCIE,
const LDSection* reloc_sect);
void moveInputFragments(EhFrame& pInFrame);
void moveInputFragments(EhFrame& pInFrame, CIE& pInCIE, CIE* pOutCIE = 0);
-private:
+ private:
LDSection* m_pSection;
SectionData* m_pSectionData;
@@ -248,11 +249,13 @@ private:
// We need this map to find the corresponding CIE for FDE. Not all FDE point
// to the nearest CIE.
CIEMap m_FoundCIEs;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(EhFrame);
};
bool operator==(const EhFrame::CIE&, const EhFrame::CIE&);
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_EHFRAME_H_
diff --git a/include/mcld/LD/EhFrameHdr.h b/include/mcld/LD/EhFrameHdr.h
index 3ca4f72..2361afc 100644
--- a/include/mcld/LD/EhFrameHdr.h
+++ b/include/mcld/LD/EhFrameHdr.h
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_EHFRAMEHDR_H
-#define MCLD_LD_EHFRAMEHDR_H
-#include <mcld/ADT/SizeTraits.h>
-#include <cassert>
+#ifndef MCLD_LD_EHFRAMEHDR_H_
+#define MCLD_LD_EHFRAMEHDR_H_
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/Support/FileOutputBuffer.h"
-#include <mcld/LD/EhFrame.h>
-#include <mcld/Support/FileOutputBuffer.h>
+#include <cassert>
namespace mcld {
class LDSection;
@@ -32,9 +32,8 @@ class FileOutputBuffer;
* __________________________ when fde_count > 0
* <uint32_t, uint32_t>+ : binary search table
*/
-class EhFrameHdr
-{
-public:
+class EhFrameHdr {
+ public:
EhFrameHdr(LDSection& pEhFrameHdr, const LDSection& pEhFrame);
~EhFrameHdr();
@@ -43,17 +42,17 @@ public:
void sizeOutput();
/// emitOutput - write out eh_frame_hdr
- template<size_t size>
- void emitOutput(FileOutputBuffer& pOutput)
- { assert(false && "Call invalid EhFrameHdr::emitOutput"); }
+ template <size_t size>
+ void emitOutput(FileOutputBuffer& pOutput) {
+ assert(false && "Call invalid EhFrameHdr::emitOutput");
+ }
-private:
+ private:
/// computePCBegin - return the address of FDE's pc
- /// @ref binutils gold: ehframe.cc:222
uint32_t computePCBegin(const EhFrame::FDE& pFDE,
const MemoryRegion& pEhFrameRegion);
-private:
+ private:
/// .eh_frame_hdr section
LDSection& m_EhFrameHdr;
@@ -65,10 +64,9 @@ private:
// Template Specification Functions
//===----------------------------------------------------------------------===//
/// emitOutput - write out eh_frame_hdr
-template<>
+template <>
void EhFrameHdr::emitOutput<32>(FileOutputBuffer& pOutput);
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_EHFRAMEHDR_H_
diff --git a/include/mcld/LD/EhFrameReader.h b/include/mcld/LD/EhFrameReader.h
index 0ae093c..a021ac4 100644
--- a/include/mcld/LD/EhFrameReader.h
+++ b/include/mcld/LD/EhFrameReader.h
@@ -6,9 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_EHFRAMEREADER_H
-#define MCLD_LD_EHFRAMEREADER_H
-#include <mcld/LD/EhFrame.h>
+#ifndef MCLD_LD_EHFRAMEREADER_H_
+#define MCLD_LD_EHFRAMEREADER_H_
+#include "mcld/LD/EhFrame.h"
+
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/DataTypes.h>
@@ -23,38 +24,25 @@ class LDSection;
* EhFrameReader is responsible to parse the input eh_frame sections and create
* the corresponding CIE and FDE entries.
*/
-class EhFrameReader
-{
-public:
+class EhFrameReader {
+ public:
typedef const char* ConstAddress;
- typedef char* Address;
+ typedef char* Address;
-public:
+ public:
/// read - read an .eh_frame section and create the corresponding
/// CIEs and FDEs
/// @param pInput [in] the Input contains this eh_frame
/// @param pEhFrame [inout] the input eh_frame
/// @return if we read all CIEs and FDEs successfully, return true. Otherwise,
/// return false;
- template<size_t BITCLASS, bool SAME_ENDIAN>
+ template <size_t BITCLASS, bool SAME_ENDIAN>
bool read(Input& pInput, EhFrame& pEhFrame);
-private:
- enum TokenKind {
- CIE,
- FDE,
- Terminator,
- Unknown,
- NumOfTokenKinds
- };
+ private:
+ enum TokenKind { CIE, FDE, Terminator, Unknown, NumOfTokenKinds };
- enum State {
- Q0,
- Q1,
- Accept,
- NumOfStates = 2,
- Reject = -1
- };
+ enum State { Q0, Q1, Accept, NumOfStates = 2, Reject = -1 };
struct Token {
TokenKind kind;
@@ -70,11 +58,13 @@ private:
typedef bool (*Action)(EhFrame& pEhFrame,
llvm::StringRef pRegion,
const Token& pToken);
-private:
+
+ private:
/// scan - scan pData from pHandler for a token.
- template<bool SAME_ENDIAN> Token scan(ConstAddress pHandler,
- uint64_t pOffset,
- llvm::StringRef pData) const;
+ template <bool SAME_ENDIAN>
+ Token scan(ConstAddress pHandler,
+ uint64_t pOffset,
+ llvm::StringRef pData) const;
static bool addCIE(EhFrame& pEhFrame,
llvm::StringRef pRegion,
@@ -93,15 +83,14 @@ private:
const Token& pToken);
};
-template<> bool
-EhFrameReader::read<32, true>(Input& pInput, EhFrame& pEhFrame);
-
-template<> EhFrameReader::Token
-EhFrameReader::scan<true>(ConstAddress pHandler,
- uint64_t pOffset,
- llvm::StringRef pData) const;
+template <>
+bool EhFrameReader::read<32, true>(Input& pInput, EhFrame& pEhFrame);
-} // namespace of mcld
+template <>
+EhFrameReader::Token EhFrameReader::scan<true>(ConstAddress pHandler,
+ uint64_t pOffset,
+ llvm::StringRef pData) const;
-#endif
+} // namespace mcld
+#endif // MCLD_LD_EHFRAMEREADER_H_
diff --git a/include/mcld/LD/GNUArchiveReader.h b/include/mcld/LD/GNUArchiveReader.h
index 69d8cf6..5319c52 100644
--- a/include/mcld/LD/GNUArchiveReader.h
+++ b/include/mcld/LD/GNUArchiveReader.h
@@ -6,26 +6,25 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_GNUARCHIVEREADER_H
-#define MCLD_LD_GNUARCHIVEREADER_H
+#ifndef MCLD_LD_GNUARCHIVEREADER_H_
+#define MCLD_LD_GNUARCHIVEREADER_H_
-#include <mcld/LD/ArchiveReader.h>
-#include <mcld/LD/Archive.h>
+#include "mcld/LD/Archive.h"
+#include "mcld/LD/ArchiveReader.h"
namespace mcld {
-class Module;
-class Input;
-class ELFObjectReader;
class Archive;
+class ELFObjectReader;
+class Input;
class LinkerConfig;
+class Module;
/** \class GNUArchiveReader
* \brief GNUArchiveReader reads GNU archive files.
*/
-class GNUArchiveReader : public ArchiveReader
-{
-public:
+class GNUArchiveReader : public ArchiveReader {
+ public:
GNUArchiveReader(Module& pModule, ELFObjectReader& pELFObjectReader);
~GNUArchiveReader();
@@ -35,9 +34,9 @@ public:
bool readArchive(const LinkerConfig& pConfig, Archive& pArchive);
/// isMyFormat
- bool isMyFormat(Input& input, bool &pContinue) const;
+ bool isMyFormat(Input& input, bool& pContinue) const;
-private:
+ private:
/// isArchive
bool isArchive(const char* pStr) const;
@@ -70,8 +69,8 @@ private:
/// shouldIncludeSymbol - given a sym name from armap and check if we should
/// include the corresponding archive member, and then return the decision
- enum Archive::Symbol::Status
- shouldIncludeSymbol(const llvm::StringRef& pSymName) const;
+ enum Archive::Symbol::Status shouldIncludeSymbol(
+ const llvm::StringRef& pSymName) const;
/// includeMember - include the object member in the given file offset, and
/// return the size of the object
@@ -86,12 +85,11 @@ private:
/// --whole-archive is the attribute for this archive file.
bool includeAllMembers(const LinkerConfig& pConfig, Archive& pArchive);
-private:
+ private:
Module& m_Module;
ELFObjectReader& m_ELFObjectReader;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_GNUARCHIVEREADER_H_
diff --git a/include/mcld/LD/GarbageCollection.h b/include/mcld/LD/GarbageCollection.h
index ed43829..b467d3a 100644
--- a/include/mcld/LD/GarbageCollection.h
+++ b/include/mcld/LD/GarbageCollection.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_GARBAGECOLLECTION_H
-#define MCLD_LD_GARBAGECOLLECTION_H
+#ifndef MCLD_LD_GARBAGECOLLECTION_H_
+#define MCLD_LD_GARBAGECOLLECTION_H_
#include <map>
#include <set>
@@ -22,20 +22,17 @@ class TargetLDBackend;
/** \class GarbageCollection
* \brief Implementation of garbage collection for --gc-section.
- * @ref GNU gold, gc.
*/
-class GarbageCollection
-{
-public:
+class GarbageCollection {
+ public:
typedef std::set<const LDSection*> SectionListTy;
typedef std::vector<const LDSection*> SectionVecTy;
/** \class SectionReachedListMap
* \brief Map the section to the list of sections which it can reach directly
*/
- class SectionReachedListMap
- {
- public:
+ class SectionReachedListMap {
+ public:
SectionReachedListMap() {}
/// addReference - add a reference from pFrom to pTo
@@ -49,15 +46,15 @@ public:
/// pSection, return NULL if the list not exists
SectionListTy* findReachedList(const LDSection& pSection);
- private:
+ private:
typedef std::map<const LDSection*, SectionListTy> ReachedSectionsTy;
- private:
+ private:
/// m_ReachedSections - map a section to the reachable sections list
ReachedSectionsTy m_ReachedSections;
};
-public:
+ public:
GarbageCollection(const LinkerConfig& pConfig,
const TargetLDBackend& pBackend,
Module& pModule);
@@ -66,13 +63,13 @@ public:
/// run - do garbage collection
bool run();
-private:
+ private:
void setUpReachedSections();
void findReferencedSections(SectionVecTy& pEntry);
void getEntrySections(SectionVecTy& pEntry);
void stripSections();
-private:
+ private:
/// m_SectionReachedListMap - map the section to the list of sections which it
/// can reach directly
SectionReachedListMap m_SectionReachedListMap;
@@ -85,7 +82,6 @@ private:
Module& m_Module;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_GARBAGECOLLECTION_H_
diff --git a/include/mcld/LD/Group.h b/include/mcld/LD/Group.h
index 05d1780..f9530bc 100644
--- a/include/mcld/LD/Group.h
+++ b/include/mcld/LD/Group.h
@@ -6,20 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_GROUP_H
-#define MCLD_LD_GROUP_H
+#ifndef MCLD_LD_GROUP_H_
+#define MCLD_LD_GROUP_H_
-namespace mcld
-{
+namespace mcld {
/** \class Group
* \brief Group records the grouping of all regions
*/
-class Group
-{
-};
+class Group {};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_GROUP_H_
diff --git a/include/mcld/LD/GroupReader.h b/include/mcld/LD/GroupReader.h
index dd59150..3690ac5 100644
--- a/include/mcld/LD/GroupReader.h
+++ b/include/mcld/LD/GroupReader.h
@@ -6,19 +6,19 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_GROUPREADER_H
-#define MCLD_LD_GROUPREADER_H
+#ifndef MCLD_LD_GROUPREADER_H_
+#define MCLD_LD_GROUPREADER_H_
-#include <mcld/Module.h>
+#include "mcld/Module.h"
-namespace mcld
-{
+namespace mcld {
class Archive;
class ArchiveReader;
+class BinaryReader;
class DynObjReader;
+class InputBuilder;
class LinkerConfig;
class ObjectReader;
-class BinaryReader;
/** \class GroupReader
* \brief GroupReader handles the Group Node in InputTree
@@ -26,9 +26,8 @@ class BinaryReader;
* Group Node is the root of sub-tree in InputTree which includes the iputs in
* the command line options --start-group and --end-group options
*/
-class GroupReader
-{
-public:
+class GroupReader {
+ public:
GroupReader(Module& pModule,
ObjectReader& pObjectReader,
DynObjReader& pDynObjReader,
@@ -44,18 +43,17 @@ public:
InputBuilder& pBuilder,
const LinkerConfig& pConfig);
-private:
+ private:
/// ArchiveListEntry - record the Archive and the corresponding input iterator
/// of the archive node
struct ArchiveListEntry {
ArchiveListEntry(Archive& pArchive, Module::input_iterator pIterator)
- : archive(pArchive), input(pIterator) {
- }
+ : archive(pArchive), input(pIterator) {}
Archive& archive;
Module::input_iterator input;
};
-private:
+ private:
Module& m_Module;
ObjectReader& m_ObjectReader;
DynObjReader& m_DynObjReader;
@@ -63,7 +61,6 @@ private:
BinaryReader& m_BinaryReader;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_GROUPREADER_H_
diff --git a/include/mcld/LD/IdenticalCodeFolding.h b/include/mcld/LD/IdenticalCodeFolding.h
index e26315e..a584fc6 100644
--- a/include/mcld/LD/IdenticalCodeFolding.h
+++ b/include/mcld/LD/IdenticalCodeFolding.h
@@ -6,14 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_IDENTICALCODEFOLDING_H
-#define MCLD_LD_IDENTICALCODEFOLDING_H
+#ifndef MCLD_LD_IDENTICALCODEFOLDING_H_
+#define MCLD_LD_IDENTICALCODEFOLDING_H_
#include <llvm/ADT/MapVector.h>
+
#include <string>
#include <vector>
namespace mcld {
+
class Input;
class LDSection;
class LinkerConfig;
@@ -27,23 +29,22 @@ class TargetLDBackend;
* Gold, http://research.google.com/pubs/pub36912.html
*/
class IdenticalCodeFolding {
-public:
+ public:
typedef std::pair<Input*, size_t> ObjectAndId;
typedef llvm::MapVector<LDSection*, ObjectAndId> KeptSections;
-private:
+ private:
class FoldingCandidate {
- public:
- FoldingCandidate()
- : sect(NULL), reloc_sect(NULL), obj(NULL)
- { }
+ public:
+ FoldingCandidate() : sect(NULL), reloc_sect(NULL), obj(NULL) {}
FoldingCandidate(LDSection* pCode, LDSection* pReloc, Input* pInput)
- : sect(pCode), reloc_sect(pReloc), obj(pInput)
- { }
+ : sect(pCode), reloc_sect(pReloc), obj(pInput) {}
- void initConstantContent(const TargetLDBackend& pBackend,
+ void initConstantContent(
+ const TargetLDBackend& pBackend,
const IdenticalCodeFolding::KeptSections& pKeptSections);
- std::string getContentWithVariables(const TargetLDBackend& pBackend,
+ std::string getContentWithVariables(
+ const TargetLDBackend& pBackend,
const IdenticalCodeFolding::KeptSections& pKeptSections);
LDSection* sect;
@@ -55,25 +56,25 @@ private:
typedef std::vector<FoldingCandidate> FoldingCandidates;
-public:
+ public:
IdenticalCodeFolding(const LinkerConfig& pConfig,
const TargetLDBackend& pBackend,
Module& pModule);
void foldIdenticalCode();
-private:
+ private:
void findCandidates(FoldingCandidates& pCandidateList);
bool matchCandidates(FoldingCandidates& pCandidateList);
-private:
+ private:
const LinkerConfig& m_Config;
const TargetLDBackend& m_Backend;
Module& m_Module;
KeptSections m_KeptSections;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_LD_IDENTICALCODEFOLDING_H_
diff --git a/include/mcld/LD/LDContext.h b/include/mcld/LD/LDContext.h
index ae09154..8533fe3 100644
--- a/include/mcld/LD/LDContext.h
+++ b/include/mcld/LD/LDContext.h
@@ -6,18 +6,20 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_LDCONTEXT_H
-#define MCLD_LD_LDCONTEXT_H
+#ifndef MCLD_LD_LDCONTEXT_H_
+#define MCLD_LD_LDCONTEXT_H_
+
+#include "mcld/LD/LDFileFormat.h"
-#include <vector>
-#include <mcld/LD/LDFileFormat.h>
#include <llvm/Support/DataTypes.h>
-#include <string>
+
#include <cassert>
+#include <string>
+#include <vector>
namespace llvm {
class StringRef;
-}
+} // namespace llvm
namespace mcld {
@@ -27,9 +29,8 @@ class LDSection;
/** \class LDContext
* \brief LDContext stores the data which a object file should has
*/
-class LDContext
-{
-public:
+class LDContext {
+ public:
typedef std::vector<LDSection*> SectionTable;
typedef SectionTable::iterator sect_iterator;
typedef SectionTable::const_iterator const_sect_iterator;
@@ -38,51 +39,49 @@ public:
typedef SymbolTable::iterator sym_iterator;
typedef SymbolTable::const_iterator const_sym_iterator;
-public:
+ public:
// ----- sections ----- //
LDContext& appendSection(LDSection& pSection);
const_sect_iterator sectBegin() const { return m_SectionTable.begin(); }
- sect_iterator sectBegin() { return m_SectionTable.begin(); }
+ sect_iterator sectBegin() { return m_SectionTable.begin(); }
const_sect_iterator sectEnd() const { return m_SectionTable.end(); }
- sect_iterator sectEnd() { return m_SectionTable.end(); }
+ sect_iterator sectEnd() { return m_SectionTable.end(); }
const LDSection* getSection(unsigned int pIdx) const;
- LDSection* getSection(unsigned int pIdx);
+ LDSection* getSection(unsigned int pIdx);
const LDSection* getSection(const std::string& pName) const;
- LDSection* getSection(const std::string& pName);
+ LDSection* getSection(const std::string& pName);
size_t getSectionIdx(const std::string& pName) const;
- size_t numOfSections() const
- { return m_SectionTable.size(); }
+ size_t numOfSections() const { return m_SectionTable.size(); }
// ----- symbols ----- //
const LDSymbol* getSymbol(unsigned int pIdx) const;
- LDSymbol* getSymbol(unsigned int pIdx);
+ LDSymbol* getSymbol(unsigned int pIdx);
const LDSymbol* getSymbol(const llvm::StringRef& pName) const;
- LDSymbol* getSymbol(const llvm::StringRef& pName);
+ LDSymbol* getSymbol(const llvm::StringRef& pName);
- void addSymbol(LDSymbol* pSym)
- { m_SymTab.push_back(pSym); }
+ void addSymbol(LDSymbol* pSym) { m_SymTab.push_back(pSym); }
const_sym_iterator symTabBegin() const { return m_SymTab.begin(); }
- sym_iterator symTabBegin() { return m_SymTab.begin(); }
+ sym_iterator symTabBegin() { return m_SymTab.begin(); }
const_sym_iterator symTabEnd() const { return m_SymTab.end(); }
- sym_iterator symTabEnd() { return m_SymTab.end(); }
+ sym_iterator symTabEnd() { return m_SymTab.end(); }
// ----- relocations ----- //
const_sect_iterator relocSectBegin() const { return m_RelocSections.begin(); }
- sect_iterator relocSectBegin() { return m_RelocSections.begin(); }
+ sect_iterator relocSectBegin() { return m_RelocSections.begin(); }
const_sect_iterator relocSectEnd() const { return m_RelocSections.end(); }
- sect_iterator relocSectEnd() { return m_RelocSections.end(); }
+ sect_iterator relocSectEnd() { return m_RelocSections.end(); }
-private:
+ private:
SectionTable m_SectionTable;
SymbolTable m_SymTab;
SectionTable m_RelocSections;
@@ -90,8 +89,6 @@ private:
// FIXME : maintain a map<section name, section index>
};
+} // namespace mcld
-} // namespace of mcld
-
-#endif
-
+#endif // MCLD_LD_LDCONTEXT_H_
diff --git a/include/mcld/LD/LDFileFormat.h b/include/mcld/LD/LDFileFormat.h
index 44d3bfc..df5d0f9 100644
--- a/include/mcld/LD/LDFileFormat.h
+++ b/include/mcld/LD/LDFileFormat.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_LDFILEFORMAT_H
-#define MCLD_LD_LDFILEFORMAT_H
+#ifndef MCLD_LD_LDFILEFORMAT_H_
+#define MCLD_LD_LDFILEFORMAT_H_
-#include <cstdio>
#include <cassert>
+#include <cstddef>
namespace mcld {
@@ -20,17 +20,17 @@ class ObjectBuilder;
/** \class LDFileFormat
* \brief LDFileFormat describes the common file formats.
*/
-class LDFileFormat
-{
-public:
+class LDFileFormat {
+ public:
enum Kind {
Null,
- TEXT, // Executable regular sections
- DATA, // Non-executable regular sections
+ TEXT, // Executable regular sections
+ DATA, // Non-executable regular sections
BSS,
NamePool,
Relocation,
Debug,
+ DebugString,
Target,
EhFrame,
EhFrameHdr,
@@ -46,10 +46,10 @@ public:
Folded
};
-protected:
+ protected:
LDFileFormat();
-public:
+ public:
virtual ~LDFileFormat();
/// initStdSections - initialize all standard section headers.
@@ -60,53 +60,53 @@ public:
// ----- access functions ----- //
LDSection& getText() {
- assert(NULL != f_pTextSection);
+ assert(f_pTextSection != NULL);
return *f_pTextSection;
}
const LDSection& getText() const {
- assert(NULL != f_pTextSection);
+ assert(f_pTextSection != NULL);
return *f_pTextSection;
}
LDSection& getData() {
- assert(NULL != f_pDataSection);
+ assert(f_pDataSection != NULL);
return *f_pDataSection;
}
const LDSection& getData() const {
- assert(NULL != f_pDataSection);
+ assert(f_pDataSection != NULL);
return *f_pDataSection;
}
LDSection& getBSS() {
- assert(NULL != f_pBSSSection);
+ assert(f_pBSSSection != NULL);
return *f_pBSSSection;
}
const LDSection& getBSS() const {
- assert(NULL != f_pBSSSection);
+ assert(f_pBSSSection != NULL);
return *f_pBSSSection;
}
LDSection& getReadOnly() {
- assert(NULL != f_pReadOnlySection);
+ assert(f_pReadOnlySection != NULL);
return *f_pReadOnlySection;
}
const LDSection& getReadOnly() const {
- assert(NULL != f_pReadOnlySection);
+ assert(f_pReadOnlySection != NULL);
return *f_pReadOnlySection;
}
-protected:
+
+ protected:
// variable name : ELF MachO
- LDSection* f_pTextSection; // .text __text
- LDSection* f_pDataSection; // .data __data
- LDSection* f_pBSSSection; // .bss __bss
- LDSection* f_pReadOnlySection; // .rodata __const
+ LDSection* f_pTextSection; // .text __text
+ LDSection* f_pDataSection; // .data __data
+ LDSection* f_pBSSSection; // .bss __bss
+ LDSection* f_pReadOnlySection; // .rodata __const
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_LDFILEFORMAT_H_
diff --git a/include/mcld/LD/LDReader.h b/include/mcld/LD/LDReader.h
index c10fc96..5bda159 100644
--- a/include/mcld/LD/LDReader.h
+++ b/include/mcld/LD/LDReader.h
@@ -6,13 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_LDREADER_H
-#define MCLD_LD_LDREADER_H
+#ifndef MCLD_LD_LDREADER_H_
+#define MCLD_LD_LDREADER_H_
-#include <llvm/Support/DataTypes.h>
-
-namespace mcld
-{
+namespace mcld {
class Input;
@@ -20,25 +17,19 @@ class Input;
* \brief LDReader provides the basic interfaces for all readers. It also
* provides basic functions to read data stream.
*/
-class LDReader
-{
-public:
- enum Endian {
- LittleEndian,
- BigEndian
- };
-
-protected:
- LDReader() { }
+class LDReader {
+ public:
+ enum Endian { LittleEndian, BigEndian };
-public:
- virtual ~LDReader() { }
+ protected:
+ LDReader() {}
- virtual bool isMyFormat(Input& pInput, bool &pContinue) const = 0;
+ public:
+ virtual ~LDReader() {}
+ virtual bool isMyFormat(Input& pInput, bool& pContinue) const = 0;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_LDREADER_H_
diff --git a/include/mcld/LD/LDSection.h b/include/mcld/LD/LDSection.h
index 4f01df8..eb89f32 100644
--- a/include/mcld/LD/LDSection.h
+++ b/include/mcld/LD/LDSection.h
@@ -6,29 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef MCLD_LD_LDSECTION_H_
+#define MCLD_LD_LDSECTION_H_
-#ifndef MCLD_LD_LDSECTION_H
-#define MCLD_LD_LDSECTION_H
+#include "mcld/Config/Config.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/Support/Allocators.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Support/Allocators.h>
-#include <mcld/Config/Config.h>
-#include <mcld/LD/LDFileFormat.h>
+
#include <string>
namespace mcld {
-class SectionData;
-class RelocData;
+class DebugString;
class EhFrame;
+class RelocData;
+class SectionData;
/** \class LDSection
* \brief LDSection represents a section header entry. It is a unified
* abstraction of a section header entry for various file formats.
*/
-class LDSection
-{
-private:
+class LDSection {
+ private:
friend class Chunk<LDSection, MCLD_SECTIONS_PER_INPUT>;
LDSection();
@@ -40,7 +41,7 @@ private:
uint64_t pSize = 0,
uint64_t pAddr = 0);
-public:
+ public:
~LDSection();
static LDSection* Create(const std::string& pName,
@@ -57,39 +58,33 @@ public:
bool hasOffset() const;
/// name - the name of this section.
- const std::string& name() const
- { return m_Name; }
+ const std::string& name() const { return m_Name; }
/// kind - the kind of this section, such as Text, BSS, GOT, and so on.
/// from LDFileFormat::Kind
- LDFileFormat::Kind kind() const
- { return m_Kind; }
+ LDFileFormat::Kind kind() const { return m_Kind; }
/// type - The categorizes the section's contents and semantics. It's
/// different from llvm::SectionKind. Type is format-dependent, but
/// llvm::SectionKind is format independent and is used for bit-code.
/// In ELF, it is sh_type
/// In MachO, it's type field of struct section::flags
- uint32_t type() const
- { return m_Type; }
+ uint32_t type() const { return m_Type; }
/// flag - An integer describes miscellaneous attributes.
/// In ELF, it is sh_flags.
/// In MachO, it's attribute field of struct section::flags
- uint32_t flag() const
- { return m_Flag; }
+ uint32_t flag() const { return m_Flag; }
/// size - An integer specifying the size in bytes of the virtual memory
/// occupied by this section.
/// In ELF, if the type() is SHT_NOBITS, this function return zero.
/// Before layouting, output's LDSection::size() should return zero.
- uint64_t size() const
- { return m_Size; }
+ uint64_t size() const { return m_Size; }
/// offset - An integer specifying the offset of this section in the file.
/// Before layouting, output's LDSection::offset() should return zero.
- uint64_t offset() const
- { return m_Offset; }
+ uint64_t offset() const { return m_Offset; }
/// addr - An integer specifying the virtual address of this section in the
/// virtual image.
@@ -101,55 +96,42 @@ public:
///
/// Because addr() in output is changing during linking, MCLinker does not
/// store the address of the output here. The address is in Layout
- uint64_t addr() const
- { return m_Addr; }
+ uint64_t addr() const { return m_Addr; }
/// align - An integer specifying the align of this section in the file.
/// Before layouting, output's LDSection::align() should return zero.
- uint32_t align() const
- { return m_Align; }
+ uint32_t align() const { return m_Align; }
- size_t index() const
- { return m_Index; }
+ size_t index() const { return m_Index; }
/// getLink - return the Link. When a section A needs the other section B
/// during linking or loading, we say B is A's Link section.
/// In ELF, InfoLink section control the ElfNN_Shdr::sh_link and sh_info.
///
/// @return if the section needs no other sections, return NULL
- LDSection* getLink()
- { return m_pLink; }
+ LDSection* getLink() { return m_pLink; }
- const LDSection* getLink() const
- { return m_pLink; }
+ const LDSection* getLink() const { return m_pLink; }
- size_t getInfo() const
- { return m_Info; }
+ size_t getInfo() const { return m_Info; }
- void setKind(LDFileFormat::Kind pKind)
- { m_Kind = pKind; }
+ void setKind(LDFileFormat::Kind pKind) { m_Kind = pKind; }
- void setSize(uint64_t size)
- { m_Size = size; }
+ void setSize(uint64_t size) { m_Size = size; }
- void setOffset(uint64_t Offset)
- { m_Offset = Offset; }
+ void setOffset(uint64_t Offset) { m_Offset = Offset; }
- void setAddr(uint64_t addr)
- { m_Addr = addr; }
+ void setAddr(uint64_t addr) { m_Addr = addr; }
- void setAlign(uint32_t align)
- { m_Align = align; }
+ void setAlign(uint32_t align) { m_Align = align; }
- void setFlag(uint32_t flag)
- { m_Flag = flag; }
+ void setFlag(uint32_t flag) { m_Flag = flag; }
- void setType(uint32_t type)
- { m_Type = type; }
+ void setType(uint32_t type) { m_Type = type; }
// ----- SectionData ----- //
const SectionData* getSectionData() const { return m_Data.sect_data; }
- SectionData* getSectionData() { return m_Data.sect_data; }
+ SectionData* getSectionData() { return m_Data.sect_data; }
void setSectionData(SectionData* pSD) { m_Data.sect_data = pSD; }
@@ -157,7 +139,7 @@ public:
// ------ RelocData ------ //
const RelocData* getRelocData() const { return m_Data.reloc_data; }
- RelocData* getRelocData() { return m_Data.reloc_data; }
+ RelocData* getRelocData() { return m_Data.reloc_data; }
void setRelocData(RelocData* pRD) { m_Data.reloc_data = pRD; }
@@ -165,32 +147,38 @@ public:
// ------ EhFrame ------ //
const EhFrame* getEhFrame() const { return m_Data.eh_frame; }
- EhFrame* getEhFrame() { return m_Data.eh_frame; }
+ EhFrame* getEhFrame() { return m_Data.eh_frame; }
void setEhFrame(EhFrame* pEhFrame) { m_Data.eh_frame = pEhFrame; }
bool hasEhFrame() const;
+ // ------ DebugString ------ //
+ const DebugString* getDebugString() const { return m_Data.debug_string; }
+ DebugString* getDebugString() { return m_Data.debug_string; }
+
+ void setDebugString(DebugString* pDebugString)
+ { m_Data.debug_string = pDebugString; }
+
+ bool hasDebugString() const;
+
/// setLink - set the sections should link with.
/// if pLink is NULL, no Link section is set.
- void setLink(LDSection* pLink)
- { m_pLink = pLink; }
+ void setLink(LDSection* pLink) { m_pLink = pLink; }
- void setInfo(size_t pInfo)
- { m_Info = pInfo; }
+ void setInfo(size_t pInfo) { m_Info = pInfo; }
- void setIndex(size_t pIndex)
- { m_Index = pIndex; }
+ void setIndex(size_t pIndex) { m_Index = pIndex; }
-private:
- union SectOrRelocData
- {
+ private:
+ union Data {
SectionData* sect_data;
RelocData* reloc_data;
EhFrame* eh_frame;
+ DebugString* debug_string;
};
-private:
+ private:
std::string m_Name;
LDFileFormat::Kind m_Kind;
@@ -206,14 +194,12 @@ private:
LDSection* m_pLink;
/// m_Data - the SectionData or RelocData of this section
- SectOrRelocData m_Data;
+ Data m_Data;
/// m_Index - the index of the file
size_t m_Index;
+}; // end of LDSection
-}; // end of LDSection
-
-} // end namespace mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_LDSECTION_H_
diff --git a/include/mcld/LD/LDSymbol.h b/include/mcld/LD/LDSymbol.h
index 45c10a8..32f8e0e 100644
--- a/include/mcld/LD/LDSymbol.h
+++ b/include/mcld/LD/LDSymbol.h
@@ -6,22 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_LDSYMBOL_H
-#define MCLD_LD_LDSYMBOL_H
+#ifndef MCLD_LD_LDSYMBOL_H_
+#define MCLD_LD_LDSYMBOL_H_
-#include <cassert>
+#include "mcld/Config/Config.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/Support/Allocators.h"
-#include <mcld/Config/Config.h>
-#include <mcld/ADT/Uncopyable.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/Support/Allocators.h>
+#include <cassert>
namespace llvm {
// forware declaration
-template<class T> void* object_creator();
+template <class T>
+void* object_creator();
-} // namespace of llvm
+} // namespace llvm
namespace mcld {
@@ -31,14 +31,13 @@ class FragmentRef;
* \brief LDSymbol provides a consistent abstraction for different formats
* in different targets.
*/
-class LDSymbol
-{
-public:
+class LDSymbol {
+ public:
// FIXME: use SizeTrait<32> or SizeTrait<64> instead of big type
typedef ResolveInfo::SizeType SizeType;
typedef uint64_t ValueType;
-public:
+ public:
~LDSymbol();
// ----- factory method ----- //
@@ -57,98 +56,88 @@ public:
bool isNull() const;
const char* name() const {
- assert(NULL != m_pResolveInfo);
+ assert(m_pResolveInfo != NULL);
return m_pResolveInfo->name();
}
unsigned int nameSize() const {
- assert(NULL != m_pResolveInfo);
+ assert(m_pResolveInfo != NULL);
return m_pResolveInfo->nameSize();
}
llvm::StringRef str() const {
- assert(NULL != m_pResolveInfo);
+ assert(m_pResolveInfo != NULL);
return llvm::StringRef(m_pResolveInfo->name(), m_pResolveInfo->nameSize());
}
bool isDyn() const {
- assert(NULL != m_pResolveInfo);
+ assert(m_pResolveInfo != NULL);
return m_pResolveInfo->isDyn();
}
unsigned int type() const {
- assert(NULL != m_pResolveInfo);
+ assert(m_pResolveInfo != NULL);
return m_pResolveInfo->type();
}
- unsigned int desc() const {
- assert(NULL != m_pResolveInfo);
+ unsigned int desc() const {
+ assert(m_pResolveInfo != NULL);
return m_pResolveInfo->desc();
}
unsigned int binding() const {
- assert(NULL != m_pResolveInfo);
+ assert(m_pResolveInfo != NULL);
return m_pResolveInfo->binding();
}
uint8_t other() const {
- assert(NULL != m_pResolveInfo);
+ assert(m_pResolveInfo != NULL);
return m_pResolveInfo->other();
}
uint8_t visibility() const {
- assert(NULL != m_pResolveInfo);
+ assert(m_pResolveInfo != NULL);
return m_pResolveInfo->other();
}
- ValueType value() const
- { return m_Value; }
-
- const FragmentRef* fragRef() const
- { return m_pFragRef; }
+ ValueType value() const { return m_Value; }
- FragmentRef* fragRef()
- { return m_pFragRef; }
+ const FragmentRef* fragRef() const { return m_pFragRef; }
+ FragmentRef* fragRef() { return m_pFragRef; }
- SizeType size() const
- { return m_pResolveInfo->size(); }
+ SizeType size() const { return m_pResolveInfo->size(); }
- ResolveInfo* resolveInfo()
- { return m_pResolveInfo; }
-
- const ResolveInfo* resolveInfo() const
- { return m_pResolveInfo; }
+ const ResolveInfo* resolveInfo() const { return m_pResolveInfo; }
+ ResolveInfo* resolveInfo() { return m_pResolveInfo; }
bool hasFragRef() const;
// ----- modifiers ----- //
void setSize(SizeType pSize) {
- assert(NULL != m_pResolveInfo);
+ assert(m_pResolveInfo != NULL);
m_pResolveInfo->setSize(pSize);
}
- void setValue(ValueType pValue)
- { m_Value = pValue; }
+ void setValue(ValueType pValue) { m_Value = pValue; }
void setFragmentRef(FragmentRef* pFragmentRef);
void setResolveInfo(const ResolveInfo& pInfo);
-private:
+ private:
friend class Chunk<LDSymbol, MCLD_SYMBOLS_PER_INPUT>;
- template<class T> friend void* llvm::object_creator();
+ template <class T>
+ friend void* llvm::object_creator();
LDSymbol();
LDSymbol(const LDSymbol& pCopy);
LDSymbol& operator=(const LDSymbol& pCopy);
-private:
+ private:
// ----- Symbol's fields ----- //
ResolveInfo* m_pResolveInfo;
FragmentRef* m_pFragRef;
ValueType m_Value;
-
};
-} // namespace mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_LDSYMBOL_H_
diff --git a/include/mcld/LD/MergedStringTable.h b/include/mcld/LD/MergedStringTable.h
new file mode 100644
index 0000000..ca18594
--- /dev/null
+++ b/include/mcld/LD/MergedStringTable.h
@@ -0,0 +1,62 @@
+//===- MergedStringTable.h ------------------------------------------------===//
+//
+// The MCLinker Project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#ifndef MCLD_LD_MERGEDSTRINGTABLE_H_
+#define MCLD_LD_MERGEDSTRINGTABLE_H_
+
+#include "mcld/Support/MemoryRegion.h"
+
+#include <llvm/ADT/StringMap.h>
+#include <llvm/ADT/StringRef.h>
+
+namespace mcld {
+
+/** \class MergedStringTable
+ * \brief MergedStringTable represents the mergeable string table. The sections
+ * with flag SHF_MERGED and SHF_STRING are mergeable. Every string in
+ * MergedStringTable is unique.
+ */
+class MergedStringTable {
+ public:
+ typedef llvm::StringMap<size_t> StringMapTy;
+
+ public:
+ MergedStringTable() {}
+
+ /// insertString - insert a string to the string table
+ /// @return false if the string already exists in the map.
+ bool insertString(llvm::StringRef pString);
+
+ /// finalizeOffset - finalize the output offset of strings. After this
+ /// function been called, any string should not be added to this table
+ /// @return the section size
+ uint64_t finalizeOffset();
+
+ /// emit - emit the string table
+ void emit(MemoryRegion& pRegion);
+
+ /// ----- observers -----///
+ /// getOutputOffset - get the output offset of the string. This should be
+ /// called after finalizeOffset.
+ size_t getOutputOffset(llvm::StringRef pStr);
+
+ private:
+ typedef StringMapTy::iterator string_map_iterator;
+ typedef StringMapTy::const_iterator const_string_map_iterator;
+
+ private:
+ /// m_StringMap - the string pool of this section. It maps the string to the
+ /// output offset. The key of this map is the string, and the value is output
+ /// offset
+ StringMapTy m_StringMap;
+};
+
+} // namespace mcld
+
+#endif // MCLD_LD_MERGEDSTRINGTABLE_H_
+
diff --git a/include/mcld/LD/MsgHandler.h b/include/mcld/LD/MsgHandler.h
index 36ba1cd..491edf7 100644
--- a/include/mcld/LD/MsgHandler.h
+++ b/include/mcld/LD/MsgHandler.h
@@ -6,23 +6,24 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_MSGHANDLER_H
-#define MCLD_LD_MSGHANDLER_H
-#include <string>
+#ifndef MCLD_LD_MSGHANDLER_H_
+#define MCLD_LD_MSGHANDLER_H_
+#include "mcld/LD/DiagnosticEngine.h"
+#include "mcld/Support/Path.h"
+
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/Twine.h>
-#include <mcld/Support/Path.h>
-#include <mcld/LD/DiagnosticEngine.h>
+
+#include <string>
namespace mcld {
/** \class MsgHandler
* \brief MsgHandler controls the timing to output message.
*/
-class MsgHandler
-{
-public:
- MsgHandler(DiagnosticEngine& pEngine);
+class MsgHandler {
+ public:
+ explicit MsgHandler(DiagnosticEngine& pEngine);
~MsgHandler();
bool emit();
@@ -31,89 +32,75 @@ public:
void addString(const std::string& pStr) const;
- void addTaggedVal(intptr_t pValue, DiagnosticEngine::ArgumentKind pKind) const;
+ void addTaggedVal(intptr_t pValue,
+ DiagnosticEngine::ArgumentKind pKind) const;
-private:
- void flushCounts()
- { m_Engine.state().numArgs = m_NumArgs; }
+ private:
+ void flushCounts() { m_Engine.state().numArgs = m_NumArgs; }
-private:
+ private:
DiagnosticEngine& m_Engine;
mutable unsigned int m_NumArgs;
};
-inline const MsgHandler &
-operator<<(const MsgHandler& pHandler, llvm::StringRef pStr)
-{
+inline const MsgHandler& operator<<(const MsgHandler& pHandler,
+ llvm::StringRef pStr) {
pHandler.addString(pStr);
return pHandler;
}
-inline const MsgHandler &
-operator<<(const MsgHandler& pHandler, const std::string& pStr)
-{
+inline const MsgHandler& operator<<(const MsgHandler& pHandler,
+ const std::string& pStr) {
pHandler.addString(pStr);
return pHandler;
}
-inline const MsgHandler &
-operator<<(const MsgHandler& pHandler, const sys::fs::Path& pPath)
-{
+inline const MsgHandler& operator<<(const MsgHandler& pHandler,
+ const sys::fs::Path& pPath) {
pHandler.addString(pPath.native());
return pHandler;
}
-inline const MsgHandler &
-operator<<(const MsgHandler& pHandler, const char* pStr)
-{
+inline const MsgHandler& operator<<(const MsgHandler& pHandler,
+ const char* pStr) {
pHandler.addTaggedVal(reinterpret_cast<intptr_t>(pStr),
DiagnosticEngine::ak_c_string);
return pHandler;
}
-inline const MsgHandler &
-operator<<(const MsgHandler& pHandler, int pValue)
-{
+inline const MsgHandler& operator<<(const MsgHandler& pHandler, int pValue) {
pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_sint);
return pHandler;
}
-inline const MsgHandler &
-operator<<(const MsgHandler& pHandler, unsigned int pValue)
-{
+inline const MsgHandler& operator<<(const MsgHandler& pHandler,
+ unsigned int pValue) {
pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_uint);
return pHandler;
}
-inline const MsgHandler &
-operator<<(const MsgHandler& pHandler, long pValue)
-{
+inline const MsgHandler& operator<<(const MsgHandler& pHandler, long pValue) {
pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_sint);
return pHandler;
}
-inline const MsgHandler &
-operator<<(const MsgHandler& pHandler, unsigned long pValue)
-{
+inline const MsgHandler& operator<<(const MsgHandler& pHandler,
+ unsigned long pValue) {
pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_uint);
return pHandler;
}
-inline const MsgHandler &
-operator<<(const MsgHandler& pHandler, unsigned long long pValue)
-{
+inline const MsgHandler& operator<<(const MsgHandler& pHandler,
+ unsigned long long pValue) {
pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_ulonglong);
return pHandler;
}
-inline const MsgHandler &
-operator<<(const MsgHandler& pHandler, bool pValue)
-{
+inline const MsgHandler& operator<<(const MsgHandler& pHandler, bool pValue) {
pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_bool);
return pHandler;
}
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_MSGHANDLER_H_
diff --git a/include/mcld/LD/NamePool.h b/include/mcld/LD/NamePool.h
index a5df150..27f124a 100644
--- a/include/mcld/LD/NamePool.h
+++ b/include/mcld/LD/NamePool.h
@@ -6,35 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_NAMEPOOL_H
-#define MCLD_LD_NAMEPOOL_H
+#ifndef MCLD_LD_NAMEPOOL_H_
+#define MCLD_LD_NAMEPOOL_H_
-#include <mcld/Config/Config.h>
-#include <mcld/ADT/HashTable.h>
-#include <mcld/ADT/StringHash.h>
-#include <mcld/ADT/Uncopyable.h>
-#include <mcld/LD/Resolver.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/Support/GCFactory.h>
-
-#include <utility>
+#include "mcld/ADT/HashTable.h"
+#include "mcld/ADT/StringHash.h"
+#include "mcld/Config/Config.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/Resolver.h"
+#include "mcld/Support/Compiler.h"
+#include "mcld/Support/GCFactory.h"
#include <llvm/ADT/StringRef.h>
-namespace mcld {
+#include <utility>
-class StringTable;
-class SymbolTableIF;
-class SectionData;
+namespace mcld {
/** \class NamePool
* \brief Store symbol and search symbol by name. Can help symbol resolution.
*
* - MCLinker is responsed for creating NamePool.
*/
-class NamePool : private Uncopyable
-{
-public:
+class NamePool {
+ public:
typedef HashTable<ResolveInfo, hash::StringHash<hash::DJB> > Table;
typedef Table::iterator syminfo_iterator;
typedef Table::const_iterator const_syminfo_iterator;
@@ -45,7 +40,7 @@ public:
typedef size_t size_type;
-public:
+ public:
explicit NamePool(size_type pSize = 3);
~NamePool();
@@ -53,13 +48,14 @@ public:
// ----- modifiers ----- //
/// createSymbol - create a symbol but do not insert into the pool.
/// The created symbol did not go through the path of symbol resolution.
- ResolveInfo* createSymbol(const llvm::StringRef& pName,
- bool pIsDyn,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- ResolveInfo::Visibility pVisibility = ResolveInfo::Default);
+ ResolveInfo* createSymbol(
+ const llvm::StringRef& pName,
+ bool pIsDyn,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ ResolveInfo::Visibility pVisibility = ResolveInfo::Default);
/// insertSymbol - insert a symbol and resolve the symbol immediately
/// @param pOldInfo - if pOldInfo is not NULL, the old ResolveInfo being
@@ -80,11 +76,11 @@ public:
/// findSymbol - find the resolved output LDSymbol
const LDSymbol* findSymbol(const llvm::StringRef& pName) const;
- LDSymbol* findSymbol(const llvm::StringRef& pName);
+ LDSymbol* findSymbol(const llvm::StringRef& pName);
/// findInfo - find the resolved ResolveInfo
const ResolveInfo* findInfo(const llvm::StringRef& pName) const;
- ResolveInfo* findInfo(const llvm::StringRef& pName);
+ ResolveInfo* findInfo(const llvm::StringRef& pName);
/// insertString - insert a string
/// if the string has existed, modify pString to the existing string
@@ -92,51 +88,45 @@ public:
llvm::StringRef insertString(const llvm::StringRef& pString);
// ----- observers ----- //
- size_type size() const
- { return m_Table.numOfEntries(); }
+ size_type size() const { return m_Table.numOfEntries(); }
- bool empty() const
- { return m_Table.empty(); }
+ bool empty() const { return m_Table.empty(); }
// syminfo_iterator - traverse the ResolveInfo in the resolved HashTable
- syminfo_iterator syminfo_begin()
- { return m_Table.begin(); }
+ syminfo_iterator syminfo_begin() { return m_Table.begin(); }
- syminfo_iterator syminfo_end()
- { return m_Table.end(); }
+ syminfo_iterator syminfo_end() { return m_Table.end(); }
- const_syminfo_iterator syminfo_begin() const
- { return m_Table.begin(); }
+ const_syminfo_iterator syminfo_begin() const { return m_Table.begin(); }
- const_syminfo_iterator syminfo_end() const
- { return m_Table.end(); }
+ const_syminfo_iterator syminfo_end() const { return m_Table.end(); }
// freeinfo_iterator - traverse the ResolveInfo those do not need to be
// resolved, for example, local symbols
- freeinfo_iterator freeinfo_begin()
- { return m_FreeInfoSet.begin(); }
+ freeinfo_iterator freeinfo_begin() { return m_FreeInfoSet.begin(); }
- freeinfo_iterator freeinfo_end()
- { return m_FreeInfoSet.end(); }
+ freeinfo_iterator freeinfo_end() { return m_FreeInfoSet.end(); }
- const_freeinfo_iterator freeinfo_begin() const
- { return m_FreeInfoSet.begin(); }
+ const_freeinfo_iterator freeinfo_begin() const {
+ return m_FreeInfoSet.begin();
+ }
- const_freeinfo_iterator freeinfo_end() const
- { return m_FreeInfoSet.end(); }
+ const_freeinfo_iterator freeinfo_end() const { return m_FreeInfoSet.end(); }
// ----- capacity ----- //
void reserve(size_type pN);
size_type capacity() const;
-private:
+ private:
Resolver* m_pResolver;
Table m_Table;
FreeInfoSet m_FreeInfoSet;
-};
-} // namespace of mcld
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NamePool);
+};
-#endif
+} // namespace mcld
+#endif // MCLD_LD_NAMEPOOL_H_
diff --git a/include/mcld/LD/ObjectReader.h b/include/mcld/LD/ObjectReader.h
index 32a8c0a..c8a5546 100644
--- a/include/mcld/LD/ObjectReader.h
+++ b/include/mcld/LD/ObjectReader.h
@@ -6,32 +6,31 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_OBJECTREADER_H
-#define MCLD_LD_OBJECTREADER_H
+#ifndef MCLD_LD_OBJECTREADER_H_
+#define MCLD_LD_OBJECTREADER_H_
+#include "mcld/ADT/HashTable.h"
+#include "mcld/ADT/StringHash.h"
#include "mcld/LD/LDReader.h"
-#include <mcld/ADT/HashTable.h>
-#include <mcld/ADT/StringHash.h>
-#include <mcld/LD/ResolveInfo.h>
+#include "mcld/LD/ResolveInfo.h"
namespace mcld {
-class Module;
class Input;
+class Module;
/** \class ObjectReader
* \brief ObjectReader provides an common interface for different object
* formats.
*/
-class ObjectReader : public LDReader
-{
-protected:
- typedef HashTable<ResolveInfo, hash::StringHash<hash::DJB> > GroupSignatureMap;
+class ObjectReader : public LDReader {
+ protected:
+ typedef HashTable<ResolveInfo, hash::StringHash<hash::DJB> >
+ GroupSignatureMap;
-protected:
- ObjectReader()
- { }
+ protected:
+ ObjectReader() {}
-public:
+ public:
virtual ~ObjectReader() { f_GroupSignatureMap.clear(); }
virtual bool readHeader(Input& pFile) = 0;
@@ -45,18 +44,14 @@ public:
/// This function should be called after symbol resolution.
virtual bool readRelocations(Input& pFile) = 0;
- GroupSignatureMap& signatures()
- { return f_GroupSignatureMap; }
+ GroupSignatureMap& signatures() { return f_GroupSignatureMap; }
- const GroupSignatureMap& signatures() const
- { return f_GroupSignatureMap; }
+ const GroupSignatureMap& signatures() const { return f_GroupSignatureMap; }
-protected:
+ protected:
GroupSignatureMap f_GroupSignatureMap;
-
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_OBJECTREADER_H_
diff --git a/include/mcld/LD/ObjectWriter.h b/include/mcld/LD/ObjectWriter.h
index b58661a..69e50be 100644
--- a/include/mcld/LD/ObjectWriter.h
+++ b/include/mcld/LD/ObjectWriter.h
@@ -6,24 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_OBJECTWRITER_H
-#define MCLD_LD_OBJECTWRITER_H
+#ifndef MCLD_LD_OBJECTWRITER_H_
+#define MCLD_LD_OBJECTWRITER_H_
#include <system_error>
namespace mcld {
-class Module;
class FileOutputBuffer;
+class Module;
/** \class ObjectWriter
* \brief ObjectWriter provides a common interface for object file writers.
*/
-class ObjectWriter
-{
-protected:
+class ObjectWriter {
+ protected:
ObjectWriter();
-public:
+ public:
virtual ~ObjectWriter();
virtual std::error_code writeObject(Module& pModule,
@@ -32,7 +31,6 @@ public:
virtual size_t getOutputSize(const Module& pModule) const = 0;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_OBJECTWRITER_H_
diff --git a/include/mcld/LD/RelocData.h b/include/mcld/LD/RelocData.h
index dff4ee0..ed649a2 100644
--- a/include/mcld/LD/RelocData.h
+++ b/include/mcld/LD/RelocData.h
@@ -6,13 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_RELOCDATA_H
-#define MCLD_LD_RELOCDATA_H
+#ifndef MCLD_LD_RELOCDATA_H_
+#define MCLD_LD_RELOCDATA_H_
-#include <mcld/Config/Config.h>
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/Support/Allocators.h>
-#include <mcld/Support/GCFactoryListTraits.h>
+#include "mcld/Config/Config.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/Support/Allocators.h"
+#include "mcld/Support/Compiler.h"
+#include "mcld/Support/GCFactoryListTraits.h"
#include <llvm/ADT/ilist.h>
#include <llvm/ADT/ilist_node.h>
@@ -27,23 +28,20 @@ class LDSection;
/** \class RelocData
* \brief RelocData stores Relocation.
*
- * Since Relocations are created by GCFactory, we use GCFactoryListTraits for the
+ * Since Relocations are created by GCFactory, we use GCFactoryListTraits for
+ *the
* RelocationList here to avoid iplist to delete Relocations.
*/
-class RelocData
-{
-private:
+class RelocData {
+ private:
friend class Chunk<RelocData, MCLD_SECTIONS_PER_INPUT>;
RelocData();
- explicit RelocData(LDSection &pSection);
+ explicit RelocData(LDSection& pSection);
- RelocData(const RelocData &); // DO NOT IMPLEMENT
- RelocData& operator=(const RelocData &); // DO NOT IMPLEMENT
-
-public:
- typedef llvm::iplist<Relocation,
- GCFactoryListTraits<Relocation> > RelocationListType;
+ public:
+ typedef llvm::iplist<Relocation, GCFactoryListTraits<Relocation> >
+ RelocationListType;
typedef RelocationListType::reference reference;
typedef RelocationListType::const_reference const_reference;
@@ -54,7 +52,7 @@ public:
typedef RelocationListType::reverse_iterator reverse_iterator;
typedef RelocationListType::const_reverse_iterator const_reverse_iterator;
-public:
+ public:
static RelocData* Create(LDSection& pSection);
static void Destroy(RelocData*& pSection);
@@ -62,10 +60,10 @@ public:
static void Clear();
const LDSection& getSection() const { return *m_pSection; }
- LDSection& getSection() { return *m_pSection; }
+ LDSection& getSection() { return *m_pSection; }
const RelocationListType& getRelocationList() const { return m_Relocations; }
- RelocationListType& getRelocationList() { return m_Relocations; }
+ RelocationListType& getRelocationList() { return m_Relocations; }
size_t size() const { return m_Relocations.size(); }
@@ -74,21 +72,22 @@ public:
RelocData& append(Relocation& pRelocation);
Relocation& remove(Relocation& pRelocation);
- reference front () { return m_Relocations.front(); }
- const_reference front () const { return m_Relocations.front(); }
- reference back () { return m_Relocations.back(); }
- const_reference back () const { return m_Relocations.back(); }
+ const_reference front() const { return m_Relocations.front(); }
+ reference front() { return m_Relocations.front(); }
+ const_reference back() const { return m_Relocations.back(); }
+ reference back() { return m_Relocations.back(); }
- const_iterator begin () const { return m_Relocations.begin(); }
- iterator begin () { return m_Relocations.begin(); }
- const_iterator end () const { return m_Relocations.end(); }
- iterator end () { return m_Relocations.end(); }
+ const_iterator begin() const { return m_Relocations.begin(); }
+ iterator begin() { return m_Relocations.begin(); }
+ const_iterator end() const { return m_Relocations.end(); }
+ iterator end() { return m_Relocations.end(); }
const_reverse_iterator rbegin() const { return m_Relocations.rbegin(); }
- reverse_iterator rbegin() { return m_Relocations.rbegin(); }
- const_reverse_iterator rend () const { return m_Relocations.rend(); }
- reverse_iterator rend () { return m_Relocations.rend(); }
+ reverse_iterator rbegin() { return m_Relocations.rbegin(); }
+ const_reverse_iterator rend() const { return m_Relocations.rend(); }
+ reverse_iterator rend() { return m_Relocations.rend(); }
- template<class Comparator> void sort(Comparator pComparator) {
+ template <class Comparator>
+ void sort(Comparator pComparator) {
/* FIXME: use llvm::iplist::sort */
std::list<Relocation*> relocs;
for (iterator it = begin(), ie = end(); it != ie; ++it)
@@ -96,17 +95,21 @@ public:
relocs.sort(pComparator);
m_Relocations.clear();
for (std::list<Relocation*>::iterator it = relocs.begin(),
- ie = relocs.end(); it != ie; ++it)
+ ie = relocs.end();
+ it != ie;
+ ++it) {
m_Relocations.push_back(*it);
+ }
}
-private:
+ private:
RelocationListType m_Relocations;
LDSection* m_pSection;
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RelocData);
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_RELOCDATA_H_
diff --git a/include/mcld/LD/RelocationFactory.h b/include/mcld/LD/RelocationFactory.h
index 205730a..6d5043b 100644
--- a/include/mcld/LD/RelocationFactory.h
+++ b/include/mcld/LD/RelocationFactory.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_RELOCATION_FACTORY_H
-#define MCLD_LD_RELOCATION_FACTORY_H
-#include <mcld/Config/Config.h>
-#include <mcld/Support/GCFactory.h>
-#include <mcld/Fragment/Relocation.h>
+#ifndef MCLD_LD_RELOCATIONFACTORY_H_
+#define MCLD_LD_RELOCATIONFACTORY_H_
+#include "mcld/Config/Config.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/Support/GCFactory.h"
namespace mcld {
@@ -22,16 +22,16 @@ class LinkerConfig;
* relocation
*
*/
-class RelocationFactory : public GCFactory<Relocation, MCLD_RELOCATIONS_PER_INPUT>
-{
-public:
+class RelocationFactory
+ : public GCFactory<Relocation, MCLD_RELOCATIONS_PER_INPUT> {
+ public:
typedef Relocation::Type Type;
typedef Relocation::Address Address;
typedef Relocation::DWord DWord;
typedef Relocation::SWord SWord;
-public:
- explicit RelocationFactory();
+ public:
+ RelocationFactory();
void setConfig(const LinkerConfig& pConfig);
@@ -40,9 +40,7 @@ public:
/// @param pType - the type of the relocation entry
/// @param pFragRef - the place to apply the relocation
/// @param pAddend - the addend of the relocation entry
- Relocation* produce(Type pType,
- FragmentRef& pFragRef,
- Address pAddend = 0);
+ Relocation* produce(Type pType, FragmentRef& pFragRef, Address pAddend = 0);
/// produceEmptyEntry - produce an empty relocation which
/// occupied memory space but all contents set to zero.
@@ -50,11 +48,10 @@ public:
void destroy(Relocation* pRelocation);
-private:
+ private:
const LinkerConfig* m_pConfig;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_RELOCATIONFACTORY_H_
diff --git a/include/mcld/LD/Relocator.h b/include/mcld/LD/Relocator.h
index 82bdf8a..99a530b 100644
--- a/include/mcld/LD/Relocator.h
+++ b/include/mcld/LD/Relocator.h
@@ -6,45 +6,34 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_RELOCATOR_H
-#define MCLD_RELOCATOR_H
+#ifndef MCLD_LD_RELOCATOR_H_
+#define MCLD_LD_RELOCATOR_H_
-#include <mcld/Fragment/Relocation.h>
+#include "mcld/Fragment/Relocation.h"
-namespace mcld
-{
+namespace mcld {
-class FragmentLinker;
-class TargetLDBackend;
+class Input;
class IRBuilder;
class Module;
-class Input;
+class TargetLDBackend;
/** \class Relocator
* \brief Relocator provides the interface of performing relocations
*/
-class Relocator
-{
-public:
- typedef Relocation::Type Type;
+class Relocator {
+ public:
+ typedef Relocation::Type Type;
typedef Relocation::Address Address;
- typedef Relocation::DWord DWord;
- typedef Relocation::SWord SWord;
- typedef Relocation::Size Size;
-
-public:
- enum Result {
- OK,
- BadReloc,
- Overflow,
- Unsupport,
- Unknown
- };
-
-public:
- Relocator(const LinkerConfig& pConfig)
- : m_Config(pConfig)
- {}
+ typedef Relocation::DWord DWord;
+ typedef Relocation::SWord SWord;
+ typedef Relocation::Size Size;
+
+ public:
+ enum Result { OK, BadReloc, Overflow, Unsupported, Unknown };
+
+ public:
+ explicit Relocator(const LinkerConfig& pConfig) : m_Config(pConfig) {}
virtual ~Relocator() = 0;
@@ -65,7 +54,8 @@ public:
LDSection& pSection,
Input& pInput) = 0;
- /// issueUndefRefError - Provides a basic version for undefined reference dump.
+ /// issueUndefRefError - Provides a basic version for undefined reference
+ /// dump.
/// It will handle the filename and function name automatically.
/// @param pReloc - a read in relocation entry
/// @param pSection - the section of relocation applying target
@@ -76,23 +66,19 @@ public:
/// initializeScan - do initialization before scan relocations in pInput
/// @return - return true for initialization success
- virtual bool initializeScan(Input& pInput)
- { return true; }
+ virtual bool initializeScan(Input& pInput) { return true; }
/// finalizeScan - do finalization after scan relocations in pInput
/// @return - return true for finalization success
- virtual bool finalizeScan(Input& pInput)
- { return true; }
+ virtual bool finalizeScan(Input& pInput) { return true; }
/// initializeApply - do initialization before apply relocations in pInput
/// @return - return true for initialization success
- virtual bool initializeApply(Input& pInput)
- { return true; }
+ virtual bool initializeApply(Input& pInput) { return true; }
/// finalizeApply - do finalization after apply relocations in pInput
/// @return - return true for finalization success
- virtual bool finalizeApply(Input& pInput)
- { return true; }
+ virtual bool finalizeApply(Input& pInput) { return true; }
/// partialScanRelocation - When doing partial linking, backend can do any
/// modification to relocation to fix the relocation offset after section
@@ -101,8 +87,7 @@ public:
/// @param pInputSym - the input LDSymbol of relocation target symbol
/// @param pSection - the section of relocation applying target
virtual void partialScanRelocation(Relocation& pReloc,
- Module& pModule,
- const LDSection& pSection);
+ Module& pModule);
// ------ observers -----//
virtual TargetLDBackend& getTarget() = 0;
@@ -119,17 +104,25 @@ public:
/// access a function pointer.
/// Note: Each target relocator should override this function, or be
/// conservative and return true to avoid getting folded.
- virtual bool mayHaveFunctionPointerAccess(const Relocation& pReloc) const
- { return true; }
+ virtual bool mayHaveFunctionPointerAccess(const Relocation& pReloc) const {
+ return true;
+ }
+
+ /// getDebugStringOffset - get the offset from the relocation target. This is
+ /// used to get the debug string offset.
+ virtual uint32_t getDebugStringOffset(Relocation& pReloc) const = 0;
-protected:
+ /// applyDebugStringOffset - apply the relocation target to specific offset.
+ /// This is used to set the debug string offset.
+ virtual void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset) = 0;
+
+ protected:
const LinkerConfig& config() const { return m_Config; }
-private:
+ private:
const LinkerConfig& m_Config;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_RELOCATOR_H_
diff --git a/include/mcld/LD/ResolveInfo.h b/include/mcld/LD/ResolveInfo.h
index 9155a7c..329a436 100644
--- a/include/mcld/LD/ResolveInfo.h
+++ b/include/mcld/LD/ResolveInfo.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_RESOLVEINFO_H
-#define MCLD_LD_RESOLVEINFO_H
+#ifndef MCLD_LD_RESOLVEINFO_H_
+#define MCLD_LD_RESOLVEINFO_H_
-#include <llvm/Support/DataTypes.h>
#include <llvm/ADT/StringRef.h>
+#include <llvm/Support/DataTypes.h>
namespace mcld {
@@ -27,16 +27,17 @@ class LinkerConfig;
* - Type - what the symbol refers to
* - Size - the size of the symbol point to
* - Value - the pointer to another LDSymbol
- * In order to save the memory and speed up the performance, FragmentLinker uses
+ * In order to save the memory and speed up the performance, FragmentLinker
+ *uses
* a bit field to store all attributes.
*
* The maximum string length is (2^16 - 1)
*/
-class ResolveInfo
-{
-friend class FragmentLinker;
-friend class IRBuilder;
-public:
+class ResolveInfo {
+ friend class FragmentLinker;
+ friend class IRBuilder;
+
+ public:
typedef uint64_t SizeType;
/** \enum Type
@@ -46,16 +47,16 @@ public:
* MachO does not need this, and can not jump between Thumb and ARM code.
*/
enum Type {
- NoType = 0,
- Object = 1,
- Function = 2,
- Section = 3,
- File = 4,
- CommonBlock = 5,
- ThreadLocal = 6,
- IndirectFunc = 10,
- LoProc = 13,
- HiProc = 15
+ NoType = 0,
+ Object = 1,
+ Function = 2,
+ Section = 3,
+ File = 4,
+ CommonBlock = 5,
+ ThreadLocal = 6,
+ IndirectFunc = 10,
+ LoProc = 13,
+ HiProc = 15
};
/** \enum Desc
@@ -64,33 +65,16 @@ public:
* Follow the naming in MachO. Like MachO nlist::n_desc
* In ELF, is a part of st_shndx
*/
- enum Desc {
- Undefined = 0,
- Define = 1,
- Common = 2,
- Indirect = 3,
- NoneDesc
- };
+ enum Desc { Undefined = 0, Define = 1, Common = 2, Indirect = 3, NoneDesc };
- enum Binding {
- Global = 0,
- Weak = 1,
- Local = 2,
- Absolute = 3,
- NoneBinding
- };
+ enum Binding { Global = 0, Weak = 1, Local = 2, Absolute = 3, NoneBinding };
- enum Visibility {
- Default = 0,
- Internal = 1,
- Hidden = 2,
- Protected = 3
- };
+ enum Visibility { Default = 0, Internal = 1, Hidden = 2, Protected = 3 };
// ----- For HashTable ----- //
typedef llvm::StringRef key_type;
-public:
+ public:
// ----- factory method ----- //
static ResolveInfo* Create(const key_type& pKey);
@@ -123,8 +107,7 @@ public:
void setReserved(uint32_t pReserved);
- void setSize(SizeType pSize)
- { m_Size = pSize; }
+ void setSize(SizeType pSize) { m_Size = pSize; }
void override(const ResolveInfo& pForm);
@@ -132,8 +115,9 @@ public:
void overrideVisibility(const ResolveInfo& pFrom);
- void setSymPtr(const LDSymbol* pSymPtr)
- { m_Ptr.sym_ptr = const_cast<LDSymbol*>(pSymPtr); }
+ void setSymPtr(const LDSymbol* pSymPtr) {
+ m_Ptr.sym_ptr = const_cast<LDSymbol*>(pSymPtr);
+ }
void setLink(const ResolveInfo* pTarget) {
m_Ptr.info_ptr = const_cast<ResolveInfo*>(pTarget);
@@ -179,37 +163,27 @@ public:
uint32_t reserved() const;
- uint8_t other() const
- { return (uint8_t)visibility(); }
+ uint8_t other() const { return (uint8_t)visibility(); }
Visibility visibility() const;
- LDSymbol* outSymbol()
- { return m_Ptr.sym_ptr; }
+ LDSymbol* outSymbol() { return m_Ptr.sym_ptr; }
- const LDSymbol* outSymbol() const
- { return m_Ptr.sym_ptr; }
+ const LDSymbol* outSymbol() const { return m_Ptr.sym_ptr; }
- ResolveInfo* link()
- { return m_Ptr.info_ptr; }
+ ResolveInfo* link() { return m_Ptr.info_ptr; }
- const ResolveInfo* link() const
- { return m_Ptr.info_ptr; }
+ const ResolveInfo* link() const { return m_Ptr.info_ptr; }
- SizeType size() const
- { return m_Size; }
+ SizeType size() const { return m_Size; }
- const char* name() const
- { return m_Name; }
+ const char* name() const { return m_Name; }
- unsigned int nameSize() const
- { return (m_BitField >> NAME_LENGTH_OFFSET); }
+ unsigned int nameSize() const { return (m_BitField >> NAME_LENGTH_OFFSET); }
- uint32_t info() const
- { return (m_BitField & INFO_MASK); }
+ uint32_t info() const { return (m_BitField & INFO_MASK); }
- uint32_t bitfield() const
- { return m_BitField; }
+ uint32_t bitfield() const { return m_BitField; }
// shouldForceLocal - check if this symbol should be forced to local
bool shouldForceLocal(const LinkerConfig& pConfig);
@@ -217,83 +191,84 @@ public:
// ----- For HashTable ----- //
bool compare(const key_type& pKey);
-private:
- static const uint32_t GLOBAL_OFFSET = 0;
- static const uint32_t GLOBAL_MASK = 1;
+ private:
+ static const uint32_t GLOBAL_OFFSET = 0;
+ static const uint32_t GLOBAL_MASK = 1;
- static const uint32_t DYN_OFFSET = 1;
- static const uint32_t DYN_MASK = 1 << DYN_OFFSET;
+ static const uint32_t DYN_OFFSET = 1;
+ static const uint32_t DYN_MASK = 1 << DYN_OFFSET;
- static const uint32_t DESC_OFFSET = 2;
- static const uint32_t DESC_MASK = 0x3 << DESC_OFFSET;
+ static const uint32_t DESC_OFFSET = 2;
+ static const uint32_t DESC_MASK = 0x3 << DESC_OFFSET;
- static const uint32_t LOCAL_OFFSET = 4;
- static const uint32_t LOCAL_MASK = 1 << LOCAL_OFFSET;
+ static const uint32_t LOCAL_OFFSET = 4;
+ static const uint32_t LOCAL_MASK = 1 << LOCAL_OFFSET;
- static const uint32_t BINDING_MASK = GLOBAL_MASK | LOCAL_MASK;
+ static const uint32_t BINDING_MASK = GLOBAL_MASK | LOCAL_MASK;
- static const uint32_t VISIBILITY_OFFSET = 5;
- static const uint32_t VISIBILITY_MASK = 0x3 << VISIBILITY_OFFSET;
+ static const uint32_t VISIBILITY_OFFSET = 5;
+ static const uint32_t VISIBILITY_MASK = 0x3 << VISIBILITY_OFFSET;
- static const uint32_t TYPE_OFFSET = 7;
- static const uint32_t TYPE_MASK = 0xF << TYPE_OFFSET;
+ static const uint32_t TYPE_OFFSET = 7;
+ static const uint32_t TYPE_MASK = 0xF << TYPE_OFFSET;
- static const uint32_t SYMBOL_OFFSET = 11;
- static const uint32_t SYMBOL_MASK = 1 << SYMBOL_OFFSET;
+ static const uint32_t SYMBOL_OFFSET = 11;
+ static const uint32_t SYMBOL_MASK = 1 << SYMBOL_OFFSET;
- static const uint32_t RESERVED_OFFSET = 12;
- static const uint32_t RESERVED_MASK = 0xF << RESERVED_OFFSET;
+ static const uint32_t RESERVED_OFFSET = 12;
+ static const uint32_t RESERVED_MASK = 0xF << RESERVED_OFFSET;
- static const uint32_t IN_DYN_OFFSET = 16;
- static const uint32_t IN_DYN_MASK = 1 << IN_DYN_OFFSET;
+ static const uint32_t IN_DYN_OFFSET = 16;
+ static const uint32_t IN_DYN_MASK = 1 << IN_DYN_OFFSET;
static const uint32_t NAME_LENGTH_OFFSET = 17;
- static const uint32_t INFO_MASK = 0xF;
- static const uint32_t RESOLVE_MASK = 0xFFFF;
+ static const uint32_t INFO_MASK = 0xF;
+ static const uint32_t RESOLVE_MASK = 0xFFFF;
union SymOrInfo {
- LDSymbol* sym_ptr;
+ LDSymbol* sym_ptr;
ResolveInfo* info_ptr;
};
-public:
- static const uint32_t global_flag = 0 << GLOBAL_OFFSET;
- static const uint32_t weak_flag = 1 << GLOBAL_OFFSET;
- static const uint32_t regular_flag = 0 << DYN_OFFSET;
- static const uint32_t dynamic_flag = 1 << DYN_OFFSET;
- static const uint32_t undefine_flag = 0 << DESC_OFFSET;
- static const uint32_t define_flag = 1 << DESC_OFFSET;
- static const uint32_t common_flag = 2 << DESC_OFFSET;
- static const uint32_t indirect_flag = 3 << DESC_OFFSET;
- static const uint32_t local_flag = 1 << LOCAL_OFFSET;
- static const uint32_t absolute_flag = BINDING_MASK;
- static const uint32_t object_flag = Object << TYPE_OFFSET;
- static const uint32_t function_flag = Function << TYPE_OFFSET;
- static const uint32_t section_flag = Section << TYPE_OFFSET;
- static const uint32_t file_flag = File << TYPE_OFFSET;
- static const uint32_t string_flag = 0 << SYMBOL_OFFSET;
- static const uint32_t symbol_flag = 1 << SYMBOL_OFFSET;
- static const uint32_t indyn_flag = 1 << IN_DYN_OFFSET;
-
-private:
+ public:
+ static const uint32_t global_flag = 0 << GLOBAL_OFFSET;
+ static const uint32_t weak_flag = 1 << GLOBAL_OFFSET;
+ static const uint32_t regular_flag = 0 << DYN_OFFSET;
+ static const uint32_t dynamic_flag = 1 << DYN_OFFSET;
+ static const uint32_t undefine_flag = 0 << DESC_OFFSET;
+ static const uint32_t define_flag = 1 << DESC_OFFSET;
+ static const uint32_t common_flag = 2 << DESC_OFFSET;
+ static const uint32_t indirect_flag = 3 << DESC_OFFSET;
+ static const uint32_t local_flag = 1 << LOCAL_OFFSET;
+ static const uint32_t absolute_flag = BINDING_MASK;
+ static const uint32_t object_flag = Object << TYPE_OFFSET;
+ static const uint32_t function_flag = Function << TYPE_OFFSET;
+ static const uint32_t section_flag = Section << TYPE_OFFSET;
+ static const uint32_t file_flag = File << TYPE_OFFSET;
+ static const uint32_t string_flag = 0 << SYMBOL_OFFSET;
+ static const uint32_t symbol_flag = 1 << SYMBOL_OFFSET;
+ static const uint32_t indyn_flag = 1 << IN_DYN_OFFSET;
+
+ private:
ResolveInfo();
ResolveInfo(const ResolveInfo& pCopy);
ResolveInfo& operator=(const ResolveInfo& pCopy);
~ResolveInfo();
-private:
+ private:
SizeType m_Size;
SymOrInfo m_Ptr;
/** m_BitField
- * 31 ... 17 16 15 12 11 10..7 6 .. 5 4 3 2 1 0
- * |length of m_Name|InDyn|reserved|Symbol|Type |ELF visibility|Local|Com|Def|Dyn|Weak|
+ * 31 ... 17 16 15 12 11 10..7 6 .. 5 4 3 2
+ * 1 0
+ * |length of m_Name|InDyn|reserved|Symbol|Type |ELF
+ * visibility|Local|Com|Def|Dyn|Weak|
*/
uint32_t m_BitField;
char m_Name[];
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_RESOLVEINFO_H_
diff --git a/include/mcld/LD/Resolver.h b/include/mcld/LD/Resolver.h
index c66431d..9b19716 100644
--- a/include/mcld/LD/Resolver.h
+++ b/include/mcld/LD/Resolver.h
@@ -6,17 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_RESOLVER_H
-#define MCLD_LD_RESOLVER_H
+#ifndef MCLD_LD_RESOLVER_H_
+#define MCLD_LD_RESOLVER_H_
+#include "mcld/LD/LDSymbol.h"
+
#include <string>
#include <utility>
-#include <mcld/LD/LDSymbol.h>
-namespace mcld
-{
+namespace mcld {
-class ResolveInfo;
class NamePool;
+class ResolveInfo;
/** \class Resolver
* \brief Resolver binds a symbol reference from one file to a symbol
@@ -26,15 +26,9 @@ class NamePool;
* two symbols depends on their type, binding and whether it is belonging to
* a shared object.
*/
-class Resolver
-{
-public:
- enum Action {
- Success,
- Warning,
- Abort,
- LastAction
- };
+class Resolver {
+ public:
+ enum Action { Success, Warning, Abort, LastAction };
/** \class Resolver::Result
* \brief the result of symbol resolution
@@ -48,33 +42,32 @@ public:
bool overriden;
};
-public:
+ public:
virtual ~Resolver();
/// shouldOverride - Can resolver override the symbol pOld by the symbol pNew?
/// @return the action should be taken.
/// @param pOld the symbol which may be overridden.
/// @param pNew the symbol which is used to replace pOld
- virtual bool resolve(ResolveInfo & __restrict__ pOld,
- const ResolveInfo & __restrict__ pNew,
- bool &pOverride, LDSymbol::ValueType pValue) const = 0;
+ virtual bool resolve(ResolveInfo& __restrict__ pOld,
+ const ResolveInfo& __restrict__ pNew,
+ bool& pOverride,
+ LDSymbol::ValueType pValue) const = 0;
/// resolveAgain - Can override by derived classes.
/// @return the pointer to resolved ResolveInfo
/// @return is the symbol existent?
virtual void resolveAgain(NamePool& pNamePool,
- unsigned int pAction,
- ResolveInfo& __restrict__ pOld,
- const ResolveInfo& __restrict__ pNew,
- Result& pResult) const {
+ unsigned int pAction,
+ ResolveInfo& __restrict__ pOld,
+ const ResolveInfo& __restrict__ pNew,
+ Result& pResult) const {
pResult.info = NULL;
pResult.existent = false;
pResult.overriden = false;
}
-
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_RESOLVER_H_
diff --git a/include/mcld/LD/SectionData.h b/include/mcld/LD/SectionData.h
index ddafaf1..22cda34 100644
--- a/include/mcld/LD/SectionData.h
+++ b/include/mcld/LD/SectionData.h
@@ -6,17 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_SECTIONDATA_H
-#define MCLD_LD_SECTIONDATA_H
+#ifndef MCLD_LD_SECTIONDATA_H_
+#define MCLD_LD_SECTIONDATA_H_
+
+#include "mcld/Config/Config.h"
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/Support/Allocators.h"
+#include "mcld/Support/Compiler.h"
#include <llvm/ADT/ilist.h>
#include <llvm/ADT/ilist_node.h>
#include <llvm/Support/DataTypes.h>
-#include <mcld/Config/Config.h>
-#include <mcld/Support/Allocators.h>
-#include <mcld/Fragment/Fragment.h>
-
namespace mcld {
class LDSection;
@@ -24,18 +25,14 @@ class LDSection;
/** \class SectionData
* \brief SectionData provides a container for all Fragments.
*/
-class SectionData
-{
-private:
+class SectionData {
+ private:
friend class Chunk<SectionData, MCLD_SECTIONS_PER_INPUT>;
SectionData();
- explicit SectionData(LDSection &pSection);
+ explicit SectionData(LDSection& pSection);
- SectionData(const SectionData &); // DO NOT IMPLEMENT
- SectionData& operator=(const SectionData &); // DO NOT IMPLEMENT
-
-public:
+ public:
typedef llvm::iplist<Fragment> FragmentListType;
typedef FragmentListType::reference reference;
@@ -47,7 +44,7 @@ public:
typedef FragmentListType::reverse_iterator reverse_iterator;
typedef FragmentListType::const_reverse_iterator const_reverse_iterator;
-public:
+ public:
static SectionData* Create(LDSection& pSection);
static void Destroy(SectionData*& pSection);
@@ -55,36 +52,37 @@ public:
static void Clear();
const LDSection& getSection() const { return *m_pSection; }
- LDSection& getSection() { return *m_pSection; }
+ LDSection& getSection() { return *m_pSection; }
- FragmentListType &getFragmentList() { return m_Fragments; }
- const FragmentListType &getFragmentList() const { return m_Fragments; }
+ const FragmentListType& getFragmentList() const { return m_Fragments; }
+ FragmentListType& getFragmentList() { return m_Fragments; }
size_t size() const { return m_Fragments.size(); }
bool empty() const { return m_Fragments.empty(); }
- reference front () { return m_Fragments.front(); }
- const_reference front () const { return m_Fragments.front(); }
- reference back () { return m_Fragments.back(); }
- const_reference back () const { return m_Fragments.back(); }
+ reference front() { return m_Fragments.front(); }
+ const_reference front() const { return m_Fragments.front(); }
+ reference back() { return m_Fragments.back(); }
+ const_reference back() const { return m_Fragments.back(); }
- const_iterator begin () const { return m_Fragments.begin(); }
- iterator begin () { return m_Fragments.begin(); }
- const_iterator end () const { return m_Fragments.end(); }
- iterator end () { return m_Fragments.end(); }
+ const_iterator begin() const { return m_Fragments.begin(); }
+ iterator begin() { return m_Fragments.begin(); }
+ const_iterator end() const { return m_Fragments.end(); }
+ iterator end() { return m_Fragments.end(); }
const_reverse_iterator rbegin() const { return m_Fragments.rbegin(); }
- reverse_iterator rbegin() { return m_Fragments.rbegin(); }
- const_reverse_iterator rend () const { return m_Fragments.rend(); }
- reverse_iterator rend () { return m_Fragments.rend(); }
+ reverse_iterator rbegin() { return m_Fragments.rbegin(); }
+ const_reverse_iterator rend() const { return m_Fragments.rend(); }
+ reverse_iterator rend() { return m_Fragments.rend(); }
-private:
+ private:
FragmentListType m_Fragments;
LDSection* m_pSection;
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SectionData);
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_SECTIONDATA_H_
diff --git a/include/mcld/LD/SectionSymbolSet.h b/include/mcld/LD/SectionSymbolSet.h
index 0f3b6e7..3de1cf3 100644
--- a/include/mcld/LD/SectionSymbolSet.h
+++ b/include/mcld/LD/SectionSymbolSet.h
@@ -6,15 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_SECTIONSYMBOLSET_H
-#define MCLD_LD_SECTIONSYMBOLSET_H
+#ifndef MCLD_LD_SECTIONSYMBOLSET_H_
+#define MCLD_LD_SECTIONSYMBOLSET_H_
-#include <mcld/ADT/HashTable.h>
-#include <mcld/ADT/HashEntry.h>
-#include <mcld/MC/SymbolCategory.h>
+#include "mcld/ADT/HashTable.h"
+#include "mcld/ADT/HashEntry.h"
+#include "mcld/MC/SymbolCategory.h"
-namespace mcld
-{
+namespace mcld {
class LDSection;
class NamePool;
@@ -24,12 +23,11 @@ class LDSymbol;
* \brief SectionSymbolSet contains the section symbols defined by linker for
* the output sections
*/
-class SectionSymbolSet
-{
-public:
+class SectionSymbolSet {
+ public:
typedef SymbolCategory SymbolTable;
-public:
+ public:
SectionSymbolSet();
~SectionSymbolSet();
@@ -45,19 +43,17 @@ public:
LDSymbol* get(const LDSection& pOutSect);
const LDSymbol* get(const LDSection& pOutSect) const;
-private:
+ private:
/// sectCompare - hash compare function for LDSection*
- struct SectCompare
- {
- bool operator()(const LDSection* X, const LDSection* Y) const
- { return (X==Y); }
+ struct SectCompare {
+ bool operator()(const LDSection* X, const LDSection* Y) const {
+ return (X == Y);
+ }
};
/// SectPtrHash - hash function for LDSection*
- struct SectPtrHash
- {
- size_t operator()(const LDSection* pKey) const
- {
+ struct SectPtrHash {
+ size_t operator()(const LDSection* pKey) const {
return (unsigned((uintptr_t)pKey) >> 4) ^
(unsigned((uintptr_t)pKey) >> 9);
}
@@ -68,11 +64,10 @@ private:
SectPtrHash,
EntryFactory<SectHashEntryType> > SectHashTableType;
-private:
+ private:
SectHashTableType* m_pSectionSymbolMap;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_SECTIONSYMBOLSET_H_
diff --git a/include/mcld/LD/StaticResolver.h b/include/mcld/LD/StaticResolver.h
index dfe0784..35ff7e7 100644
--- a/include/mcld/LD/StaticResolver.h
+++ b/include/mcld/LD/StaticResolver.h
@@ -6,53 +6,51 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_STATICRESOLVER_H
-#define MCLD_LD_STATICRESOLVER_H
+#ifndef MCLD_LD_STATICRESOLVER_H_
+#define MCLD_LD_STATICRESOLVER_H_
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/Resolver.h"
+
#include <string>
-#include <mcld/LD/Resolver.h>
-#include <mcld/LD/ResolveInfo.h>
-namespace mcld
-{
+namespace mcld {
class NamePool;
/** \class StaticResolver
*/
-class StaticResolver : public Resolver
-{
-public:
+class StaticResolver : public Resolver {
+ public:
/** \enum LinkAction
* LinkAction follows BFD:linker.c (binary file descriptor).
* List all actions to take in the state table
*/
- enum LinkAction
- {
- FAIL, /* abort. */
- NOACT, /* no action. */
- UND, /* override by symbol undefined symbol. */
- WEAK, /* override by symbol weak undefined. */
- DEF, /* override by symbol defined. */
- DEFW, /* override by symbol weak defined. */
- DEFD, /* override by symbol dynamic defined. */
- DEFWD, /* override by symbol dynamic weak defined. */
- MDEFD, /* mark symbol dynamic defined. */
- MDEFWD, /* mark symbol dynamic weak defined. */
- DUND, /* override dynamic defined symbol by undefined one. */
- DUNDW, /* oevrride dynamic defined symbol by weak undefined one. */
- COM, /* override by symbol common. */
- CREF, /* Possibly warn about common reference to defined symbol. */
- CDEF, /* redefine existing common symbol. */
- BIG, /* override by symbol common using largest size. */
- MBIG, /* mark common symbol by larger size. */
- IND, /* override by indirect symbol. */
- CIND, /* mark indirect symbol from existing common symbol. */
- MDEF, /* multiple definition error. */
- MIND, /* multiple indirect symbols. */
- REFC /* Mark indirect symbol referenced and then CYCLE. */
+ enum LinkAction {
+ FAIL, // abort.
+ NOACT, // no action.
+ UND, // override by symbol undefined symbol.
+ WEAK, // override by symbol weak undefined.
+ DEF, // override by symbol defined.
+ DEFW, // override by symbol weak defined.
+ DEFD, // override by symbol dynamic defined.
+ DEFWD, // override by symbol dynamic weak defined.
+ MDEFD, // mark symbol dynamic defined.
+ MDEFWD, // mark symbol dynamic weak defined.
+ DUND, // override dynamic defined symbol by undefined one.
+ DUNDW, // oevrride dynamic defined symbol by weak undefined one.
+ COM, // override by symbol common.
+ CREF, // Possibly warn about common reference to defined symbol.
+ CDEF, // redefine existing common symbol.
+ BIG, // override by symbol common using largest size.
+ MBIG, // mark common symbol by larger size.
+ IND, // override by indirect symbol.
+ CIND, // mark indirect symbol from existing common symbol.
+ MDEF, // multiple definition error.
+ MIND, // multiple indirect symbols.
+ REFC // Mark indirect symbol referenced and then CYCLE.
};
-private:
+ private:
// These are the values generated by the bit codes.
/** Encoding:
* D -> define
@@ -62,28 +60,26 @@ private:
* C -> common
* I -> indirect
*/
- enum
- {
- U = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::undefine_flag,
- w_U = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::undefine_flag,
- d_U = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::undefine_flag,
- wd_U = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::undefine_flag,
- D = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::define_flag,
- w_D = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::define_flag,
- d_D = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::define_flag,
- wd_D = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::define_flag,
- C = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::common_flag,
- w_C = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::common_flag,
- d_C = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::common_flag,
- wd_C = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::common_flag,
- I = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::indirect_flag,
- w_I = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::indirect_flag,
- d_I = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::indirect_flag,
- wd_I = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::indirect_flag
+ enum {
+ U = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::undefine_flag, // NOLINT
+ w_U = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::undefine_flag, // NOLINT
+ d_U = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::undefine_flag, // NOLINT
+ wd_U = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::undefine_flag, // NOLINT
+ D = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::define_flag, // NOLINT
+ w_D = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::define_flag, // NOLINT
+ d_D = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::define_flag, // NOLINT
+ wd_D = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::define_flag, // NOLINT
+ C = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::common_flag, // NOLINT
+ w_C = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::common_flag, // NOLINT
+ d_C = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::common_flag, // NOLINT
+ wd_C = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::common_flag, // NOLINT
+ I = ResolveInfo::global_flag | ResolveInfo::regular_flag | ResolveInfo::indirect_flag, // NOLINT
+ w_I = ResolveInfo::weak_flag | ResolveInfo::regular_flag | ResolveInfo::indirect_flag, // NOLINT
+ d_I = ResolveInfo::global_flag | ResolveInfo::dynamic_flag | ResolveInfo::indirect_flag, // NOLINT
+ wd_I = ResolveInfo::weak_flag | ResolveInfo::dynamic_flag | ResolveInfo::indirect_flag // NOLINT
};
- enum ORDINATE
- {
+ enum ORDINATE {
U_ORD,
w_U_ORD,
d_U_ORD,
@@ -99,18 +95,19 @@ private:
LAST_ORD
};
-public:
+ public:
virtual ~StaticResolver();
/// shouldOverride - Can resolver override the symbol pOld by the symbol pNew?
/// @return successfully resolved, return true; otherwise, return false.
/// @param pOld the symbol which may be overridden.
/// @param pNew the symbol which is used to replace pOld
- virtual bool resolve(ResolveInfo & __restrict__ pOld,
- const ResolveInfo & __restrict__ pNew,
- bool &pOverride, LDSymbol::ValueType pValue) const;
+ virtual bool resolve(ResolveInfo& __restrict__ pOld,
+ const ResolveInfo& __restrict__ pNew,
+ bool& pOverride,
+ LDSymbol::ValueType pValue) const;
-private:
+ private:
inline unsigned int getOrdinate(const ResolveInfo& pInfo) const {
if (pInfo.isAbsolute() && pInfo.isDyn())
return d_D_ORD;
@@ -128,7 +125,6 @@ private:
}
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_STATICRESOLVER_H_
diff --git a/include/mcld/LD/StubFactory.h b/include/mcld/LD/StubFactory.h
index 23dc5ec..2a093d0 100644
--- a/include/mcld/LD/StubFactory.h
+++ b/include/mcld/LD/StubFactory.h
@@ -6,26 +6,26 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_STUBFACTORY_H
-#define MCLD_LD_STUBFACTORY_H
+#ifndef MCLD_LD_STUBFACTORY_H_
+#define MCLD_LD_STUBFACTORY_H_
#include <llvm/Support/DataTypes.h>
+
#include <vector>
namespace mcld {
-class Stub;
-class Relocation;
class BranchIslandFactory;
class IRBuilder;
+class Relocation;
+class Stub;
/** \class StubFactory
* \brief the clone factory of Stub
*
*/
-class StubFactory
-{
-public:
+class StubFactory {
+ public:
~StubFactory();
/// addPrototype - register a stub prototype
@@ -37,20 +37,20 @@ public:
IRBuilder& pBuilder,
BranchIslandFactory& pBRIslandFactory);
-private:
+ private:
/// findPrototype - find if there is a registered stub prototype for the given
/// relocation
Stub* findPrototype(const Relocation& pReloc,
const uint64_t pSource,
uint64_t pTargetSymValue);
-private:
- typedef std::vector<Stub*> StubPoolType;
+ private:
+ typedef std::vector<Stub*> StubPoolType;
-private:
- StubPoolType m_StubPool; // stub pool
+ private:
+ StubPoolType m_StubPool; // stub pool
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_LD_STUBFACTORY_H_
diff --git a/include/mcld/LD/TextDiagnosticPrinter.h b/include/mcld/LD/TextDiagnosticPrinter.h
index 262901b..60939aa 100644
--- a/include/mcld/LD/TextDiagnosticPrinter.h
+++ b/include/mcld/LD/TextDiagnosticPrinter.h
@@ -6,23 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LD_TEXTDIAGNOSTICPRINTER_H
-#define MCLD_LD_TEXTDIAGNOSTICPRINTER_H
-#include <mcld/LD/DiagnosticPrinter.h>
+#ifndef MCLD_LD_TEXTDIAGNOSTICPRINTER_H_
+#define MCLD_LD_TEXTDIAGNOSTICPRINTER_H_
+#include "mcld/LD/DiagnosticPrinter.h"
+
#include <llvm/Support/raw_ostream.h>
-namespace mcld
-{
+namespace mcld {
class LinkerConfig;
/** \class TextDiagnosticPrinter
* \brief The plain, text-based DiagnosticPrinter.
*/
-class TextDiagnosticPrinter : public DiagnosticPrinter
-{
-public:
- TextDiagnosticPrinter(llvm::raw_ostream& pOStream, const LinkerConfig& pConfig);
+class TextDiagnosticPrinter : public DiagnosticPrinter {
+ public:
+ TextDiagnosticPrinter(llvm::raw_ostream& pOStream,
+ const LinkerConfig& pConfig);
virtual ~TextDiagnosticPrinter();
@@ -35,13 +35,12 @@ public:
virtual void endInput();
-private:
+ private:
llvm::raw_ostream& m_OStream;
const LinkerConfig& m_Config;
const Input* m_pInput;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LD_TEXTDIAGNOSTICPRINTER_H_
diff --git a/include/mcld/Linker.h b/include/mcld/Linker.h
index 1982c13..9fe8f8f 100644
--- a/include/mcld/Linker.h
+++ b/include/mcld/Linker.h
@@ -6,32 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LINKER_H
-#define MCLD_LINKER_H
+#ifndef MCLD_LINKER_H_
+#define MCLD_LINKER_H_
#include <string>
namespace mcld {
-class Module;
+class FileHandle;
+class FileOutputBuffer;
+class IRBuilder;
class LinkerConfig;
class LinkerScript;
-
+class Module;
+class ObjectLinker;
class Target;
class TargetLDBackend;
-class IRBuilder;
-class ObjectLinker;
-
-class FileHandle;
-class FileOutputBuffer;
-
/** \class Linker
* \brief Linker is a modular linker.
*/
-class Linker
-{
-public:
+class Linker {
+ public:
Linker();
~Linker();
@@ -63,7 +59,7 @@ public:
bool reset();
-private:
+ private:
bool initTarget();
bool initBackend();
@@ -72,7 +68,7 @@ private:
bool initEmulator(LinkerScript& pScript);
-private:
+ private:
LinkerConfig* m_pConfig;
IRBuilder* m_pIRBuilder;
@@ -81,7 +77,6 @@ private:
ObjectLinker* m_pObjLinker;
};
-} // namespace of MC Linker
-
-#endif
+} // namespace mcld
+#endif // MCLD_LINKER_H_
diff --git a/include/mcld/LinkerConfig.h b/include/mcld/LinkerConfig.h
index 4507206..36033e7 100644
--- a/include/mcld/LinkerConfig.h
+++ b/include/mcld/LinkerConfig.h
@@ -6,16 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LINKERCONFIG_H
-#define MCLD_LINKERCONFIG_H
+#ifndef MCLD_LINKERCONFIG_H_
+#define MCLD_LINKERCONFIG_H_
-#include <llvm/ADT/Triple.h>
+#include "mcld/GeneralOptions.h"
+#include "mcld/TargetOptions.h"
+#include "mcld/AttributeOption.h"
+#include "mcld/Support/Path.h"
-#include <mcld/GeneralOptions.h>
-#include <mcld/TargetOptions.h>
-#include <mcld/BitcodeOption.h>
-#include <mcld/AttributeOption.h>
-#include <mcld/Support/Path.h>
+#include <llvm/ADT/Triple.h>
#include <string>
@@ -27,17 +26,9 @@ namespace mcld {
* bitcode() - the bitcode being linked
* attribute() - the attribute options
*/
-class LinkerConfig
-{
-public:
- enum CodeGenType {
- Unknown,
- Object,
- DynObj,
- Exec,
- External,
- Binary
- };
+class LinkerConfig {
+ public:
+ enum CodeGenType { Unknown, Object, DynObj, Exec, External, Binary };
/** \enum CodePosition
* CodePosition indicates the ability of the generated output to be
@@ -56,30 +47,27 @@ public:
* output.
*/
enum CodePosition {
- Independent, ///< Position Independent
- DynamicDependent, ///< Can call outside libraries
- StaticDependent, ///< Can not call outside libraries
- Unset ///< Undetermine code position mode
+ Independent, ///< Position Independent
+ DynamicDependent, ///< Can call outside libraries
+ StaticDependent, ///< Can not call outside libraries
+ Unset ///< Undetermine code position mode
};
-public:
+ public:
LinkerConfig();
- explicit LinkerConfig(const std::string &pTripleString);
+ explicit LinkerConfig(const std::string& pTripleString);
~LinkerConfig();
const GeneralOptions& options() const { return m_Options; }
- GeneralOptions& options() { return m_Options; }
+ GeneralOptions& options() { return m_Options; }
- const TargetOptions& targets() const { return m_Targets; }
- TargetOptions& targets() { return m_Targets; }
-
- const BitcodeOption& bitcode() const { return m_Bitcode; }
- BitcodeOption& bitcode() { return m_Bitcode; }
+ const TargetOptions& targets() const { return m_Targets; }
+ TargetOptions& targets() { return m_Targets; }
const AttributeOption& attribute() const { return m_Attribute; }
- AttributeOption& attribute() { return m_Attribute; }
+ AttributeOption& attribute() { return m_Attribute; }
CodeGenType codeGenType() const { return m_CodeGenType; }
@@ -88,24 +76,22 @@ public:
CodePosition codePosition() const { return m_CodePosition; }
void setCodePosition(CodePosition pPosition) { m_CodePosition = pPosition; }
- bool isCodeIndep() const { return (Independent == m_CodePosition); }
+ bool isCodeIndep() const { return (Independent == m_CodePosition); }
bool isCodeDynamic() const { return (DynamicDependent == m_CodePosition); }
- bool isCodeStatic() const { return (StaticDependent == m_CodePosition); }
+ bool isCodeStatic() const { return (StaticDependent == m_CodePosition); }
static const char* version();
-private:
+ private:
// ----- General Options ----- //
GeneralOptions m_Options;
TargetOptions m_Targets;
- BitcodeOption m_Bitcode;
AttributeOption m_Attribute;
CodeGenType m_CodeGenType;
CodePosition m_CodePosition;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LINKERCONFIG_H_
diff --git a/include/mcld/LinkerScript.h b/include/mcld/LinkerScript.h
index 581c517..3e2737e 100644
--- a/include/mcld/LinkerScript.h
+++ b/include/mcld/LinkerScript.h
@@ -6,18 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_LINKERSCRIPT_H
-#define MCLD_LINKERSCRIPT_H
+#ifndef MCLD_LINKERSCRIPT_H_
+#define MCLD_LINKERSCRIPT_H_
+
+#include "mcld/ADT/HashTable.h"
+#include "mcld/ADT/StringEntry.h"
+#include "mcld/ADT/StringHash.h"
+#include "mcld/MC/SearchDirs.h"
+#include "mcld/Object/SectionMap.h"
+#include "mcld/Script/AssertCmd.h"
+#include "mcld/Script/Assignment.h"
+
+#include <llvm/ADT/StringRef.h>
+
#include <string>
#include <vector>
-#include <llvm/ADT/StringRef.h>
-#include <mcld/ADT/StringEntry.h>
-#include <mcld/ADT/StringHash.h>
-#include <mcld/ADT/HashTable.h>
-#include <mcld/Object/SectionMap.h>
-#include <mcld/MC/SearchDirs.h>
-#include <mcld/Script/Assignment.h>
-#include <mcld/Script/AssertCmd.h>
namespace mcld {
@@ -26,9 +29,8 @@ class LDSymbol;
/** \class LinkerScript
*
*/
-class LinkerScript
-{
-public:
+class LinkerScript {
+ public:
typedef HashTable<StringEntry<llvm::StringRef>,
hash::StringHash<hash::DJB>,
StringEntryFactory<llvm::StringRef> > SymbolRenameMap;
@@ -41,34 +43,34 @@ public:
typedef std::vector<AssertCmd> Assertions;
-public:
+ public:
LinkerScript();
~LinkerScript();
const SymbolRenameMap& renameMap() const { return m_SymbolRenames; }
- SymbolRenameMap& renameMap() { return m_SymbolRenames; }
+ SymbolRenameMap& renameMap() { return m_SymbolRenames; }
const AddressMap& addressMap() const { return m_AddressMap; }
- AddressMap& addressMap() { return m_AddressMap; }
+ AddressMap& addressMap() { return m_AddressMap; }
const SectionMap& sectionMap() const { return m_SectionMap; }
- SectionMap& sectionMap() { return m_SectionMap; }
+ SectionMap& sectionMap() { return m_SectionMap; }
const Assignments& assignments() const { return m_Assignments; }
- Assignments& assignments() { return m_Assignments; }
+ Assignments& assignments() { return m_Assignments; }
const Assertions& assertions() const { return m_Assertions; }
- Assertions& assertions() { return m_Assertions; }
+ Assertions& assertions() { return m_Assertions; }
/// search directory
const SearchDirs& directories() const { return m_SearchDirs; }
- SearchDirs& directories() { return m_SearchDirs; }
+ SearchDirs& directories() { return m_SearchDirs; }
/// sysroot
const sys::fs::Path& sysroot() const;
- void setSysroot(const sys::fs::Path &pPath);
+ void setSysroot(const sys::fs::Path& pPath);
bool hasSysroot() const;
@@ -86,7 +88,7 @@ public:
bool hasOutputFile() const;
-private:
+ private:
SymbolRenameMap m_SymbolRenames;
AddressMap m_AddressMap;
SectionMap m_SectionMap;
@@ -97,7 +99,6 @@ private:
std::string m_OutputFile;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_LINKERSCRIPT_H_
diff --git a/include/mcld/MC/Attribute.h b/include/mcld/MC/Attribute.h
index 227ae29..37db1e8 100644
--- a/include/mcld/MC/Attribute.h
+++ b/include/mcld/MC/Attribute.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MC_ATTRIBUTE_H
-#define MCLD_MC_ATTRIBUTE_H
+#ifndef MCLD_MC_ATTRIBUTE_H_
+#define MCLD_MC_ATTRIBUTE_H_
namespace mcld {
@@ -28,48 +28,39 @@ class AttributeSet;
* which have identical attributes share common attribute. AttributeBase is
* the shared storage for attribute.
*/
-class AttributeBase
-{
-public:
+class AttributeBase {
+ public:
AttributeBase()
- : m_WholeArchive(false),
- m_AsNeeded(false),
- m_AddNeeded(true),
- m_Static(false)
- { }
+ : m_WholeArchive(false),
+ m_AsNeeded(false),
+ m_AddNeeded(true),
+ m_Static(false) {}
AttributeBase(const AttributeBase& pBase)
- : m_WholeArchive(pBase.m_WholeArchive),
- m_AsNeeded(pBase.m_AsNeeded),
- m_AddNeeded(pBase.m_AddNeeded),
- m_Static(pBase.m_Static)
- { }
+ : m_WholeArchive(pBase.m_WholeArchive),
+ m_AsNeeded(pBase.m_AsNeeded),
+ m_AddNeeded(pBase.m_AddNeeded),
+ m_Static(pBase.m_Static) {}
- virtual ~AttributeBase()
- { }
+ virtual ~AttributeBase() {}
// ----- observers ----- //
// represent GNU ld --whole-archive/--no-whole-archive options
- bool isWholeArchive() const
- { return m_WholeArchive; }
+ bool isWholeArchive() const { return m_WholeArchive; }
// represent GNU ld --as-needed/--no-as-needed options
- bool isAsNeeded() const
- { return m_AsNeeded; }
+ bool isAsNeeded() const { return m_AsNeeded; }
// represent GNU ld --add-needed/--no-add-needed options
- bool isAddNeeded() const
- { return m_AddNeeded; }
+ bool isAddNeeded() const { return m_AddNeeded; }
// represent GNU ld -static option
- bool isStatic() const
- { return m_Static; }
+ bool isStatic() const { return m_Static; }
// represent GNU ld -call_shared option
- bool isDynamic() const
- { return !m_Static; }
+ bool isDynamic() const { return !m_Static; }
-public:
+ public:
bool m_WholeArchive : 1;
bool m_AsNeeded : 1;
bool m_AddNeeded : 1;
@@ -83,33 +74,24 @@ public:
* For conventience and producing less bugs, we move the stoarges of attributes
* onto AttributeBase, and modifiers remains with the class Attribute.
*/
-class Attribute : public AttributeBase
-{
-public:
+class Attribute : public AttributeBase {
+ public:
// ----- modifiers ----- //
- void setWholeArchive()
- { m_WholeArchive = true; }
+ void setWholeArchive() { m_WholeArchive = true; }
- void unsetWholeArchive()
- { m_WholeArchive = false; }
+ void unsetWholeArchive() { m_WholeArchive = false; }
- void setAsNeeded()
- { m_AsNeeded = true; }
+ void setAsNeeded() { m_AsNeeded = true; }
- void unsetAsNeeded()
- { m_AsNeeded = false; }
+ void unsetAsNeeded() { m_AsNeeded = false; }
- void setAddNeeded()
- { m_AddNeeded = true; }
+ void setAddNeeded() { m_AddNeeded = true; }
- void unsetAddNeeded()
- { m_AddNeeded = false; }
+ void unsetAddNeeded() { m_AddNeeded = false; }
- void setStatic()
- { m_Static = true; }
+ void setStatic() { m_Static = true; }
- void setDynamic()
- { m_Static = false; }
+ void setDynamic() { m_Static = false; }
};
/** \class AttrConstraint
@@ -124,38 +106,27 @@ public:
*
* @see SectLinker
*/
-class AttrConstraint : public AttributeBase
-{
-public:
- void enableWholeArchive()
- { m_WholeArchive = true; }
+class AttrConstraint : public AttributeBase {
+ public:
+ void enableWholeArchive() { m_WholeArchive = true; }
- void disableWholeArchive()
- { m_WholeArchive = false; }
+ void disableWholeArchive() { m_WholeArchive = false; }
- void enableAsNeeded()
- { m_AsNeeded = true; }
+ void enableAsNeeded() { m_AsNeeded = true; }
- void disableAsNeeded()
- { m_AsNeeded = false; }
+ void disableAsNeeded() { m_AsNeeded = false; }
- void enableAddNeeded()
- { m_AddNeeded = true; }
+ void enableAddNeeded() { m_AddNeeded = true; }
- void disableAddNeeded()
- { m_AddNeeded = false; }
+ void disableAddNeeded() { m_AddNeeded = false; }
- void setSharedSystem()
- { m_Static = false; }
+ void setSharedSystem() { m_Static = false; }
- void setStaticSystem()
- { m_Static = true; }
+ void setStaticSystem() { m_Static = true; }
- bool isSharedSystem() const
- { return !m_Static; }
+ bool isSharedSystem() const { return !m_Static; }
- bool isStaticSystem() const
- { return m_Static; }
+ bool isStaticSystem() const { return m_Static; }
bool isLegal(const Attribute& pAttr) const;
};
@@ -175,9 +146,8 @@ public:
* the attribute of the input file. If the searching fails, AttributeProxy
* requests a new attribute from the AttributeSet.
*/
-class AttributeProxy
-{
-public:
+class AttributeProxy {
+ public:
AttributeProxy(AttributeSet& pParent,
const Attribute& pBase,
const AttrConstraint& pConstraint);
@@ -195,8 +165,7 @@ public:
bool isDynamic() const;
- const Attribute* attr() const
- { return m_pBase; }
+ const Attribute* attr() const { return m_pBase; }
// ----- modifiers ----- //
void setWholeArchive();
@@ -210,28 +179,24 @@ public:
AttributeProxy& assign(Attribute* pBase);
-private:
- AttributeSet &m_AttrPool;
- const Attribute *m_pBase;
+ private:
+ AttributeSet& m_AttrPool;
+ const Attribute* m_pBase;
const AttrConstraint& m_Constraint;
};
-
// ----- comparisons ----- //
-inline bool operator== (const Attribute& pLHS, const Attribute& pRHS)
-{
+inline bool operator==(const Attribute& pLHS, const Attribute& pRHS) {
return ((pLHS.isWholeArchive() == pRHS.isWholeArchive()) &&
- (pLHS.isAsNeeded() == pRHS.isAsNeeded()) &&
- (pLHS.isAddNeeded() == pRHS.isAddNeeded()) &&
- (pLHS.isStatic() == pRHS.isStatic()));
+ (pLHS.isAsNeeded() == pRHS.isAsNeeded()) &&
+ (pLHS.isAddNeeded() == pRHS.isAddNeeded()) &&
+ (pLHS.isStatic() == pRHS.isStatic()));
}
-inline bool operator!= (const Attribute& pLHS, const Attribute& pRHS)
-{
+inline bool operator!=(const Attribute& pLHS, const Attribute& pRHS) {
return !(pLHS == pRHS);
}
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_MC_ATTRIBUTE_H_
diff --git a/include/mcld/MC/AttributeSet.h b/include/mcld/MC/AttributeSet.h
index 6dc8801..e415c30 100644
--- a/include/mcld/MC/AttributeSet.h
+++ b/include/mcld/MC/AttributeSet.h
@@ -6,9 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MC_ATTRIBUTESET_H
-#define MCLD_MC_ATTRIBUTESET_H
-#include <mcld/ADT/Uncopyable.h>
+#ifndef MCLD_MC_ATTRIBUTESET_H_
+#define MCLD_MC_ATTRIBUTESET_H_
+#include "mcld/Support/Compiler.h"
+
#include <vector>
namespace mcld {
@@ -21,39 +22,40 @@ class Attribute;
* Clients delegates Attributes to AttributeSet. AttributeSet deletes delegated
* Attributes during destruction.
*/
-class AttributeSet : private Uncopyable
-{
-private:
+class AttributeSet {
+ private:
typedef std::vector<Attribute*> AttrSet;
-public:
+ public:
typedef AttrSet::iterator iterator;
typedef AttrSet::const_iterator const_iterator;
-public:
+ public:
AttributeSet(unsigned int pNum, const Attribute& pPredefined);
~AttributeSet();
// ----- iterators ----- //
const_iterator begin() const { return m_AttrSet.begin(); }
- iterator begin() { return m_AttrSet.begin(); }
- const_iterator end () const { return m_AttrSet.end(); }
- iterator end () { return m_AttrSet.end(); }
+ iterator begin() { return m_AttrSet.begin(); }
+ const_iterator end() const { return m_AttrSet.end(); }
+ iterator end() { return m_AttrSet.end(); }
// exists- return the recorded attribute whose content is identical to the
// input attribute.
- Attribute *exists(const Attribute& pAttr) const;
+ Attribute* exists(const Attribute& pAttr) const;
// record - record the attribute no mater if it has been recorded.
void record(Attribute& pAttr);
-private:
+ private:
AttrSet m_AttrSet;
const Attribute& m_Predefined;
-};
-} // namespace of mcld
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AttributeSet);
+};
-#endif
+} // namespace mcld
+#endif // MCLD_MC_ATTRIBUTESET_H_
diff --git a/include/mcld/MC/CommandAction.h b/include/mcld/MC/CommandAction.h
index ab4e35a..85f3e2b 100644
--- a/include/mcld/MC/CommandAction.h
+++ b/include/mcld/MC/CommandAction.h
@@ -6,13 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MC_COMMANDACTION_H
-#define MCLD_MC_COMMANDACTION_H
+#ifndef MCLD_MC_COMMANDACTION_H_
+#define MCLD_MC_COMMANDACTION_H_
+
+#include "mcld/MC/InputAction.h"
+#include "mcld/Script/ScriptFile.h"
+#include "mcld/Support/Path.h"
#include <string>
-#include <mcld/Support/Path.h>
-#include <mcld/MC/InputAction.h>
-#include <mcld/Script/ScriptFile.h>
namespace mcld {
@@ -24,158 +25,145 @@ class LinkerConfig;
// Derived InputAction
//===----------------------------------------------------------------------===//
/// InputFileAction
-class InputFileAction : public InputAction
-{
-public:
- explicit InputFileAction(unsigned int pPosition, const sys::fs::Path &pPath);
+class InputFileAction : public InputAction {
+ public:
+ InputFileAction(unsigned int pPosition, const sys::fs::Path& pPath);
+
+ InputFileAction(unsigned int pPosition, const char* pPath);
const sys::fs::Path& path() const { return m_Path; }
bool activate(InputBuilder&) const;
-private:
+ private:
sys::fs::Path m_Path;
};
/// NamespecAction
-class NamespecAction : public InputAction
-{
-public:
+class NamespecAction : public InputAction {
+ public:
NamespecAction(unsigned int pPosition,
- const std::string &pNamespec,
+ const std::string& pNamespec,
const SearchDirs& pSearchDirs);
- const std::string &namespec() const { return m_Namespec; }
+ const std::string& namespec() const { return m_Namespec; }
bool activate(InputBuilder&) const;
-private:
+ private:
std::string m_Namespec;
const SearchDirs& m_SearchDirs;
};
/// BitcodeAction
-class BitcodeAction : public InputAction
-{
-public:
- BitcodeAction(unsigned int pPosition, const sys::fs::Path &pPath);
+class BitcodeAction : public InputAction {
+ public:
+ BitcodeAction(unsigned int pPosition, const sys::fs::Path& pPath);
const sys::fs::Path& path() const { return m_Path; }
bool activate(InputBuilder&) const;
-private:
+ private:
sys::fs::Path m_Path;
};
/// StartGroupAction
-class StartGroupAction : public InputAction
-{
-public:
+class StartGroupAction : public InputAction {
+ public:
explicit StartGroupAction(unsigned int pPosition);
bool activate(InputBuilder&) const;
};
/// EndGroupAction
-class EndGroupAction : public InputAction
-{
-public:
+class EndGroupAction : public InputAction {
+ public:
explicit EndGroupAction(unsigned int pPosition);
bool activate(InputBuilder&) const;
};
/// WholeArchiveAction
-class WholeArchiveAction : public InputAction
-{
-public:
+class WholeArchiveAction : public InputAction {
+ public:
explicit WholeArchiveAction(unsigned int pPosition);
bool activate(InputBuilder&) const;
};
/// NoWholeArchiveAction
-class NoWholeArchiveAction : public InputAction
-{
-public:
+class NoWholeArchiveAction : public InputAction {
+ public:
explicit NoWholeArchiveAction(unsigned int pPosition);
bool activate(InputBuilder&) const;
};
/// AsNeededAction
-class AsNeededAction : public InputAction
-{
-public:
+class AsNeededAction : public InputAction {
+ public:
explicit AsNeededAction(unsigned int pPosition);
bool activate(InputBuilder&) const;
};
/// NoAsNeededAction
-class NoAsNeededAction : public InputAction
-{
-public:
+class NoAsNeededAction : public InputAction {
+ public:
explicit NoAsNeededAction(unsigned int pPosition);
bool activate(InputBuilder&) const;
};
/// AddNeededAction
-class AddNeededAction : public InputAction
-{
-public:
+class AddNeededAction : public InputAction {
+ public:
explicit AddNeededAction(unsigned int pPosition);
bool activate(InputBuilder&) const;
};
/// NoAddNeededAction
-class NoAddNeededAction : public InputAction
-{
-public:
+class NoAddNeededAction : public InputAction {
+ public:
explicit NoAddNeededAction(unsigned int pPosition);
bool activate(InputBuilder&) const;
};
/// BDynamicAction
-class BDynamicAction : public InputAction
-{
-public:
+class BDynamicAction : public InputAction {
+ public:
explicit BDynamicAction(unsigned int pPosition);
bool activate(InputBuilder&) const;
};
/// BStaticAction
-class BStaticAction : public InputAction
-{
-public:
+class BStaticAction : public InputAction {
+ public:
explicit BStaticAction(unsigned int pPosition);
bool activate(InputBuilder&) const;
};
/// DefSymAction
-class DefSymAction : public InputAction
-{
-public:
+class DefSymAction : public InputAction {
+ public:
explicit DefSymAction(unsigned int pPosition, std::string& pAssignment);
bool activate(InputBuilder&) const;
const std::string& assignment() const { return m_Assignment; }
-private:
+ private:
std::string& m_Assignment;
};
/// ScriptAction
-class ScriptAction : public InputAction
-{
-public:
+class ScriptAction : public InputAction {
+ public:
ScriptAction(unsigned int pPosition,
const std::string& pFileName,
ScriptFile::Kind pKind,
@@ -187,13 +175,12 @@ public:
ScriptFile::Kind kind() const { return m_Kind; }
-private:
+ private:
std::string m_FileName;
ScriptFile::Kind m_Kind;
const SearchDirs& m_SearchDirs;
};
-} // end of namespace mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_MC_COMMANDACTION_H_
diff --git a/include/mcld/MC/ContextFactory.h b/include/mcld/MC/ContextFactory.h
index 34512f6..6067476 100644
--- a/include/mcld/MC/ContextFactory.h
+++ b/include/mcld/MC/ContextFactory.h
@@ -6,15 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MC_CONTEXTFACTORY_H
-#define MCLD_MC_CONTEXTFACTORY_H
+#ifndef MCLD_MC_CONTEXTFACTORY_H_
+#define MCLD_MC_CONTEXTFACTORY_H_
-#include <mcld/LD/LDContext.h>
-#include <mcld/Support/UniqueGCFactory.h>
-#include <mcld/Support/Path.h>
+#include "mcld/LD/LDContext.h"
+#include "mcld/Support/UniqueGCFactory.h"
+#include "mcld/Support/Path.h"
-namespace mcld
-{
+namespace mcld {
/** \class ContextFactory
* \brief ContextFactory avoids the duplicated LDContext of the same file.
*
@@ -29,17 +28,16 @@ namespace mcld
* @see LDContext
* @see UniqueGCFactoryBase
*/
-class ContextFactory : public UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>
-{
-public:
+class ContextFactory : public UniqueGCFactoryBase<sys::fs::Path, LDContext, 0> {
+ public:
explicit ContextFactory(size_t pNum);
~ContextFactory();
LDContext* produce();
LDContext* produce(const sys::fs::Path& pPath);
+ LDContext* produce(const char* pPath);
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_MC_CONTEXTFACTORY_H_
diff --git a/include/mcld/MC/FileAction.h b/include/mcld/MC/FileAction.h
index 7671c0a..ab135d7 100644
--- a/include/mcld/MC/FileAction.h
+++ b/include/mcld/MC/FileAction.h
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MC_FILEACTION_H
-#define MCLD_MC_FILEACTION_H
-#include <mcld/MC/InputAction.h>
-#include <mcld/Support/FileHandle.h>
+#ifndef MCLD_MC_FILEACTION_H_
+#define MCLD_MC_FILEACTION_H_
+#include "mcld/MC/InputAction.h"
+#include "mcld/Support/FileHandle.h"
namespace mcld {
@@ -18,9 +18,8 @@ class ContextFactory;
/** \class ContextAction
* \brief ContextAction is a command object to create input's LDContext.
*/
-class ContextAction : public InputAction
-{
-public:
+class ContextAction : public InputAction {
+ public:
explicit ContextAction(unsigned int pPosition);
bool activate(InputBuilder& pBuilder) const;
@@ -29,21 +28,19 @@ public:
/** \class MemoryAreaAction
* \brief MemoryAreaAction is a command object to create input's MemoryArea.
*/
-class MemoryAreaAction : public InputAction
-{
-public:
+class MemoryAreaAction : public InputAction {
+ public:
MemoryAreaAction(unsigned int pPosition,
- FileHandle::OpenMode pMode,
- FileHandle::Permission pPerm = FileHandle::System);
+ FileHandle::OpenModeEnum pMode,
+ FileHandle::PermissionEnum pPerm = FileHandle::System);
bool activate(InputBuilder& pBuilder) const;
-private:
+ private:
FileHandle::OpenMode m_Mode;
FileHandle::Permission m_Permission;
};
-} // end of namespace mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_MC_FILEACTION_H_
diff --git a/include/mcld/MC/Input.h b/include/mcld/MC/Input.h
index da3a647..dfd7df3 100644
--- a/include/mcld/MC/Input.h
+++ b/include/mcld/MC/Input.h
@@ -10,26 +10,26 @@
// Input class inherits MCLDFile, which is used to represent a input file
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MC_INPUT_H
-#define MCLD_MC_INPUT_H
+#ifndef MCLD_MC_INPUT_H_
+#define MCLD_MC_INPUT_H_
-#include <mcld/Support/Path.h>
+#include "mcld/Support/Path.h"
namespace mcld {
-class MemoryArea;
class AttributeProxy;
class Attribute;
class InputFactory;
class LDContext;
+class MemoryArea;
/** \class Input
* \brief Input provides the information of a input file.
*/
-class Input
-{
-friend class InputFactory;
-public:
+class Input {
+ friend class InputFactory;
+
+ public:
enum Type {
Unknown,
Binary,
@@ -42,11 +42,10 @@ public:
External
};
-public:
+ public:
explicit Input(llvm::StringRef pName);
- Input(llvm::StringRef pName,
- const AttributeProxy& pAttr);
+ Input(llvm::StringRef pName, const AttributeProxy& pAttr);
Input(llvm::StringRef pName,
const sys::fs::Path& pPath,
@@ -61,76 +60,57 @@ public:
~Input();
- const std::string& name() const
- { return m_Name; }
+ const std::string& name() const { return m_Name; }
- void setName(const std::string& pName)
- { m_Name = pName; }
+ void setName(const std::string& pName) { m_Name = pName; }
- const sys::fs::Path& path() const
- { return m_Path; }
+ const sys::fs::Path& path() const { return m_Path; }
- void setPath(const sys::fs::Path& pPath)
- { m_Path = pPath; }
+ void setPath(const sys::fs::Path& pPath) { m_Path = pPath; }
- void setType(unsigned int pType)
- { m_Type = pType; }
+ void setType(unsigned int pType) { m_Type = pType; }
- unsigned int type() const
- { return m_Type; }
+ unsigned int type() const { return m_Type; }
- bool isRecognized() const
- { return (m_Type != Unknown); }
+ bool isRecognized() const { return (m_Type != Unknown); }
- bool hasAttribute() const
- { return (NULL != m_pAttr); }
+ bool hasAttribute() const { return (m_pAttr != NULL); }
- const Attribute* attribute() const
- { return m_pAttr; }
+ const Attribute* attribute() const { return m_pAttr; }
- bool isNeeded() const
- { return m_bNeeded; }
+ bool isNeeded() const { return m_bNeeded; }
- void setNeeded()
- { m_bNeeded = true; }
+ void setNeeded() { m_bNeeded = true; }
- bool noExport() const
- { return m_bNoExport; }
+ bool noExport() const { return m_bNoExport; }
- void setNoExport()
- { m_bNoExport = true; }
+ void setNoExport() { m_bNoExport = true; }
- off_t fileOffset() const
- { return m_fileOffset; }
+ off_t fileOffset() const { return m_fileOffset; }
- void setFileOffset(off_t pFileOffset)
- { m_fileOffset = pFileOffset; }
+ void setFileOffset(off_t pFileOffset) { m_fileOffset = pFileOffset; }
// ----- memory area ----- //
- void setMemArea(MemoryArea* pMemArea)
- { m_pMemArea = pMemArea; }
+ void setMemArea(MemoryArea* pMemArea) { m_pMemArea = pMemArea; }
- bool hasMemArea() const
- { return (NULL != m_pMemArea); }
+ bool hasMemArea() const { return (m_pMemArea != NULL); }
const MemoryArea* memArea() const { return m_pMemArea; }
- MemoryArea* memArea() { return m_pMemArea; }
+ MemoryArea* memArea() { return m_pMemArea; }
// ----- context ----- //
- void setContext(LDContext* pContext)
- { m_pContext = pContext; }
+ void setContext(LDContext* pContext) { m_pContext = pContext; }
- bool hasContext() const
- { return (NULL != m_pContext); }
+ bool hasContext() const { return (m_pContext != NULL); }
const LDContext* context() const { return m_pContext; }
- LDContext* context() { return m_pContext; }
+ LDContext* context() { return m_pContext; }
-private:
+ private:
unsigned int m_Type;
std::string m_Name;
sys::fs::Path m_Path;
- Attribute *m_pAttr;
+ Attribute* m_pAttr;
bool m_bNeeded;
bool m_bNoExport;
off_t m_fileOffset;
@@ -138,7 +118,6 @@ private:
LDContext* m_pContext;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_MC_INPUT_H_
diff --git a/include/mcld/MC/InputAction.h b/include/mcld/MC/InputAction.h
index 46b43f0..d03829c 100644
--- a/include/mcld/MC/InputAction.h
+++ b/include/mcld/MC/InputAction.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MC_INPUTACTION_H
-#define MCLD_MC_INPUTACTION_H
+#ifndef MCLD_MC_INPUTACTION_H_
+#define MCLD_MC_INPUTACTION_H_
namespace mcld {
@@ -20,31 +20,30 @@ class InputBuilder;
/** \class InputAction
* \brief InputAction is a command object to construct mcld::InputTree.
*/
-class InputAction
-{
-protected:
+class InputAction {
+ protected:
explicit InputAction(unsigned int pPosition);
-public:
+ public:
virtual ~InputAction();
virtual bool activate(InputBuilder&) const = 0;
unsigned int position() const { return m_Position; }
- bool operator<(const InputAction& pOther) const
- { return (position() < pOther.position()); }
+ bool operator<(const InputAction& pOther) const {
+ return (position() < pOther.position());
+ }
-private:
+ private:
InputAction(); // DO_NOT_IMPLEMENT
- InputAction(const InputAction& ); // DO_NOT_IMPLEMENT
- InputAction& operator=(const InputAction& ); // DO_NOT_IMPLEMENT
+ InputAction(const InputAction&); // DO_NOT_IMPLEMENT
+ InputAction& operator=(const InputAction&); // DO_NOT_IMPLEMENT
-private:
+ private:
unsigned int m_Position;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_MC_INPUTACTION_H_
diff --git a/include/mcld/MC/InputBuilder.h b/include/mcld/MC/InputBuilder.h
index 9918c0d..ba43baa 100644
--- a/include/mcld/MC/InputBuilder.h
+++ b/include/mcld/MC/InputBuilder.h
@@ -6,32 +6,31 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MC_INPUTBUILDER_H
-#define MCLD_MC_INPUTBUILDER_H
+#ifndef MCLD_MC_INPUTBUILDER_H_
+#define MCLD_MC_INPUTBUILDER_H_
-#include <string>
-#include <stack>
+#include "mcld/InputTree.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Support/FileHandle.h"
-#include <mcld/InputTree.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Support/FileHandle.h>
+#include <stack>
+#include <string>
namespace mcld {
-class LinkerConfig;
-class InputFactory;
+class AttrConstraint;
class ContextFactory;
+class InputFactory;
+class LinkerConfig;
class MemoryAreaFactory;
-class AttrConstraint;
/** \class InputBuilder
* \brief InputBuilder recieves InputActions and build the InputTree.
*
* InputBuilder build input tree and inputs.
*/
-class InputBuilder
-{
-public:
+class InputBuilder {
+ public:
explicit InputBuilder(const LinkerConfig& pConfig);
InputBuilder(const LinkerConfig& pConfig,
@@ -44,15 +43,15 @@ public:
// ----- input tree operations ----- //
const InputTree& getCurrentTree() const;
- InputTree& getCurrentTree();
+ InputTree& getCurrentTree();
void setCurrentTree(InputTree& pInputTree);
// ----- root of input tree ----- //
const InputTree::iterator& getCurrentNode() const { return m_Root; }
- InputTree::iterator& getCurrentNode() { return m_Root; }
+ InputTree::iterator& getCurrentNode() { return m_Root; }
- template<InputTree::Direction DIRECTION>
+ template <InputTree::Direction DIRECTION>
InputTree& createNode(const std::string& pName,
const sys::fs::Path& pPath,
unsigned int pType = Input::Unknown);
@@ -67,7 +66,7 @@ public:
bool setMemory(Input& pInput,
FileHandle::OpenMode pMode,
- FileHandle::Permission pPerm = FileHandle::System);
+ FileHandle::Permission pPerm);
bool setMemory(Input& pInput, void* pMemBuffer, size_t pSize);
@@ -80,9 +79,9 @@ public:
const AttrConstraint& getConstraint() const;
const AttributeProxy& getAttributes() const;
- AttributeProxy& getAttributes();
+ AttributeProxy& getAttributes();
-private:
+ private:
const LinkerConfig& m_Config;
InputFactory* m_pInputFactory;
@@ -95,18 +94,17 @@ private:
std::stack<InputTree::iterator> m_ReturnStack;
bool m_bOwnFactory;
-
};
//===----------------------------------------------------------------------===//
// Template implement
//===----------------------------------------------------------------------===//
-template<> inline InputTree&
-InputBuilder::createNode<InputTree::Inclusive>(const std::string& pName,
- const sys::fs::Path& pPath,
- unsigned int pType)
-{
- assert(NULL != m_pCurrentTree && NULL != m_pMove);
+template <>
+inline InputTree& InputBuilder::createNode<InputTree::Inclusive>(
+ const std::string& pName,
+ const sys::fs::Path& pPath,
+ unsigned int pType) {
+ assert(m_pCurrentTree != NULL && m_pMove != NULL);
Input* input = createInput(pName, pPath, pType);
m_pCurrentTree->insert(m_Root, *m_pMove, *input);
@@ -116,12 +114,12 @@ InputBuilder::createNode<InputTree::Inclusive>(const std::string& pName,
return *m_pCurrentTree;
}
-template<> inline InputTree&
-InputBuilder::createNode<InputTree::Positional>(const std::string& pName,
- const sys::fs::Path& pPath,
- unsigned int pType)
-{
- assert(NULL != m_pCurrentTree && NULL != m_pMove);
+template <>
+inline InputTree& InputBuilder::createNode<InputTree::Positional>(
+ const std::string& pName,
+ const sys::fs::Path& pPath,
+ unsigned int pType) {
+ assert(m_pCurrentTree != NULL && m_pMove != NULL);
Input* input = createInput(pName, pPath, pType);
m_pCurrentTree->insert(m_Root, *m_pMove, *input);
@@ -131,7 +129,6 @@ InputBuilder::createNode<InputTree::Positional>(const std::string& pName,
return *m_pCurrentTree;
}
-} // end of namespace mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_MC_INPUTBUILDER_H_
diff --git a/include/mcld/MC/InputFactory.h b/include/mcld/MC/InputFactory.h
index 6dbeee5..de42b9e 100644
--- a/include/mcld/MC/InputFactory.h
+++ b/include/mcld/MC/InputFactory.h
@@ -6,16 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MC_INPUTFACTORY_H
-#define MCLD_MC_INPUTFACTORY_H
-#include <mcld/Support/GCFactory.h>
-#include <mcld/MC/Input.h>
+#ifndef MCLD_MC_INPUTFACTORY_H_
+#define MCLD_MC_INPUTFACTORY_H_
+#include "mcld/MC/Input.h"
+#include "mcld/Support/GCFactory.h"
namespace mcld {
-class LinkerConfig;
class AttributeProxy;
class AttributeSet;
+class LinkerConfig;
/** \class InputFactory
* \brief InputFactory controls the production and destruction of
@@ -26,12 +26,11 @@ class AttributeSet;
*
* \see llvm::sys::Path
*/
-class InputFactory : public GCFactory<Input,0>
-{
-public:
+class InputFactory : public GCFactory<Input, 0> {
+ public:
typedef GCFactory<Input, 0> Alloc;
-public:
+ public:
InputFactory(size_t pNum, const LinkerConfig& pConfig);
~InputFactory();
@@ -42,17 +41,21 @@ public:
unsigned int pType = Input::Unknown,
off_t pFileOffset = 0);
+ Input* produce(llvm::StringRef pName,
+ const char* pPath,
+ unsigned int pType = Input::Unknown,
+ off_t pFileOffset = 0);
+
// ----- attributes ----- //
/// attr - the last touched attribute.
const AttributeProxy& attr() const { return *m_pLast; }
- AttributeProxy& attr() { return *m_pLast; }
+ AttributeProxy& attr() { return *m_pLast; }
-private:
+ private:
AttributeProxy* m_pLast;
AttributeSet* m_pAttrSet;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_MC_INPUTFACTORY_H_
diff --git a/include/mcld/MC/MCLDDirectory.h b/include/mcld/MC/MCLDDirectory.h
index de2abb5..674ffae 100644
--- a/include/mcld/MC/MCLDDirectory.h
+++ b/include/mcld/MC/MCLDDirectory.h
@@ -6,45 +6,43 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MC_MCLDDIRECTORY_H
-#define MCLD_MC_MCLDDIRECTORY_H
+#ifndef MCLD_MC_MCLDDIRECTORY_H_
+#define MCLD_MC_MCLDDIRECTORY_H_
#include "mcld/Support/Directory.h"
#include "mcld/Support/FileSystem.h"
+
#include <llvm/ADT/StringRef.h>
+
#include <string>
-namespace mcld
-{
+namespace mcld {
/** \class MCLDDirectory
* \brief MCLDDirectory is an directory entry for library search.
*
*/
-class MCLDDirectory : public sys::fs::Directory
-{
-public:
+class MCLDDirectory : public sys::fs::Directory {
+ public:
MCLDDirectory();
- MCLDDirectory(const char* pName);
- MCLDDirectory(const std::string& pName);
- MCLDDirectory(llvm::StringRef pName);
+ explicit MCLDDirectory(const char* pName);
+ explicit MCLDDirectory(const std::string& pName);
+ explicit MCLDDirectory(llvm::StringRef pName);
virtual ~MCLDDirectory();
-public:
- MCLDDirectory &assign(llvm::StringRef pName);
+ public:
+ MCLDDirectory& assign(llvm::StringRef pName);
bool isInSysroot() const;
/// setSysroot - if MCLDDirectory is in sysroot, modify the path.
void setSysroot(const sys::fs::Path& pPath);
- const std::string& name() const
- { return m_Name; }
+ const std::string& name() const { return m_Name; }
-private:
+ private:
std::string m_Name;
bool m_bInSysroot;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_MC_MCLDDIRECTORY_H_
diff --git a/include/mcld/MC/SearchDirs.h b/include/mcld/MC/SearchDirs.h
index d09450d..e219d32 100644
--- a/include/mcld/MC/SearchDirs.h
+++ b/include/mcld/MC/SearchDirs.h
@@ -6,21 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MC_SEARCHDIRS_H
-#define MCLD_MC_SEARCHDIRS_H
-#include <mcld/ADT/Uncopyable.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Support/Path.h>
+#ifndef MCLD_MC_SEARCHDIRS_H_
+#define MCLD_MC_SEARCHDIRS_H_
+
+#include "mcld/MC/Input.h"
+#include "mcld/Support/Path.h"
+#include "mcld/Support/Compiler.h"
#include <llvm/ADT/StringRef.h>
-#include <vector>
#include <string>
+#include <vector>
namespace mcld {
-class MCLDFile;
class MCLDDirectory;
+class MCLDFile;
/** \class SearchDirs
* \brief SearchDirs contains the list of paths that MCLinker will search for
@@ -31,35 +32,34 @@ class MCLDDirectory;
*
* @see MCLDDirectory.
*/
-class SearchDirs : private Uncopyable
-{
-public:
+class SearchDirs {
+ public:
typedef std::vector<MCLDDirectory*> DirList;
typedef DirList::iterator iterator;
typedef DirList::const_iterator const_iterator;
-public:
+ public:
SearchDirs();
- SearchDirs(const sys::fs::Path& pSysRoot);
+ explicit SearchDirs(const sys::fs::Path& pSysRoot);
~SearchDirs();
// find - give a namespec, return a real path of the shared object.
- sys::fs::Path*
- find(const std::string& pNamespec, mcld::Input::Type pPreferType);
+ sys::fs::Path* find(const std::string& pNamespec,
+ mcld::Input::Type pPreferType);
- const sys::fs::Path*
- find(const std::string& pNamespec, mcld::Input::Type pPreferType) const;
+ const sys::fs::Path* find(const std::string& pNamespec,
+ mcld::Input::Type pPreferType) const;
void setSysRoot(const sys::fs::Path& pSysRoot) { m_SysRoot = pSysRoot; }
const sys::fs::Path& sysroot() const { return m_SysRoot; }
// ----- iterators ----- //
const_iterator begin() const { return m_DirList.begin(); }
- iterator begin() { return m_DirList.begin(); }
- const_iterator end () const { return m_DirList.end(); }
- iterator end () { return m_DirList.end(); }
+ iterator begin() { return m_DirList.begin(); }
+ const_iterator end() const { return m_DirList.end(); }
+ iterator end() { return m_DirList.end(); }
// ----- modifiers ----- //
bool insert(const char* pDirectory);
@@ -68,12 +68,14 @@ public:
bool insert(const sys::fs::Path& pDirectory);
-private:
+ private:
DirList m_DirList;
sys::fs::Path m_SysRoot;
-};
-} // namespace of mcld
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SearchDirs);
+};
-#endif
+} // namespace mcld
+#endif // MCLD_MC_SEARCHDIRS_H_
diff --git a/include/mcld/MC/SymbolCategory.h b/include/mcld/MC/SymbolCategory.h
index 1ceb471..4a04ec5 100644
--- a/include/mcld/MC/SymbolCategory.h
+++ b/include/mcld/MC/SymbolCategory.h
@@ -6,29 +6,27 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MC_SYMBOLCATEGORY_H
-#define MCLD_MC_SYMBOLCATEGORY_H
+#ifndef MCLD_MC_SYMBOLCATEGORY_H_
+#define MCLD_MC_SYMBOLCATEGORY_H_
#include <cstddef>
#include <vector>
-namespace mcld
-{
+namespace mcld {
class LDSymbol;
class ResolveInfo;
/** \class SymbolCategory
* \brief SymbolCategory groups output LDSymbol into different categories.
*/
-class SymbolCategory
-{
-private:
+class SymbolCategory {
+ private:
typedef std::vector<LDSymbol*> OutputSymbols;
-public:
+ public:
typedef OutputSymbols::iterator iterator;
typedef OutputSymbols::const_iterator const_iterator;
-public:
+ public:
SymbolCategory();
~SymbolCategory();
@@ -45,17 +43,17 @@ public:
SymbolCategory& changeToDynamic(LDSymbol& pSymbol);
// ----- access ----- //
- LDSymbol& at(size_t pPosition)
- { return *m_OutputSymbols.at(pPosition); }
+ LDSymbol& at(size_t pPosition) { return *m_OutputSymbols.at(pPosition); }
- const LDSymbol& at(size_t pPosition) const
- { return *m_OutputSymbols.at(pPosition); }
+ const LDSymbol& at(size_t pPosition) const {
+ return *m_OutputSymbols.at(pPosition);
+ }
- LDSymbol& operator[](size_t pPosition)
- { return *m_OutputSymbols[pPosition]; }
+ LDSymbol& operator[](size_t pPosition) { return *m_OutputSymbols[pPosition]; }
- const LDSymbol& operator[](size_t pPosition) const
- { return *m_OutputSymbols[pPosition]; }
+ const LDSymbol& operator[](size_t pPosition) const {
+ return *m_OutputSymbols[pPosition];
+ }
// ----- observers ----- //
size_t numOfSymbols() const;
@@ -122,20 +120,12 @@ public:
const_iterator regularBegin() const;
const_iterator regularEnd() const;
-private:
- class Category
- {
- public:
- enum Type {
- File,
- Local,
- LocalDyn,
- Common,
- Dynamic,
- Regular
- };
-
- public:
+ private:
+ class Category {
+ public:
+ enum Type { File, Local, LocalDyn, Common, Dynamic, Regular };
+
+ public:
Type type;
size_t begin;
@@ -144,38 +134,29 @@ private:
Category* prev;
Category* next;
- public:
- Category(Type pType)
- : type(pType),
- begin(0),
- end(0),
- prev(NULL),
- next(NULL) {
- }
+ public:
+ explicit Category(Type pType)
+ : type(pType), begin(0), end(0), prev(NULL), next(NULL) {}
- size_t size() const
- { return (end - begin); }
+ size_t size() const { return (end - begin); }
- bool empty() const
- { return (begin == end); }
+ bool empty() const { return (begin == end); }
- bool isFirst() const
- { return (NULL == prev); }
+ bool isFirst() const { return (prev == NULL); }
- bool isLast() const
- { return (NULL == next); }
+ bool isLast() const { return (next == NULL); }
static Type categorize(const ResolveInfo& pInfo);
};
-private:
+ private:
SymbolCategory& add(LDSymbol& pSymbol, Category::Type pTarget);
SymbolCategory& arrange(LDSymbol& pSymbol,
Category::Type pSource,
Category::Type pTarget);
-private:
+ private:
OutputSymbols m_OutputSymbols;
Category* m_pFile;
@@ -186,7 +167,6 @@ private:
Category* m_pRegular;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_MC_SYMBOLCATEGORY_H_
diff --git a/include/mcld/MC/ZOption.h b/include/mcld/MC/ZOption.h
index b2e4c68..6468614 100644
--- a/include/mcld/MC/ZOption.h
+++ b/include/mcld/MC/ZOption.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MC_ZOPTION_H
-#define MCLD_MC_ZOPTION_H
+#ifndef MCLD_MC_ZOPTION_H_
+#define MCLD_MC_ZOPTION_H_
#include <llvm/Support/DataTypes.h>
@@ -16,9 +16,8 @@ namespace mcld {
/** \class ZOption
* \brief The -z options for GNU ld compatibility.
*/
-class ZOption
-{
-public:
+class ZOption {
+ public:
enum Kind {
CombReloc,
NoCombReloc,
@@ -44,9 +43,13 @@ public:
Unknown
};
-public:
+ public:
ZOption();
+ explicit ZOption(Kind pKind);
+
+ ZOption(Kind pKind, uint64_t pPageSize);
+
Kind kind() const { return m_Kind; }
void setKind(Kind pKind) { m_Kind = pKind; }
@@ -55,12 +58,11 @@ public:
void setPageSize(uint64_t pPageSize) { m_PageSize = pPageSize; }
-private:
+ private:
Kind m_Kind;
uint64_t m_PageSize;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_MC_ZOPTION_H_
diff --git a/include/mcld/Module.h b/include/mcld/Module.h
index b18ff9b..fdeb442 100644
--- a/include/mcld/Module.h
+++ b/include/mcld/Module.h
@@ -10,13 +10,13 @@
// Module contains the intermediate representation (LDIR) of MCLinker.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_MODULE_H
-#define MCLD_MODULE_H
+#ifndef MCLD_MODULE_H_
+#define MCLD_MODULE_H_
-#include <mcld/InputTree.h>
-#include <mcld/LD/NamePool.h>
-#include <mcld/LD/SectionSymbolSet.h>
-#include <mcld/MC/SymbolCategory.h>
+#include "mcld/InputTree.h"
+#include "mcld/LD/NamePool.h"
+#include "mcld/LD/SectionSymbolSet.h"
+#include "mcld/MC/SymbolCategory.h"
#include <vector>
#include <string>
@@ -31,9 +31,8 @@ class LDSymbol;
/** \class Module
* \brief Module provides the intermediate representation for linking.
*/
-class Module
-{
-public:
+class Module {
+ public:
typedef std::vector<Input*> ObjectList;
typedef ObjectList::iterator obj_iterator;
typedef ObjectList::const_iterator const_obj_iterator;
@@ -57,7 +56,7 @@ public:
typedef AliasList::iterator alias_iterator;
typedef AliasList::const_iterator const_alias_iterator;
-public:
+ public:
explicit Module(LinkerScript& pScript);
Module(const std::string& pName, LinkerScript& pScript);
@@ -70,86 +69,88 @@ public:
const LinkerScript& getScript() const { return m_Script; }
- LinkerScript& getScript() { return m_Script; }
+ LinkerScript& getScript() { return m_Script; }
// ----- link-in objects ----- //
const ObjectList& getObjectList() const { return m_ObjectList; }
- ObjectList& getObjectList() { return m_ObjectList; }
+ ObjectList& getObjectList() { return m_ObjectList; }
const_obj_iterator obj_begin() const { return m_ObjectList.begin(); }
- obj_iterator obj_begin() { return m_ObjectList.begin(); }
- const_obj_iterator obj_end () const { return m_ObjectList.end(); }
- obj_iterator obj_end () { return m_ObjectList.end(); }
+ obj_iterator obj_begin() { return m_ObjectList.begin(); }
+ const_obj_iterator obj_end() const { return m_ObjectList.end(); }
+ obj_iterator obj_end() { return m_ObjectList.end(); }
// ----- link-in libraries ----- //
const LibraryList& getLibraryList() const { return m_LibraryList; }
- LibraryList& getLibraryList() { return m_LibraryList; }
+ LibraryList& getLibraryList() { return m_LibraryList; }
const_lib_iterator lib_begin() const { return m_LibraryList.begin(); }
- lib_iterator lib_begin() { return m_LibraryList.begin(); }
- const_lib_iterator lib_end () const { return m_LibraryList.end(); }
- lib_iterator lib_end () { return m_LibraryList.end(); }
+ lib_iterator lib_begin() { return m_LibraryList.begin(); }
+ const_lib_iterator lib_end() const { return m_LibraryList.end(); }
+ lib_iterator lib_end() { return m_LibraryList.end(); }
// ----- link-in inputs ----- //
const InputTree& getInputTree() const { return m_MainTree; }
- InputTree& getInputTree() { return m_MainTree; }
+ InputTree& getInputTree() { return m_MainTree; }
const_input_iterator input_begin() const { return m_MainTree.begin(); }
- input_iterator input_begin() { return m_MainTree.begin(); }
- const_input_iterator input_end () const { return m_MainTree.end(); }
- input_iterator input_end () { return m_MainTree.end(); }
+ input_iterator input_begin() { return m_MainTree.begin(); }
+ const_input_iterator input_end() const { return m_MainTree.end(); }
+ input_iterator input_end() { return m_MainTree.end(); }
-/// @}
-/// @name Section Accessors
-/// @{
+ /// @}
+ /// @name Section Accessors
+ /// @{
// ----- sections ----- //
const SectionTable& getSectionTable() const { return m_SectionTable; }
- SectionTable& getSectionTable() { return m_SectionTable; }
+ SectionTable& getSectionTable() { return m_SectionTable; }
- iterator begin() { return m_SectionTable.begin(); }
- const_iterator begin() const { return m_SectionTable.begin(); }
- iterator end () { return m_SectionTable.end(); }
- const_iterator end () const { return m_SectionTable.end(); }
- LDSection* front() { return m_SectionTable.front(); }
+ iterator begin() { return m_SectionTable.begin(); }
+ const_iterator begin() const { return m_SectionTable.begin(); }
+ iterator end() { return m_SectionTable.end(); }
+ const_iterator end() const { return m_SectionTable.end(); }
+ LDSection* front() { return m_SectionTable.front(); }
const LDSection* front() const { return m_SectionTable.front(); }
- LDSection* back () { return m_SectionTable.back(); }
- const LDSection* back () const { return m_SectionTable.back(); }
- size_t size () const { return m_SectionTable.size(); }
- bool empty() const { return m_SectionTable.empty(); }
+ LDSection* back() { return m_SectionTable.back(); }
+ const LDSection* back() const { return m_SectionTable.back(); }
+ size_t size() const { return m_SectionTable.size(); }
+ bool empty() const { return m_SectionTable.empty(); }
- LDSection* getSection(const std::string& pName);
+ LDSection* getSection(const std::string& pName);
const LDSection* getSection(const std::string& pName) const;
-/// @}
-/// @name Symbol Accessors
-/// @{
+ /// @}
+ /// @name Symbol Accessors
+ /// @{
// ----- symbols ----- //
const SymbolTable& getSymbolTable() const { return m_SymbolTable; }
- SymbolTable& getSymbolTable() { return m_SymbolTable; }
+ SymbolTable& getSymbolTable() { return m_SymbolTable; }
- sym_iterator sym_begin() { return m_SymbolTable.begin(); }
- const_sym_iterator sym_begin() const { return m_SymbolTable.begin(); }
- sym_iterator sym_end () { return m_SymbolTable.end(); }
- const_sym_iterator sym_end () const { return m_SymbolTable.end(); }
- size_t sym_size () const { return m_SymbolTable.numOfSymbols(); }
+ sym_iterator sym_begin() { return m_SymbolTable.begin(); }
+ const_sym_iterator sym_begin() const { return m_SymbolTable.begin(); }
+ sym_iterator sym_end() { return m_SymbolTable.end(); }
+ const_sym_iterator sym_end() const { return m_SymbolTable.end(); }
+ size_t sym_size() const { return m_SymbolTable.numOfSymbols(); }
// ----- section symbols ----- //
- const LDSymbol* getSectionSymbol(const LDSection& pSection) const
- { return m_SectSymbolSet.get(pSection); }
+ const LDSymbol* getSectionSymbol(const LDSection& pSection) const {
+ return m_SectSymbolSet.get(pSection);
+ }
- LDSymbol* getSectionSymbol(const LDSection& pSection)
- { return m_SectSymbolSet.get(pSection); }
+ LDSymbol* getSectionSymbol(const LDSection& pSection) {
+ return m_SectSymbolSet.get(pSection);
+ }
- const SectionSymbolSet& getSectionSymbolSet() const
- { return m_SectSymbolSet; }
- SectionSymbolSet& getSectionSymbolSet()
- { return m_SectSymbolSet; }
+ const SectionSymbolSet& getSectionSymbolSet() const {
+ return m_SectSymbolSet;
+ }
+ SectionSymbolSet& getSectionSymbolSet() { return m_SectSymbolSet; }
// ----- names ----- //
const NamePool& getNamePool() const { return m_NamePool; }
- NamePool& getNamePool() { return m_NamePool; }
+ NamePool& getNamePool() { return m_NamePool; }
// ----- Aliases ----- //
// create an alias list for pSym, the aliases of pSym
@@ -160,7 +161,7 @@ public:
void addAlias(const ResolveInfo& pAlias);
AliasList* getAliasList(const ResolveInfo& pSym);
-private:
+ private:
std::string m_Name;
LinkerScript& m_Script;
ObjectList m_ObjectList;
@@ -173,7 +174,6 @@ private:
std::vector<AliasList*> m_AliasLists;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_MODULE_H_
diff --git a/include/mcld/Object/ObjectBuilder.h b/include/mcld/Object/ObjectBuilder.h
index 57b672e..a1d3319 100644
--- a/include/mcld/Object/ObjectBuilder.h
+++ b/include/mcld/Object/ObjectBuilder.h
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_OBJECT_OBJECTBUILDER_H
-#define MCLD_OBJECT_OBJECTBUILDER_H
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/LD/EhFrame.h>
+#ifndef MCLD_OBJECT_OBJECTBUILDER_H_
+#define MCLD_OBJECT_OBJECTBUILDER_H_
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDFileFormat.h"
#include <llvm/Support/DataTypes.h>
@@ -17,31 +17,32 @@
namespace mcld {
-class Module;
-class LDSection;
-class SectionData;
class Fragment;
class Input;
+class LDSection;
+class Module;
+class SectionData;
/** \class ObjectBuilder
* \brief ObjectBuilder recieve ObjectAction and build the mcld::Module.
*/
-class ObjectBuilder
-{
-public:
- ObjectBuilder(Module& pTheModule);
+class ObjectBuilder {
+ public:
+ explicit ObjectBuilder(Module& pTheModule);
-/// @}
-/// @name Section Methods
-/// @{
+ /// @}
+ /// @name Section Methods
+ /// @{
/// CreateSection - To create an output LDSection in mcld::Module.
/// Link scripts and command line options define some SECTIONS commands that
- /// specify where input sections are placed into output sections. This function
+ /// specify where input sections are placed into output sections. This
+ /// function
/// checks SECTIONS commands to change given name to the output section name.
/// This function creates a new LDSection and push the created LDSection into
/// @ref mcld::Module.
///
- /// To create an input LDSection in mcld::LDContext, use @ref LDSection::Create().
+ /// To create an input LDSection in mcld::LDContext, use @ref
+ /// LDSection::Create().
///
/// @see SectionMap
///
@@ -73,9 +74,9 @@ public:
static void UpdateSectionAlign(LDSection& pSection,
uint32_t pAlignConstraint);
-/// @}
-/// @name Fragment Methods
-/// @{
+ /// @}
+ /// @name Fragment Methods
+ /// @{
/// AppendFragment - To append pFrag to the given SectionData pSD.
/// In order to keep the alignment of pFrag, This function inserts an
/// AlignFragment before pFrag if pAlignConstraint is larger than 1.
@@ -87,14 +88,14 @@ public:
/// @param [in, out] pSD The section data being appended.
/// @param [in] pAlignConstraint The alignment constraint.
/// @return Total size of the inserted fragments.
- static uint64_t AppendFragment(Fragment& pFrag, SectionData& pSD,
+ static uint64_t AppendFragment(Fragment& pFrag,
+ SectionData& pSD,
uint32_t pAlignConstraint = 1);
-private:
+ private:
Module& m_Module;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_OBJECT_OBJECTBUILDER_H_
diff --git a/include/mcld/Object/ObjectLinker.h b/include/mcld/Object/ObjectLinker.h
index 9d54d2e..e3bd0f8 100644
--- a/include/mcld/Object/ObjectLinker.h
+++ b/include/mcld/Object/ObjectLinker.h
@@ -6,37 +6,35 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_OBJECT_OBJECTLINKER_H
-#define MCLD_OBJECT_OBJECTLINKER_H
+#ifndef MCLD_OBJECT_OBJECTLINKER_H_
+#define MCLD_OBJECT_OBJECTLINKER_H_
#include <llvm/Support/DataTypes.h>
namespace mcld {
-class Module;
-class LinkerConfig;
-class IRBuilder;
-class TargetLDBackend;
-class FileOutputBuffer;
-class ObjectReader;
-class DynObjReader;
class ArchiveReader;
-class GroupReader;
class BinaryReader;
-class ScriptReader;
-class ObjectWriter;
+class BinaryWriter;
+class DynObjReader;
class DynObjWriter;
class ExecWriter;
-class BinaryWriter;
+class FileOutputBuffer;
+class GroupReader;
+class IRBuilder;
+class LinkerConfig;
+class Module;
+class ObjectReader;
+class ObjectWriter;
class Relocation;
class ResolveInfo;
+class ScriptReader;
+class TargetLDBackend;
/** \class ObjectLinker
*/
-class ObjectLinker
-{
-public:
- ObjectLinker(const LinkerConfig& pConfig,
- TargetLDBackend& pLDBackend);
+class ObjectLinker {
+ public:
+ ObjectLinker(const LinkerConfig& pConfig, TargetLDBackend& pLDBackend);
~ObjectLinker();
@@ -126,28 +124,28 @@ public:
bool postProcessing(FileOutputBuffer& pOutput);
// ----- readers and writers ----- //
- const ObjectReader* getObjectReader () const { return m_pObjectReader; }
- ObjectReader* getObjectReader () { return m_pObjectReader; }
+ const ObjectReader* getObjectReader() const { return m_pObjectReader; }
+ ObjectReader* getObjectReader() { return m_pObjectReader; }
- const DynObjReader* getDynObjReader () const { return m_pDynObjReader; }
- DynObjReader* getDynObjReader () { return m_pDynObjReader; }
+ const DynObjReader* getDynObjReader() const { return m_pDynObjReader; }
+ DynObjReader* getDynObjReader() { return m_pDynObjReader; }
const ArchiveReader* getArchiveReader() const { return m_pArchiveReader; }
- ArchiveReader* getArchiveReader() { return m_pArchiveReader; }
+ ArchiveReader* getArchiveReader() { return m_pArchiveReader; }
- const GroupReader* getGroupReader () const { return m_pGroupReader; }
- GroupReader* getGroupReader () { return m_pGroupReader; }
+ const GroupReader* getGroupReader() const { return m_pGroupReader; }
+ GroupReader* getGroupReader() { return m_pGroupReader; }
- const BinaryReader* getBinaryReader () const { return m_pBinaryReader; }
- BinaryReader* getBinaryReader () { return m_pBinaryReader; }
+ const BinaryReader* getBinaryReader() const { return m_pBinaryReader; }
+ BinaryReader* getBinaryReader() { return m_pBinaryReader; }
- const ScriptReader* getScriptReader () const { return m_pScriptReader; }
- ScriptReader* getScriptReader () { return m_pScriptReader; }
+ const ScriptReader* getScriptReader() const { return m_pScriptReader; }
+ ScriptReader* getScriptReader() { return m_pScriptReader; }
- const ObjectWriter* getWriter () const { return m_pWriter; }
- ObjectWriter* getWriter () { return m_pWriter; }
+ const ObjectWriter* getWriter() const { return m_pWriter; }
+ ObjectWriter* getWriter() { return m_pWriter; }
-private:
+ private:
/// normalSyncRelocationResult - sync relocation result when producing shared
/// objects or executables
void normalSyncRelocationResult(FileOutputBuffer& pOutput);
@@ -164,22 +162,23 @@ private:
/// section symbol and not defined in the discarded section
void addSymbolToOutput(ResolveInfo& pInfo, Module& pModule);
-private:
+ private:
const LinkerConfig& m_Config;
Module* m_pModule;
IRBuilder* m_pBuilder;
- TargetLDBackend &m_LDBackend;
+ TargetLDBackend& m_LDBackend;
// ----- readers and writers ----- //
- ObjectReader* m_pObjectReader;
- DynObjReader* m_pDynObjReader;
+ ObjectReader* m_pObjectReader;
+ DynObjReader* m_pDynObjReader;
ArchiveReader* m_pArchiveReader;
- GroupReader* m_pGroupReader;
- BinaryReader* m_pBinaryReader;
- ScriptReader* m_pScriptReader;
- ObjectWriter* m_pWriter;
+ GroupReader* m_pGroupReader;
+ BinaryReader* m_pBinaryReader;
+ ScriptReader* m_pScriptReader;
+ ObjectWriter* m_pWriter;
};
-} // end namespace mcld
-#endif
+} // namespace mcld
+
+#endif // MCLD_OBJECT_OBJECTLINKER_H_
diff --git a/include/mcld/Object/SectionMap.h b/include/mcld/Object/SectionMap.h
index bbb4823..46ba7b9 100644
--- a/include/mcld/Object/SectionMap.h
+++ b/include/mcld/Object/SectionMap.h
@@ -6,15 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_OBJECT_SECTIONMAP_H
-#define MCLD_OBJECT_SECTIONMAP_H
+#ifndef MCLD_OBJECT_SECTIONMAP_H_
+#define MCLD_OBJECT_SECTIONMAP_H_
+
+#include "mcld/Script/Assignment.h"
+#include "mcld/Script/InputSectDesc.h"
+#include "mcld/Script/OutputSectDesc.h"
-#include <mcld/Script/OutputSectDesc.h>
-#include <mcld/Script/InputSectDesc.h>
-#include <mcld/Script/Assignment.h>
#include <llvm/Support/DataTypes.h>
-#include <vector>
+
#include <string>
+#include <vector>
namespace mcld {
@@ -24,34 +26,33 @@ class LDSection;
/** \class SectionMap
* \brief descirbe how to map input sections into output sections
*/
-class SectionMap
-{
-public:
+class SectionMap {
+ public:
class Input {
- public:
+ public:
typedef std::vector<std::pair<Fragment*, Assignment> > DotAssignments;
typedef DotAssignments::const_iterator const_dot_iterator;
typedef DotAssignments::iterator dot_iterator;
Input(const std::string& pName, InputSectDesc::KeepPolicy pPolicy);
- Input(const InputSectDesc& pInputDesc);
+ explicit Input(const InputSectDesc& pInputDesc);
InputSectDesc::KeepPolicy policy() const { return m_Policy; }
const InputSectDesc::Spec& spec() const { return m_Spec; }
const LDSection* getSection() const { return m_pSection; }
- LDSection* getSection() { return m_pSection; }
+ LDSection* getSection() { return m_pSection; }
const_dot_iterator dot_begin() const { return m_DotAssignments.begin(); }
- dot_iterator dot_begin() { return m_DotAssignments.begin(); }
- const_dot_iterator dot_end () const { return m_DotAssignments.end(); }
- dot_iterator dot_end () { return m_DotAssignments.end(); }
+ dot_iterator dot_begin() { return m_DotAssignments.begin(); }
+ const_dot_iterator dot_end() const { return m_DotAssignments.end(); }
+ dot_iterator dot_end() { return m_DotAssignments.end(); }
const DotAssignments& dotAssignments() const { return m_DotAssignments; }
- DotAssignments& dotAssignments() { return m_DotAssignments; }
+ DotAssignments& dotAssignments() { return m_DotAssignments; }
- private:
+ private:
InputSectDesc::KeepPolicy m_Policy;
InputSectDesc::Spec m_Spec;
LDSection* m_pSection;
@@ -59,7 +60,7 @@ public:
};
class Output {
- public:
+ public:
typedef std::vector<Input*> InputList;
typedef InputList::const_iterator const_iterator;
typedef InputList::iterator iterator;
@@ -70,16 +71,16 @@ public:
typedef DotAssignments::const_iterator const_dot_iterator;
typedef DotAssignments::iterator dot_iterator;
- Output(const std::string& pName);
- Output(const OutputSectDesc& pOutputDesc);
+ explicit Output(const std::string& pName);
+ explicit Output(const OutputSectDesc& pOutputDesc);
const std::string& name() const { return m_Name; }
const OutputSectDesc::Prolog& prolog() const { return m_Prolog; }
- OutputSectDesc::Prolog& prolog() { return m_Prolog; }
+ OutputSectDesc::Prolog& prolog() { return m_Prolog; }
const OutputSectDesc::Epilog& epilog() const { return m_Epilog; }
- OutputSectDesc::Epilog& epilog() { return m_Epilog; }
+ OutputSectDesc::Epilog& epilog() { return m_Epilog; }
size_t order() const { return m_Order; }
@@ -88,19 +89,19 @@ public:
bool hasContent() const;
const LDSection* getSection() const { return m_pSection; }
- LDSection* getSection() { return m_pSection; }
+ LDSection* getSection() { return m_pSection; }
void setSection(LDSection* pSection) { m_pSection = pSection; }
const_iterator begin() const { return m_InputList.begin(); }
- iterator begin() { return m_InputList.begin(); }
- const_iterator end () const { return m_InputList.end(); }
- iterator end () { return m_InputList.end(); }
+ iterator begin() { return m_InputList.begin(); }
+ const_iterator end() const { return m_InputList.end(); }
+ iterator end() { return m_InputList.end(); }
const_reference front() const { return m_InputList.front(); }
- reference front() { return m_InputList.front(); }
- const_reference back () const { return m_InputList.back(); }
- reference back () { return m_InputList.back(); }
+ reference front() { return m_InputList.front(); }
+ const_reference back() const { return m_InputList.back(); }
+ reference back() { return m_InputList.back(); }
size_t size() const { return m_InputList.size(); }
@@ -111,20 +112,20 @@ public:
void append(Input* pInput) { m_InputList.push_back(pInput); }
const_dot_iterator dot_begin() const { return m_DotAssignments.begin(); }
- dot_iterator dot_begin() { return m_DotAssignments.begin(); }
- const_dot_iterator dot_end () const { return m_DotAssignments.end(); }
- dot_iterator dot_end () { return m_DotAssignments.end(); }
+ dot_iterator dot_begin() { return m_DotAssignments.begin(); }
+ const_dot_iterator dot_end() const { return m_DotAssignments.end(); }
+ dot_iterator dot_end() { return m_DotAssignments.end(); }
const_dot_iterator find_first_explicit_dot() const;
- dot_iterator find_first_explicit_dot();
+ dot_iterator find_first_explicit_dot();
const_dot_iterator find_last_explicit_dot() const;
- dot_iterator find_last_explicit_dot();
+ dot_iterator find_last_explicit_dot();
const DotAssignments& dotAssignments() const { return m_DotAssignments; }
- DotAssignments& dotAssignments() { return m_DotAssignments; }
+ DotAssignments& dotAssignments() { return m_DotAssignments; }
- private:
+ private:
std::string m_Name;
OutputSectDesc::Prolog m_Prolog;
OutputSectDesc::Epilog m_Epilog;
@@ -135,10 +136,10 @@ public:
DotAssignments m_DotAssignments;
};
- struct SHOCompare
- {
- bool operator()(const Output* LHS, const Output* RHS) const
- { return LHS->order() < RHS->order(); }
+ struct SHOCompare {
+ bool operator()(const Output* LHS, const Output* RHS) const {
+ return LHS->order() < RHS->order();
+ }
};
typedef std::pair<const Output*, const Input*> const_mapping;
@@ -153,59 +154,57 @@ public:
typedef OutputDescList::const_reverse_iterator const_reverse_iterator;
typedef OutputDescList::reverse_iterator reverse_iterator;
-public:
+ public:
~SectionMap();
const_mapping find(const std::string& pInputFile,
const std::string& pInputSection) const;
- mapping find(const std::string& pInputFile,
- const std::string& pInputSection);
+ mapping find(const std::string& pInputFile, const std::string& pInputSection);
const_iterator find(const std::string& pOutputSection) const;
- iterator find(const std::string& pOutputSection);
+ iterator find(const std::string& pOutputSection);
- std::pair<mapping, bool>
- insert(const std::string& pInputSection,
- const std::string& pOutputSection,
- InputSectDesc::KeepPolicy pPolicy = InputSectDesc::NoKeep);
- std::pair<mapping, bool>
- insert(const InputSectDesc& pInputDesc, const OutputSectDesc& pOutputDesc);
+ std::pair<mapping, bool> insert(
+ const std::string& pInputSection,
+ const std::string& pOutputSection,
+ InputSectDesc::KeepPolicy pPolicy = InputSectDesc::NoKeep);
+ std::pair<mapping, bool> insert(const InputSectDesc& pInputDesc,
+ const OutputSectDesc& pOutputDesc);
- bool empty() const { return m_OutputDescList.empty(); }
- size_t size () const { return m_OutputDescList.size(); }
+ bool empty() const { return m_OutputDescList.empty(); }
+ size_t size() const { return m_OutputDescList.size(); }
const_iterator begin() const { return m_OutputDescList.begin(); }
- iterator begin() { return m_OutputDescList.begin(); }
- const_iterator end () const { return m_OutputDescList.end(); }
- iterator end () { return m_OutputDescList.end(); }
+ iterator begin() { return m_OutputDescList.begin(); }
+ const_iterator end() const { return m_OutputDescList.end(); }
+ iterator end() { return m_OutputDescList.end(); }
const_reference front() const { return m_OutputDescList.front(); }
- reference front() { return m_OutputDescList.front(); }
- const_reference back () const { return m_OutputDescList.back(); }
- reference back () { return m_OutputDescList.back(); }
+ reference front() { return m_OutputDescList.front(); }
+ const_reference back() const { return m_OutputDescList.back(); }
+ reference back() { return m_OutputDescList.back(); }
const_reverse_iterator rbegin() const { return m_OutputDescList.rbegin(); }
- reverse_iterator rbegin() { return m_OutputDescList.rbegin(); }
- const_reverse_iterator rend () const { return m_OutputDescList.rend(); }
- reverse_iterator rend () { return m_OutputDescList.rend(); }
+ reverse_iterator rbegin() { return m_OutputDescList.rbegin(); }
+ const_reverse_iterator rend() const { return m_OutputDescList.rend(); }
+ reverse_iterator rend() { return m_OutputDescList.rend(); }
iterator insert(iterator pPosition, LDSection* pSection);
// fixupDotSymbols - ensure the dot assignments are valid
void fixupDotSymbols();
-private:
+ private:
bool matched(const Input& pInput,
const std::string& pInputFile,
const std::string& pInputSection) const;
bool matched(const WildcardPattern& pPattern, const std::string& pName) const;
-private:
+ private:
OutputDescList m_OutputDescList;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_OBJECT_SECTIONMAP_H_
diff --git a/include/mcld/Script/AssertCmd.h b/include/mcld/Script/AssertCmd.h
index 14ead49..9201891 100644
--- a/include/mcld/Script/AssertCmd.h
+++ b/include/mcld/Script/AssertCmd.h
@@ -6,14 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_ASSERTCMD_H
-#define MCLD_SCRIPT_ASSERTCMD_H
+#ifndef MCLD_SCRIPT_ASSERTCMD_H_
+#define MCLD_SCRIPT_ASSERTCMD_H_
+
+#include "mcld/Script/ScriptCommand.h"
-#include <mcld/Script/ScriptCommand.h>
#include <string>
-namespace mcld
-{
+namespace mcld {
class RpnExpr;
class Module;
@@ -22,9 +22,8 @@ class Module;
* \brief This class defines the interfaces to assert command.
*/
-class AssertCmd : public ScriptCommand
-{
-public:
+class AssertCmd : public ScriptCommand {
+ public:
AssertCmd(RpnExpr& pRpnExpr, const std::string& pMessage);
~AssertCmd();
@@ -32,24 +31,23 @@ public:
AssertCmd& operator=(const AssertCmd& pAssertCmd);
const RpnExpr& getRpnExpr() const { return m_RpnExpr; }
- RpnExpr& getRpnExpr() { return m_RpnExpr; }
+ RpnExpr& getRpnExpr() { return m_RpnExpr; }
const std::string& message() const { return m_Message; }
void dump() const;
- static bool classof(const ScriptCommand* pCmd)
- {
+ static bool classof(const ScriptCommand* pCmd) {
return pCmd->getKind() == ScriptCommand::ASSERT;
}
void activate(Module& pModule);
-private:
+ private:
RpnExpr& m_RpnExpr;
std::string m_Message;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SCRIPT_ASSERTCMD_H_
diff --git a/include/mcld/Script/Assignment.h b/include/mcld/Script/Assignment.h
index c81e871..ced4d19 100644
--- a/include/mcld/Script/Assignment.h
+++ b/include/mcld/Script/Assignment.h
@@ -6,44 +6,34 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_ASSIGNMENT_H
-#define MCLD_SCRIPT_ASSIGNMENT_H
+#ifndef MCLD_SCRIPT_ASSIGNMENT_H_
+#define MCLD_SCRIPT_ASSIGNMENT_H_
-#include <mcld/Script/ScriptCommand.h>
+#include "mcld/Script/ScriptCommand.h"
-namespace mcld
-{
+namespace mcld {
class Module;
+class RpnEvaluator;
class RpnExpr;
class SymOperand;
-class RpnEvaluator;
/** \class Assignment
* \brief This class defines the interfaces to assignment command.
*/
-class Assignment : public ScriptCommand
-{
-public:
+class Assignment : public ScriptCommand {
+ public:
enum Level {
- OUTSIDE_SECTIONS, // outside SECTIONS command
- OUTPUT_SECTION, // related to an output section
- INPUT_SECTION // related to an input section
+ OUTSIDE_SECTIONS, // outside SECTIONS command
+ OUTPUT_SECTION, // related to an output section
+ INPUT_SECTION // related to an input section
};
- enum Type {
- DEFAULT,
- HIDDEN,
- PROVIDE,
- PROVIDE_HIDDEN
- };
+ enum Type { DEFAULT, HIDDEN, PROVIDE, PROVIDE_HIDDEN };
-public:
- Assignment(Level pLevel,
- Type pType,
- SymOperand& pSymbol,
- RpnExpr& pRpnExpr);
+ public:
+ Assignment(Level pLevel, Type pType, SymOperand& pSymbol, RpnExpr& pRpnExpr);
~Assignment();
@@ -54,15 +44,14 @@ public:
Type type() const { return m_Type; }
const SymOperand& symbol() const { return m_Symbol; }
- SymOperand& symbol() { return m_Symbol; }
+ SymOperand& symbol() { return m_Symbol; }
const RpnExpr& getRpnExpr() const { return m_RpnExpr; }
- RpnExpr& getRpnExpr() { return m_RpnExpr; }
+ RpnExpr& getRpnExpr() { return m_RpnExpr; }
void dump() const;
- static bool classof(const ScriptCommand* pCmd)
- {
+ static bool classof(const ScriptCommand* pCmd) {
return pCmd->getKind() == ScriptCommand::ASSIGNMENT;
}
@@ -71,14 +60,13 @@ public:
/// assign - evaluate the rhs and assign the result to lhs.
bool assign(RpnEvaluator& pEvaluator);
-private:
+ private:
Level m_Level;
Type m_Type;
SymOperand& m_Symbol;
RpnExpr& m_RpnExpr;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_ASSIGNMENT_H_
diff --git a/include/mcld/Script/BinaryOp.h b/include/mcld/Script/BinaryOp.h
index c96521e..f684ffa 100644
--- a/include/mcld/Script/BinaryOp.h
+++ b/include/mcld/Script/BinaryOp.h
@@ -6,14 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_BINARYOP_H
-#define MCLD_SCRIPT_BINARYOP_H
+#ifndef MCLD_SCRIPT_BINARYOP_H_
+#define MCLD_SCRIPT_BINARYOP_H_
+
+#include "mcld/Script/Operator.h"
-#include <mcld/Script/Operator.h>
#include <cstddef>
-namespace mcld
-{
+namespace mcld {
class Operand;
class IntOperand;
@@ -24,109 +24,97 @@ class TargetLDBackend;
* \brief This class defines the interfaces to an binary operator token.
*/
-template<Operator::Type TYPE>
-class BinaryOp : public Operator
-{
-private:
+template <Operator::Type TYPE>
+class BinaryOp : public Operator {
+ private:
friend class Operator;
- BinaryOp()
- : Operator(Operator::BINARY, TYPE), m_Size(0)
- {
+ BinaryOp() : Operator(Operator::BINARY, TYPE), m_Size(0) {
m_pOperand[0] = m_pOperand[1] = NULL;
}
-public:
- ~BinaryOp()
- {}
+ public:
+ ~BinaryOp() {}
IntOperand* eval(const Module& pModule, const TargetLDBackend& pBackend);
- void appendOperand(Operand* pOperand)
- {
+ void appendOperand(Operand* pOperand) {
m_pOperand[m_Size++] = pOperand;
if (m_Size == 2)
m_Size = 0;
}
-private:
+ private:
size_t m_Size;
Operand* m_pOperand[2];
};
-template<>
+template <>
IntOperand* BinaryOp<Operator::MUL>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* BinaryOp<Operator::DIV>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* BinaryOp<Operator::MOD>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* BinaryOp<Operator::ADD>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* BinaryOp<Operator::SUB>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* BinaryOp<Operator::LSHIFT>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* BinaryOp<Operator::RSHIFT>::eval(const Module&,
const TargetLDBackend&);
-template<>
-IntOperand* BinaryOp<Operator::LT>::eval(const Module&,
- const TargetLDBackend&);
-template<>
-IntOperand* BinaryOp<Operator::LE>::eval(const Module&,
- const TargetLDBackend&);
-template<>
-IntOperand* BinaryOp<Operator::GT>::eval(const Module&,
- const TargetLDBackend&);
-template<>
-IntOperand* BinaryOp<Operator::GE>::eval(const Module&,
- const TargetLDBackend&);
-template<>
-IntOperand* BinaryOp<Operator::EQ>::eval(const Module&,
- const TargetLDBackend&);
-template<>
-IntOperand* BinaryOp<Operator::NE>::eval(const Module&,
- const TargetLDBackend&);
-template<>
+template <>
+IntOperand* BinaryOp<Operator::LT>::eval(const Module&, const TargetLDBackend&);
+template <>
+IntOperand* BinaryOp<Operator::LE>::eval(const Module&, const TargetLDBackend&);
+template <>
+IntOperand* BinaryOp<Operator::GT>::eval(const Module&, const TargetLDBackend&);
+template <>
+IntOperand* BinaryOp<Operator::GE>::eval(const Module&, const TargetLDBackend&);
+template <>
+IntOperand* BinaryOp<Operator::EQ>::eval(const Module&, const TargetLDBackend&);
+template <>
+IntOperand* BinaryOp<Operator::NE>::eval(const Module&, const TargetLDBackend&);
+template <>
IntOperand* BinaryOp<Operator::BITWISE_AND>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* BinaryOp<Operator::BITWISE_XOR>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* BinaryOp<Operator::BITWISE_OR>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* BinaryOp<Operator::LOGICAL_AND>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* BinaryOp<Operator::LOGICAL_OR>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* BinaryOp<Operator::ALIGN>::eval(const Module&,
const TargetLDBackend&);
-template<>
-IntOperand*
-BinaryOp<Operator::DATA_SEGMENT_RELRO_END>::eval(const Module&,
- const TargetLDBackend&);
-template<>
+template <>
+IntOperand* BinaryOp<Operator::DATA_SEGMENT_RELRO_END>::eval(
+ const Module&,
+ const TargetLDBackend&);
+template <>
IntOperand* BinaryOp<Operator::MAX>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* BinaryOp<Operator::MIN>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* BinaryOp<Operator::SEGMENT_START>::eval(const Module&,
const TargetLDBackend&);
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_BINARYOP_H_
diff --git a/include/mcld/Script/EntryCmd.h b/include/mcld/Script/EntryCmd.h
index 509cc9a..90a4d8a 100644
--- a/include/mcld/Script/EntryCmd.h
+++ b/include/mcld/Script/EntryCmd.h
@@ -6,14 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_ENTRYCMD_H
-#define MCLD_SCRIPT_ENTRYCMD_H
+#ifndef MCLD_SCRIPT_ENTRYCMD_H_
+#define MCLD_SCRIPT_ENTRYCMD_H_
+
+#include "mcld/Script/ScriptCommand.h"
-#include <mcld/Script/ScriptCommand.h>
#include <string>
-namespace mcld
-{
+namespace mcld {
class Module;
@@ -21,26 +21,23 @@ class Module;
* \brief This class defines the interfaces to Entry command.
*/
-class EntryCmd : public ScriptCommand
-{
-public:
- EntryCmd(const std::string& pEntry);
+class EntryCmd : public ScriptCommand {
+ public:
+ explicit EntryCmd(const std::string& pEntry);
~EntryCmd();
void dump() const;
- static bool classof(const ScriptCommand* pCmd)
- {
+ static bool classof(const ScriptCommand* pCmd) {
return pCmd->getKind() == ScriptCommand::ENTRY;
}
void activate(Module& pModule);
-private:
+ private:
std::string m_Entry;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_ENTRYCMD_H_
diff --git a/include/mcld/Script/ExprToken.h b/include/mcld/Script/ExprToken.h
index a182b3c..2e680b2 100644
--- a/include/mcld/Script/ExprToken.h
+++ b/include/mcld/Script/ExprToken.h
@@ -6,42 +6,33 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_EXPRTOKEN_H
-#define MCLD_SCRIPT_EXPRTOKEN_H
+#ifndef MCLD_SCRIPT_EXPRTOKEN_H_
+#define MCLD_SCRIPT_EXPRTOKEN_H_
-namespace mcld
-{
+namespace mcld {
/** \class ExprToken
* \brief This class defines the interfaces to an expression token.
*/
-class ExprToken
-{
-public:
- enum Kind {
- OPERATOR,
- OPERAND
- };
+class ExprToken {
+ public:
+ enum Kind { OPERATOR, OPERAND };
-protected:
- ExprToken(Kind pKind)
- : m_Kind(pKind)
- {}
+ protected:
+ explicit ExprToken(Kind pKind) : m_Kind(pKind) {}
-public:
- virtual ~ExprToken()
- {}
+ public:
+ virtual ~ExprToken() {}
virtual void dump() const = 0;
Kind kind() const { return m_Kind; }
-private:
+ private:
Kind m_Kind;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_EXPRTOKEN_H_
diff --git a/include/mcld/Script/FileToken.h b/include/mcld/Script/FileToken.h
index 4beaacb..e10e00e 100644
--- a/include/mcld/Script/FileToken.h
+++ b/include/mcld/Script/FileToken.h
@@ -6,33 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_FILETOKEN_H
-#define MCLD_SCRIPT_FILETOKEN_H
+#ifndef MCLD_SCRIPT_FILETOKEN_H_
+#define MCLD_SCRIPT_FILETOKEN_H_
-#include <mcld/Script/InputToken.h>
-#include <mcld/Support/Allocators.h>
-#include <mcld/Config/Config.h>
+#include "mcld/Config/Config.h"
+#include "mcld/Script/InputToken.h"
+#include "mcld/Support/Allocators.h"
-namespace mcld
-{
+namespace mcld {
/** \class FileToken
* \brief This class defines the interfaces to a filename in INPUT/GROUP
* command.
*/
-class FileToken : public InputToken
-{
-private:
+class FileToken : public InputToken {
+ private:
friend class Chunk<FileToken, MCLD_SYMBOLS_PER_INPUT>;
FileToken();
FileToken(const std::string& pName, bool pAsNeeded);
-public:
+ public:
~FileToken();
- static bool classof(const InputToken* pToken)
- {
+ static bool classof(const InputToken* pToken) {
return pToken->type() == InputToken::File;
}
@@ -42,6 +39,6 @@ public:
static void clear();
};
-} // namepsace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SCRIPT_FILETOKEN_H_
diff --git a/include/mcld/Script/FlexLexer.h b/include/mcld/Script/FlexLexer.h
index f09ab20..3514ee1 100644
--- a/include/mcld/Script/FlexLexer.h
+++ b/include/mcld/Script/FlexLexer.h
@@ -58,158 +58,151 @@
#define __FLEX_LEXER_H
#include <iostream>
-# ifndef FLEX_STD
-# define FLEX_STD std::
-# endif
+#ifndef FLEX_STD
+#define FLEX_STD std::
+#endif
extern "C++" {
-
struct yy_buffer_state;
typedef int yy_state_type;
class FlexLexer {
-public:
- virtual ~FlexLexer() { }
-
- const char* YYText() const { return yytext; }
- int YYLeng() const { return yyleng; }
-
- virtual void
- yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
- virtual struct yy_buffer_state*
- yy_create_buffer( FLEX_STD istream* s, int size ) = 0;
- virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
- virtual void yyrestart( FLEX_STD istream* s ) = 0;
-
- virtual int yylex() = 0;
-
- // Call yylex with new input/output sources.
- int yylex( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 )
- {
- switch_streams( new_in, new_out );
- return yylex();
- }
-
- // Switch to new input/output streams. A nil stream pointer
- // indicates "keep the current one".
- virtual void switch_streams( FLEX_STD istream* new_in = 0,
- FLEX_STD ostream* new_out = 0 ) = 0;
-
- int lineno() const { return yylineno; }
-
- int debug() const { return yy_flex_debug; }
- void set_debug( int flag ) { yy_flex_debug = flag; }
-
-protected:
- char* yytext;
- int yyleng;
- int yylineno; // only maintained if you use %option yylineno
- int yy_flex_debug; // only has effect with -d or "%option debug"
-};
+ public:
+ virtual ~FlexLexer() {}
+
+ const char* YYText() const { return yytext; }
+ int YYLeng() const { return yyleng; }
+
+ virtual void yy_switch_to_buffer(struct yy_buffer_state* new_buffer) = 0;
+ virtual struct yy_buffer_state* yy_create_buffer(FLEX_STD istream* s,
+ int size) = 0;
+ virtual void yy_delete_buffer(struct yy_buffer_state* b) = 0;
+ virtual void yyrestart(FLEX_STD istream* s) = 0;
+
+ virtual int yylex() = 0;
+
+ // Call yylex with new input/output sources.
+ int yylex(FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0) {
+ switch_streams(new_in, new_out);
+ return yylex();
+ }
+
+ // Switch to new input/output streams. A nil stream pointer
+ // indicates "keep the current one".
+ virtual void switch_streams(FLEX_STD istream* new_in = 0,
+ FLEX_STD ostream* new_out = 0) = 0;
+ int lineno() const { return yylineno; }
+
+ int debug() const { return yy_flex_debug; }
+ void set_debug(int flag) { yy_flex_debug = flag; }
+
+ protected:
+ char* yytext;
+ int yyleng;
+ int yylineno; // only maintained if you use %option yylineno
+ int yy_flex_debug; // only has effect with -d or "%option debug"
+};
}
-#endif // FLEXLEXER_H
+#endif // FLEXLEXER_H
-#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
+#if defined(yyFlexLexer) || !defined(yyFlexLexerOnce)
// Either this is the first time through (yyFlexLexerOnce not defined),
// or this is a repeated include to define a different flavor of
// yyFlexLexer, as discussed in the flex manual.
#define yyFlexLexerOnce
extern "C++" {
-
class yyFlexLexer : public FlexLexer {
-public:
- // arg_yyin and arg_yyout default to the cin and cout, but we
- // only make that assignment when initializing in yylex().
- yyFlexLexer( FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0 );
+ public:
+ // arg_yyin and arg_yyout default to the cin and cout, but we
+ // only make that assignment when initializing in yylex().
+ yyFlexLexer(FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0);
- virtual ~yyFlexLexer();
+ virtual ~yyFlexLexer();
- void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
- struct yy_buffer_state* yy_create_buffer( FLEX_STD istream* s, int size );
- void yy_delete_buffer( struct yy_buffer_state* b );
- void yyrestart( FLEX_STD istream* s );
+ void yy_switch_to_buffer(struct yy_buffer_state* new_buffer);
+ struct yy_buffer_state* yy_create_buffer(FLEX_STD istream* s, int size);
+ void yy_delete_buffer(struct yy_buffer_state* b);
+ void yyrestart(FLEX_STD istream* s);
- void yypush_buffer_state( struct yy_buffer_state* new_buffer );
- void yypop_buffer_state();
+ void yypush_buffer_state(struct yy_buffer_state* new_buffer);
+ void yypop_buffer_state();
- virtual int yylex();
- virtual void switch_streams( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 );
- virtual int yywrap();
+ virtual int yylex();
+ virtual void switch_streams(FLEX_STD istream* new_in,
+ FLEX_STD ostream* new_out = 0);
+ virtual int yywrap();
-protected:
- virtual int LexerInput( char* buf, int max_size );
- virtual void LexerOutput( const char* buf, int size );
- virtual void LexerError( const char* msg );
+ protected:
+ virtual int LexerInput(char* buf, int max_size);
+ virtual void LexerOutput(const char* buf, int size);
+ virtual void LexerError(const char* msg);
- void yyunput( int c, char* buf_ptr );
- int yyinput();
+ void yyunput(int c, char* buf_ptr);
+ int yyinput();
- void yy_load_buffer_state();
- void yy_init_buffer( struct yy_buffer_state* b, FLEX_STD istream* s );
- void yy_flush_buffer( struct yy_buffer_state* b );
+ void yy_load_buffer_state();
+ void yy_init_buffer(struct yy_buffer_state* b, FLEX_STD istream* s);
+ void yy_flush_buffer(struct yy_buffer_state* b);
- int yy_start_stack_ptr;
- int yy_start_stack_depth;
- int* yy_start_stack;
+ int yy_start_stack_ptr;
+ int yy_start_stack_depth;
+ int* yy_start_stack;
- void yy_push_state( int new_state );
- void yy_pop_state();
- int yy_top_state();
+ void yy_push_state(int new_state);
+ void yy_pop_state();
+ int yy_top_state();
- yy_state_type yy_get_previous_state();
- yy_state_type yy_try_NUL_trans( yy_state_type current_state );
- int yy_get_next_buffer();
+ yy_state_type yy_get_previous_state();
+ yy_state_type yy_try_NUL_trans(yy_state_type current_state);
+ int yy_get_next_buffer();
- FLEX_STD istream* yyin; // input source for default LexerInput
- FLEX_STD ostream* yyout; // output sink for default LexerOutput
+ FLEX_STD istream* yyin; // input source for default LexerInput
+ FLEX_STD ostream* yyout; // output sink for default LexerOutput
- // yy_hold_char holds the character lost when yytext is formed.
- char yy_hold_char;
+ // yy_hold_char holds the character lost when yytext is formed.
+ char yy_hold_char;
- // Number of characters read into yy_ch_buf.
- int yy_n_chars;
+ // Number of characters read into yy_ch_buf.
+ int yy_n_chars;
- // Points to current character in buffer.
- char* yy_c_buf_p;
+ // Points to current character in buffer.
+ char* yy_c_buf_p;
- int yy_init; // whether we need to initialize
- int yy_start; // start state number
+ int yy_init; // whether we need to initialize
+ int yy_start; // start state number
- // Flag which is used to allow yywrap()'s to do buffer switches
- // instead of setting up a fresh yyin. A bit of a hack ...
- int yy_did_buffer_switch_on_eof;
+ // Flag which is used to allow yywrap()'s to do buffer switches
+ // instead of setting up a fresh yyin. A bit of a hack ...
+ int yy_did_buffer_switch_on_eof;
+ size_t yy_buffer_stack_top; /**< index of top of stack. */
+ size_t yy_buffer_stack_max; /**< capacity of stack. */
+ struct yy_buffer_state** yy_buffer_stack; /**< Stack as an array. */
+ void yyensure_buffer_stack(void);
- size_t yy_buffer_stack_top; /**< index of top of stack. */
- size_t yy_buffer_stack_max; /**< capacity of stack. */
- struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */
- void yyensure_buffer_stack(void);
+ // The following are not always needed, but may be depending
+ // on use of certain flex features (like REJECT or yymore()).
- // The following are not always needed, but may be depending
- // on use of certain flex features (like REJECT or yymore()).
+ yy_state_type yy_last_accepting_state;
+ char* yy_last_accepting_cpos;
- yy_state_type yy_last_accepting_state;
- char* yy_last_accepting_cpos;
+ yy_state_type* yy_state_buf;
+ yy_state_type* yy_state_ptr;
- yy_state_type* yy_state_buf;
- yy_state_type* yy_state_ptr;
+ char* yy_full_match;
+ int* yy_full_state;
+ int yy_full_lp;
- char* yy_full_match;
- int* yy_full_state;
- int yy_full_lp;
+ int yy_lp;
+ int yy_looking_for_trail_begin;
- int yy_lp;
- int yy_looking_for_trail_begin;
-
- int yy_more_flag;
- int yy_more_len;
- int yy_more_offset;
- int yy_prev_more_offset;
+ int yy_more_flag;
+ int yy_more_len;
+ int yy_more_offset;
+ int yy_prev_more_offset;
};
-
}
-#endif // yyFlexLexer || ! yyFlexLexerOnce
-
+#endif // yyFlexLexer || ! yyFlexLexerOnce
diff --git a/include/mcld/Script/GroupCmd.h b/include/mcld/Script/GroupCmd.h
index 5a016db..8f3f171 100644
--- a/include/mcld/Script/GroupCmd.h
+++ b/include/mcld/Script/GroupCmd.h
@@ -6,27 +6,25 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_GROUPCMD_H
-#define MCLD_SCRIPT_GROUPCMD_H
+#ifndef MCLD_SCRIPT_GROUPCMD_H_
+#define MCLD_SCRIPT_GROUPCMD_H_
-#include <mcld/Script/ScriptCommand.h>
+#include "mcld/Script/ScriptCommand.h"
-namespace mcld
-{
+namespace mcld {
-class StringList;
class InputTree;
class InputBuilder;
class GroupReader;
class LinkerConfig;
+class StringList;
/** \class GroupCmd
* \brief This class defines the interfaces to Group command.
*/
-class GroupCmd : public ScriptCommand
-{
-public:
+class GroupCmd : public ScriptCommand {
+ public:
GroupCmd(StringList& pStringList,
InputTree& pInputTree,
InputBuilder& pBuilder,
@@ -36,14 +34,13 @@ public:
void dump() const;
- static bool classof(const ScriptCommand* pCmd)
- {
+ static bool classof(const ScriptCommand* pCmd) {
return pCmd->getKind() == ScriptCommand::GROUP;
}
void activate(Module& pModule);
-private:
+ private:
StringList& m_StringList;
InputTree& m_InputTree;
InputBuilder& m_Builder;
@@ -51,7 +48,6 @@ private:
const LinkerConfig& m_Config;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_GROUPCMD_H_
diff --git a/include/mcld/Script/InputCmd.h b/include/mcld/Script/InputCmd.h
new file mode 100644
index 0000000..694fcda
--- /dev/null
+++ b/include/mcld/Script/InputCmd.h
@@ -0,0 +1,59 @@
+//===- InputCmd.h ---------------------------------------------------------===//
+//
+// The MCLinker Project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#ifndef MCLD_SCRIPT_INPUTCMD_H_
+#define MCLD_SCRIPT_INPUTCMD_H_
+
+#include "mcld/Script/ScriptCommand.h"
+
+namespace mcld {
+
+class ArchiveReader;
+class DynObjReader;
+class InputBuilder;
+class InputTree;
+class LinkerConfig;
+class ObjectReader;
+class StringList;
+
+/** \class InputCmd
+ * \brief This class defines the interfaces to Input command.
+ */
+
+class InputCmd : public ScriptCommand {
+ public:
+ InputCmd(StringList& pStringList,
+ InputTree& pInputTree,
+ InputBuilder& pBuilder,
+ ObjectReader& pObjectReader,
+ ArchiveReader& pArchiveReader,
+ DynObjReader& pDynObjReader,
+ const LinkerConfig& pConfig);
+ ~InputCmd();
+
+ void dump() const;
+
+ static bool classof(const ScriptCommand* pCmd) {
+ return pCmd->getKind() == ScriptCommand::INPUT;
+ }
+
+ void activate(Module& pModule);
+
+ private:
+ StringList& m_StringList;
+ InputTree& m_InputTree;
+ InputBuilder& m_Builder;
+ ObjectReader& m_ObjectReader;
+ ArchiveReader& m_ArchiveReader;
+ DynObjReader& m_DynObjReader;
+ const LinkerConfig& m_Config;
+};
+
+} // namespace mcld
+
+#endif // MCLD_SCRIPT_INPUTCMD_H_
diff --git a/include/mcld/Script/InputSectDesc.h b/include/mcld/Script/InputSectDesc.h
index ede2a3d..a883769 100644
--- a/include/mcld/Script/InputSectDesc.h
+++ b/include/mcld/Script/InputSectDesc.h
@@ -6,30 +6,26 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_INPUTSECTDESC_H
-#define MCLD_SCRIPT_INPUTSECTDESC_H
+#ifndef MCLD_SCRIPT_INPUTSECTDESC_H_
+#define MCLD_SCRIPT_INPUTSECTDESC_H_
+
+#include "mcld/Script/ScriptCommand.h"
+#include "mcld/Script/StringList.h"
-#include <mcld/Script/ScriptCommand.h>
-#include <mcld/Script/StringList.h>
#include <cassert>
-namespace mcld
-{
+namespace mcld {
-class WildcardPattern;
class OutputSectDesc;
+class WildcardPattern;
/** \class InputSectDesc
* \brief This class defines the interfaces to input section description.
*/
-class InputSectDesc : public ScriptCommand
-{
-public:
- enum KeepPolicy {
- Keep,
- NoKeep
- };
+class InputSectDesc : public ScriptCommand {
+ public:
+ enum KeepPolicy { Keep, NoKeep };
struct Spec {
bool hasFile() const { return m_pWildcardFile != NULL; }
@@ -72,7 +68,7 @@ public:
StringList* m_pWildcardSections;
};
-public:
+ public:
InputSectDesc(KeepPolicy pPolicy,
const Spec& pSpec,
const OutputSectDesc& pOutputDesc);
@@ -84,19 +80,18 @@ public:
void dump() const;
- static bool classof(const ScriptCommand* pCmd)
- {
+ static bool classof(const ScriptCommand* pCmd) {
return pCmd->getKind() == ScriptCommand::INPUT_SECT_DESC;
}
void activate(Module& pModule);
-private:
+ private:
KeepPolicy m_KeepPolicy;
Spec m_Spec;
const OutputSectDesc& m_OutputSectDesc;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SCRIPT_INPUTSECTDESC_H_
diff --git a/include/mcld/Script/InputToken.h b/include/mcld/Script/InputToken.h
index 057c06d..9f761c3 100644
--- a/include/mcld/Script/InputToken.h
+++ b/include/mcld/Script/InputToken.h
@@ -6,48 +6,41 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_INPUTTOKEN_H
-#define MCLD_SCRIPT_INPUTTOKEN_H
+#ifndef MCLD_SCRIPT_INPUTTOKEN_H_
+#define MCLD_SCRIPT_INPUTTOKEN_H_
-#include <mcld/Script/StrToken.h>
+#include "mcld/Script/StrToken.h"
-namespace mcld
-{
+namespace mcld {
/** \class InputToken
* \brief This class defines the interfaces to a file/namespec token.
*/
-class InputToken : public StrToken
-{
-public:
- enum Type {
- Unknown,
- File,
- NameSpec
- };
+class InputToken : public StrToken {
+ public:
+ enum Type { Unknown, File, NameSpec };
-protected:
+ protected:
InputToken();
InputToken(Type pType, const std::string& pName, bool pAsNeeded);
-public:
+ public:
virtual ~InputToken();
Type type() const { return m_Type; }
bool asNeeded() const { return m_bAsNeeded; }
- static bool classof(const StrToken* pToken)
- {
+ static bool classof(const StrToken* pToken) {
return pToken->kind() == StrToken::Input;
}
-private:
+ private:
Type m_Type;
bool m_bAsNeeded;
};
-} // namepsace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SCRIPT_INPUTTOKEN_H_
diff --git a/include/mcld/Script/NameSpec.h b/include/mcld/Script/NameSpec.h
index 50040fa..a8db136 100644
--- a/include/mcld/Script/NameSpec.h
+++ b/include/mcld/Script/NameSpec.h
@@ -6,33 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_NAMESPEC_H
-#define MCLD_SCRIPT_NAMESPEC_H
+#ifndef MCLD_SCRIPT_NAMESPEC_H_
+#define MCLD_SCRIPT_NAMESPEC_H_
-#include <mcld/Script/InputToken.h>
-#include <mcld/Support/Allocators.h>
-#include <mcld/Config/Config.h>
+#include "mcld/Config/Config.h"
+#include "mcld/Script/InputToken.h"
+#include "mcld/Support/Allocators.h"
-namespace mcld
-{
+namespace mcld {
/** \class NameSpec
* \brief This class defines the interfaces to a namespec in INPUT/GROUP
* command.
*/
-class NameSpec : public InputToken
-{
-private:
+class NameSpec : public InputToken {
+ private:
friend class Chunk<NameSpec, MCLD_SYMBOLS_PER_INPUT>;
NameSpec();
NameSpec(const std::string& pName, bool pAsNeeded);
-public:
+ public:
~NameSpec();
- static bool classof(const InputToken* pToken)
- {
+ static bool classof(const InputToken* pToken) {
return pToken->type() == InputToken::NameSpec;
}
@@ -42,6 +39,6 @@ public:
static void clear();
};
-} // namepsace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SCRIPT_NAMESPEC_H_
diff --git a/include/mcld/Script/NullaryOp.h b/include/mcld/Script/NullaryOp.h
index 00a7db2..129d756 100644
--- a/include/mcld/Script/NullaryOp.h
+++ b/include/mcld/Script/NullaryOp.h
@@ -6,14 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_NULLOP_H
-#define MCLD_SCRIPT_NULLOP_H
+#ifndef MCLD_SCRIPT_NULLARYOP_H_
+#define MCLD_SCRIPT_NULLARYOP_H_
+
+#include "mcld/Script/Operator.h"
-#include <mcld/Script/Operator.h>
#include <cassert>
-namespace mcld
-{
+namespace mcld {
class Operand;
class IntOperand;
@@ -24,39 +24,32 @@ class TargetLDBackend;
* \brief This class defines the interfaces to an nullary operator token.
*/
-template<Operator::Type TYPE>
-class NullaryOp : public Operator
-{
-private:
+template <Operator::Type TYPE>
+class NullaryOp : public Operator {
+ private:
friend class Operator;
- NullaryOp()
- : Operator(Operator::NULLARY, TYPE)
- {}
+ NullaryOp() : Operator(Operator::NULLARY, TYPE) {}
-public:
- ~NullaryOp()
- {}
+ public:
+ ~NullaryOp() {}
IntOperand* eval(const Module& pModule, const TargetLDBackend& pBackend);
- void appendOperand(Operand* pOperand)
- {
- assert(0);
- }
+ void appendOperand(Operand* pOperand) { assert(0); }
};
-template<>
+template <>
IntOperand* NullaryOp<Operator::SIZEOF_HEADERS>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* NullaryOp<Operator::MAXPAGESIZE>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* NullaryOp<Operator::COMMONPAGESIZE>::eval(const Module&,
const TargetLDBackend&);
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SCRIPT_NULLARYOP_H_
diff --git a/include/mcld/Script/Operand.h b/include/mcld/Script/Operand.h
index 86c1228..9258a32 100644
--- a/include/mcld/Script/Operand.h
+++ b/include/mcld/Script/Operand.h
@@ -6,52 +6,46 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_OPERAND_H
-#define MCLD_SCRIPT_OPERAND_H
+#ifndef MCLD_SCRIPT_OPERAND_H_
+#define MCLD_SCRIPT_OPERAND_H_
+
+#include "mcld/Config/Config.h"
+#include "mcld/Object/SectionMap.h"
+#include "mcld/Script/ExprToken.h"
+#include "mcld/Support/Allocators.h"
-#include <mcld/Script/ExprToken.h>
-#include <mcld/Object/SectionMap.h>
-#include <mcld/Support/Allocators.h>
-#include <mcld/Config/Config.h>
#include <llvm/Support/DataTypes.h>
+
#include <string>
+
#include <cassert>
-namespace mcld
-{
+namespace mcld {
/** \class Operand
* \brief This class defines the interfaces to an operand token.
*/
-class Operand : public ExprToken
-{
-public:
- enum Type {
- SYMBOL,
- INTEGER,
- SECTION,
- SECTION_DESC,
- FRAGMENT
- };
-
-protected:
- Operand(Type pType);
+class Operand : public ExprToken {
+ public:
+ enum Type { SYMBOL, INTEGER, SECTION, SECTION_DESC, FRAGMENT };
+
+ protected:
+ explicit Operand(Type pType);
virtual ~Operand();
-public:
+ public:
Type type() const { return m_Type; }
virtual bool isDot() const { return false; }
virtual uint64_t value() const = 0;
- static bool classof(const ExprToken* pToken)
- {
+ static bool classof(const ExprToken* pToken) {
return pToken->kind() == ExprToken::OPERAND;
}
-private:
+ private:
Type m_Type;
};
@@ -59,14 +53,13 @@ private:
* \brief This class defines the interfaces to a symbol operand.
*/
-class SymOperand : public Operand
-{
-private:
+class SymOperand : public Operand {
+ private:
friend class Chunk<SymOperand, MCLD_SYMBOLS_PER_INPUT>;
SymOperand();
- SymOperand(const std::string& pName);
+ explicit SymOperand(const std::string& pName);
-public:
+ public:
void dump() const;
const std::string& name() const { return m_Name; }
@@ -77,8 +70,7 @@ public:
void setValue(uint64_t pValue) { m_Value = pValue; }
- static bool classof(const Operand* pOperand)
- {
+ static bool classof(const Operand* pOperand) {
return pOperand->type() == Operand::SYMBOL;
}
@@ -87,7 +79,7 @@ public:
static void destroy(SymOperand*& pOperand);
static void clear();
-private:
+ private:
std::string m_Name;
uint64_t m_Value;
};
@@ -96,22 +88,20 @@ private:
* \brief This class defines the interfaces to an integer operand.
*/
-class IntOperand : public Operand
-{
-private:
+class IntOperand : public Operand {
+ private:
friend class Chunk<IntOperand, MCLD_SYMBOLS_PER_INPUT>;
IntOperand();
- IntOperand(uint64_t pValue);
+ explicit IntOperand(uint64_t pValue);
-public:
+ public:
void dump() const;
uint64_t value() const { return m_Value; }
void setValue(uint64_t pValue) { m_Value = pValue; }
- static bool classof(const Operand* pOperand)
- {
+ static bool classof(const Operand* pOperand) {
return pOperand->type() == Operand::INTEGER;
}
@@ -120,7 +110,7 @@ public:
static void destroy(IntOperand*& pOperand);
static void clear();
-private:
+ private:
uint64_t m_Value;
};
@@ -129,26 +119,23 @@ private:
*/
class LDSection;
-class SectOperand : public Operand
-{
-private:
+class SectOperand : public Operand {
+ private:
friend class Chunk<SectOperand, MCLD_SECTIONS_PER_INPUT>;
SectOperand();
- SectOperand(const std::string& pName);
+ explicit SectOperand(const std::string& pName);
-public:
+ public:
void dump() const;
const std::string& name() const { return m_Name; }
- uint64_t value() const
- {
+ uint64_t value() const {
assert(0);
return 0;
}
- static bool classof(const Operand* pOperand)
- {
+ static bool classof(const Operand* pOperand) {
return pOperand->type() == Operand::SECTION;
}
@@ -157,7 +144,7 @@ public:
static void destroy(SectOperand*& pOperand);
static void clear();
-private:
+ private:
std::string m_Name;
};
@@ -165,26 +152,23 @@ private:
* \brief This class defines the interfaces to an section name operand.
*/
-class SectDescOperand : public Operand
-{
-private:
+class SectDescOperand : public Operand {
+ private:
friend class Chunk<SectDescOperand, MCLD_SECTIONS_PER_INPUT>;
SectDescOperand();
- SectDescOperand(const SectionMap::Output* pOutputDesc);
+ explicit SectDescOperand(const SectionMap::Output* pOutputDesc);
-public:
+ public:
void dump() const;
const SectionMap::Output* outputDesc() const { return m_pOutputDesc; }
- uint64_t value() const
- {
+ uint64_t value() const {
assert(0);
return 0;
}
- static bool classof(const Operand* pOperand)
- {
+ static bool classof(const Operand* pOperand) {
return pOperand->type() == Operand::SECTION_DESC;
}
@@ -193,7 +177,7 @@ public:
static void destroy(SectDescOperand*& pOperand);
static void clear();
-private:
+ private:
const SectionMap::Output* m_pOutputDesc;
};
@@ -203,23 +187,21 @@ private:
class Fragment;
-class FragOperand : public Operand
-{
-private:
+class FragOperand : public Operand {
+ private:
friend class Chunk<FragOperand, MCLD_SYMBOLS_PER_INPUT>;
FragOperand();
- FragOperand(Fragment& pFragment);
+ explicit FragOperand(Fragment& pFragment);
-public:
+ public:
void dump() const;
const Fragment* frag() const { return m_pFragment; }
- Fragment* frag() { return m_pFragment; }
+ Fragment* frag() { return m_pFragment; }
uint64_t value() const;
- static bool classof(const Operand* pOperand)
- {
+ static bool classof(const Operand* pOperand) {
return pOperand->type() == Operand::FRAGMENT;
}
@@ -228,11 +210,10 @@ public:
static void destroy(FragOperand*& pOperand);
static void clear();
-private:
+ private:
Fragment* m_pFragment;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_OPERAND_H_
diff --git a/include/mcld/Script/Operator.h b/include/mcld/Script/Operator.h
index b438b4d..017e735 100644
--- a/include/mcld/Script/Operator.h
+++ b/include/mcld/Script/Operator.h
@@ -6,100 +6,93 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_OPERATOR_INTERFACE_H
-#define MCLD_SCRIPT_OPERATOR_INTERFACE_H
+#ifndef MCLD_SCRIPT_OPERATOR_H_
+#define MCLD_SCRIPT_OPERATOR_H_
-#include <mcld/Script/ExprToken.h>
+#include "mcld/Script/ExprToken.h"
#include <llvm/Support/DataTypes.h>
-namespace mcld
-{
+namespace mcld {
-class Operand;
class IntOperand;
class Module;
+class Operand;
class TargetLDBackend;
/** \class Operator
* \brief This class defines the interfaces to an operator token.
*/
-class Operator : public ExprToken
-{
-public:
- enum Arity {
- NULLARY,
- UNARY,
- BINARY,
- TERNARY
- };
+class Operator : public ExprToken {
+ public:
+ enum Arity { NULLARY, UNARY, BINARY, TERNARY };
enum Type {
/* arithmetic operator */
- UNARY_PLUS = 0,
+ UNARY_PLUS = 0,
UNARY_MINUS = 1,
LOGICAL_NOT = 2,
BITWISE_NOT = 3,
- MUL = 4,
- DIV = 5,
- MOD = 6,
- ADD = 7,
- SUB = 8,
- LSHIFT = 9,
- RSHIFT = 10,
- LT = 11,
- LE = 12,
- GT = 13,
- GE = 14,
- EQ = 15,
- NE = 16,
+ MUL = 4,
+ DIV = 5,
+ MOD = 6,
+ ADD = 7,
+ SUB = 8,
+ LSHIFT = 9,
+ RSHIFT = 10,
+ LT = 11,
+ LE = 12,
+ GT = 13,
+ GE = 14,
+ EQ = 15,
+ NE = 16,
BITWISE_AND = 17,
BITWISE_XOR = 18,
- BITWISE_OR = 19,
+ BITWISE_OR = 19,
LOGICAL_AND = 20,
- LOGICAL_OR = 21,
- TERNARY_IF = 22,
- ASSIGN = 23,
- ADD_ASSIGN = 24,
- SUB_ASSIGN = 25,
- MUL_ASSIGN = 26,
- DIV_ASSIGN = 27,
- AND_ASSIGN = 28,
- OR_ASSIGN = 29,
- LS_ASSIGN = 30,
- RS_ASSIGN = 31,
+ LOGICAL_OR = 21,
+ TERNARY_IF = 22,
+ ASSIGN = 23,
+ ADD_ASSIGN = 24,
+ SUB_ASSIGN = 25,
+ MUL_ASSIGN = 26,
+ DIV_ASSIGN = 27,
+ AND_ASSIGN = 28,
+ OR_ASSIGN = 29,
+ LS_ASSIGN = 30,
+ RS_ASSIGN = 31,
/* function */
- ABSOLUTE = 32,
- ADDR = 33,
- ALIGN = 34,
- ALIGNOF = 35,
- BLOCK = 36,
- DATA_SEGMENT_ALIGN = 37,
- DATA_SEGMENT_END = 38,
+ ABSOLUTE = 32,
+ ADDR = 33,
+ ALIGN = 34,
+ ALIGNOF = 35,
+ BLOCK = 36,
+ DATA_SEGMENT_ALIGN = 37,
+ DATA_SEGMENT_END = 38,
DATA_SEGMENT_RELRO_END = 39,
- DEFINED = 40,
- LENGTH = 41,
- LOADADDR = 42,
- MAX = 43,
- MIN = 44,
- NEXT = 45,
- ORIGIN = 46,
- SEGMENT_START = 47,
- SIZEOF = 48,
- SIZEOF_HEADERS = 49,
- MAXPAGESIZE = 50,
- COMMONPAGESIZE = 51
+ DEFINED = 40,
+ LENGTH = 41,
+ LOADADDR = 42,
+ MAX = 43,
+ MIN = 44,
+ NEXT = 45,
+ ORIGIN = 46,
+ SEGMENT_START = 47,
+ SIZEOF = 48,
+ SIZEOF_HEADERS = 49,
+ MAXPAGESIZE = 50,
+ COMMONPAGESIZE = 51
};
static const char* OpNames[];
-protected:
+ protected:
Operator(Arity pArity, Type pType);
const IntOperand* result() const { return m_pIntOperand; }
- IntOperand* result() { return m_pIntOperand; }
+ IntOperand* result() { return m_pIntOperand; }
-public:
+ public:
virtual ~Operator();
Arity arity() const { return m_Arity; }
@@ -113,116 +106,113 @@ public:
virtual void appendOperand(Operand* pOperand) = 0;
- static bool classof(const ExprToken* pToken)
- {
+ static bool classof(const ExprToken* pToken) {
return pToken->kind() == ExprToken::OPERATOR;
}
- template<Operator::Type TYPE>
+ template <Operator::Type TYPE>
static Operator& create();
-private:
+ private:
Arity m_Arity;
Type m_Type;
IntOperand* m_pIntOperand;
};
/* Nullary operator */
-template<>
+template <>
Operator& Operator::create<Operator::SIZEOF_HEADERS>();
-template<>
+template <>
Operator& Operator::create<Operator::MAXPAGESIZE>();
-template<>
+template <>
Operator& Operator::create<Operator::COMMONPAGESIZE>();
/* Unary operator */
-template<>
+template <>
Operator& Operator::create<Operator::UNARY_PLUS>();
-template<>
+template <>
Operator& Operator::create<Operator::UNARY_MINUS>();
-template<>
+template <>
Operator& Operator::create<Operator::LOGICAL_NOT>();
-template<>
+template <>
Operator& Operator::create<Operator::BITWISE_NOT>();
-template<>
+template <>
Operator& Operator::create<Operator::ABSOLUTE>();
-template<>
+template <>
Operator& Operator::create<Operator::ADDR>();
-template<>
+template <>
Operator& Operator::create<Operator::ALIGNOF>();
-template<>
+template <>
Operator& Operator::create<Operator::DATA_SEGMENT_END>();
-template<>
+template <>
Operator& Operator::create<Operator::DEFINED>();
-template<>
+template <>
Operator& Operator::create<Operator::LENGTH>();
-template<>
+template <>
Operator& Operator::create<Operator::LOADADDR>();
-template<>
+template <>
Operator& Operator::create<Operator::NEXT>();
-template<>
+template <>
Operator& Operator::create<Operator::ORIGIN>();
-template<>
+template <>
Operator& Operator::create<Operator::SIZEOF>();
/* Binary operator */
-template<>
+template <>
Operator& Operator::create<Operator::MUL>();
-template<>
+template <>
Operator& Operator::create<Operator::DIV>();
-template<>
+template <>
Operator& Operator::create<Operator::MOD>();
-template<>
+template <>
Operator& Operator::create<Operator::ADD>();
-template<>
+template <>
Operator& Operator::create<Operator::SUB>();
-template<>
+template <>
Operator& Operator::create<Operator::LSHIFT>();
-template<>
+template <>
Operator& Operator::create<Operator::RSHIFT>();
-template<>
+template <>
Operator& Operator::create<Operator::LT>();
-template<>
+template <>
Operator& Operator::create<Operator::LE>();
-template<>
+template <>
Operator& Operator::create<Operator::GT>();
-template<>
+template <>
Operator& Operator::create<Operator::GE>();
-template<>
+template <>
Operator& Operator::create<Operator::EQ>();
-template<>
+template <>
Operator& Operator::create<Operator::NE>();
-template<>
+template <>
Operator& Operator::create<Operator::BITWISE_AND>();
-template<>
+template <>
Operator& Operator::create<Operator::BITWISE_XOR>();
-template<>
+template <>
Operator& Operator::create<Operator::BITWISE_OR>();
-template<>
+template <>
Operator& Operator::create<Operator::LOGICAL_AND>();
-template<>
+template <>
Operator& Operator::create<Operator::LOGICAL_OR>();
-template<>
+template <>
Operator& Operator::create<Operator::ALIGN>();
-template<>
+template <>
Operator& Operator::create<Operator::DATA_SEGMENT_RELRO_END>();
-template<>
+template <>
Operator& Operator::create<Operator::MAX>();
-template<>
+template <>
Operator& Operator::create<Operator::MIN>();
-template<>
+template <>
Operator& Operator::create<Operator::SEGMENT_START>();
/* Ternary operator */
-template<>
+template <>
Operator& Operator::create<Operator::TERNARY_IF>();
-template<>
-Operator&
-Operator::create<Operator::DATA_SEGMENT_ALIGN>();
-} // namespace of mcld
-
-#endif
+template <>
+Operator& Operator::create<Operator::DATA_SEGMENT_ALIGN>();
+} // namespace mcld
+#endif // MCLD_SCRIPT_OPERATOR_H_
diff --git a/include/mcld/Script/OutputArchCmd.h b/include/mcld/Script/OutputArchCmd.h
index aad97fc..1c22697 100644
--- a/include/mcld/Script/OutputArchCmd.h
+++ b/include/mcld/Script/OutputArchCmd.h
@@ -6,14 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_OUTPUTARCHCMD_H
-#define MCLD_SCRIPT_OUTPUTARCHCMD_H
+#ifndef MCLD_SCRIPT_OUTPUTARCHCMD_H_
+#define MCLD_SCRIPT_OUTPUTARCHCMD_H_
+
+#include "mcld/Script/ScriptCommand.h"
-#include <mcld/Script/ScriptCommand.h>
#include <string>
-namespace mcld
-{
+namespace mcld {
class Module;
@@ -21,26 +21,23 @@ class Module;
* \brief This class defines the interfaces to OutputArch command.
*/
-class OutputArchCmd : public ScriptCommand
-{
-public:
- OutputArchCmd(const std::string& pArch);
+class OutputArchCmd : public ScriptCommand {
+ public:
+ explicit OutputArchCmd(const std::string& pArch);
~OutputArchCmd();
void dump() const;
- static bool classof(const ScriptCommand* pCmd)
- {
+ static bool classof(const ScriptCommand* pCmd) {
return pCmd->getKind() == ScriptCommand::OUTPUT_ARCH;
}
void activate(Module& pModule);
-private:
+ private:
std::string m_Arch;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_OUTPUTARCHCMD_H_
diff --git a/include/mcld/Script/OutputCmd.h b/include/mcld/Script/OutputCmd.h
index 0ee895f..d7afa25 100644
--- a/include/mcld/Script/OutputCmd.h
+++ b/include/mcld/Script/OutputCmd.h
@@ -6,14 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_OUTPUTCMD_H
-#define MCLD_SCRIPT_OUTPUTCMD_H
+#ifndef MCLD_SCRIPT_OUTPUTCMD_H_
+#define MCLD_SCRIPT_OUTPUTCMD_H_
+
+#include "mcld/Script/ScriptCommand.h"
-#include <mcld/Script/ScriptCommand.h>
#include <string>
-namespace mcld
-{
+namespace mcld {
class Module;
@@ -21,27 +21,24 @@ class Module;
* \brief This class defines the interfaces to Output command.
*/
-class OutputCmd : public ScriptCommand
-{
-public:
- OutputCmd(const std::string& pOutputFile);
+class OutputCmd : public ScriptCommand {
+ public:
+ explicit OutputCmd(const std::string& pOutputFile);
~OutputCmd();
void dump() const;
- static bool classof(const ScriptCommand* pCmd)
- {
+ static bool classof(const ScriptCommand* pCmd) {
return pCmd->getKind() == ScriptCommand::OUTPUT;
}
void activate(Module& pModule);
-private:
+ private:
std::string m_OutputFile;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_OUTPUTCMD_H_
diff --git a/include/mcld/Script/OutputFormatCmd.h b/include/mcld/Script/OutputFormatCmd.h
index 0c34872..307f738 100644
--- a/include/mcld/Script/OutputFormatCmd.h
+++ b/include/mcld/Script/OutputFormatCmd.h
@@ -6,15 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_OUTPUTFORMATCMD_H
-#define MCLD_SCRIPT_OUTPUTFORMATCMD_H
+#ifndef MCLD_SCRIPT_OUTPUTFORMATCMD_H_
+#define MCLD_SCRIPT_OUTPUTFORMATCMD_H_
+
+#include "mcld/Script/ScriptCommand.h"
-#include <mcld/Script/ScriptCommand.h>
#include <string>
#include <vector>
-namespace mcld
-{
+namespace mcld {
class Module;
@@ -22,39 +22,36 @@ class Module;
* \brief This class defines the interfaces to OutputFormat command.
*/
-class OutputFormatCmd : public ScriptCommand
-{
-public:
+class OutputFormatCmd : public ScriptCommand {
+ public:
typedef std::vector<std::string> FormatList;
typedef FormatList::const_iterator const_iterator;
typedef FormatList::iterator iterator;
-public:
- OutputFormatCmd(const std::string& pFormat);
+ public:
+ explicit OutputFormatCmd(const std::string& pFormat);
OutputFormatCmd(const std::string& pDefault,
const std::string& pBig,
const std::string& pLittle);
~OutputFormatCmd();
const_iterator begin() const { return m_FormatList.begin(); }
- iterator begin() { return m_FormatList.begin(); }
- const_iterator end() const { return m_FormatList.end(); }
- iterator end() { return m_FormatList.end(); }
+ iterator begin() { return m_FormatList.begin(); }
+ const_iterator end() const { return m_FormatList.end(); }
+ iterator end() { return m_FormatList.end(); }
void dump() const;
- static bool classof(const ScriptCommand* pCmd)
- {
+ static bool classof(const ScriptCommand* pCmd) {
return pCmd->getKind() == ScriptCommand::OUTPUT_FORMAT;
}
void activate(Module& pModule);
-private:
+ private:
FormatList m_FormatList;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_OUTPUTFORMATCMD_H_
diff --git a/include/mcld/Script/OutputSectDesc.h b/include/mcld/Script/OutputSectDesc.h
index abf4613..c8df493 100644
--- a/include/mcld/Script/OutputSectDesc.h
+++ b/include/mcld/Script/OutputSectDesc.h
@@ -6,16 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_OUTPUTSECTDESC_H
-#define MCLD_SCRIPT_OUTPUTSECTDESC_H
+#ifndef MCLD_SCRIPT_OUTPUTSECTDESC_H_
+#define MCLD_SCRIPT_OUTPUTSECTDESC_H_
+
+#include "mcld/Script/ScriptCommand.h"
-#include <mcld/Script/ScriptCommand.h>
-#include <vector>
#include <string>
+#include <vector>
+
#include <cassert>
-namespace mcld
-{
+namespace mcld {
class RpnExpr;
class StringList;
@@ -24,11 +25,10 @@ class StringList;
* \brief This class defines the interfaces to output section description.
*/
-class OutputSectDesc : public ScriptCommand
-{
-public:
+class OutputSectDesc : public ScriptCommand {
+ public:
enum Type {
- LOAD, // ALLOC
+ LOAD, // ALLOC
NOLOAD,
DSECT,
COPY,
@@ -36,11 +36,7 @@ public:
OVERLAY
};
- enum Constraint {
- NO_CONSTRAINT,
- ONLY_IF_RO,
- ONLY_IF_RW
- };
+ enum Constraint { NO_CONSTRAINT, ONLY_IF_RO, ONLY_IF_RW };
struct Prolog {
bool hasVMA() const { return m_pVMA != NULL; }
@@ -53,9 +49,7 @@ public:
return *m_pVMA;
}
- void setType(Type pType) {
- m_Type = pType;
- }
+ void setType(Type pType) { m_Type = pType; }
Type type() const { return m_Type; }
@@ -91,7 +85,7 @@ public:
return false;
if (m_Type != pRHS.m_Type)
return false;
- if (m_pLMA!= pRHS.m_pLMA)
+ if (m_pLMA != pRHS.m_pLMA)
return false;
if (m_pAlign != pRHS.m_pAlign)
return false;
@@ -162,19 +156,19 @@ public:
typedef OutputSectCmds::const_reference const_reference;
typedef OutputSectCmds::reference reference;
-public:
+ public:
OutputSectDesc(const std::string& pName, const Prolog& pProlog);
~OutputSectDesc();
- const_iterator begin() const { return m_OutputSectCmds.begin(); }
- iterator begin() { return m_OutputSectCmds.begin(); }
- const_iterator end() const { return m_OutputSectCmds.end(); }
- iterator end() { return m_OutputSectCmds.end(); }
+ const_iterator begin() const { return m_OutputSectCmds.begin(); }
+ iterator begin() { return m_OutputSectCmds.begin(); }
+ const_iterator end() const { return m_OutputSectCmds.end(); }
+ iterator end() { return m_OutputSectCmds.end(); }
const_reference front() const { return m_OutputSectCmds.front(); }
- reference front() { return m_OutputSectCmds.front(); }
- const_reference back() const { return m_OutputSectCmds.back(); }
- reference back() { return m_OutputSectCmds.back(); }
+ reference front() { return m_OutputSectCmds.front(); }
+ const_reference back() const { return m_OutputSectCmds.back(); }
+ reference back() { return m_OutputSectCmds.back(); }
const std::string& name() const { return m_Name; }
@@ -184,8 +178,7 @@ public:
void dump() const;
- static bool classof(const ScriptCommand* pCmd)
- {
+ static bool classof(const ScriptCommand* pCmd) {
return pCmd->getKind() == ScriptCommand::OUTPUT_SECT_DESC;
}
@@ -199,13 +192,13 @@ public:
const Epilog& epilog() const { return m_Epilog; }
-private:
+ private:
OutputSectCmds m_OutputSectCmds;
std::string m_Name;
Prolog m_Prolog;
Epilog m_Epilog;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SCRIPT_OUTPUTSECTDESC_H_
diff --git a/include/mcld/Script/RpnEvaluator.h b/include/mcld/Script/RpnEvaluator.h
index 7e35e86..d71366b 100644
--- a/include/mcld/Script/RpnEvaluator.h
+++ b/include/mcld/Script/RpnEvaluator.h
@@ -6,31 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_RPNEVALUATOR_H
-#define MCLD_SCRIPT_RPNEVALUATOR_H
+#ifndef MCLD_SCRIPT_RPNEVALUATOR_H_
+#define MCLD_SCRIPT_RPNEVALUATOR_H_
+
+#include <cstdint>
namespace mcld {
-class RpnExpr;
class Module;
+class RpnExpr;
class TargetLDBackend;
/** \class RpnEvaluator
* \brief RpnEvaluator evaluate a rpn expression
*/
-class RpnEvaluator
-{
-public:
+class RpnEvaluator {
+ public:
RpnEvaluator(const Module& pModule, const TargetLDBackend& pBackend);
// evaluate a valid expression and set the value in the second parameter
bool eval(const RpnExpr& pExpr, uint64_t& pResult);
-private:
+ private:
const Module& m_Module;
const TargetLDBackend& m_Backend;
};
-} // mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SCRIPT_RPNEVALUATOR_H_
diff --git a/include/mcld/Script/RpnExpr.h b/include/mcld/Script/RpnExpr.h
index eaf4f72..c80314d 100644
--- a/include/mcld/Script/RpnExpr.h
+++ b/include/mcld/Script/RpnExpr.h
@@ -6,16 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_RPNEXPR_H
-#define MCLD_SCRIPT_RPNEXPR_H
+#ifndef MCLD_SCRIPT_RPNEXPR_H_
+#define MCLD_SCRIPT_RPNEXPR_H_
+
+#include "mcld/Config/Config.h"
+#include "mcld/Object/SectionMap.h"
+#include "mcld/Support/Allocators.h"
-#include <mcld/Support/Allocators.h>
-#include <mcld/Config/Config.h>
-#include <mcld/Object/SectionMap.h>
#include <vector>
-namespace mcld
-{
+namespace mcld {
class ExprToken;
class Fragment;
@@ -24,24 +24,23 @@ class Fragment;
* \brief This class defines the interfaces to a rpn expression.
*/
-class RpnExpr
-{
-public:
+class RpnExpr {
+ public:
typedef std::vector<ExprToken*> TokenQueue;
typedef TokenQueue::const_iterator const_iterator;
typedef TokenQueue::iterator iterator;
-private:
+ private:
friend class Chunk<RpnExpr, MCLD_SYMBOLS_PER_INPUT>;
RpnExpr();
-public:
+ public:
~RpnExpr();
const_iterator begin() const { return m_TokenQueue.begin(); }
- iterator begin() { return m_TokenQueue.begin(); }
- const_iterator end() const { return m_TokenQueue.end(); }
- iterator end() { return m_TokenQueue.end(); }
+ iterator begin() { return m_TokenQueue.begin(); }
+ const_iterator end() const { return m_TokenQueue.end(); }
+ iterator end() { return m_TokenQueue.end(); }
size_t size() const { return m_TokenQueue.size(); }
@@ -68,11 +67,10 @@ public:
// buildHelperExpr - build the helper expr: `fragment'
static RpnExpr* buildHelperExpr(Fragment& pFrag);
-private:
+ private:
TokenQueue m_TokenQueue;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_RPNEXPR_H_
diff --git a/include/mcld/Script/ScriptCommand.h b/include/mcld/Script/ScriptCommand.h
index d670b01..f8d3a6e 100644
--- a/include/mcld/Script/ScriptCommand.h
+++ b/include/mcld/Script/ScriptCommand.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_COMMAND_H
-#define MCLD_SCRIPT_COMMAND_H
+#ifndef MCLD_SCRIPT_SCRIPTCOMMAND_H_
+#define MCLD_SCRIPT_SCRIPTCOMMAND_H_
namespace mcld {
@@ -16,29 +16,27 @@ class Module;
/** \class ScriptCommand
* \brief This class defines the interfaces to a script command.
*/
-class ScriptCommand
-{
-public:
+class ScriptCommand {
+ public:
enum Kind {
+ ASSERT,
+ ASSIGNMENT,
ENTRY,
- OUTPUT_FORMAT,
GROUP,
+ INPUT,
+ INPUT_SECT_DESC,
OUTPUT,
- SEARCH_DIR,
OUTPUT_ARCH,
- ASSERT,
- ASSIGNMENT,
- SECTIONS,
+ OUTPUT_FORMAT,
+ SEARCH_DIR,
OUTPUT_SECT_DESC,
- INPUT_SECT_DESC
+ SECTIONS
};
-protected:
- ScriptCommand(Kind pKind)
- : m_Kind(pKind)
- {}
+ protected:
+ explicit ScriptCommand(Kind pKind) : m_Kind(pKind) {}
-public:
+ public:
virtual ~ScriptCommand() = 0;
virtual void dump() const = 0;
@@ -47,11 +45,10 @@ public:
Kind getKind() const { return m_Kind; }
-private:
+ private:
Kind m_Kind;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_SCRIPTCOMMAND_H_
diff --git a/include/mcld/Script/ScriptFile.h b/include/mcld/Script/ScriptFile.h
index b54ba1f..dad2776 100644
--- a/include/mcld/Script/ScriptFile.h
+++ b/include/mcld/Script/ScriptFile.h
@@ -6,40 +6,42 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_SCRIPTFILE_H
-#define MCLD_SCRIPT_SCRIPTFILE_H
+#ifndef MCLD_SCRIPT_SCRIPTFILE_H_
+#define MCLD_SCRIPT_SCRIPTFILE_H_
+
+#include "mcld/Script/Assignment.h"
+#include "mcld/Script/InputSectDesc.h"
+#include "mcld/Script/OutputSectDesc.h"
-#include <mcld/Script/Assignment.h>
-#include <mcld/Script/OutputSectDesc.h>
-#include <mcld/Script/InputSectDesc.h>
-#include <vector>
#include <string>
+#include <vector>
-namespace mcld
-{
+namespace mcld {
-class ScriptCommand;
+class ArchiveReader;
+class DynObjReader;
+class GroupReader;
class Input;
-class InputTree;
class InputBuilder;
-class GroupReader;
+class InputTree;
class LinkerConfig;
-class RpnExpr;
-class StringList;
class Module;
+class ObjectReader;
+class ScriptCommand;
+class StringList;
+class RpnExpr;
/** \class ScriptFile
* \brief This class defines the interfaces to a linker script file.
*/
-class ScriptFile
-{
-public:
+class ScriptFile {
+ public:
enum Kind {
- LDScript, // -T
- Expression, // --defsym
- VersionScript, // --version-script
- DynamicList, // --dynamic-list
+ LDScript, // -T
+ Expression, // --defsym
+ VersionScript, // --version-script
+ DynamicList, // --dynamic-list
Unknown
};
@@ -49,32 +51,32 @@ public:
typedef CommandQueue::const_reference const_reference;
typedef CommandQueue::reference reference;
-public:
+ public:
ScriptFile(Kind pKind, Input& pInput, InputBuilder& pBuilder);
~ScriptFile();
- const_iterator begin() const { return m_CommandQueue.begin(); }
- iterator begin() { return m_CommandQueue.begin(); }
- const_iterator end() const { return m_CommandQueue.end(); }
- iterator end() { return m_CommandQueue.end(); }
+ const_iterator begin() const { return m_CommandQueue.begin(); }
+ iterator begin() { return m_CommandQueue.begin(); }
+ const_iterator end() const { return m_CommandQueue.end(); }
+ iterator end() { return m_CommandQueue.end(); }
const_reference front() const { return m_CommandQueue.front(); }
- reference front() { return m_CommandQueue.front(); }
- const_reference back() const { return m_CommandQueue.back(); }
- reference back() { return m_CommandQueue.back(); }
+ reference front() { return m_CommandQueue.front(); }
+ const_reference back() const { return m_CommandQueue.back(); }
+ reference back() { return m_CommandQueue.back(); }
const Input& input() const { return m_Input; }
- Input& input() { return m_Input; }
+ Input& input() { return m_Input; }
size_t size() const { return m_CommandQueue.size(); }
Kind getKind() const { return m_Kind; }
const InputTree& inputs() const { return *m_pInputTree; }
- InputTree& inputs() { return *m_pInputTree; }
+ InputTree& inputs() { return *m_pInputTree; }
const std::string& name() const { return m_Name; }
- std::string& name() { return m_Name; }
+ std::string& name() { return m_Name; }
void dump() const;
void activate(Module& pModule);
@@ -89,6 +91,14 @@ public:
const std::string& pBig,
const std::string& pLittle);
+ /// INPUT(file, file, ...)
+ /// INPUT(file file ...)
+ void addInputCmd(StringList& pStringList,
+ ObjectReader& pObjectReader,
+ ArchiveReader& pArchiveReader,
+ DynObjReader& pDynObjReader,
+ const LinkerConfig& pConfig);
+
/// GROUP(file, file, ...)
/// GROUP(file file ...)
void addGroupCmd(StringList& pStringList,
@@ -128,11 +138,11 @@ public:
RpnExpr* createRpnExpr();
const RpnExpr* getCurrentRpnExpr() const { return m_pRpnExpr; }
- RpnExpr* getCurrentRpnExpr() { return m_pRpnExpr; }
+ RpnExpr* getCurrentRpnExpr() { return m_pRpnExpr; }
StringList* createStringList();
const StringList* getCurrentStringList() const { return m_pStringList; }
- StringList* getCurrentStringList() { return m_pStringList; }
+ StringList* getCurrentStringList() { return m_pStringList; }
void setAsNeeded(bool pEnable = true);
bool asNeeded() const { return m_bAsNeeded; }
@@ -141,7 +151,7 @@ public:
static void clearParserStrPool();
-private:
+ private:
Kind m_Kind;
Input& m_Input;
std::string m_Name;
@@ -156,7 +166,6 @@ private:
bool m_bAsNeeded;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_SCRIPTFILE_H_
diff --git a/include/mcld/Script/ScriptReader.h b/include/mcld/Script/ScriptReader.h
index a3f91c4..a04b89f 100644
--- a/include/mcld/Script/ScriptReader.h
+++ b/include/mcld/Script/ScriptReader.h
@@ -6,25 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_SCRIPTREADER_H
-#define MCLD_SCRIPT_SCRIPTREADER_H
+#ifndef MCLD_SCRIPT_SCRIPTREADER_H_
+#define MCLD_SCRIPT_SCRIPTREADER_H_
-#include <mcld/LD/LDReader.h>
+#include "mcld/LD/LDReader.h"
namespace mcld {
-class Module;
-class ScriptFile;
-class Input;
+class ArchiveReader;
+class DynObjReader;
class GroupReader;
+class Input;
class LinkerConfig;
class LinkerScript;
+class Module;
+class ObjectReader;
+class ScriptFile;
class TargetLDBackend;
-class ScriptReader : public LDReader
-{
-public:
- ScriptReader(GroupReader& pGroupReader);
+class ScriptReader : public LDReader {
+ public:
+ ScriptReader(ObjectReader& pObjectReader,
+ ArchiveReader& pArchiveReader,
+ DynObjReader& pDynObjReader,
+ GroupReader& pGroupReader);
~ScriptReader();
@@ -32,15 +37,15 @@ public:
bool readScript(const LinkerConfig& pConfig, ScriptFile& pScriptFile);
/// isMyFormat
- bool isMyFormat(Input& pInput, bool &pContinue) const;
+ bool isMyFormat(Input& pInput, bool& pContinue) const;
- GroupReader& getGroupReader() { return m_GroupReader; }
-
-private:
+ private:
+ ObjectReader& m_ObjectReader;
+ ArchiveReader& m_ArchiveReader;
+ DynObjReader& m_DynObjReader;
GroupReader& m_GroupReader;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_SCRIPTREADER_H_
diff --git a/include/mcld/Script/ScriptScanner.h b/include/mcld/Script/ScriptScanner.h
index 4cab6ec..4a572a1 100644
--- a/include/mcld/Script/ScriptScanner.h
+++ b/include/mcld/Script/ScriptScanner.h
@@ -6,22 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_SCRIPTSCANNER_H
-#define MCLD_SCRIPT_SCRIPTSCANNER_H
+#ifndef MCLD_SCRIPT_SCRIPTSCANNER_H_
+#define MCLD_SCRIPT_SCRIPTSCANNER_H_
#ifndef __FLEX_LEXER_H
#include "FlexLexer.h"
#endif
#ifndef YY_DECL
-#define YY_DECL \
- mcld::ScriptParser::token_type \
- mcld::ScriptScanner::lex(mcld::ScriptParser::semantic_type* yylval, \
- mcld::ScriptParser::location_type* yylloc, \
- const mcld::ScriptFile& pScriptFile)
+#define YY_DECL \
+ mcld::ScriptParser::token_type mcld::ScriptScanner::lex( \
+ mcld::ScriptParser::semantic_type* yylval, \
+ mcld::ScriptParser::location_type* yylloc, \
+ const mcld::ScriptFile& pScriptFile)
#endif
-#include <mcld/Script/ScriptFile.h>
+#include "mcld/Script/ScriptFile.h"
#include "ScriptParser.h"
#include <stack>
@@ -30,10 +30,9 @@ namespace mcld {
/** \class ScriptScanner
*
*/
-class ScriptScanner : public yyFlexLexer
-{
-public:
- ScriptScanner(std::istream* yyin = NULL, std::ostream* yyout = NULL);
+class ScriptScanner : public yyFlexLexer {
+ public:
+ explicit ScriptScanner(std::istream* yyin = NULL, std::ostream* yyout = NULL);
virtual ~ScriptScanner();
@@ -45,15 +44,14 @@ public:
void popLexState();
-private:
+ private:
void enterComments(ScriptParser::location_type& pLocation);
-private:
+ private:
ScriptFile::Kind m_Kind;
std::stack<ScriptFile::Kind> m_StateStack;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_SCRIPTSCANNER_H_
diff --git a/include/mcld/Script/SearchDirCmd.h b/include/mcld/Script/SearchDirCmd.h
index 3358b6e..ceb584b 100644
--- a/include/mcld/Script/SearchDirCmd.h
+++ b/include/mcld/Script/SearchDirCmd.h
@@ -6,14 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_SEARCHDIRCMD_H
-#define MCLD_SCRIPT_SEARCHDIRCMD_H
+#ifndef MCLD_SCRIPT_SEARCHDIRCMD_H_
+#define MCLD_SCRIPT_SEARCHDIRCMD_H_
+
+#include "mcld/Script/ScriptCommand.h"
-#include <mcld/Script/ScriptCommand.h>
#include <string>
-namespace mcld
-{
+namespace mcld {
class Module;
@@ -21,26 +21,23 @@ class Module;
* \brief This class defines the interfaces to SEARCH_DIR command.
*/
-class SearchDirCmd : public ScriptCommand
-{
-public:
- SearchDirCmd(const std::string& pPath);
+class SearchDirCmd : public ScriptCommand {
+ public:
+ explicit SearchDirCmd(const std::string& pPath);
~SearchDirCmd();
void dump() const;
void activate(Module& pModule);
- static bool classof(const ScriptCommand* pCmd)
- {
+ static bool classof(const ScriptCommand* pCmd) {
return pCmd->getKind() == ScriptCommand::SEARCH_DIR;
}
-private:
+ private:
std::string m_Path;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_SEARCHDIRCMD_H_
diff --git a/include/mcld/Script/SectionsCmd.h b/include/mcld/Script/SectionsCmd.h
index f64a841..93a55c2 100644
--- a/include/mcld/Script/SectionsCmd.h
+++ b/include/mcld/Script/SectionsCmd.h
@@ -6,15 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_SECTIONSCMD_H
-#define MCLD_SCRIPT_SECTIONSCMD_H
+#ifndef MCLD_SCRIPT_SECTIONSCMD_H_
+#define MCLD_SCRIPT_SECTIONSCMD_H_
+
+#include "mcld/Script/ScriptCommand.h"
-#include <mcld/Script/ScriptCommand.h>
#include <llvm/Support/DataTypes.h>
+
#include <vector>
-namespace mcld
-{
+namespace mcld {
class Module;
@@ -22,28 +23,27 @@ class Module;
* \brief This class defines the interfaces to SECTIONS command.
*/
-class SectionsCmd : public ScriptCommand
-{
-public:
+class SectionsCmd : public ScriptCommand {
+ public:
typedef std::vector<ScriptCommand*> SectionCommands;
typedef SectionCommands::const_iterator const_iterator;
typedef SectionCommands::iterator iterator;
typedef SectionCommands::const_reference const_reference;
typedef SectionCommands::reference reference;
-public:
+ public:
SectionsCmd();
~SectionsCmd();
- const_iterator begin() const { return m_SectionCommands.begin(); }
- iterator begin() { return m_SectionCommands.begin(); }
- const_iterator end() const { return m_SectionCommands.end(); }
- iterator end() { return m_SectionCommands.end(); }
+ const_iterator begin() const { return m_SectionCommands.begin(); }
+ iterator begin() { return m_SectionCommands.begin(); }
+ const_iterator end() const { return m_SectionCommands.end(); }
+ iterator end() { return m_SectionCommands.end(); }
const_reference front() const { return m_SectionCommands.front(); }
- reference front() { return m_SectionCommands.front(); }
- const_reference back() const { return m_SectionCommands.back(); }
- reference back() { return m_SectionCommands.back(); }
+ reference front() { return m_SectionCommands.front(); }
+ const_reference back() const { return m_SectionCommands.back(); }
+ reference back() { return m_SectionCommands.back(); }
size_t size() const { return m_SectionCommands.size(); }
@@ -51,8 +51,7 @@ public:
void dump() const;
- static bool classof(const ScriptCommand* pCmd)
- {
+ static bool classof(const ScriptCommand* pCmd) {
return pCmd->getKind() == ScriptCommand::SECTIONS;
}
@@ -60,10 +59,10 @@ public:
void push_back(ScriptCommand* pCommand);
-private:
+ private:
SectionCommands m_SectionCommands;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SCRIPT_SECTIONSCMD_H_
diff --git a/include/mcld/Script/StrToken.h b/include/mcld/Script/StrToken.h
index 08aef06..2800367 100644
--- a/include/mcld/Script/StrToken.h
+++ b/include/mcld/Script/StrToken.h
@@ -6,46 +6,40 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_STRTOKEN_H
-#define MCLD_SCRIPT_STRTOKEN_H
+#ifndef MCLD_SCRIPT_STRTOKEN_H_
+#define MCLD_SCRIPT_STRTOKEN_H_
+
+#include "mcld/Config/Config.h"
+#include "mcld/Support/Allocators.h"
-#include <mcld/Support/Allocators.h>
-#include <mcld/Config/Config.h>
#include <string>
-namespace mcld
-{
+namespace mcld {
/** \class StrToken
* \brief This class defines the interfaces to a element in EXCLUDE_FILE list
* or in Output Section Phdr, or be a base class of other str token.
*/
-class StrToken
-{
-public:
- enum Kind {
- Unknown,
- String,
- Input,
- Wildcard
- };
+class StrToken {
+ public:
+ enum Kind { Unknown, String, Input, Wildcard };
-private:
+ private:
friend class Chunk<StrToken, MCLD_SYMBOLS_PER_INPUT>;
-protected:
+
+ protected:
StrToken();
StrToken(Kind pKind, const std::string& pString);
-public:
+ public:
virtual ~StrToken();
Kind kind() const { return m_Kind; }
const std::string& name() const { return m_Name; }
- static bool classof(const StrToken* pToken)
- {
+ static bool classof(const StrToken* pToken) {
return pToken->kind() == StrToken::String;
}
@@ -54,11 +48,11 @@ public:
static void destroy(StrToken*& pToken);
static void clear();
-private:
+ private:
Kind m_Kind;
std::string m_Name;
};
-} // namepsace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SCRIPT_STRTOKEN_H_
diff --git a/include/mcld/Script/StringList.h b/include/mcld/Script/StringList.h
index 76255d0..7c938b1 100644
--- a/include/mcld/Script/StringList.h
+++ b/include/mcld/Script/StringList.h
@@ -6,15 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_STRINGLIST_H
-#define MCLD_SCRIPT_STRINGLIST_H
+#ifndef MCLD_SCRIPT_STRINGLIST_H_
+#define MCLD_SCRIPT_STRINGLIST_H_
+
+#include "mcld/Config/Config.h"
+#include "mcld/Support/Allocators.h"
-#include <mcld/Config/Config.h>
-#include <mcld/Support/Allocators.h>
#include <vector>
-namespace mcld
-{
+namespace mcld {
class StrToken;
@@ -22,31 +22,30 @@ class StrToken;
* \brief This class defines the interfaces to StringList.
*/
-class StringList
-{
-public:
+class StringList {
+ public:
typedef std::vector<StrToken*> Tokens;
typedef Tokens::const_iterator const_iterator;
typedef Tokens::iterator iterator;
typedef Tokens::const_reference const_reference;
typedef Tokens::reference reference;
-private:
+ private:
friend class Chunk<StringList, MCLD_SYMBOLS_PER_INPUT>;
StringList();
-public:
+ public:
~StringList();
- const_iterator begin() const { return m_Tokens.begin(); }
- iterator begin() { return m_Tokens.begin(); }
- const_iterator end() const { return m_Tokens.end(); }
- iterator end() { return m_Tokens.end(); }
+ const_iterator begin() const { return m_Tokens.begin(); }
+ iterator begin() { return m_Tokens.begin(); }
+ const_iterator end() const { return m_Tokens.end(); }
+ iterator end() { return m_Tokens.end(); }
const_reference front() const { return m_Tokens.front(); }
- reference front() { return m_Tokens.front(); }
- const_reference back() const { return m_Tokens.back(); }
- reference back() { return m_Tokens.back(); }
+ reference front() { return m_Tokens.front(); }
+ const_reference back() const { return m_Tokens.back(); }
+ reference back() { return m_Tokens.back(); }
bool empty() const { return m_Tokens.empty(); }
@@ -59,11 +58,10 @@ public:
static void destroy(StringList*& pStringList);
static void clear();
-private:
+ private:
Tokens m_Tokens;
};
-} // namepsace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_STRINGLIST_H_
diff --git a/include/mcld/Script/TernaryOp.h b/include/mcld/Script/TernaryOp.h
index bf47bca..a837c14 100644
--- a/include/mcld/Script/TernaryOp.h
+++ b/include/mcld/Script/TernaryOp.h
@@ -6,63 +6,58 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_TERNARYOP_H
-#define MCLD_SCRIPT_TERNARYOP_H
+#ifndef MCLD_SCRIPT_TERNARYOP_H_
+#define MCLD_SCRIPT_TERNARYOP_H_
+
+#include "mcld/Script/Operator.h"
-#include <mcld/Script/Operator.h>
#include <cstddef>
-namespace mcld
-{
+namespace mcld {
-class Operand;
class IntOperand;
class Module;
+class Operand;
class TargetLDBackend;
/** \class TernaryOP
* \brief This class defines the interfaces to an binary operator token.
*/
-template<Operator::Type TYPE>
-class TernaryOp : public Operator
-{
-private:
+template <Operator::Type TYPE>
+class TernaryOp : public Operator {
+ private:
friend class Operator;
- TernaryOp()
- : Operator(Operator::TERNARY, TYPE)
- {
+ TernaryOp() : Operator(Operator::TERNARY, TYPE) {
m_pOperand[0] = m_pOperand[1] = m_pOperand[2] = NULL;
}
-public:
- ~TernaryOp()
- {}
+ public:
+ ~TernaryOp() {}
IntOperand* eval(const Module& pModule, const TargetLDBackend& pBackend);
- void appendOperand(Operand* pOperand)
- {
+ void appendOperand(Operand* pOperand) {
m_pOperand[m_Size++] = pOperand;
if (m_Size == 3)
m_Size = 0;
}
-private:
+ private:
size_t m_Size;
Operand* m_pOperand[3];
};
-template<>
+template <>
IntOperand* TernaryOp<Operator::TERNARY_IF>::eval(const Module&,
const TargetLDBackend&);
-template<>
-IntOperand*
-TernaryOp<Operator::DATA_SEGMENT_ALIGN>::eval(const Module&,
- const TargetLDBackend&);
+template <>
+IntOperand* TernaryOp<Operator::DATA_SEGMENT_ALIGN>::eval(
+ const Module&,
+ const TargetLDBackend&);
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SCRIPT_TERNARYOP_H_
diff --git a/include/mcld/Script/UnaryOp.h b/include/mcld/Script/UnaryOp.h
index b7f69c6..922e192 100644
--- a/include/mcld/Script/UnaryOp.h
+++ b/include/mcld/Script/UnaryOp.h
@@ -6,94 +6,86 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_UNARYOP_H
-#define MCLD_SCRIPT_UNARYOP_H
+#ifndef MCLD_SCRIPT_UNARYOP_H_
+#define MCLD_SCRIPT_UNARYOP_H_
+
+#include "mcld/Script/Operator.h"
-#include <mcld/Script/Operator.h>
#include <cstddef>
-namespace mcld
-{
+namespace mcld {
-class Operand;
class IntOperand;
class Module;
+class Operand;
class TargetLDBackend;
/** \class UnaryOp
* \brief This class defines the interfaces to an unary operator token.
*/
-template<Operator::Type TYPE>
-class UnaryOp : public Operator
-{
-private:
+template <Operator::Type TYPE>
+class UnaryOp : public Operator {
+ private:
friend class Operator;
- UnaryOp()
- : Operator(Operator::UNARY, TYPE), m_pOperand(NULL)
- {}
+ UnaryOp() : Operator(Operator::UNARY, TYPE), m_pOperand(NULL) {}
-public:
- ~UnaryOp()
- {}
+ public:
+ ~UnaryOp() {}
IntOperand* eval(const Module& pModule, const TargetLDBackend& pBackend);
- void appendOperand(Operand* pOperand)
- {
- m_pOperand = pOperand;
- }
+ void appendOperand(Operand* pOperand) { m_pOperand = pOperand; }
-private:
+ private:
Operand* m_pOperand;
};
-template<>
+template <>
IntOperand* UnaryOp<Operator::UNARY_PLUS>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* UnaryOp<Operator::UNARY_MINUS>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* UnaryOp<Operator::LOGICAL_NOT>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* UnaryOp<Operator::BITWISE_NOT>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* UnaryOp<Operator::ABSOLUTE>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* UnaryOp<Operator::ADDR>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* UnaryOp<Operator::ALIGNOF>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* UnaryOp<Operator::DATA_SEGMENT_END>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* UnaryOp<Operator::DEFINED>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* UnaryOp<Operator::LENGTH>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* UnaryOp<Operator::LOADADDR>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* UnaryOp<Operator::NEXT>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* UnaryOp<Operator::ORIGIN>::eval(const Module&,
const TargetLDBackend&);
-template<>
+template <>
IntOperand* UnaryOp<Operator::SIZEOF>::eval(const Module&,
const TargetLDBackend&);
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SCRIPT_UNARYOP_H_
diff --git a/include/mcld/Script/WildcardPattern.h b/include/mcld/Script/WildcardPattern.h
index fe81ee3..75b1405 100644
--- a/include/mcld/Script/WildcardPattern.h
+++ b/include/mcld/Script/WildcardPattern.h
@@ -6,24 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SCRIPT_WILDCARDPATTERN_H
-#define MCLD_SCRIPT_WILDCARDPATTERN_H
+#ifndef MCLD_SCRIPT_WILDCARDPATTERN_H_
+#define MCLD_SCRIPT_WILDCARDPATTERN_H_
+
+#include "mcld/Config/Config.h"
+#include "mcld/Script/StrToken.h"
+#include "mcld/Support/Allocators.h"
-#include <mcld/Script/StrToken.h>
-#include <mcld/Support/Allocators.h>
-#include <mcld/Config/Config.h>
#include <llvm/ADT/StringRef.h>
-namespace mcld
-{
+namespace mcld {
/** \class WildcardPattern
* \brief This class defines the interfaces to Input Section Wildcard Patterns
*/
-class WildcardPattern : public StrToken
-{
-public:
+class WildcardPattern : public StrToken {
+ public:
enum SortPolicy {
SORT_NONE,
SORT_BY_NAME,
@@ -33,12 +32,12 @@ public:
SORT_BY_INIT_PRIORITY
};
-private:
+ private:
friend class Chunk<WildcardPattern, MCLD_SYMBOLS_PER_INPUT>;
WildcardPattern();
WildcardPattern(const std::string& pPattern, SortPolicy pPolicy);
-public:
+ public:
~WildcardPattern();
SortPolicy sortPolicy() const { return m_SortPolicy; }
@@ -47,8 +46,7 @@ public:
llvm::StringRef prefix() const;
- static bool classof(const StrToken* pToken)
- {
+ static bool classof(const StrToken* pToken) {
return pToken->kind() == StrToken::Wildcard;
}
@@ -58,11 +56,11 @@ public:
static void destroy(WildcardPattern*& pToken);
static void clear();
-private:
+ private:
SortPolicy m_SortPolicy;
bool m_bIsPrefix;
};
-} // namepsace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SCRIPT_WILDCARDPATTERN_H_
diff --git a/include/mcld/Support/Allocators.h b/include/mcld/Support/Allocators.h
index bb95bd6..c66b77e 100644
--- a/include/mcld/Support/Allocators.h
+++ b/include/mcld/Support/Allocators.h
@@ -1,4 +1,4 @@
-//===- Allocators.h ---------------------------------------------------------===//
+//===- Allocators.h -------------------------------------------------------===//
//
// The MCLinker Project
//
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_ALLOCATORS_H
-#define MCLD_SUPPORT_ALLOCATORS_H
-#include <mcld/ADT/Uncopyable.h>
-#include <mcld/ADT/TypeTraits.h>
+#ifndef MCLD_SUPPORT_ALLOCATORS_H_
+#define MCLD_SUPPORT_ALLOCATORS_H_
+#include "mcld/ADT/TypeTraits.h"
+#include "mcld/Support/Compiler.h"
#include <cstddef>
#include <cstdlib>
@@ -21,44 +21,39 @@ namespace mcld {
*
* @see LinearAllocator
*/
-template<typename DataType, size_t ChunkSize>
-class Chunk
-{
-public:
+template <typename DataType, size_t ChunkSize>
+class Chunk {
+ public:
typedef DataType value_type;
-public:
- Chunk()
- : next(0), bound(0)
- { }
+
+ public:
+ Chunk() : next(NULL), bound(0) {}
static size_t size() { return ChunkSize; }
- static void construct(value_type* pPtr)
- { new (pPtr) value_type(); }
+ static void construct(value_type* pPtr) { new (pPtr) value_type(); }
- static void construct(value_type* pPtr, const value_type& pValue)
- { new (pPtr) value_type(pValue); }
+ static void construct(value_type* pPtr, const value_type& pValue) {
+ new (pPtr) value_type(pValue);
+ }
- static void destroy(value_type* pPtr)
- { }
+ static void destroy(value_type* pPtr) {}
-public:
+ public:
Chunk* next;
size_t bound;
DataType data[ChunkSize];
};
-template<typename DataType>
-class Chunk<DataType, 0>
-{
-public:
+template <typename DataType>
+class Chunk<DataType, 0> {
+ public:
typedef DataType value_type;
-public:
- Chunk()
- : next(0), bound(0) {
- if (0 != m_Size)
- data = (DataType*)malloc(sizeof(DataType)*m_Size);
+ public:
+ Chunk() : next(NULL), bound(0) {
+ if (m_Size != 0)
+ data = reinterpret_cast<DataType*>(malloc(sizeof(DataType) * m_Size));
else
data = 0;
}
@@ -72,79 +67,69 @@ public:
static void setSize(size_t pSize) { m_Size = pSize; }
- static void construct(value_type* pPtr)
- { new (pPtr) value_type(); }
+ static void construct(value_type* pPtr) { new (pPtr) value_type(); }
- static void construct(value_type* pPtr, const value_type& pValue)
- { new (pPtr) value_type(pValue); }
+ static void construct(value_type* pPtr, const value_type& pValue) {
+ new (pPtr) value_type(pValue);
+ }
- static void destroy(value_type* pPtr)
- { pPtr->~value_type(); }
+ static void destroy(value_type* pPtr) { pPtr->~value_type(); }
-public:
+ public:
Chunk* next;
size_t bound;
- DataType *data;
+ DataType* data;
static size_t m_Size;
};
-template<typename DataType>
+template <typename DataType>
size_t Chunk<DataType, 0>::m_Size = 0;
-template<typename ChunkType>
-class LinearAllocatorBase : private Uncopyable
-{
-public:
- typedef ChunkType chunk_type;
- typedef typename ChunkType::value_type value_type;
- typedef typename ChunkType::value_type* pointer;
- typedef typename ChunkType::value_type& reference;
+template <typename ChunkType>
+class LinearAllocatorBase {
+ public:
+ typedef ChunkType chunk_type;
+ typedef typename ChunkType::value_type value_type;
+ typedef typename ChunkType::value_type* pointer;
+ typedef typename ChunkType::value_type& reference;
typedef const typename ChunkType::value_type* const_pointer;
typedef const typename ChunkType::value_type& const_reference;
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef unsigned char byte_type;
-
-protected:
- LinearAllocatorBase()
- : m_pRoot(0),
- m_pCurrent(0),
- m_AllocatedNum(0) {
- }
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef unsigned char byte_type;
+
+ protected:
+ LinearAllocatorBase() : m_pRoot(NULL), m_pCurrent(NULL), m_AllocatedNum(0) {}
// LinearAllocatorBase does NOT mean to destroy the allocated memory.
// If you want a memory allocator to release memory at destruction, please
// use GCFactory series.
- virtual ~LinearAllocatorBase()
- { }
+ virtual ~LinearAllocatorBase() {}
-public:
- pointer address(reference X) const
- { return &X; }
+ public:
+ pointer address(reference X) const { return &X; }
- const_pointer address(const_reference X) const
- { return &X; }
+ const_pointer address(const_reference X) const { return &X; }
/// standard construct - constructing an object on the location pointed by
// pPtr, and using its copy constructor to initialized its value to pValue.
//
// @param pPtr the address where the object to be constructed
// @param pValue the value to be constructed
- void construct(pointer pPtr, const_reference pValue)
- { chunk_type::construct(pPtr, pValue); }
+ void construct(pointer pPtr, const_reference pValue) {
+ chunk_type::construct(pPtr, pValue);
+ }
/// default construct - constructing an object on the location pointed by
// pPtr, and using its default constructor to initialized its value to
// pValue.
//
// @param pPtr the address where the object to be constructed
- void construct(pointer pPtr)
- { chunk_type::construct(pPtr); }
+ void construct(pointer pPtr) { chunk_type::construct(pPtr); }
/// standard destroy - destroy data on arbitrary address
// @para pPtr the address where the data to be destruected.
- void destroy(pointer pPtr)
- { chunk_type::destroy(pPtr); }
+ void destroy(pointer pPtr) { chunk_type::destroy(pPtr); }
/// allocate - allocate N data in order.
// - Disallow to allocate a chunk whose size is bigger than a chunk.
@@ -152,7 +137,7 @@ public:
// @param N the number of allocated data.
// @return the start address of the allocated memory
pointer allocate(size_type N) {
- if (0 == N || N > chunk_type::size())
+ if (N == 0 || N > chunk_type::size())
return 0;
if (empty())
@@ -183,10 +168,8 @@ public:
/// deallocate - deallocate N data from the pPtr
// - if we can simply release some memory, then do it. Otherwise, do
// nothing.
- void deallocate(pointer &pPtr, size_type N) {
- if (0 == N ||
- N > chunk_type::size() ||
- 0 == m_pCurrent->bound ||
+ void deallocate(pointer& pPtr, size_type N) {
+ if (N == 0 || N > chunk_type::size() || m_pCurrent->bound == 0 ||
N >= m_pCurrent->bound)
return;
if (!isAvailable(pPtr))
@@ -196,8 +179,8 @@ public:
}
/// deallocate - clone function of deallocating one datum
- void deallocate(pointer &pPtr) {
- if (0 == m_pCurrent->bound)
+ void deallocate(pointer& pPtr) {
+ if (m_pCurrent->bound == 0)
return;
if (!isAvailable(pPtr))
return;
@@ -208,7 +191,7 @@ public:
/// isIn - whether the pPtr is in the current chunk?
bool isIn(pointer pPtr) const {
if (pPtr >= &(m_pCurrent->data[0]) &&
- pPtr <= &(m_pCurrent->data[chunk_type::size()-1]))
+ pPtr <= &(m_pCurrent->data[chunk_type::size() - 1]))
return true;
return false;
}
@@ -216,7 +199,7 @@ public:
/// isIn - whether the pPtr is allocated, and can be constructed.
bool isAvailable(pointer pPtr) const {
if (pPtr >= &(m_pCurrent->data[m_pCurrent->bound]) &&
- pPtr <= &(m_pCurrent->data[chunk_type::size()-1]))
+ pPtr <= &(m_pCurrent->data[chunk_type::size() - 1]))
return true;
return false;
}
@@ -229,8 +212,8 @@ public:
/// clear - clear all chunks
void clear() {
- chunk_type *cur = m_pRoot, *prev;
- while (0 != cur) {
+ chunk_type* cur = m_pRoot, *prev;
+ while (cur != 0) {
prev = cur;
cur = cur->next;
for (unsigned int idx = 0; idx != prev->bound; ++idx)
@@ -241,32 +224,32 @@ public:
}
// ----- observers ----- //
- bool empty() const {
- return (0 == m_pRoot);
- }
+ bool empty() const { return (m_pRoot == 0); }
- size_type max_size() const
- { return m_AllocatedNum; }
+ size_type max_size() const { return m_AllocatedNum; }
-protected:
+ protected:
inline void initialize() {
m_pRoot = new chunk_type();
m_pCurrent = m_pRoot;
m_AllocatedNum += chunk_type::size();
}
- inline chunk_type *getNewChunk() {
- chunk_type *result = new chunk_type();
+ inline chunk_type* getNewChunk() {
+ chunk_type* result = new chunk_type();
m_pCurrent->next = result;
m_pCurrent = result;
m_AllocatedNum += chunk_type::size();
return result;
}
-protected:
- chunk_type *m_pRoot;
- chunk_type *m_pCurrent;
- size_type m_AllocatedNum;
+ protected:
+ chunk_type* m_pRoot;
+ chunk_type* m_pCurrent;
+ size_type m_AllocatedNum;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LinearAllocatorBase);
};
/** \class LinearAllocator
@@ -285,167 +268,145 @@ protected:
* template argument DataType is the DataType to be allocated
* template argument ChunkSize is the number of bytes of a chunk
*/
-template<typename DataType, size_t ChunkSize>
-class LinearAllocator : public LinearAllocatorBase<Chunk<DataType, ChunkSize> >
-{
-public:
- template<typename NewDataType>
+template <typename DataType, size_t ChunkSize>
+class LinearAllocator
+ : public LinearAllocatorBase<Chunk<DataType, ChunkSize> > {
+ public:
+ template <typename NewDataType>
struct rebind {
typedef LinearAllocator<NewDataType, ChunkSize> other;
};
-public:
- LinearAllocator()
- : LinearAllocatorBase<Chunk<DataType, ChunkSize> >() {
- }
+ public:
+ LinearAllocator() : LinearAllocatorBase<Chunk<DataType, ChunkSize> >() {}
- virtual ~LinearAllocator()
- { }
+ virtual ~LinearAllocator() {}
};
-template<typename DataType>
-class LinearAllocator<DataType, 0> : public LinearAllocatorBase<Chunk<DataType, 0> >
-{
-public:
- template<typename NewDataType>
+template <typename DataType>
+class LinearAllocator<DataType, 0>
+ : public LinearAllocatorBase<Chunk<DataType, 0> > {
+ public:
+ template <typename NewDataType>
struct rebind {
typedef LinearAllocator<NewDataType, 0> other;
};
-public:
+ public:
explicit LinearAllocator(size_t pNum)
- : LinearAllocatorBase<Chunk<DataType, 0> >() {
+ : LinearAllocatorBase<Chunk<DataType, 0> >() {
Chunk<DataType, 0>::setSize(pNum);
}
- virtual ~LinearAllocator()
- { }
+ virtual ~LinearAllocator() {}
};
-template<typename DataType>
-class MallocAllocator
-{
-public:
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef DataType* pointer;
+template <typename DataType>
+class MallocAllocator {
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef DataType* pointer;
typedef const DataType* const_pointer;
- typedef DataType& reference;
+ typedef DataType& reference;
typedef const DataType& const_reference;
- typedef DataType value_type;
+ typedef DataType value_type;
- template<typename OtherDataType>
- struct rebind
- {
+ template <typename OtherDataType>
+ struct rebind {
typedef MallocAllocator<OtherDataType> other;
};
-public:
- MallocAllocator() throw()
- { }
+ public:
+ MallocAllocator() throw() {}
- MallocAllocator(const MallocAllocator&) throw()
- { }
+ MallocAllocator(const MallocAllocator&) throw() {}
- ~MallocAllocator() throw()
- { }
+ ~MallocAllocator() throw() {}
- pointer address(reference X) const
- { return &X; }
+ pointer address(reference X) const { return &X; }
- const_pointer address(const_reference X) const
- { return &X; }
+ const_pointer address(const_reference X) const { return &X; }
- pointer allocate(size_type pNumOfElements, const void* = 0)
- {
+ pointer allocate(size_type pNumOfElements, const void* = 0) {
return static_cast<DataType*>(
- std::malloc(pNumOfElements*sizeof(DataType)));
+ std::malloc(pNumOfElements * sizeof(DataType)));
}
- void deallocate(pointer pObject, size_type)
- { std::free(static_cast<void*>(pObject)); }
-
- size_type max_size() const throw()
- { return size_t(-1) / sizeof(DataType); }
+ void deallocate(pointer pObject, size_type) {
+ std::free(static_cast<void*>(pObject));
+ }
- void construct(pointer pObject, const DataType& pValue)
- { ::new((void *)pObject) value_type(pValue); }
+ size_type max_size() const throw() { return size_t(-1) / sizeof(DataType); }
- void destroy(pointer pObject)
- { pObject->~DataType(); }
+ void construct(pointer pObject, const DataType& pValue) {
+ ::new (reinterpret_cast<void*>(pObject)) value_type(pValue);
+ }
+ void destroy(pointer pObject) { pObject->~DataType(); }
};
-template<>
-class MallocAllocator<void>
-{
-public:
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef void* pointer;
+template <>
+class MallocAllocator<void> {
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef void* pointer;
typedef const void* const_pointer;
- typedef void* reference;
+ typedef void* reference;
typedef const void* const_reference;
- typedef void* value_type;
+ typedef void* value_type;
- template<typename OtherDataType>
- struct rebind
- {
+ template <typename OtherDataType>
+ struct rebind {
typedef MallocAllocator<OtherDataType> other;
};
-public:
- MallocAllocator() throw()
- { }
+ public:
+ MallocAllocator() throw() {}
- MallocAllocator(const MallocAllocator&) throw()
- { }
+ MallocAllocator(const MallocAllocator&) throw() {}
- ~MallocAllocator() throw()
- { }
+ ~MallocAllocator() throw() {}
- size_type max_size() const throw()
- { return size_t(-1) / sizeof(void*); }
+ size_type max_size() const throw() { return size_t(-1) / sizeof(void*); }
- pointer address(reference X) const
- { return X; }
+ pointer address(reference X) const { return X; }
- const_pointer address(const_reference X) const
- { return X; }
+ const_pointer address(const_reference X) const { return X; }
- template<typename DataType>
+ template <typename DataType>
DataType* allocate(size_type pNumOfElements, const void* = 0) {
return static_cast<DataType*>(
- std::malloc(pNumOfElements*sizeof(DataType)));
+ std::malloc(pNumOfElements * sizeof(DataType)));
}
pointer allocate(size_type pNumOfElements, const void* = 0) {
return std::malloc(pNumOfElements);
}
- template<typename DataType>
- void deallocate(DataType* pObject, size_type)
- { std::free(static_cast<void*>(pObject)); }
+ template <typename DataType>
+ void deallocate(DataType* pObject, size_type) {
+ std::free(static_cast<void*>(pObject));
+ }
- void deallocate(pointer pObject, size_type)
- { std::free(pObject); }
+ void deallocate(pointer pObject, size_type) { std::free(pObject); }
- template<typename DataType>
- void construct(DataType* pObject, const DataType& pValue)
- { /* do nothing */ }
+ template <typename DataType>
+ void construct(DataType* pObject, const DataType& pValue) { /* do nothing */
+ }
- void construct(pointer pObject, const_reference pValue)
- { /* do nothing */ }
+ void construct(pointer pObject, const_reference pValue) { /* do nothing */
+ }
- template<typename DataType>
- void destroy(DataType* pObject)
- { /* do nothing */ }
+ template <typename DataType>
+ void destroy(DataType* pObject) { /* do nothing */
+ }
- void destroy(pointer pObject)
- { /* do nothing */ }
+ void destroy(pointer pObject) { /* do nothing */
+ }
};
-} // namespace mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SUPPORT_ALLOCATORS_H_
diff --git a/include/mcld/Support/CommandLine.h b/include/mcld/Support/CommandLine.h
index 1801354..8c10b91 100644
--- a/include/mcld/Support/CommandLine.h
+++ b/include/mcld/Support/CommandLine.h
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_COMMANDLINE_H
-#define MCLD_SUPPORT_COMMANDLINE_H
-#include <mcld/Support/FileSystem.h>
-#include <mcld/MC/ZOption.h>
+#ifndef MCLD_SUPPORT_COMMANDLINE_H_
+#define MCLD_SUPPORT_COMMANDLINE_H_
+#include "mcld/MC/ZOption.h"
+#include "mcld/Support/FileSystem.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/Triple.h>
@@ -23,18 +23,17 @@ namespace cl {
//===----------------------------------------------------------------------===//
// SearchDirParser
//===----------------------------------------------------------------------===//
-class SearchDirParser : public llvm::cl::basic_parser<std::string>
-{
-public:
+class SearchDirParser : public llvm::cl::basic_parser<std::string> {
+ public:
// parse - Return true on error.
- bool parse(Option &pOption,
+ bool parse(Option& pOption,
StringRef pArgName,
StringRef pArg,
- std::string &pValue);
+ std::string& pValue);
- const char *getValueName() const { return "searchdir"; }
+ const char* getValueName() const { return "searchdir"; }
- void printOptionDiff(const Option &pOption,
+ void printOptionDiff(const Option& pOption,
StringRef pValue,
OptVal pDefault,
size_t pGlobalWidth) const;
@@ -45,11 +44,10 @@ public:
//===----------------------------------------------------------------------===//
// FalseParser
//===----------------------------------------------------------------------===//
-class FalseParser : public cl::parser<bool>
-{
-public:
+class FalseParser : public cl::parser<bool> {
+ public:
// parse - Return true on error.
- bool parse(cl::Option &O, StringRef ArgName, StringRef Arg, bool &Val) {
+ bool parse(cl::Option& O, StringRef ArgName, StringRef Arg, bool& Val) {
if (cl::parser<bool>::parse(O, ArgName, Arg, Val))
return false;
Val = false;
@@ -60,18 +58,17 @@ public:
//===----------------------------------------------------------------------===//
// parser<mcld::sys::fs::Path>
//===----------------------------------------------------------------------===//
-template<>
-class parser<mcld::sys::fs::Path> : public basic_parser<mcld::sys::fs::Path>
-{
-public:
- bool parse(Option &O,
+template <>
+class parser<mcld::sys::fs::Path> : public basic_parser<mcld::sys::fs::Path> {
+ public:
+ bool parse(Option& O,
StringRef ArgName,
StringRef Arg,
- mcld::sys::fs::Path &Val);
+ mcld::sys::fs::Path& Val);
- virtual const char *getValueName() const { return "path"; }
- void printOptionDiff(const Option &O,
- const mcld::sys::fs::Path &V,
+ virtual const char* getValueName() const { return "path"; }
+ void printOptionDiff(const Option& O,
+ const mcld::sys::fs::Path& V,
OptVal Default,
size_t GlobalWidth) const;
virtual void anchor();
@@ -80,22 +77,20 @@ public:
//===----------------------------------------------------------------------===//
// parser<mcld::ZOption>
//===----------------------------------------------------------------------===//
-template<>
-class parser<mcld::ZOption> : public llvm::cl::basic_parser<mcld::ZOption>
-{
-public:
- bool parse(Option &O, StringRef ArgName, StringRef Arg, mcld::ZOption &Val);
+template <>
+class parser<mcld::ZOption> : public llvm::cl::basic_parser<mcld::ZOption> {
+ public:
+ bool parse(Option& O, StringRef ArgName, StringRef Arg, mcld::ZOption& Val);
- virtual const char *getValueName() const { return "z-option"; }
- void printOptionDiff(const Option &O,
- const mcld::ZOption &V,
+ virtual const char* getValueName() const { return "z-option"; }
+ void printOptionDiff(const Option& O,
+ const mcld::ZOption& V,
OptVal Default,
size_t GlobalWidth) const;
virtual void anchor();
};
-} // namespace of cl
-} // namespace of llvm
-
-#endif
+} // namespace cl
+} // namespace llvm
+#endif // MCLD_SUPPORT_COMMANDLINE_H_
diff --git a/include/mcld/Support/Compiler.h b/include/mcld/Support/Compiler.h
new file mode 100644
index 0000000..9a0d738
--- /dev/null
+++ b/include/mcld/Support/Compiler.h
@@ -0,0 +1,30 @@
+//===- Compiler.h ---------------------------------------------------------===//
+//
+// The MCLinker Project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#ifndef MCLD_SUPPORT_COMPILER_H_
+#define MCLD_SUPPORT_COMPILER_H_
+
+#include <llvm/Support/Compiler.h>
+
+// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions. It goes
+// in the private: declarations in a class.
+#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
+ TypeName(const TypeName&) = delete; \
+ void operator=(const TypeName&) = delete
+
+// A macro to disallow all the implicit constructors, namely the default
+// constructor, copy constructor and operator= functions.
+//
+// This should be used in the private: declarations for a class that wants to
+// prevent anyone from instantiating it. This is especially useful for classes
+// containing only static methods.
+#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
+ TypeName() = delete; \
+ DISALLOW_COPY_AND_ASSIGN(TypeName)
+
+#endif // MCLD_SUPPORT_COMPILER_H_
diff --git a/include/mcld/Support/Demangle.h b/include/mcld/Support/Demangle.h
index b6f7412..6f671b9 100644
--- a/include/mcld/Support/Demangle.h
+++ b/include/mcld/Support/Demangle.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_DEMANGLE_H
-#define MCLD_SUPPORT_DEMANGLE_H
+#ifndef MCLD_SUPPORT_DEMANGLE_H_
+#define MCLD_SUPPORT_DEMANGLE_H_
#include <string>
@@ -17,6 +17,6 @@ std::string demangleName(const std::string& mangled_name);
bool isCtorOrDtor(const char* pName, size_t pLength);
-} // namespace mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SUPPORT_DEMANGLE_H_
diff --git a/include/mcld/Support/Directory.h b/include/mcld/Support/Directory.h
index 09b7221..00ba531 100644
--- a/include/mcld/Support/Directory.h
+++ b/include/mcld/Support/Directory.h
@@ -6,17 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_DIRECTORY_H
-#define MCLD_SUPPORT_DIRECTORY_H
+#ifndef MCLD_SUPPORT_DIRECTORY_H_
+#define MCLD_SUPPORT_DIRECTORY_H_
+
+#include "mcld/ADT/TypeTraits.h"
+#include "mcld/Support/FileSystem.h"
+#include "mcld/Support/Path.h"
+#include "mcld/Support/PathCache.h"
-#include <mcld/ADT/TypeTraits.h>
-#include <mcld/Support/FileSystem.h>
-#include <mcld/Support/Path.h>
#include <llvm/Support/Allocator.h>
#include <cstddef>
-#include "PathCache.h"
-
namespace mcld {
namespace sys {
namespace fs {
@@ -28,18 +28,19 @@ class DirIterator;
* non-symbolic link status, and a FileStatus object for symbolic link
* status. The FileStatus objects act as value caches.
*/
-class Directory
-{
-friend mcld::sys::fs::PathCache::entry_type* detail::bring_one_into_cache(DirIterator& pIter);
-friend void detail::open_dir(Directory& pDir);
-friend void detail::close_dir(Directory& pDir);
-private:
+class Directory {
+ friend mcld::sys::fs::PathCache::entry_type* detail::bring_one_into_cache(
+ DirIterator& pIter);
+ friend void detail::open_dir(Directory& pDir);
+ friend void detail::close_dir(Directory& pDir);
+
+ private:
friend class DirIterator;
-public:
+ public:
typedef DirIterator iterator;
-public:
+ public:
/// default constructor
Directory();
@@ -48,6 +49,10 @@ public:
FileStatus st = FileStatus(),
FileStatus symlink_st = FileStatus());
+ explicit Directory(const char* pPath,
+ FileStatus st = FileStatus(),
+ FileStatus symlink_st = FileStatus());
+
/// copy constructor
/// when a copying construction happens, the cache is not copied.
Directory(const Directory& pCopy);
@@ -70,8 +75,7 @@ public:
bool isGood() const;
/// path - the path of the directory
- const Path& path() const
- { return m_Path; }
+ const Path& path() const { return m_Path; }
FileStatus status() const;
FileStatus symlinkStatus() const;
@@ -82,7 +86,7 @@ public:
iterator begin();
iterator end();
-protected:
+ protected:
mcld::sys::fs::Path m_Path;
mutable FileStatus m_FileStatus;
mutable FileStatus m_SymLinkStatus;
@@ -102,28 +106,28 @@ protected:
*
* @see Directory
*/
-class DirIterator
-{
-friend mcld::sys::fs::PathCache::entry_type* detail::bring_one_into_cache(DirIterator& pIter);
-friend class Directory;
-public:
- typedef mcld::sys::fs::PathCache DirCache;
-
-public:
- typedef Directory value_type;
- typedef ConstTraits<Directory> const_traits;
- typedef NonConstTraits<Directory> non_const_traits;
- typedef std::input_iterator_tag iterator_category;
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
-
-private:
- explicit DirIterator(Directory* pParent,
- const DirCache::iterator& pIter);
-
-public:
+class DirIterator {
+ friend mcld::sys::fs::PathCache::entry_type* detail::bring_one_into_cache(
+ DirIterator& pIter);
+ friend class Directory;
+
+ public:
+ typedef mcld::sys::fs::PathCache DirCache;
+
+ public:
+ typedef Directory value_type;
+ typedef ConstTraits<Directory> const_traits;
+ typedef NonConstTraits<Directory> non_const_traits;
+ typedef std::input_iterator_tag iterator_category;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+
+ private:
+ explicit DirIterator(Directory* pParent, const DirCache::iterator& pIter);
+
+ public:
// Since StringMapIterator has no default constructor, we also have none.
- DirIterator(const DirIterator &X);
+ DirIterator(const DirIterator& X);
~DirIterator();
DirIterator& operator=(const DirIterator& pCopy);
@@ -138,14 +142,14 @@ public:
bool operator==(const DirIterator& y) const;
bool operator!=(const DirIterator& y) const;
-private:
- Directory* m_pParent; // get handler
- DirCache::iterator m_Iter; // for full situation
+ private:
+ Directory* m_pParent; // get handler
+ DirCache::iterator m_Iter; // for full situation
DirCache::entry_type* m_pEntry;
};
-} // namespace of fs
-} // namespace of sys
-} // namespace of mcld
+} // namespace fs
+} // namespace sys
+} // namespace mcld
-#endif
+#endif // MCLD_SUPPORT_DIRECTORY_H_
diff --git a/include/mcld/Support/ELF.h b/include/mcld/Support/ELF.h
index 321c3c6..d1cdc0c 100644
--- a/include/mcld/Support/ELF.h
+++ b/include/mcld/Support/ELF.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_ELF_H
-#define MCLD_SUPPORT_ELF_H
+#ifndef MCLD_SUPPORT_ELF_H_
+#define MCLD_SUPPORT_ELF_H_
namespace mcld {
namespace ELF {
@@ -18,17 +18,11 @@ enum SHF {
// other sections of the same type.
SHF_ORDERED = 0x40000000,
- // This section is excluded from input of an executable or shared object.
- // Ignore this flag if SHF_ALLOC is also set or if a relocation refers to
- // the section
- SHF_EXCLUDE = 0x80000000,
-
// Section with data that is GP relative addressable.
SHF_MIPS_GPREL = 0x10000000
-}; // enum SHF
-
-} // namespace of ELF
-} // namespace of mcld
+}; // enum SHF
-#endif
+} // namespace ELF
+} // namespace mcld
+#endif // MCLD_SUPPORT_ELF_H_
diff --git a/include/mcld/Support/FileHandle.h b/include/mcld/Support/FileHandle.h
index ecd335c..96467f1 100644
--- a/include/mcld/Support/FileHandle.h
+++ b/include/mcld/Support/FileHandle.h
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_FILEHANDLE_H
-#define MCLD_SUPPORT_FILEHANDLE_H
-#include <mcld/Support/Path.h>
-#include <mcld/ADT/Flags.h>
+#ifndef MCLD_SUPPORT_FILEHANDLE_H_
+#define MCLD_SUPPORT_FILEHANDLE_H_
+#include "mcld/ADT/Flags.h"
+#include "mcld/Support/Path.h"
#include <errno.h>
@@ -22,50 +22,46 @@ namespace mcld {
* Operators of FileHandle should neither throw exceptions nor call expressive
* diagnostic output.
*/
-class FileHandle
-{
-public:
- enum IOState
- {
- GoodBit = 0, // no error
- BadBit = 1L << 0, // error due to the inappropriate operation
- EOFBit = 1L << 1, // reached End-Of-File
- FailBit = 1L << 2, // internal logic fail
- DeputedBit = 1L << 3, // the file descriptor is delegated
+class FileHandle {
+ public:
+ enum IOState {
+ GoodBit = 0, // no error
+ BadBit = 1L << 0, // error due to the inappropriate operation
+ EOFBit = 1L << 1, // reached End-Of-File
+ FailBit = 1L << 2, // internal logic fail
+ DeputedBit = 1L << 3, // the file descriptor is delegated
IOStateEnd = 1L << 16
};
- enum OpenModeEnum
- {
- NotOpen = 0x00,
- ReadOnly = 0x01,
+ enum OpenModeEnum {
+ NotOpen = 0x00,
+ ReadOnly = 0x01,
WriteOnly = 0x02,
ReadWrite = ReadOnly | WriteOnly,
- Append = 0x04,
- Create = 0x08,
- Truncate = 0x10,
- Unknown = 0xFF
+ Append = 0x04,
+ Create = 0x08,
+ Truncate = 0x10,
+ Unknown = 0xFF
};
typedef Flags<OpenModeEnum> OpenMode;
- enum PermissionEnum
- {
- ReadOwner = 0x0400,
- WriteOwner = 0x0200,
- ExeOwner = 0x0100,
- ReadGroup = 0x0040,
- WriteGroup = 0x0020,
- ExeGroup = 0x0010,
- ReadOther = 0x0004,
- WriteOther = 0x0002,
- ExeOther = 0x0001,
- System = 0xFFFF
+ enum PermissionEnum {
+ ReadOwner = 0x0400,
+ WriteOwner = 0x0200,
+ ExeOwner = 0x0100,
+ ReadGroup = 0x0040,
+ WriteGroup = 0x0020,
+ ExeGroup = 0x0010,
+ ReadOther = 0x0004,
+ WriteOther = 0x0002,
+ ExeOther = 0x0001,
+ System = 0xFFFF
};
typedef Flags<PermissionEnum> Permission;
-public:
+ public:
FileHandle();
~FileHandle();
@@ -73,11 +69,9 @@ public:
/// open - open the file.
/// @return if we meet any trouble during opening the file, return false.
/// use rdstate() to see what happens.
- bool open(const sys::fs::Path& pPath,
- OpenMode pMode,
- Permission pPerm = System);
+ bool open(const sys::fs::Path& pPath, OpenMode pMode, Permission pPerm);
- bool delegate(int pFD, OpenMode pMode = Unknown);
+ bool delegate(int pFD, OpenModeEnum pMode = Unknown);
bool close();
@@ -97,17 +91,13 @@ public:
bool munmap(void* pMemBuffer, size_t pLength);
// ----- observers ----- //
- const sys::fs::Path& path() const
- { return m_Path; }
+ const sys::fs::Path& path() const { return m_Path; }
- size_t size() const
- { return m_Size; }
+ size_t size() const { return m_Size; }
- int handler() const
- { return m_Handler; }
+ int handler() const { return m_Handler; }
- uint16_t rdstate() const
- { return m_State; }
+ uint16_t rdstate() const { return m_State; }
bool isOpened() const;
@@ -127,7 +117,7 @@ public:
int error() const { return errno; }
-private:
+ private:
sys::fs::Path m_Path;
int m_Handler;
unsigned int m_Size;
@@ -135,7 +125,6 @@ private:
OpenMode m_OpenMode;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SUPPORT_FILEHANDLE_H_
diff --git a/include/mcld/Support/FileOutputBuffer.h b/include/mcld/Support/FileOutputBuffer.h
index 6b48e14..afe670f 100644
--- a/include/mcld/Support/FileOutputBuffer.h
+++ b/include/mcld/Support/FileOutputBuffer.h
@@ -6,13 +6,15 @@
// license. see license.txt for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_FILEOUTPUTBUFFER_H
-#define MCLD_SUPPORT_FILEOUTPUTBUFFER_H
+#ifndef MCLD_SUPPORT_FILEOUTPUTBUFFER_H_
+#define MCLD_SUPPORT_FILEOUTPUTBUFFER_H_
+
+#include "mcld/Support/MemoryRegion.h"
-#include <mcld/Support/MemoryRegion.h>
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/DataTypes.h>
#include <llvm/Support/FileSystem.h>
+
#include <system_error>
namespace mcld {
@@ -22,7 +24,7 @@ class FileHandle;
/// FileOutputBuffer - This interface is borrowed from llvm bassically, and we
/// may use ostream to emit output later.
class FileOutputBuffer {
-public:
+ public:
/// Factory method to create an OutputBuffer object which manages a read/write
/// buffer of the specified size. When committed, the buffer will be written
/// to the file at the specified path.
@@ -32,18 +34,16 @@ public:
/// Returns a pointer to the start of the buffer.
uint8_t* getBufferStart() {
- return (uint8_t*)m_pRegion->data();
+ return reinterpret_cast<uint8_t*>(m_pRegion->data());
}
/// Returns a pointer to the end of the buffer.
uint8_t* getBufferEnd() {
- return (uint8_t*)m_pRegion->data() + m_pRegion->size();
+ return reinterpret_cast<uint8_t*>(m_pRegion->data()) + m_pRegion->size();
}
/// Returns size of the buffer.
- size_t getBufferSize() const {
- return m_pRegion->size();
- }
+ size_t getBufferSize() const { return m_pRegion->size(); }
MemoryRegion request(size_t pOffset, size_t pLength);
@@ -52,9 +52,9 @@ public:
~FileOutputBuffer();
-private:
- FileOutputBuffer(const FileOutputBuffer &);
- FileOutputBuffer &operator=(const FileOutputBuffer &);
+ private:
+ FileOutputBuffer(const FileOutputBuffer&);
+ FileOutputBuffer& operator=(const FileOutputBuffer&);
FileOutputBuffer(llvm::sys::fs::mapped_file_region* pRegion,
FileHandle& pFileHandle);
@@ -63,6 +63,6 @@ private:
FileHandle& m_FileHandle;
};
-} // namespace mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SUPPORT_FILEOUTPUTBUFFER_H_
diff --git a/include/mcld/Support/FileSystem.h b/include/mcld/Support/FileSystem.h
index ba4edff..15b33f9 100644
--- a/include/mcld/Support/FileSystem.h
+++ b/include/mcld/Support/FileSystem.h
@@ -10,23 +10,22 @@
// filesystem (v3), but modified to remove exception handling and the
// path class.
//===----------------------------------------------------------------------===//
+#ifndef MCLD_SUPPORT_FILESYSTEM_H_
+#define MCLD_SUPPORT_FILESYSTEM_H_
-#ifndef MCLD_SUPPORT_FILESYSTEM_H
-#define MCLD_SUPPORT_FILESYSTEM_H
-
+#include "mcld/Config/Config.h"
#include "mcld/Support/PathCache.h"
-#include <mcld/Config/Config.h>
-#include <string>
+
#include <iosfwd>
#include <locale>
+#include <string>
namespace mcld {
namespace sys {
namespace fs {
-enum FileType
-{
+enum FileType {
StatusError,
StatusUnknown = StatusError,
FileNotFound,
@@ -46,19 +45,16 @@ enum FileType
/** \class FileStatus
* \brief FileStatus
*/
-class FileStatus
-{
-public:
- FileStatus()
- : m_Value(StatusError) {}
+class FileStatus {
+ public:
+ FileStatus() : m_Value(StatusError) {}
- explicit FileStatus(FileType v)
- : m_Value(v) {}
+ explicit FileStatus(FileType v) : m_Value(v) {}
- void setType(FileType v) { m_Value = v; }
- FileType type() const { return m_Value; }
+ void setType(FileType v) { m_Value = v; }
+ FileType type() const { return m_Value; }
-private:
+ private:
FileType m_Value;
};
@@ -66,7 +62,7 @@ inline bool operator==(const FileStatus& rhs, const FileStatus& lhs) {
return rhs.type() == lhs.type();
}
-inline bool operator!=(const FileStatus& rhs, const FileStatus& lhs ) {
+inline bool operator!=(const FileStatus& rhs, const FileStatus& lhs) {
return !(rhs == lhs);
}
@@ -74,8 +70,8 @@ class Path;
class DirIterator;
class Directory;
-bool exists(const Path &pPath);
-bool is_directory(const Path &pPath);
+bool exists(const Path& pPath);
+bool is_directory(const Path& pPath);
namespace detail {
@@ -100,14 +96,17 @@ int open(const Path& pPath, int pOFlag, int pPermission);
ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset);
ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset);
int ftruncate(int pFD, size_t pLength);
-void* mmap(void *pAddr, size_t pLen,
- int pProt, int pFlags, int pFD, off_t pOffset);
-int munmap(void *pAddr, size_t pLen);
-
-} // namespace of detail
-} // namespace of fs
-} // namespace of sys
-} // namespace of mcld
-
-#endif
-
+void* mmap(void* pAddr,
+ size_t pLen,
+ int pProt,
+ int pFlags,
+ int pFD,
+ off_t pOffset);
+int munmap(void* pAddr, size_t pLen);
+
+} // namespace detail
+} // namespace fs
+} // namespace sys
+} // namespace mcld
+
+#endif // MCLD_SUPPORT_FILESYSTEM_H_
diff --git a/include/mcld/Support/GCFactory.h b/include/mcld/Support/GCFactory.h
index 452f539..fd86cdd 100644
--- a/include/mcld/Support/GCFactory.h
+++ b/include/mcld/Support/GCFactory.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_GCFACTORY_H
-#define MCLD_SUPPORT_GCFACTORY_H
+#ifndef MCLD_SUPPORT_GCFACTORY_H_
+#define MCLD_SUPPORT_GCFACTORY_H_
#include "mcld/ADT/TypeTraits.h"
#include "mcld/Support/Allocators.h"
@@ -15,24 +15,21 @@
#include <cstddef>
#include <iterator>
-namespace mcld
-{
+namespace mcld {
/** \class DataIteratorBase
* \brief DataIteratorBase provides the basic functions of DataIterator
* @see DataIterator
*/
-template<typename ChunkType>
-struct DataIteratorBase
-{
-public:
+template <typename ChunkType>
+struct DataIteratorBase {
+ public:
ChunkType* m_pChunk;
unsigned int m_Pos;
-public:
+ public:
DataIteratorBase(ChunkType* X, unsigned int pPos)
- : m_pChunk(X), m_Pos(pPos)
- { }
+ : m_pChunk(X), m_Pos(pPos) {}
inline void advance() {
++m_Pos;
@@ -44,55 +41,49 @@ public:
}
}
- bool operator==(const DataIteratorBase& y) const
- { return ((this->m_pChunk == y.m_pChunk) && (this->m_Pos == y.m_Pos)); }
+ bool operator==(const DataIteratorBase& y) const {
+ return ((this->m_pChunk == y.m_pChunk) && (this->m_Pos == y.m_Pos));
+ }
- bool operator!=(const DataIteratorBase& y) const
- { return ((this->m_pChunk != y.m_pChunk) || (this->m_Pos != y.m_Pos)); }
+ bool operator!=(const DataIteratorBase& y) const {
+ return ((this->m_pChunk != y.m_pChunk) || (this->m_Pos != y.m_Pos));
+ }
};
/** \class DataIterator
* \brief DataIterator provides STL compatible iterator for allocators
*/
-template<typename ChunkType, class Traits>
-class DataIterator : public DataIteratorBase<ChunkType>
-{
-public:
- typedef typename ChunkType::value_type value_type;
- typedef Traits traits;
- typedef typename traits::pointer pointer;
- typedef typename traits::reference reference;
+template <typename ChunkType, class Traits>
+class DataIterator : public DataIteratorBase<ChunkType> {
+ public:
+ typedef typename ChunkType::value_type value_type;
+ typedef Traits traits;
+ typedef typename traits::pointer pointer;
+ typedef typename traits::reference reference;
typedef DataIterator<ChunkType, Traits> Self;
- typedef DataIteratorBase<ChunkType> Base;
+ typedef DataIteratorBase<ChunkType> Base;
- typedef typename traits::nonconst_traits nonconst_traits;
+ typedef typename traits::nonconst_traits nonconst_traits;
typedef DataIterator<ChunkType, nonconst_traits> iterator;
- typedef typename traits::const_traits const_traits;
- typedef DataIterator<ChunkType, const_traits> const_iterator;
- typedef std::forward_iterator_tag iterator_category;
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
+ typedef typename traits::const_traits const_traits;
+ typedef DataIterator<ChunkType, const_traits> const_iterator;
+ typedef std::forward_iterator_tag iterator_category;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
-public:
- DataIterator()
- : Base(0, 0)
- { }
+ public:
+ DataIterator() : Base(NULL, 0) {}
- DataIterator(ChunkType* pChunk, unsigned int pPos)
- : Base(pChunk, pPos)
- { }
+ DataIterator(ChunkType* pChunk, unsigned int pPos) : Base(pChunk, pPos) {}
- DataIterator(const DataIterator& pCopy)
- : Base(pCopy.m_pChunk, pCopy.m_Pos)
- { }
+ DataIterator(const DataIterator& pCopy) : Base(pCopy.m_pChunk, pCopy.m_Pos) {}
- ~DataIterator()
- { }
+ ~DataIterator() {}
// ----- operators ----- //
reference operator*() {
- if (0 == this->m_pChunk)
- assert(0 && "data iterator goes to a invalid position");
+ assert(this->m_pChunk != NULL &&
+ "data iterator goes to a invalid position");
return this->m_pChunk->data[Base::m_Pos];
}
@@ -108,39 +99,31 @@ public:
}
};
-template<typename Alloc>
-class GCFactoryBase : public Alloc
-{
-public:
+template <typename Alloc>
+class GCFactoryBase : public Alloc {
+ public:
typedef DataIterator<typename Alloc::chunk_type,
- NonConstTraits<
- typename Alloc::value_type> > iterator;
+ NonConstTraits<typename Alloc::value_type> > iterator;
typedef DataIterator<typename Alloc::chunk_type,
- ConstTraits<
- typename Alloc::value_type> > const_iterator;
+ ConstTraits<typename Alloc::value_type> > const_iterator;
typedef typename Alloc::value_type value_type;
- typedef typename Alloc::pointer pointer;
- typedef typename Alloc::reference reference;
- typedef typename Alloc::size_type size_type;
+ typedef typename Alloc::pointer pointer;
+ typedef typename Alloc::reference reference;
+ typedef typename Alloc::size_type size_type;
-protected:
- GCFactoryBase()
- : Alloc(), m_NumAllocData(0)
- { }
+ protected:
+ GCFactoryBase() : Alloc(), m_NumAllocData(0) {}
- GCFactoryBase(size_t pNum)
- : Alloc(pNum), m_NumAllocData(0)
- { }
+ explicit GCFactoryBase(size_t pNum) : Alloc(pNum), m_NumAllocData(0) {}
-public:
- virtual ~GCFactoryBase()
- { Alloc::clear(); }
+ public:
+ virtual ~GCFactoryBase() { Alloc::clear(); }
// ----- modifiers ----- //
value_type* allocate(size_t N) {
value_type* result = Alloc::allocate(N);
- if (0 != result)
+ if (result != NULL)
m_NumAllocData += N;
return result;
}
@@ -150,15 +133,15 @@ public:
return Alloc::allocate();
}
- void deallocate(pointer &pPtr, size_type N) {
+ void deallocate(pointer& pPtr, size_type N) {
Alloc::deallocate(pPtr, N);
- if (0 == pPtr)
+ if (pPtr == NULL)
m_NumAllocData -= N;
}
- void deallocate(pointer &pPtr) {
+ void deallocate(pointer& pPtr) {
Alloc::deallocate(pPtr);
- if (0 == pPtr)
+ if (pPtr == NULL)
--m_NumAllocData;
}
@@ -168,35 +151,30 @@ public:
}
// ----- iterators ----- //
- iterator begin()
- { return iterator(Alloc::m_pRoot, 0); }
+ iterator begin() { return iterator(Alloc::m_pRoot, 0); }
- const_iterator begin() const
- { return const_iterator(Alloc::m_pRoot, 0); }
+ const_iterator begin() const { return const_iterator(Alloc::m_pRoot, 0); }
iterator end() {
- return (0 == Alloc::m_pCurrent)?
- begin():
- iterator(Alloc::m_pCurrent, Alloc::m_pCurrent->bound);
+ return (Alloc::m_pCurrent) == 0
+ ? begin()
+ : iterator(Alloc::m_pCurrent, Alloc::m_pCurrent->bound);
}
const_iterator end() const {
- return (0 == Alloc::m_pCurrent)?
- begin():
- const_iterator(Alloc::m_pCurrent, Alloc::m_pCurrent->bound);
+ return (Alloc::m_pCurrent) == 0
+ ? begin()
+ : const_iterator(Alloc::m_pCurrent, Alloc::m_pCurrent->bound);
}
// ----- observers ----- //
- bool empty() const
- { return Alloc::empty(); }
+ bool empty() const { return Alloc::empty(); }
- unsigned int capacity() const
- { return Alloc::max_size(); }
+ unsigned int capacity() const { return Alloc::max_size(); }
- unsigned int size() const
- { return m_NumAllocData; }
+ unsigned int size() const { return m_NumAllocData; }
-protected:
+ protected:
unsigned int m_NumAllocData;
};
@@ -204,25 +182,20 @@ protected:
* \brief GCFactory provides a factory that guaratees to remove all allocated
* data.
*/
-template<typename DataType, size_t ChunkSize>
-class GCFactory : public GCFactoryBase<LinearAllocator<DataType, ChunkSize> >
-{
-public:
- GCFactory()
- : GCFactoryBase<LinearAllocator<DataType, ChunkSize> >()
- { }
+template <typename DataType, size_t ChunkSize>
+class GCFactory : public GCFactoryBase<LinearAllocator<DataType, ChunkSize> > {
+ public:
+ GCFactory() : GCFactoryBase<LinearAllocator<DataType, ChunkSize> >() {}
};
-template<typename DataType>
-class GCFactory<DataType, 0> : public GCFactoryBase<LinearAllocator<DataType, 0> >
-{
-public:
- GCFactory(size_t pNum)
- : GCFactoryBase<LinearAllocator<DataType, 0> >(pNum)
- { }
+template <typename DataType>
+class GCFactory<DataType, 0>
+ : public GCFactoryBase<LinearAllocator<DataType, 0> > {
+ public:
+ explicit GCFactory(size_t pNum)
+ : GCFactoryBase<LinearAllocator<DataType, 0> >(pNum) {}
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SUPPORT_GCFACTORY_H_
diff --git a/include/mcld/Support/GCFactoryListTraits.h b/include/mcld/Support/GCFactoryListTraits.h
index 7a8871c..b8afe81 100644
--- a/include/mcld/Support/GCFactoryListTraits.h
+++ b/include/mcld/Support/GCFactoryListTraits.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_GCFACTORYLISTTRAITS_H
-#define MCLD_SUPPORT_GCFACTORYLISTTRAITS_H
+#ifndef MCLD_SUPPORT_GCFACTORYLISTTRAITS_H_
+#define MCLD_SUPPORT_GCFACTORYLISTTRAITS_H_
-#include <llvm/ADT/ilist_node.h>
#include <llvm/ADT/ilist.h>
+#include <llvm/ADT/ilist_node.h>
#include <assert.h>
@@ -20,44 +20,41 @@ namespace mcld {
* \brief GCFactoryListTraits provides trait class for llvm::iplist when
* the nodes in the list is produced by GCFactory.
*/
-template<typename DataType>
-class GCFactoryListTraits : public llvm::ilist_default_traits<DataType>
-{
-private:
- class SentinelNode : public DataType
- {
- public:
- SentinelNode() { }
+template <typename DataType>
+class GCFactoryListTraits : public llvm::ilist_default_traits<DataType> {
+ private:
+ class SentinelNode : public DataType {
+ public:
+ SentinelNode() {}
};
-public:
+ public:
// override the traits provided in llvm::ilist_sentinel_traits since we've
// defined our own sentinel.
- DataType *createSentinel() const
- { return reinterpret_cast<DataType*>(&mSentinel); }
+ DataType* createSentinel() const {
+ return reinterpret_cast<DataType*>(&mSentinel);
+ }
- static void destroySentinel(DataType*) { }
+ static void destroySentinel(DataType* pData) {}
- DataType *provideInitialHead() const
- { return createSentinel(); }
+ DataType* provideInitialHead() const { return createSentinel(); }
- DataType *ensureHead(DataType*) const
- { return createSentinel(); }
+ DataType* ensureHead(DataType* pData) const { return createSentinel(); }
- static void noteHead(DataType*, DataType*) { }
+ static void noteHead(DataType* pNew, DataType* pSentinel) {}
// override the traits provided in llvm::ilist_node_traits since
- static DataType *createNode(const DataType &V) {
+ static DataType* createNode(const DataType& V) {
assert(false && "Only GCFactory knows how to create a node.");
}
- static void deleteNode(DataType *V) {
+ static void deleteNode(DataType* V) {
// No action. GCFactory will handle it by itself.
}
-private:
+ private:
mutable SentinelNode mSentinel;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SUPPORT_GCFACTORYLISTTRAITS_H_
diff --git a/include/mcld/Support/LEB128.h b/include/mcld/Support/LEB128.h
index e90980f..2c6c1c8 100644
--- a/include/mcld/Support/LEB128.h
+++ b/include/mcld/Support/LEB128.h
@@ -6,9 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-
-#ifndef MCLD_SUPPORT_LEB128_H
-#define MCLD_SUPPORT_LEB128_H
+#ifndef MCLD_SUPPORT_LEB128_H_
+#define MCLD_SUPPORT_LEB128_H_
#include <stdint.h>
#include <sys/types.h>
@@ -20,20 +19,20 @@ namespace leb128 {
typedef unsigned char ByteType;
/* Forward declarations */
-template<typename IntType>
-size_t encode(ByteType *&pBuf, IntType pValue);
+template <typename IntType>
+size_t encode(ByteType*& pBuf, IntType pValue);
-template<typename IntType>
-IntType decode(const ByteType *pBuf, size_t &pSize);
+template <typename IntType>
+IntType decode(const ByteType* pBuf, size_t& pSize);
-template<typename IntType>
-IntType decode(const ByteType *&pBuf);
+template <typename IntType>
+IntType decode(const ByteType*& pBuf);
/*
* Given an integer, this function returns the number of bytes required to
* encode it in ULEB128 format.
*/
-template<typename IntType>
+template <typename IntType>
size_t size(IntType pValue) {
size_t size = 1;
while (pValue > 0x80) {
@@ -49,66 +48,66 @@ size_t size(IntType pValue) {
* given buffer pointer to the point just past the end of the write value and
* return the number of bytes being written.
*/
-template<>
-size_t encode<uint64_t>(ByteType *&pBuf, uint64_t pValue);
+template <>
+size_t encode<uint64_t>(ByteType*& pBuf, uint64_t pValue);
-template<>
-size_t encode<uint32_t>(ByteType *&pBuf, uint32_t pValue);
+template <>
+size_t encode<uint32_t>(ByteType*& pBuf, uint32_t pValue);
/*
* Encoding functions for signed LEB128.
*/
-template<>
-size_t encode<int64_t>(ByteType *&pBuf, int64_t pValue);
+template <>
+size_t encode<int64_t>(ByteType*& pBuf, int64_t pValue);
-template<>
-size_t encode<int32_t>(ByteType *&pBuf, int32_t pValue);
+template <>
+size_t encode<int32_t>(ByteType*& pBuf, int32_t pValue);
/*
* Read an integer encoded in ULEB128 format from the given buffer. pSize will
* contain the number of bytes used in the buffer to encode the returned
* integer.
*/
-template<>
-uint64_t decode<uint64_t>(const ByteType *pBuf, size_t &pSize);
+template <>
+uint64_t decode<uint64_t>(const ByteType* pBuf, size_t& pSize);
/*
* Read an integer encoded in ULEB128 format from the given buffer. Update the
* given buffer pointer to the point just past the end of the read value.
*/
-template<>
-uint64_t decode<uint64_t>(const ByteType *&pBuf);
+template <>
+uint64_t decode<uint64_t>(const ByteType*& pBuf);
/*
* Decoding functions for signed LEB128.
*/
-template<>
-int64_t decode<int64_t>(const ByteType *pBuf, size_t &pSize);
+template <>
+int64_t decode<int64_t>(const ByteType* pBuf, size_t& pSize);
-template<>
-int64_t decode<int64_t>(const ByteType *&pBuf);
+template <>
+int64_t decode<int64_t>(const ByteType*& pBuf);
/*
* The functions below handle the signed byte stream. This helps the user to get
* rid of annoying type conversions when using the LEB128 encoding/decoding APIs
* defined above.
*/
-template<typename IntType>
-size_t encode(char *&pBuf, IntType pValue) {
+template <typename IntType>
+size_t encode(char*& pBuf, IntType pValue) {
return encode<IntType>(reinterpret_cast<ByteType*&>(pBuf), pValue);
}
-template<typename IntType>
-IntType decode(const char *pBuf, size_t &pSize) {
+template <typename IntType>
+IntType decode(const char* pBuf, size_t& pSize) {
return decode<IntType>(reinterpret_cast<const ByteType*>(pBuf), pSize);
}
-template<typename IntType>
-IntType decode(const char *&pBuf) {
+template <typename IntType>
+IntType decode(const char*& pBuf) {
return decode<IntType>(reinterpret_cast<const ByteType*&>(pBuf));
}
-} // namespace of leb128
-} // namespace of mcld
+} // namespace leb128
+} // namespace mcld
-#endif
+#endif // MCLD_SUPPORT_LEB128_H_
diff --git a/include/mcld/Support/MemoryArea.h b/include/mcld/Support/MemoryArea.h
index 570e293..105b23a 100644
--- a/include/mcld/Support/MemoryArea.h
+++ b/include/mcld/Support/MemoryArea.h
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_MEMORYAREA_H
-#define MCLD_SUPPORT_MEMORYAREA_H
+#ifndef MCLD_SUPPORT_MEMORYAREA_H_
+#define MCLD_SUPPORT_MEMORYAREA_H_
-#include <mcld/ADT/Uncopyable.h>
+#include "mcld/Support/Compiler.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/MemoryBuffer.h>
@@ -19,10 +19,10 @@ namespace mcld {
/** \class MemoryArea
* \brief MemoryArea is used to manage input read-only memory space.
*/
-class MemoryArea : private Uncopyable
-{
+class MemoryArea {
friend class MemoryAreaFactory;
-public:
+
+ public:
// constructor by file handler.
// If the given file handler is read-only, client can not request a region
// that out of the file size.
@@ -39,10 +39,13 @@ public:
size_t size() const;
-private:
+ private:
std::unique_ptr<llvm::MemoryBuffer> m_pMemoryBuffer;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MemoryArea);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SUPPORT_MEMORYAREA_H_
diff --git a/include/mcld/Support/MemoryAreaFactory.h b/include/mcld/Support/MemoryAreaFactory.h
index 8b6d879..348169b 100644
--- a/include/mcld/Support/MemoryAreaFactory.h
+++ b/include/mcld/Support/MemoryAreaFactory.h
@@ -6,16 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_MEMORYAREAFACTORY_H
-#define MCLD_SUPPORT_MEMORYAREAFACTORY_H
-#include <mcld/Support/GCFactory.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/Path.h>
-#include <mcld/Support/FileHandle.h>
+#ifndef MCLD_SUPPORT_MEMORYAREAFACTORY_H_
+#define MCLD_SUPPORT_MEMORYAREAFACTORY_H_
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/GCFactory.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/Path.h"
+
#include <llvm/ADT/StringMap.h>
-namespace mcld
-{
+namespace mcld {
/** \class MemoryAreaFactory
* \brief MemoryAreaFactory avoids creating duplicated MemoryAreas of the
@@ -35,16 +35,14 @@ namespace mcld
*
* @see MemoryRegion
*/
-class MemoryAreaFactory : public GCFactory<MemoryArea, 0>
-{
-public:
+class MemoryAreaFactory : public GCFactory<MemoryArea, 0> {
+ public:
explicit MemoryAreaFactory(size_t pNum);
virtual ~MemoryAreaFactory();
// produce - create a MemoryArea and open its file.
- MemoryArea* produce(const sys::fs::Path& pPath,
- FileHandle::OpenMode pMode);
+ MemoryArea* produce(const sys::fs::Path& pPath, FileHandle::OpenMode pMode);
// produce - create a MemoryArea and open its file.
MemoryArea* produce(const sys::fs::Path& pPath,
@@ -60,10 +58,11 @@ public:
MemoryArea* produce(int pFD, FileHandle::OpenMode pMode);
void destruct(MemoryArea* pArea);
-private:
+
+ private:
llvm::StringMap<MemoryArea*> m_AreaMap;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SUPPORT_MEMORYAREAFACTORY_H_
diff --git a/include/mcld/Support/MemoryRegion.h b/include/mcld/Support/MemoryRegion.h
index ff81a30..28205f1 100644
--- a/include/mcld/Support/MemoryRegion.h
+++ b/include/mcld/Support/MemoryRegion.h
@@ -6,10 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_MEMORYREGION_H
-#define MCLD_SUPPORT_MEMORYREGION_H
+#ifndef MCLD_SUPPORT_MEMORYREGION_H_
+#define MCLD_SUPPORT_MEMORYREGION_H_
+
+#include "mcld/ADT/TypeTraits.h"
-#include <mcld/ADT/TypeTraits.h>
#include <llvm/ADT/ArrayRef.h>
#include <llvm/Support/DataTypes.h>
@@ -21,6 +22,6 @@ typedef ConstTraits<uint8_t>::pointer ConstAddress;
typedef llvm::ArrayRef<uint8_t> ConstMemoryRegion;
typedef llvm::MutableArrayRef<uint8_t> MemoryRegion;
-} // namespace mcld
+} // namespace mcld
-#endif
+#endif // MCLD_SUPPORT_MEMORYREGION_H_
diff --git a/include/mcld/Support/MsgHandling.h b/include/mcld/Support/MsgHandling.h
index 71d173e..5720ce5 100644
--- a/include/mcld/Support/MsgHandling.h
+++ b/include/mcld/Support/MsgHandling.h
@@ -6,9 +6,9 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_MSGHANDLING_H
-#define MCLD_SUPPORT_MSGHANDLING_H
-#include <mcld/LD/MsgHandler.h>
+#ifndef MCLD_SUPPORT_MSGHANDLING_H_
+#define MCLD_SUPPORT_MSGHANDLING_H_
+#include "mcld/LD/MsgHandler.h"
namespace mcld {
@@ -33,45 +33,37 @@ MsgHandler debug(unsigned int pID);
MsgHandler note(unsigned int pID);
MsgHandler ignore(unsigned int pID);
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// Inline functions
//===----------------------------------------------------------------------===//
-inline mcld::MsgHandler mcld::unreachable(unsigned int pID)
-{
+inline mcld::MsgHandler mcld::unreachable(unsigned int pID) {
return getDiagnosticEngine().report(pID, DiagnosticEngine::Unreachable);
}
-inline mcld::MsgHandler mcld::fatal(unsigned int pID)
-{
+inline mcld::MsgHandler mcld::fatal(unsigned int pID) {
return getDiagnosticEngine().report(pID, DiagnosticEngine::Fatal);
}
-inline mcld::MsgHandler mcld::error(unsigned int pID)
-{
+inline mcld::MsgHandler mcld::error(unsigned int pID) {
return getDiagnosticEngine().report(pID, DiagnosticEngine::Error);
}
-inline mcld::MsgHandler mcld::warning(unsigned int pID)
-{
+inline mcld::MsgHandler mcld::warning(unsigned int pID) {
return getDiagnosticEngine().report(pID, DiagnosticEngine::Warning);
}
-inline mcld::MsgHandler mcld::debug(unsigned int pID)
-{
+inline mcld::MsgHandler mcld::debug(unsigned int pID) {
return getDiagnosticEngine().report(pID, DiagnosticEngine::Debug);
}
-inline mcld::MsgHandler mcld::note(unsigned int pID)
-{
+inline mcld::MsgHandler mcld::note(unsigned int pID) {
return getDiagnosticEngine().report(pID, DiagnosticEngine::Note);
}
-inline mcld::MsgHandler mcld::ignore(unsigned int pID)
-{
+inline mcld::MsgHandler mcld::ignore(unsigned int pID) {
return getDiagnosticEngine().report(pID, DiagnosticEngine::Ignore);
}
-#endif
-
+#endif // MCLD_SUPPORT_MSGHANDLING_H_
diff --git a/include/mcld/Support/Path.h b/include/mcld/Support/Path.h
index 9fdb95c..33f4705 100644
--- a/include/mcld/Support/Path.h
+++ b/include/mcld/Support/Path.h
@@ -10,11 +10,12 @@
// filesystem (v3), but modified to remove exception handling and the
// path class.
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_PATH_H
-#define MCLD_SUPPORT_PATH_H
+#ifndef MCLD_SUPPORT_PATH_H_
+#define MCLD_SUPPORT_PATH_H_
+
+#include "mcld/Config/Config.h"
#include <llvm/Support/raw_ostream.h>
-#include <mcld/Config/Config.h>
#include <iosfwd>
#include <functional>
@@ -22,8 +23,8 @@
#include <locale>
namespace mcld {
-namespace sys {
-namespace fs {
+namespace sys {
+namespace fs {
#if defined(MCLD_ON_WIN32)
const char preferred_separator = '/';
@@ -40,29 +41,29 @@ const char dot = '.';
* \brief Path provides an abstraction for the path to a file or directory in
* the operating system's filesystem.
*/
-class Path
-{
-public:
- typedef char ValueType;
- typedef std::string StringType;
+class Path {
+ public:
+ typedef char ValueType;
+ typedef std::string StringType;
-public:
+ public:
Path();
- Path(const ValueType* s);
- Path(const StringType &s);
+ explicit Path(const ValueType* s);
+ explicit Path(const StringType& s);
Path(const Path& pCopy);
virtual ~Path();
// ----- assignments ----- //
template <class InputIterator>
Path& assign(InputIterator begin, InputIterator end);
- Path& assign(const StringType &s);
+ Path& assign(const StringType& s);
Path& assign(const ValueType* s, unsigned int length);
// ----- appends ----- //
template <class InputIterator>
Path& append(InputIterator begin, InputIterator end);
Path& append(const Path& pPath);
+ Path& append(const StringType& pPath);
// ----- observers ----- //
bool empty() const;
@@ -71,10 +72,9 @@ public:
bool isFromPWD() const;
const StringType& native() const { return m_PathName; }
- StringType& native() { return m_PathName; }
+ StringType& native() { return m_PathName; }
- const ValueType* c_str() const
- { return m_PathName.c_str(); }
+ const ValueType* c_str() const { return m_PathName.c_str(); }
// ----- decomposition ----- //
Path parent_path() const;
@@ -86,42 +86,41 @@ public:
StringType generic_string() const;
bool canonicalize();
-public:
+ public:
StringType::size_type m_append_separator_if_needed();
void m_erase_redundant_separator(StringType::size_type sep_pos);
-protected:
+ protected:
StringType m_PathName;
};
-bool operator==(const Path& pLHS,const Path& pRHS);
-bool operator!=(const Path& pLHS,const Path& pRHS);
+bool operator==(const Path& pLHS, const Path& pRHS);
+bool operator!=(const Path& pLHS, const Path& pRHS);
Path operator+(const Path& pLHS, const Path& pRHS);
//===----------------------------------------------------------------------===//
// Non-member Functions
//===----------------------------------------------------------------------===//
-bool exists(const Path &pPath);
+bool exists(const Path& pPath);
-bool is_directory(const Path &pPath);
+bool is_directory(const Path& pPath);
template <class Char, class Traits>
-inline std::basic_ostream<Char, Traits>&
-operator<<(std::basic_ostream<Char, Traits>& pOS, const Path& pPath)
-{
+inline std::basic_ostream<Char, Traits>& operator<<(
+ std::basic_ostream<Char, Traits>& pOS,
+ const Path& pPath) {
return pOS << pPath.native();
}
template <class Char, class Traits>
-inline std::basic_istream<Char, Traits>&
-operator>>(std::basic_istream<Char, Traits>& pOS, Path& pPath)
-{
+inline std::basic_istream<Char, Traits>& operator>>(
+ std::basic_istream<Char, Traits>& pOS,
+ Path& pPath) {
return pOS >> pPath.native();
}
-inline llvm::raw_ostream&
-operator<<(llvm::raw_ostream& pOS, const Path& pPath)
-{
+inline llvm::raw_ostream& operator<<(llvm::raw_ostream& pOS,
+ const Path& pPath) {
return pOS << pPath.native();
}
@@ -129,8 +128,7 @@ operator<<(llvm::raw_ostream& pOS, const Path& pPath)
// class path member template implementation
//===----------------------------------------------------------------------===//
template <class InputIterator>
-Path& Path::assign(InputIterator begin, InputIterator end)
-{
+Path& Path::assign(InputIterator begin, InputIterator end) {
m_PathName.clear();
if (begin != end)
m_PathName.append<InputIterator>(begin, end);
@@ -138,8 +136,7 @@ Path& Path::assign(InputIterator begin, InputIterator end)
}
template <class InputIterator>
-Path& Path::append(InputIterator begin, InputIterator end)
-{
+Path& Path::append(InputIterator begin, InputIterator end) {
if (begin == end)
return *this;
StringType::size_type sep_pos(m_append_separator_if_needed());
@@ -149,28 +146,26 @@ Path& Path::append(InputIterator begin, InputIterator end)
return *this;
}
-} // namespace of fs
-} // namespace of sys
-} // namespace of mcld
+} // namespace fs
+} // namespace sys
+} // namespace mcld
//===----------------------------------------------------------------------===//
// STL compatible functions
//===----------------------------------------------------------------------===//
namespace std {
-template<>
-struct less<mcld::sys::fs::Path> : public binary_function<mcld::sys::fs::Path,
- mcld::sys::fs::Path,
- bool>
-{
- bool operator() (const mcld::sys::fs::Path& pX,const mcld::sys::fs::Path& pY) const {
+template <>
+struct less<mcld::sys::fs::Path>
+ : public binary_function<mcld::sys::fs::Path, mcld::sys::fs::Path, bool> {
+ bool operator()(const mcld::sys::fs::Path& pX,
+ const mcld::sys::fs::Path& pY) const {
if (pX.generic_string().size() < pY.generic_string().size())
return true;
return (pX.generic_string() < pY.generic_string());
}
};
-} // namespace of std
-
-#endif
+} // namespace std
+#endif // MCLD_SUPPORT_PATH_H_
diff --git a/include/mcld/Support/PathCache.h b/include/mcld/Support/PathCache.h
index aca49fb..8b61556 100644
--- a/include/mcld/Support/PathCache.h
+++ b/include/mcld/Support/PathCache.h
@@ -6,29 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_PATHCACHE_H
-#define MCLD_SUPPORT_PATHCACHE_H
+#ifndef MCLD_SUPPORT_PATHCACHE_H_
+#define MCLD_SUPPORT_PATHCACHE_H_
-#include <mcld/ADT/HashEntry.h>
-#include <mcld/ADT/HashTable.h>
-#include <mcld/ADT/StringHash.h>
-#include <mcld/Support/Path.h>
+#include "mcld/ADT/HashEntry.h"
+#include "mcld/ADT/HashTable.h"
+#include "mcld/ADT/StringHash.h"
+#include "mcld/Support/Path.h"
namespace mcld {
-namespace sys {
-namespace fs {
+namespace sys {
+namespace fs {
-namespace {
- typedef HashEntry<llvm::StringRef,
- mcld::sys::fs::Path,
- hash::StringCompare<llvm::StringRef> > HashEntryType;
-} // anonymous namespace
+typedef HashEntry<llvm::StringRef,
+ mcld::sys::fs::Path,
+ hash::StringCompare<llvm::StringRef> > HashEntryType;
-typedef HashTable<HashEntryType, hash::StringHash<hash::BKDR>, EntryFactory<HashEntryType> > PathCache;
+typedef HashTable<HashEntryType,
+ hash::StringHash<hash::DJB>,
+ EntryFactory<HashEntryType> > PathCache;
-} // namespace of fs
-} // namespace of sys
-} // namespace of mcld
-
-#endif
+} // namespace fs
+} // namespace sys
+} // namespace mcld
+#endif // MCLD_SUPPORT_PATHCACHE_H_
diff --git a/include/mcld/Support/RealPath.h b/include/mcld/Support/RealPath.h
index b630fd6..b5edc76 100644
--- a/include/mcld/Support/RealPath.h
+++ b/include/mcld/Support/RealPath.h
@@ -6,64 +6,61 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_REALPATH_H
-#define MCLD_SUPPORT_REALPATH_H
+#ifndef MCLD_SUPPORT_REALPATH_H_
+#define MCLD_SUPPORT_REALPATH_H_
#include "mcld/Support/Path.h"
+
#include <string>
namespace mcld {
-namespace sys {
-namespace fs {
+namespace sys {
+namespace fs {
/** \class RealPath
* \brief The canonicalized absolute pathname.
*
*/
-class RealPath : public Path
-{
-public:
- typedef Path::ValueType ValueType;
+class RealPath : public Path {
+ public:
+ typedef Path::ValueType ValueType;
typedef Path::StringType StringType;
-public:
+ public:
RealPath();
- explicit RealPath(const ValueType* s );
- explicit RealPath(const StringType &s );
+ explicit RealPath(const ValueType* s);
+ explicit RealPath(const StringType& s);
explicit RealPath(const Path& pPath);
~RealPath();
RealPath& assign(const Path& pPath);
-protected:
+ protected:
void initialize();
};
-} // namespace of fs
-} // namespace of sys
-} // namespace of mcld
+} // namespace fs
+} // namespace sys
+} // namespace mcld
-//-------------------------------------------------------------------------//
-// STL compatible functions //
-//-------------------------------------------------------------------------//
+//----------------------------------------------------------------------------//
+// STL compatible functions //
+//----------------------------------------------------------------------------//
namespace std {
-template<>
-struct less<mcld::sys::fs::RealPath> : public binary_function<
- mcld::sys::fs::RealPath,
- mcld::sys::fs::RealPath,
- bool>
-{
- bool operator() (const mcld::sys::fs::RealPath& pX,
- const mcld::sys::fs::RealPath& pY) const {
+template <>
+struct less<mcld::sys::fs::RealPath>
+ : public binary_function<mcld::sys::fs::RealPath,
+ mcld::sys::fs::RealPath,
+ bool> {
+ bool operator()(const mcld::sys::fs::RealPath& pX,
+ const mcld::sys::fs::RealPath& pY) const {
if (pX.native().size() < pY.native().size())
return true;
return (pX.native() < pY.native());
}
};
-} // namespace of std
-
-
-#endif
+} // namespace std
+#endif // MCLD_SUPPORT_REALPATH_H_
diff --git a/include/mcld/Support/SystemUtils.h b/include/mcld/Support/SystemUtils.h
index 7057110..4502e20 100644
--- a/include/mcld/Support/SystemUtils.h
+++ b/include/mcld/Support/SystemUtils.h
@@ -6,11 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_SYSTEMUTILS_H
-#define MCLD_SUPPORT_SYSTEMUTILS_H
+#ifndef MCLD_SUPPORT_SYSTEMUTILS_H_
+#define MCLD_SUPPORT_SYSTEMUTILS_H_
+
+#include "mcld/Config/Config.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Config/Config.h>
+
#include <string>
namespace mcld {
@@ -22,7 +24,7 @@ typedef off_t Offset;
/** \fn strerror
* \brief system error message
*/
-char *strerror(int pErrnum);
+char* strerror(int pErrnum);
std::string getDefaultTargetTriple();
@@ -34,8 +36,7 @@ long GetRandomNum();
/// SetRandomSeed - set the initial seed value for future calls to random().
void SetRandomSeed(unsigned pSeed);
-} // namespace of sys
-} // namespace of mcld
-
-#endif
+} // namespace sys
+} // namespace mcld
+#endif // MCLD_SUPPORT_SYSTEMUTILS_H_
diff --git a/include/mcld/Support/Target.h b/include/mcld/Support/Target.h
index 021fc2e..703dc82 100644
--- a/include/mcld/Support/Target.h
+++ b/include/mcld/Support/Target.h
@@ -6,16 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_TARGET_H
-#define MCLD_SUPPORT_TARGET_H
+#ifndef MCLD_SUPPORT_TARGET_H_
+#define MCLD_SUPPORT_TARGET_H_
#include <string>
-#include <list>
namespace llvm {
class Target;
class Triple;
class TargetMachine;
-} // namespace of llvm
+} // namespace llvm
namespace mcld {
@@ -32,32 +31,31 @@ class TargetLDBackend;
/** \class Target
* \brief Target collects target specific information
*/
-class Target
-{
+class Target {
friend class mcld::MCLDTargetMachine;
friend class mcld::TargetRegistry;
-public:
+ public:
typedef unsigned int (*TripleMatchQualityFnTy)(const llvm::Triple& pTriple);
- typedef MCLDTargetMachine *(*TargetMachineCtorTy)(const llvm::Target &,
- const mcld::Target &,
- llvm::TargetMachine &,
+ typedef MCLDTargetMachine* (*TargetMachineCtorTy)(const llvm::Target&,
+ const mcld::Target&,
+ llvm::TargetMachine&,
const std::string&);
- typedef MCLinker *(*MCLinkerCtorTy)(const std::string& pTriple,
+ typedef MCLinker* (*MCLinkerCtorTy)(const std::string& pTriple,
LinkerConfig&,
Module&,
FileHandle& pFileHandle);
typedef bool (*EmulationFnTy)(LinkerScript&, LinkerConfig&);
- typedef TargetLDBackend *(*TargetLDBackendCtorTy)(const LinkerConfig&);
+ typedef TargetLDBackend* (*TargetLDBackendCtorTy)(const LinkerConfig&);
- typedef DiagnosticLineInfo *(*DiagnosticLineInfoCtorTy)(const mcld::Target&,
+ typedef DiagnosticLineInfo* (*DiagnosticLineInfoCtorTy)(const mcld::Target&,
const std::string&);
-public:
+ public:
Target();
/// getName - get the target name
@@ -71,7 +69,7 @@ public:
llvm::TargetMachine& pTM) const;
/// createMCLinker - create target-specific MCLinker
- MCLinker *createMCLinker(const std::string &pTriple,
+ MCLinker* createMCLinker(const std::string& pTriple,
LinkerConfig& pConfig,
Module& pModule,
FileHandle& pFileHandle) const;
@@ -84,10 +82,11 @@ public:
TargetLDBackend* createLDBackend(const LinkerConfig& pConfig) const;
/// createDiagnosticLineInfo - create target-specific DiagnosticLineInfo
- DiagnosticLineInfo* createDiagnosticLineInfo(const mcld::Target& pTarget,
- const std::string& pTriple) const;
+ DiagnosticLineInfo* createDiagnosticLineInfo(
+ const mcld::Target& pTarget,
+ const std::string& pTriple) const;
-private:
+ private:
/// Name - The target name
const char* Name;
@@ -99,7 +98,6 @@ private:
DiagnosticLineInfoCtorTy DiagnosticLineInfoCtorFn;
};
-} //end namespace mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SUPPORT_TARGET_H_
diff --git a/include/mcld/Support/TargetRegistry.h b/include/mcld/Support/TargetRegistry.h
index 1ae6245..c76ff74 100644
--- a/include/mcld/Support/TargetRegistry.h
+++ b/include/mcld/Support/TargetRegistry.h
@@ -6,36 +6,36 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_TARGETREGISTRY_H
-#define MCLD_SUPPORT_TARGETREGISTRY_H
-#include <mcld/Support/Target.h>
+#ifndef MCLD_SUPPORT_TARGETREGISTRY_H_
+#define MCLD_SUPPORT_TARGETREGISTRY_H_
+#include "mcld/Support/Target.h"
+
#include <llvm/ADT/Triple.h>
-#include <string>
#include <list>
+#include <string>
namespace llvm {
class TargetMachine;
class MCCodeEmitter;
class MCContext;
class AsmPrinter;
-} // namespace of llvm
+} // namespace llvm
namespace mcld {
/** \class TargetRegistry
* \brief TargetRegistry is an object adapter of llvm::TargetRegistry
*/
-class TargetRegistry
-{
-public:
+class TargetRegistry {
+ public:
typedef std::list<mcld::Target*> TargetListTy;
typedef TargetListTy::iterator iterator;
-private:
+ private:
static TargetListTy s_TargetList;
-public:
+ public:
static iterator begin() { return s_TargetList.begin(); }
static iterator end() { return s_TargetList.end(); }
@@ -54,36 +54,13 @@ public:
const char* pName,
Target::TripleMatchQualityFnTy pQualityFn);
- /// RegisterTargetMachine - Register a TargetMachine implementation for the
- /// given target.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct a TargetMachine for the target.
- static void RegisterTargetMachine(mcld::Target &T, mcld::Target::TargetMachineCtorTy Fn)
- {
- // Ignore duplicate registration.
- if (!T.TargetMachineCtorFn)
- T.TargetMachineCtorFn = Fn;
- }
-
- /// RegisterMCLinker - Register a MCLinker implementation for the given
- /// target.
- ///
- /// @param T - the target being registered
- /// @param Fn - A function to create MCLinker for the target
- static void RegisterMCLinker(mcld::Target &T, mcld::Target::MCLinkerCtorTy Fn)
- {
- if (!T.MCLinkerCtorFn)
- T.MCLinkerCtorFn = Fn;
- }
-
/// RegisterEmulation - Register a emulation function for the target.
/// target.
///
/// @param T - the target being registered
/// @param Fn - A emulation function
- static void RegisterEmulation(mcld::Target &T, mcld::Target::EmulationFnTy Fn)
- {
+ static void RegisterEmulation(mcld::Target& T,
+ mcld::Target::EmulationFnTy Fn) {
if (!T.EmulationFn)
T.EmulationFn = Fn;
}
@@ -93,8 +70,8 @@ public:
///
/// @param T - The target being registered
/// @param Fn - A function to create TargetLDBackend for the target
- static void RegisterTargetLDBackend(mcld::Target &T, mcld::Target::TargetLDBackendCtorTy Fn)
- {
+ static void RegisterTargetLDBackend(mcld::Target& T,
+ mcld::Target::TargetLDBackendCtorTy Fn) {
if (!T.TargetLDBackendCtorFn)
T.TargetLDBackendCtorFn = Fn;
}
@@ -104,10 +81,9 @@ public:
///
/// @param T - The target being registered
/// @param Fn - A function to create DiagnosticLineInfo for the target
- static void
- RegisterDiagnosticLineInfo(mcld::Target &T,
- mcld::Target::DiagnosticLineInfoCtorTy Fn)
- {
+ static void RegisterDiagnosticLineInfo(
+ mcld::Target& T,
+ mcld::Target::DiagnosticLineInfoCtorTy Fn) {
if (!T.DiagnosticLineInfoCtorFn)
T.DiagnosticLineInfoCtorFn = Fn;
}
@@ -116,7 +92,7 @@ public:
///
/// @param Triple - The Triple string
/// @param Error - The returned error message
- static const mcld::Target *lookupTarget(const std::string& pTriple,
+ static const mcld::Target* lookupTarget(const std::string& pTriple,
std::string& pError);
/// lookupTarget - Look up MCLinker target by an architecture name
@@ -127,9 +103,9 @@ public:
/// @param pArch - The architecture name
/// @param pTriple - The target triple
/// @param pError - The returned error message
- static const mcld::Target *lookupTarget(const std::string& pArchName,
+ static const mcld::Target* lookupTarget(const std::string& pArchName,
llvm::Triple& pTriple,
- std::string &Error);
+ std::string& Error);
};
/// RegisterTarget - Helper function for registering a target, for use in the
@@ -140,15 +116,14 @@ public:
/// extern "C" void MCLDInitializeFooTargetInfo() {
/// RegisterTarget<llvm::Foo> X(TheFooTarget, "foo", "Foo description");
/// }
-template<llvm::Triple::ArchType TargetArchType = llvm::Triple::UnknownArch>
-struct RegisterTarget
-{
-public:
- RegisterTarget(mcld::Target &pTarget, const char* pName) {
+template <llvm::Triple::ArchType TargetArchType = llvm::Triple::UnknownArch>
+struct RegisterTarget {
+ public:
+ RegisterTarget(mcld::Target& pTarget, const char* pName) {
// if we've registered one, then return immediately.
TargetRegistry::iterator target, ie = TargetRegistry::end();
for (target = TargetRegistry::begin(); target != ie; ++target) {
- if (0 == strcmp((*target)->name(), pName))
+ if (strcmp((*target)->name(), pName) == 0)
return;
}
@@ -162,31 +137,6 @@ public:
}
};
-/// RegisterTargetMachine - Helper template for registering a target machine
-/// implementation, for use in the target machine initialization
-/// function. Usage:
-///
-/// extern "C" void MCLDInitializeFooTarget() {
-/// extern mcld::Target TheFooTarget;
-/// RegisterTargetMachine<mcld::FooTargetMachine> X(TheFooTarget);
-/// }
-template<class TargetMachineImpl>
-struct RegisterTargetMachine
-{
- RegisterTargetMachine(mcld::Target &T) {
- TargetRegistry::RegisterTargetMachine(T, &Allocator);
- }
-
-private:
- static MCLDTargetMachine *Allocator(const llvm::Target& pLLVMTarget,
- const mcld::Target& pMCLDTarget,
- llvm::TargetMachine& pTM,
- const std::string& pTriple) {
- return new TargetMachineImpl(pTM, pLLVMTarget, pMCLDTarget, pTriple);
- }
-};
-
-} //end namespace mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SUPPORT_TARGETREGISTRY_H_
diff --git a/include/mcld/Support/TargetSelect.h b/include/mcld/Support/TargetSelect.h
index 32e568b..96bd510 100644
--- a/include/mcld/Support/TargetSelect.h
+++ b/include/mcld/Support/TargetSelect.h
@@ -6,94 +6,69 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_TARGETSELECT_H
-#define MCLD_SUPPORT_TARGETSELECT_H
+#ifndef MCLD_SUPPORT_TARGETSELECT_H_
+#define MCLD_SUPPORT_TARGETSELECT_H_
extern "C" {
- // Declare all of the target-initialization functions that are available.
+// Declare all of the target-initialization functions that are available.
#define MCLD_TARGET(TargetName) void MCLDInitialize##TargetName##LDTargetInfo();
-#include "mcld/Config/Targets.def"
+#include "mcld/Config/Targets.def" // NOLINT [build/include] [4]
- // Declare all of the target-dependent functions that are available.
-#define MCLD_TARGET(TargetName) void MCLDInitialize##TargetName##LDTarget();
-#include "mcld/Config/Targets.def"
-
- // Declare all of the target-depedent linker information
-#define MCLD_LINKER(TargetName) void MCLDInitialize##TargetName##LDInfo();
-#include "mcld/Config/Linkers.def"
-
- // Declare all of the available linker environment.
-#define MCLD_LINKER(TargetName) void MCLDInitialize##TargetName##MCLinker();
-#include "mcld/Config/Linkers.def"
-
- // Declare all of the available emulators.
+// Declare all of the available emulators.
#define MCLD_TARGET(TargetName) void MCLDInitialize##TargetName##Emulation();
-#include "mcld/Config/Targets.def"
+#include "mcld/Config/Targets.def" // NOLINT [build/include] [4]
- // Declare all of the available target-specific linker
+// Declare all of the available target-specific linker
#define MCLD_LINKER(TargetName) void MCLDInitialize##TargetName##LDBackend();
-#include "mcld/Config/Linkers.def"
-
- // Declare all of the available target-specific diagnostic line infomation
-#define MCLD_LINKER(TargetName) void MCLDInitialize##TargetName##DiagnosticLineInfo();
-#include "mcld/Config/Linkers.def"
-
-} // extern "C"
-
-namespace mcld
-{
- /// InitializeAllTargetInfos - The main program should call this function if
- /// it wants access to all available targets that MCLD is configured to
- /// support, to make them available via the TargetRegistry.
- ///
- /// It is legal for a client to make multiple calls to this function.
- inline void InitializeAllTargetInfos() {
+#include "mcld/Config/Linkers.def" // NOLINT [build/include] [4]
+
+// Declare all of the available target-specific diagnostic line infomation
+#define MCLD_LINKER(TargetName) \
+ void MCLDInitialize##TargetName##DiagnosticLineInfo();
+#include "mcld/Config/Linkers.def" // NOLINT [build/include] [4]
+
+} // extern "C"
+
+namespace mcld {
+/// InitializeAllTargetInfos - The main program should call this function if
+/// it wants access to all available targets that MCLD is configured to
+/// support, to make them available via the TargetRegistry.
+///
+/// It is legal for a client to make multiple calls to this function.
+inline void InitializeAllTargetInfos() {
#define MCLD_TARGET(TargetName) MCLDInitialize##TargetName##LDTargetInfo();
-#include "mcld/Config/Targets.def"
- }
+#include "mcld/Config/Targets.def" // NOLINT [build/include] [4]
+}
- /// InitializeAllTargets - The main program should call this function if it
- /// wants access to all available target machines that MCLD is configured to
- /// support, to make them available via the TargetRegistry.
- ///
- /// It is legal for a client to make multiple calls to this function.
- inline void InitializeAllTargets() {
- mcld::InitializeAllTargetInfos();
+/// InitializeAllTargets - The main program should call this function if it
+/// wants access to all available target machines that MCLD is configured to
+/// support, to make them available via the TargetRegistry.
+///
+/// It is legal for a client to make multiple calls to this function.
+inline void InitializeAllTargets() {
+ mcld::InitializeAllTargetInfos();
#define MCLD_TARGET(TargetName) MCLDInitialize##TargetName##LDBackend();
-#include "mcld/Config/Targets.def"
- }
+#include "mcld/Config/Targets.def" // NOLINT [build/include] [4]
+}
- /// InitializeAllEmulations - The main program should call this function if
- /// it wants all emulations to be configured to support. This function makes
- /// all emulations available via the TargetRegistry.
- inline void InitializeAllEmulations() {
+/// InitializeAllEmulations - The main program should call this function if
+/// it wants all emulations to be configured to support. This function makes
+/// all emulations available via the TargetRegistry.
+inline void InitializeAllEmulations() {
#define MCLD_TARGET(TargetName) MCLDInitialize##TargetName##Emulation();
-#include "mcld/Config/Targets.def"
- }
-
- /// InitializeAllLinkers - The main program should call this function if it
- /// wants all linkers that is configured to support, to make them
- /// available via the TargetRegistry.
- ///
- /// It is legal for a client to make multiple calls to this function.
- inline void InitializeAllLinkers() {
-#define MCLD_TARGET(TargetName) MCLDInitialize##TargetName##LDTarget();
-#include "mcld/Config/Targets.def"
-
-#define MCLD_LINKER(TargetName) MCLDInitialize##TargetName##MCLinker();
-#include "mcld/Config/Linkers.def"
- }
-
- /// InitializeMsgHandler - The main program should call this function if it
- /// wants to print linker-specific messages. To make them available via the
- /// TargetRegistry.
- inline void InitializeAllDiagnostics() {
-#define MCLD_LINKER(TargetName) MCLDInitialize##TargetName##DiagnosticLineInfo();
-#include "mcld/Config/Linkers.def"
- }
+#include "mcld/Config/Targets.def" // NOLINT [build/include] [4]
+}
-} // namespace of mcld
+/// InitializeMsgHandler - The main program should call this function if it
+/// wants to print linker-specific messages. To make them available via the
+/// TargetRegistry.
+inline void InitializeAllDiagnostics() {
+#define MCLD_LINKER(TargetName) \
+ MCLDInitialize##TargetName##DiagnosticLineInfo();
+#include "mcld/Config/Linkers.def" // NOLINT [build/include] [4]
+}
-#endif
+} // namespace mcld
+#endif // MCLD_SUPPORT_TARGETSELECT_H_
diff --git a/include/mcld/Support/UniqueGCFactory.h b/include/mcld/Support/UniqueGCFactory.h
index 8d7927b..a0d5a8f 100644
--- a/include/mcld/Support/UniqueGCFactory.h
+++ b/include/mcld/Support/UniqueGCFactory.h
@@ -6,39 +6,36 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_UNIQUEGCFACTORY_H
-#define MCLD_SUPPORT_UNIQUEGCFACTORY_H
+#ifndef MCLD_SUPPORT_UNIQUEGCFACTORY_H_
+#define MCLD_SUPPORT_UNIQUEGCFACTORY_H_
#include "mcld/Support/GCFactory.h"
+
#include <map>
#include <utility>
-namespace mcld
-{
+namespace mcld {
/** \class UniqueGCFactoryBase
* \brief UniqueGCFactories are unique associative factories, meaning that
* no two elements have the same key.
*/
-template<typename KeyType, typename DataType, size_t ChunkSize>
-class UniqueGCFactoryBase : public GCFactoryBase<LinearAllocator<DataType, ChunkSize> >
-{
-protected:
+template <typename KeyType, typename DataType, size_t ChunkSize>
+class UniqueGCFactoryBase
+ : public GCFactoryBase<LinearAllocator<DataType, ChunkSize> > {
+ protected:
typedef GCFactoryBase<LinearAllocator<DataType, ChunkSize> > Alloc;
typedef std::map<KeyType, DataType*> KeyMap;
-protected:
+ protected:
UniqueGCFactoryBase()
- : GCFactoryBase<LinearAllocator<DataType, ChunkSize> >()
- { }
+ : GCFactoryBase<LinearAllocator<DataType, ChunkSize> >() {}
- UniqueGCFactoryBase(size_t pNum)
- : GCFactoryBase<LinearAllocator<DataType, ChunkSize> >(pNum)
- { }
+ explicit UniqueGCFactoryBase(size_t pNum)
+ : GCFactoryBase<LinearAllocator<DataType, ChunkSize> >(pNum) {}
-public:
- virtual ~UniqueGCFactoryBase()
- { f_KeyMap.clear(); }
+ public:
+ virtual ~UniqueGCFactoryBase() { f_KeyMap.clear(); }
DataType* find(const KeyType& pKey) {
typename KeyMap::iterator dataIter = f_KeyMap.find(pKey);
@@ -80,12 +77,10 @@ public:
return data;
}
-protected:
+ protected:
KeyMap f_KeyMap;
-
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_SUPPORT_UNIQUEGCFACTORY_H_
diff --git a/include/mcld/Support/raw_ostream.h b/include/mcld/Support/raw_ostream.h
index aae2336..b3a9f83 100644
--- a/include/mcld/Support/raw_ostream.h
+++ b/include/mcld/Support/raw_ostream.h
@@ -6,17 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_SUPPORT_RAWOSTREAM_H
-#define MCLD_SUPPORT_RAWOSTREAM_H
-#include <string>
+#ifndef MCLD_SUPPORT_RAW_OSTREAM_H_
+#define MCLD_SUPPORT_RAW_OSTREAM_H_
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/raw_ostream.h>
+#include <string>
+
namespace mcld {
-class raw_fd_ostream : public llvm::raw_fd_ostream
-{
-public:
+class raw_fd_ostream : public llvm::raw_fd_ostream {
+ public:
/// raw_fd_ostream - Open the specified file for writing. If an error occurs,
/// information about the error is put into ErrorInfo, and the stream should
/// be immediately destroyed; the string will be empty if no error occurred.
@@ -27,44 +27,41 @@ public:
/// itself to own the file descriptor. In particular, it will close the
/// file descriptor when it is done (this is necessary to detect
/// output errors).
- raw_fd_ostream(const char *pFilename,
- std::string &pErrorInfo,
+ raw_fd_ostream(const char* pFilename,
+ std::error_code& pErrorCode,
llvm::sys::fs::OpenFlags pFlags = llvm::sys::fs::F_None);
/// raw_fd_ostream ctor - FD is the file descriptor that this writes to. If
/// ShouldClose is true, this closes the file when the stream is destroyed.
- raw_fd_ostream(int pFD, bool pShouldClose, bool pUnbuffered=false);
+ raw_fd_ostream(int pFD, bool pShouldClose, bool pUnbuffered = false);
virtual ~raw_fd_ostream();
void setColor(bool pEnable = true);
+ llvm::raw_ostream& changeColor(enum llvm::raw_ostream::Colors pColors,
+ bool pBold = false,
+ bool pBackground = false);
- llvm::raw_ostream &changeColor(enum llvm::raw_ostream::Colors pColors,
- bool pBold=false,
- bool pBackground=false);
+ llvm::raw_ostream& resetColor();
- llvm::raw_ostream &resetColor();
-
- llvm::raw_ostream &reverseColor();
+ llvm::raw_ostream& reverseColor();
bool is_displayed() const;
-private:
+ private:
bool m_bConfigColor : 1;
bool m_bSetColor : 1;
-
};
/// outs() - This returns a reference to a raw_ostream for standard output.
/// Use it like: outs() << "foo" << "bar";
-mcld::raw_fd_ostream &outs();
+mcld::raw_fd_ostream& outs();
/// errs() - This returns a reference to a raw_ostream for standard error.
/// Use it like: errs() << "foo" << "bar";
-mcld::raw_fd_ostream &errs();
-
-} // namespace of mcld
+mcld::raw_fd_ostream& errs();
-#endif
+} // namespace mcld
+#endif // MCLD_SUPPORT_RAW_OSTREAM_H_
diff --git a/include/mcld/Target/DarwinLDBackend.h b/include/mcld/Target/DarwinLDBackend.h
index f4bc29f..bc2fd2b 100644
--- a/include/mcld/Target/DarwinLDBackend.h
+++ b/include/mcld/Target/DarwinLDBackend.h
@@ -6,23 +6,19 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGET_DARWINLDBACKEND_H
-#define MCLD_TARGET_DARWINLDBACKEND_H
+#ifndef MCLD_TARGET_DARWINLDBACKEND_H_
+#define MCLD_TARGET_DARWINLDBACKEND_H_
-namespace mcld
-{
+namespace mcld {
/** \class DarwinLDBackend
- * \brief DarwinLDBackend provides a common interface for all Darwin OS LDBackend.
+ * \brief DarwinLDBackend provides a common interface for all Darwin OS
+ * LDBackend.
*
* \see
*/
-class DarwinLDBackend
-{
+class DarwinLDBackend {};
-};
-
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_TARGET_DARWINLDBACKEND_H_
diff --git a/include/mcld/Target/ELFAttribute.h b/include/mcld/Target/ELFAttribute.h
index aa2d8ea..a50e13e 100644
--- a/include/mcld/Target/ELFAttribute.h
+++ b/include/mcld/Target/ELFAttribute.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGET_ELFATTRIBUTE_H
-#define MCLD_TARGET_ELFATTRIBUTE_H
+#ifndef MCLD_TARGET_ELFATTRIBUTE_H_
+#define MCLD_TARGET_ELFATTRIBUTE_H_
-#include <mcld/Support/MemoryRegion.h>
-#include <mcld/Target/ELFAttributeData.h>
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Target/ELFAttributeData.h"
#include <llvm/ADT/SmallVector.h>
#include <llvm/ADT/StringRef.h>
@@ -26,97 +26,95 @@ class LinkerConfig;
/** \class ELFAttribute
* \brief ELFAttribute is the attribute section in an ELF file.
*/
-class ELFAttribute
-{
-public:
+class ELFAttribute {
+ public:
// ARM [ABI-addenda], 2.2.3.
- static const char FormatVersion = 'A';
- static const size_t FormatVersionFieldSize = sizeof(FormatVersion); // a byte
- static const size_t SubsectionLengthFieldSize = 4; // a 4-byte integer
+ static const char FormatVersion = 'A';
+ static const size_t FormatVersionFieldSize = sizeof(FormatVersion); // a byte
+ static const size_t SubsectionLengthFieldSize = 4; // a 4-byte integer
// MinimalELFAttributeSubsectionSize is the minimal number of bytes a valid
// subsection in ELF attribute section should have.
- static const size_t MinimalELFAttributeSubsectionSize
- = 1 /* Tag_File, see ARM [ABI-addenda], 2.2.4 */ +
- 4 /* byte-size, see ARM [ABI-addenda], 2.2.4 */;
+ static const size_t MinimalELFAttributeSubsectionSize =
+ 1 /* Tag_File, see ARM [ABI-addenda], 2.2.4 */ +
+ 4 /* byte-size, see ARM [ABI-addenda], 2.2.4 */;
// MinimalELFAttributeSectionSize is the minimal number of bytes a valid ELF
// attribute section should have.
- static const size_t MinimalELFAttributeSectionSize
- = FormatVersionFieldSize + SubsectionLengthFieldSize +
- 2 /* vendor-name, a char plus '\0', see ARM [ABI-addenda], 2.2.3 */ +
- 1 * MinimalELFAttributeSubsectionSize;
+ static const size_t MinimalELFAttributeSectionSize =
+ FormatVersionFieldSize + SubsectionLengthFieldSize +
+ 2 /* vendor-name, a char plus '\0', see ARM [ABI-addenda], 2.2.3 */ +
+ 1 * MinimalELFAttributeSubsectionSize;
-public:
- ELFAttribute(const GNULDBackend &pBackend, const LinkerConfig& pConfig)
- : m_Backend(pBackend), m_Config(pConfig) { }
+ public:
+ ELFAttribute(const GNULDBackend& pBackend, const LinkerConfig& pConfig)
+ : m_Backend(pBackend), m_Config(pConfig) {}
~ELFAttribute();
-public:
+ public:
/// merge - merge attributes from input (attribute) section
- bool merge(const Input &pInput, LDSection &pInputAttrSectHdr);
+ bool merge(const Input& pInput, LDSection& pInputAttrSectHdr);
/// sizeOutput - calculate the number of bytes required to encode this
/// attribute data section
size_t sizeOutput() const;
/// emit - encode and write out this attribute section
- size_t emit(MemoryRegion &pRegion) const;
+ size_t emit(MemoryRegion& pRegion) const;
- inline const GNULDBackend &backend() const { return m_Backend; }
+ inline const GNULDBackend& backend() const { return m_Backend; }
- inline const LinkerConfig &config() const { return m_Config; }
+ inline const LinkerConfig& config() const { return m_Config; }
// Place vendor's attribute data under the management.
void registerAttributeData(ELFAttributeData& pAttrData);
-private:
+ private:
/** \class Subsection
* \brief A helper class to wrap ELFAttributeData and to provide general
* interfaces for ELFAttribute to operate on
*/
class Subsection {
- public:
- Subsection(ELFAttribute &pParent, ELFAttributeData &pAttrData)
- : m_Parent(pParent), m_AttrData(pAttrData) { }
+ public:
+ Subsection(ELFAttribute& pParent, ELFAttributeData& pAttrData)
+ : m_Parent(pParent), m_AttrData(pAttrData) {}
- public:
- bool isMyAttribute(llvm::StringRef pVendorName) const
- {
+ public:
+ bool isMyAttribute(llvm::StringRef pVendorName) const {
return (m_AttrData.getVendorName() == pVendorName);
}
/// merge - Merge the attributes from the section in the input data.
- bool merge(const Input &pInput, ConstAddress pData, size_t pSize);
+ bool merge(const Input& pInput, ConstAddress pData, size_t pSize);
/// sizeOutput - calculate the number of bytes required to encode this
/// subsection
size_t sizeOutput() const;
/// emit - write out this attribute subsection to the buffer.
- size_t emit(char *pBuf) const;
+ size_t emit(char* pBuf) const;
- private:
+ private:
// The attribute section this subsection belongs to
- ELFAttribute &m_Parent;
+ ELFAttribute& m_Parent;
// The attribute data containing in this subsection
- ELFAttributeData &m_AttrData;
+ ELFAttributeData& m_AttrData;
};
// Obtain the corresponding subsection of the specified vendor
- Subsection *getSubsection(llvm::StringRef pVendorName) const;
+ Subsection* getSubsection(llvm::StringRef pVendorName) const;
-private:
- const GNULDBackend &m_Backend;
+ private:
+ const GNULDBackend& m_Backend;
- const LinkerConfig &m_Config;
+ const LinkerConfig& m_Config;
// There is at most two subsections ("aeabi" and "gnu") in most cases.
llvm::SmallVector<Subsection*, 2> m_Subsections;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_TARGET_ELFATTRIBUTE_H_
diff --git a/include/mcld/Target/ELFAttributeData.h b/include/mcld/Target/ELFAttributeData.h
index 1480bb7..0c58366 100644
--- a/include/mcld/Target/ELFAttributeData.h
+++ b/include/mcld/Target/ELFAttributeData.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGET_ELFATTRIBUTEDATA_H
-#define MCLD_TARGET_ELFATTRIBUTEDATA_H
+#ifndef MCLD_TARGET_ELFATTRIBUTEDATA_H_
+#define MCLD_TARGET_ELFATTRIBUTEDATA_H_
#include <stdint.h>
#include <string>
@@ -22,30 +22,29 @@ class LinkerConfig;
/** \class ELFAttributeData
* \brief ELFAttributeData handles data in vendor attribute subsection.
*/
-class ELFAttributeData
-{
-public:
+class ELFAttributeData {
+ public:
typedef uint32_t TagType;
// Generic attribute tags shared between all vendors
enum {
- Tag_NULL = 0,
- Tag_File = 1,
- Tag_Section = 2,
- Tag_Symbol = 3,
+ Tag_NULL = 0,
+ Tag_File = 1,
+ Tag_Section = 2,
+ Tag_Symbol = 3,
};
-public:
- ELFAttributeData(const char* pVendor) : m_Vendor(pVendor) { }
+ public:
+ explicit ELFAttributeData(const char* pVendor) : m_Vendor(pVendor) {}
- virtual ~ELFAttributeData() { }
+ virtual ~ELFAttributeData() {}
-public:
- inline const std::string &getVendorName() const { return m_Vendor; }
+ public:
+ inline const std::string& getVendorName() const { return m_Vendor; }
/// getAttributeValue - query the data store for the attribute value of the
/// given tag.
- virtual const ELFAttributeValue *getAttributeValue(TagType pTag) const = 0;
+ virtual const ELFAttributeValue* getAttributeValue(TagType pTag) const = 0;
/// getOrCreateAttributeValue - obtain attribute value for the given tag and
/// create if it does not exist.
@@ -53,45 +52,49 @@ public:
/// It returns a pair containing the attribute value instance (guaranteed to
/// be non-NULL) and a boolean value indicating whether the instance is newly
/// created (true) or not (false.)
- virtual std::pair<ELFAttributeValue*, bool>
- getOrCreateAttributeValue(TagType pTag) = 0;
+ virtual std::pair<ELFAttributeValue*, bool> getOrCreateAttributeValue(
+ TagType pTag) = 0;
/// preMerge - hooks to call before starting merge the attribute data in an
/// input.
- virtual bool preMerge(const Input &pInput) { return true; }
+ virtual bool preMerge(const Input& pInput) { return true; }
/// merge - implement logics to merge input attribute to the output.
- virtual bool merge(const LinkerConfig& pConfig, const Input &pInput,
- TagType pTag, const ELFAttributeValue& pInAttr) = 0;
+ virtual bool merge(const LinkerConfig& pConfig,
+ const Input& pInput,
+ TagType pTag,
+ const ELFAttributeValue& pInAttr) = 0;
/// postMerge - hooks to call after finishing merge the attribute data from an
/// input.
- virtual bool postMerge(const LinkerConfig& pConfig, const Input &pInput)
- { return true; }
+ virtual bool postMerge(const LinkerConfig& pConfig, const Input& pInput) {
+ return true;
+ }
/// sizeOutput - obtain number of bytes required to encode the attribute data.
virtual size_t sizeOutput() const = 0;
/// emit - write out attribute data to the buffer and return the number of
/// bytes written
- virtual size_t emit(char *pBuf) const = 0;
+ virtual size_t emit(char* pBuf) const = 0;
-public:
+ public:
/// ReadTag - read an attribute tag from input buffer.
///
/// If the read succeeds, pBuf moves to the new position just pass the end of
/// the tag in the buffer and pBufSize decreases the size of tag in the
/// buffer. Otherwise, this function will return false and change nothing
/// except leaving undefined value in pTag.
- static bool ReadTag(TagType& pTag, const char* &pBuf, size_t &pBufSize);
+ static bool ReadTag(TagType& pTag, const char*& pBuf, size_t& pBufSize);
/// ReadValue - read an attribute value from input buffer
///
/// Similar with ReadTag() while this reads attribute value from the input
/// buffer. Note that the value type of the attribute must be properly set in
/// pValue prior the call.
- static bool ReadValue(ELFAttributeValue& pValue, const char* &pBuf,
- size_t &pBufSize);
+ static bool ReadValue(ELFAttributeValue& pValue,
+ const char*& pBuf,
+ size_t& pBufSize);
/// WriteAttribute - write an attribute tag plus value to buffer.
///
@@ -99,13 +102,14 @@ public:
/// attribute data just written. Otherwise, it returns false and leaves pBuf
/// in an undefined position. Note that buffer is guaranteed to be able to
/// contain the attribute data.
- static bool WriteAttribute(TagType pTag, const ELFAttributeValue& pValue,
- char* &pBuf);
+ static bool WriteAttribute(TagType pTag,
+ const ELFAttributeValue& pValue,
+ char*& pBuf);
-private:
+ private:
const std::string m_Vendor;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_TARGET_ELFATTRIBUTEDATA_H_
diff --git a/include/mcld/Target/ELFAttributeValue.h b/include/mcld/Target/ELFAttributeValue.h
index f4ee3dc..e654a6c 100644
--- a/include/mcld/Target/ELFAttributeValue.h
+++ b/include/mcld/Target/ELFAttributeValue.h
@@ -6,85 +6,75 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGET_ELFATTRIBUTEVALUE_H
-#define MCLD_TARGET_ELFATTRIBUTEVALUE_H
+#ifndef MCLD_TARGET_ELFATTRIBUTEVALUE_H_
+#define MCLD_TARGET_ELFATTRIBUTEVALUE_H_
#include <string>
-namespace mcld
-{
+namespace mcld {
/** \class ELFAttributeValue
* \brief ELFAttributeValue stroes the value of an attribute tag. The attribtue
* tag itself is not stored in this object.
*/
-class ELFAttributeValue
-{
-public:
+class ELFAttributeValue {
+ public:
// Type of value that an attribute tag holds.
enum Type {
// The value contains no data and has unknown type.
Uninitialized = 0,
// The value contains integer data.
- Int = 1L << 0,
+ Int = 1L << 0,
// The value contains string data.
- String = 1L << 1,
+ String = 1L << 1,
// This is for attribute in which "default value" (0 for int type and empty
// string for string type) has special meaning for them. That is, the
// default value is "disabled" and meaningful for those attribute.
- NoDefault = 1L << 2,
+ NoDefault = 1L << 2,
};
-public:
- ELFAttributeValue()
- : m_Type(Uninitialized), m_IntValue(0), m_StringValue() { }
+ public:
+ ELFAttributeValue() : m_Type(Uninitialized), m_IntValue(0), m_StringValue() {}
- ~ELFAttributeValue() { }
+ ~ELFAttributeValue() {}
-public:
- unsigned int type() const
- { return m_Type; }
+ public:
+ unsigned int type() const { return m_Type; }
- void setType(unsigned int pType)
- { m_Type = pType; }
+ void setType(unsigned int pType) { m_Type = pType; }
- unsigned int getIntValue() const
- { return m_IntValue; }
+ unsigned int getIntValue() const { return m_IntValue; }
- void setIntValue(unsigned int pIntValue)
- { m_IntValue = pIntValue; }
+ void setIntValue(unsigned int pIntValue) { m_IntValue = pIntValue; }
- const std::string &getStringValue() const
- { return m_StringValue; }
+ const std::string& getStringValue() const { return m_StringValue; }
- void setStringValue(const std::string &pStringValue)
- { m_StringValue = pStringValue; }
+ void setStringValue(const std::string& pStringValue) {
+ m_StringValue = pStringValue;
+ }
- void setStringValue(const char *pStringValue, size_t pSize)
- { m_StringValue.assign(pStringValue, pSize); }
+ void setStringValue(const char* pStringValue, size_t pSize) {
+ m_StringValue.assign(pStringValue, pSize);
+ }
- void setStringValue(const char *pStringValue)
- { m_StringValue.assign(pStringValue); }
+ void setStringValue(const char* pStringValue) {
+ m_StringValue.assign(pStringValue);
+ }
size_t getSize() const;
- inline bool isUninitialized() const
- { return (m_Type == Uninitialized); }
+ inline bool isUninitialized() const { return (m_Type == Uninitialized); }
- inline bool isInitialized() const
- { return !isUninitialized(); }
+ inline bool isInitialized() const { return !isUninitialized(); }
- inline bool isIntValue() const
- { return (m_Type & Int); }
+ inline bool isIntValue() const { return (m_Type & Int); }
- inline bool isStringValue() const
- { return (m_Type & String); }
+ inline bool isStringValue() const { return (m_Type & String); }
- inline bool hasNoDefault() const
- { return (m_Type & NoDefault); }
+ inline bool hasNoDefault() const { return (m_Type & NoDefault); }
bool isDefaultValue() const;
@@ -96,27 +86,28 @@ public:
bool equals(const ELFAttributeValue& pValue) const;
- bool operator==(const ELFAttributeValue& pValue) const
- { return equals(pValue); }
- bool operator!=(const ELFAttributeValue& pValue) const
- { return !equals(pValue); }
+ bool operator==(const ELFAttributeValue& pValue) const {
+ return equals(pValue);
+ }
+ bool operator!=(const ELFAttributeValue& pValue) const {
+ return !equals(pValue);
+ }
/// reset - reset this value to the uninitialized state
- void reset()
- {
+ void reset() {
m_Type = Uninitialized;
m_IntValue = 0;
m_StringValue.clear();
return;
}
-private:
+ private:
unsigned int m_Type;
unsigned int m_IntValue;
std::string m_StringValue;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // MCLD_TARGET_ELFATTRIBUTEVALUE_H_
diff --git a/include/mcld/Target/ELFDynamic.h b/include/mcld/Target/ELFDynamic.h
index 87d0f0f..42feeb6 100644
--- a/include/mcld/Target/ELFDynamic.h
+++ b/include/mcld/Target/ELFDynamic.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGET_ELFDYNAMIC_H
-#define MCLD_TARGET_ELFDYNAMIC_H
+#ifndef MCLD_TARGET_ELFDYNAMIC_H_
+#define MCLD_TARGET_ELFDYNAMIC_H_
-#include <mcld/LD/LDSection.h>
-#include <mcld/Support/FileOutputBuffer.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/Support/FileOutputBuffer.h"
#include <llvm/Support/ELF.h>
#include <vector>
#include <cstring>
@@ -27,12 +27,11 @@ namespace elf_dynamic {
* \brief EntryIF provides a common interface for one entry in the dynamic
* section
*/
-class EntryIF
-{
-protected:
+class EntryIF {
+ protected:
EntryIF();
-public:
+ public:
virtual ~EntryIF();
virtual EntryIF* clone() const = 0;
@@ -44,100 +43,86 @@ public:
virtual void setValue(uint64_t pTag, uint64_t pValue) = 0;
};
-template<size_t BITNUMBER, bool LITTLEENDIAN>
-class Entry
-{ };
-
-template<>
-class Entry<32, true> : public EntryIF
-{
-public:
- typedef llvm::ELF::Elf32_Dyn Pair;
- typedef llvm::ELF::Elf32_Sym Symbol;
- typedef llvm::ELF::Elf32_Rel Rel;
+template <size_t BITNUMBER, bool LITTLEENDIAN>
+class Entry {};
+
+template <>
+class Entry<32, true> : public EntryIF {
+ public:
+ typedef llvm::ELF::Elf32_Dyn Pair;
+ typedef llvm::ELF::Elf32_Sym Symbol;
+ typedef llvm::ELF::Elf32_Rel Rel;
typedef llvm::ELF::Elf32_Rela Rela;
-public:
+ public:
inline Entry();
inline ~Entry();
- Entry* clone() const
- { return new Entry(); }
+ Entry* clone() const { return new Entry(); }
- size_t size() const
- { return sizeof(Pair); }
+ size_t size() const { return sizeof(Pair); }
- size_t symbolSize() const
- { return sizeof(Symbol); }
+ size_t symbolSize() const { return sizeof(Symbol); }
- size_t relSize() const
- { return sizeof(Rel); }
+ size_t relSize() const { return sizeof(Rel); }
- size_t relaSize() const
- { return sizeof(Rela); }
+ size_t relaSize() const { return sizeof(Rela); }
inline void setValue(uint64_t pTag, uint64_t pValue);
inline size_t emit(uint8_t* pAddress) const;
-private:
+ private:
Pair m_Pair;
};
-template<>
-class Entry<64, true> : public EntryIF
-{
-public:
- typedef llvm::ELF::Elf64_Dyn Pair;
- typedef llvm::ELF::Elf64_Sym Symbol;
- typedef llvm::ELF::Elf64_Rel Rel;
+template <>
+class Entry<64, true> : public EntryIF {
+ public:
+ typedef llvm::ELF::Elf64_Dyn Pair;
+ typedef llvm::ELF::Elf64_Sym Symbol;
+ typedef llvm::ELF::Elf64_Rel Rel;
typedef llvm::ELF::Elf64_Rela Rela;
-public:
+ public:
inline Entry();
inline ~Entry();
- Entry* clone() const
- { return new Entry(); }
+ Entry* clone() const { return new Entry(); }
- size_t size() const
- { return sizeof(Pair); }
+ size_t size() const { return sizeof(Pair); }
- size_t symbolSize() const
- { return sizeof(Symbol); }
+ size_t symbolSize() const { return sizeof(Symbol); }
- size_t relSize() const
- { return sizeof(Rel); }
+ size_t relSize() const { return sizeof(Rel); }
- size_t relaSize() const
- { return sizeof(Rela); }
+ size_t relaSize() const { return sizeof(Rela); }
inline void setValue(uint64_t pTag, uint64_t pValue);
inline size_t emit(uint8_t* pAddress) const;
-private:
+ private:
Pair m_Pair;
};
#include "ELFDynamic.tcc"
-} // namespace of elf_dynamic
+} // namespace elf_dynamic
/** \class ELFDynamic
* \brief ELFDynamic is the .dynamic section in ELF shared and executable
* files.
*/
-class ELFDynamic
-{
-public:
+class ELFDynamic {
+ public:
typedef std::vector<elf_dynamic::EntryIF*> EntryListType;
typedef EntryListType::iterator iterator;
typedef EntryListType::const_iterator const_iterator;
-public:
+ public:
ELFDynamic(const GNULDBackend& pBackend, const LinkerConfig& pConfig);
virtual ~ELFDynamic();
@@ -160,22 +145,22 @@ public:
void applySoname(uint64_t pStrTabIdx);
const_iterator needBegin() const { return m_NeedList.begin(); }
- iterator needBegin() { return m_NeedList.begin(); }
+ iterator needBegin() { return m_NeedList.begin(); }
const_iterator needEnd() const { return m_NeedList.end(); }
- iterator needEnd() { return m_NeedList.end(); }
+ iterator needEnd() { return m_NeedList.end(); }
/// emit
void emit(const LDSection& pSection, MemoryRegion& pRegion) const;
-protected:
+ protected:
/// reserveTargetEntries - reserve target dependent entries
virtual void reserveTargetEntries(const ELFFileFormat& pFormat) = 0;
/// applyTargetEntries - apply target-dependant
virtual void applyTargetEntries(const ELFFileFormat& pFormat) = 0;
-protected:
+ protected:
void reserveOne(uint64_t pTag);
void applyOne(uint64_t pTag, uint64_t pValue);
@@ -184,7 +169,7 @@ protected:
const LinkerConfig& config() const { return m_Config; }
-private:
+ private:
EntryListType m_EntryList;
EntryListType m_NeedList;
elf_dynamic::EntryIF* m_pEntryFactory;
@@ -197,7 +182,6 @@ private:
size_t m_Idx;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_TARGET_ELFDYNAMIC_H_
diff --git a/include/mcld/Target/ELFDynamic.tcc b/include/mcld/Target/ELFDynamic.tcc
index 5d67be4..2a00c79 100644
--- a/include/mcld/Target/ELFDynamic.tcc
+++ b/include/mcld/Target/ELFDynamic.tcc
@@ -9,24 +9,20 @@
//===----------------------------------------------------------------------===//
/// 32-bit dynamic entry
-Entry<32, true>::Entry()
-{
+Entry<32, true>::Entry() {
m_Pair.d_tag = 0;
m_Pair.d_un.d_val = 0;
}
-Entry<32, true>::~Entry()
-{
+Entry<32, true>::~Entry() {
}
-void Entry<32, true>::setValue(uint64_t pTag, uint64_t pValue)
-{
+void Entry<32, true>::setValue(uint64_t pTag, uint64_t pValue) {
m_Pair.d_tag = pTag;
m_Pair.d_un.d_val = pValue;
}
-size_t Entry<32, true>::emit(uint8_t* pAddress) const
-{
+size_t Entry<32, true>::emit(uint8_t* pAddress) const {
memcpy(reinterpret_cast<void*>(pAddress),
reinterpret_cast<const void*>(&m_Pair),
sizeof(Pair));
@@ -35,27 +31,22 @@ size_t Entry<32, true>::emit(uint8_t* pAddress) const
//===----------------------------------------------------------------------===//
/// 64-bit dynamic entry
-Entry<64, true>::Entry()
-{
+Entry<64, true>::Entry() {
m_Pair.d_tag = 0;
m_Pair.d_un.d_val = 0;
}
-Entry<64, true>::~Entry()
-{
+Entry<64, true>::~Entry() {
}
-void Entry<64, true>::setValue(uint64_t pTag, uint64_t pValue)
-{
+void Entry<64, true>::setValue(uint64_t pTag, uint64_t pValue) {
m_Pair.d_tag = pTag;
m_Pair.d_un.d_val = pValue;
}
-size_t Entry<64, true>::emit(uint8_t* pAddress) const
-{
+size_t Entry<64, true>::emit(uint8_t* pAddress) const {
memcpy(reinterpret_cast<void*>(pAddress),
reinterpret_cast<const void*>(&m_Pair),
sizeof(Pair));
return sizeof(Pair);
}
-
diff --git a/include/mcld/Target/ELFEmulation.h b/include/mcld/Target/ELFEmulation.h
index 0e9a1ec..3c6e6f7 100644
--- a/include/mcld/Target/ELFEmulation.h
+++ b/include/mcld/Target/ELFEmulation.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGET_ELFEMULATION_H
-#define MCLD_TARGET_ELFEMULATION_H
+#ifndef MCLD_TARGET_ELFEMULATION_H_
+#define MCLD_TARGET_ELFEMULATION_H_
namespace mcld {
@@ -16,7 +16,6 @@ class LinkerScript;
bool MCLDEmulateELF(LinkerScript& pScript, LinkerConfig& pConfig);
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_TARGET_ELFEMULATION_H_
diff --git a/include/mcld/Target/GNUInfo.h b/include/mcld/Target/GNUInfo.h
index 2eb53da..2a55688 100644
--- a/include/mcld/Target/GNUInfo.h
+++ b/include/mcld/Target/GNUInfo.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGET_GNUINFO_H
-#define MCLD_TARGET_GNUINFO_H
+#ifndef MCLD_TARGET_GNUINFO_H_
+#define MCLD_TARGET_GNUINFO_H_
#include <llvm/ADT/Triple.h>
#include <llvm/Support/ELF.h>
@@ -16,12 +16,11 @@ namespace mcld {
/** \class GNUInfo
* \brief GNUInfo records ELF-dependent and target-dependnet data fields
*/
-class GNUInfo
-{
-public:
- GNUInfo(const llvm::Triple& pTriple);
+class GNUInfo {
+ public:
+ explicit GNUInfo(const llvm::Triple& pTriple);
- virtual ~GNUInfo() { }
+ virtual ~GNUInfo() {}
/// ELFVersion - the value of e_ident[EI_VERSION]
virtual uint8_t ELFVersion() const { return llvm::ELF::EV_CURRENT; }
@@ -35,7 +34,8 @@ public:
/// ABIVersion - the value of e_ident[EI_ABIVRESION]
virtual uint8_t ABIVersion() const { return 0x0; }
- /// defaultTextSegmentAddr - target should specify its own default start address
+ /// defaultTextSegmentAddr - target should specify its own default start
+ /// address
/// of the text segment. esp. for exec.
virtual uint64_t defaultTextSegmentAddr() const { return 0x0; }
@@ -62,11 +62,10 @@ public:
/// here. If target favors the different size, please override this function
virtual uint64_t abiPageSize() const { return 0x1000; }
-protected:
+ protected:
const llvm::Triple& m_Triple;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_TARGET_GNUINFO_H_
diff --git a/include/mcld/Target/GNULDBackend.h b/include/mcld/Target/GNULDBackend.h
index 351111d..93f7b1b 100644
--- a/include/mcld/Target/GNULDBackend.h
+++ b/include/mcld/Target/GNULDBackend.h
@@ -6,16 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGET_GNULDBACKEND_H
-#define MCLD_TARGET_GNULDBACKEND_H
-#include <mcld/Target/TargetLDBackend.h>
+#ifndef MCLD_TARGET_GNULDBACKEND_H_
+#define MCLD_TARGET_GNULDBACKEND_H_
-#include <mcld/Module.h>
-#include <mcld/LD/GNUArchiveReader.h>
-#include <mcld/LD/ELFDynObjReader.h>
-#include <mcld/LD/ELFBinaryReader.h>
-#include <mcld/LD/ELFObjectReader.h>
-#include <mcld/LD/ELFObjectWriter.h>
+#include "mcld/Module.h"
+#include "mcld/LD/ELFBinaryReader.h"
+#include "mcld/LD/ELFDynObjReader.h"
+#include "mcld/LD/ELFObjectReader.h"
+#include "mcld/LD/ELFObjectWriter.h"
+#include "mcld/LD/GNUArchiveReader.h"
+#include "mcld/Target/TargetLDBackend.h"
#include <llvm/Support/ELF.h>
@@ -23,34 +23,33 @@
namespace mcld {
-class Module;
-class LinkerConfig;
-class IRBuilder;
-class Layout;
-class EhFrameHdr;
class BranchIslandFactory;
-class StubFactory;
-class GNUInfo;
-class ELFFileFormat;
-class ELFSegmentFactory;
+class EhFrameHdr;
class ELFAttribute;
class ELFDynamic;
class ELFDynObjFileFormat;
class ELFExecFileFormat;
+class ELFFileFormat;
class ELFObjectFileFormat;
+class ELFSegmentFactory;
+class GNUInfo;
+class IRBuilder;
+class Layout;
+class LinkerConfig;
class LinkerScript;
+class Module;
class Relocation;
+class StubFactory;
/** \class GNULDBackend
* \brief GNULDBackend provides a common interface for all GNU Unix-OS
* LDBackend.
*/
-class GNULDBackend : public TargetLDBackend
-{
-protected:
+class GNULDBackend : public TargetLDBackend {
+ protected:
GNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo);
-public:
+ public:
virtual ~GNULDBackend();
// ----- readers/writers ----- //
@@ -66,7 +65,7 @@ public:
/// getOutputFormat - get the sections of the output file.
const ELFFileFormat* getOutputFormat() const;
- ELFFileFormat* getOutputFormat();
+ ELFFileFormat* getOutputFormat();
// ----- target symbols ----- //
/// initStandardSymbols - initialize standard symbols.
@@ -83,8 +82,7 @@ public:
/// @return ture - if backend set the symbol value sucessfully
/// @return false - if backend do not recognize the symbol
bool finalizeSymbols() {
- return (finalizeStandardSymbols() &&
- finalizeTargetSymbols());
+ return (finalizeStandardSymbols() && finalizeTargetSymbols());
}
/// finalizeStandardSymbols - set the value of standard symbols
@@ -99,13 +97,13 @@ public:
size_t sectionStartOffset() const;
const GNUInfo& getInfo() const { return *m_pInfo; }
- GNUInfo& getInfo() { return *m_pInfo; }
+ GNUInfo& getInfo() { return *m_pInfo; }
bool hasTextRel() const { return m_bHasTextRel; }
bool hasStaticTLS() const { return m_bHasStaticTLS; }
- /// getSegmentStartAddr - this function returns the start address of the segment
+ /// getSegmentStartAddr - return the start address of the segment
uint64_t getSegmentStartAddr(const LinkerScript& pScript) const;
/// sizeShstrtab - compute the size of .shstrtab
@@ -121,7 +119,8 @@ public:
MemoryRegion& pRegion) const = 0;
/// emitRegNamePools - emit regular name pools - .symtab, .strtab
- virtual void emitRegNamePools(const Module& pModule, FileOutputBuffer& pOutput);
+ virtual void emitRegNamePools(const Module& pModule,
+ FileOutputBuffer& pOutput);
/// emitNamePools - emit dynamic name pools - .dyntab, .dynstr, .hash
virtual void emitDynNamePools(Module& pModule, FileOutputBuffer& pOutput);
@@ -147,8 +146,7 @@ public:
/// orderSymbolTable - order symbol table before emitting
virtual void orderSymbolTable(Module& pModule);
- void setHasStaticTLS(bool pVal = true)
- { m_bHasStaticTLS = pVal; }
+ void setHasStaticTLS(bool pVal = true) { m_bHasStaticTLS = pVal; }
/// getSectionOrder - compute the layout order of the section
/// Layout calls this function to get the default order of the pSectHdr.
@@ -167,11 +165,12 @@ public:
///
/// By default, this function returns the maximun order, and pSectHdr
/// will be the last section to be laid out.
- virtual unsigned int getTargetSectionOrder(const LDSection& pSectHdr) const
- { return (unsigned int)-1; }
+ virtual unsigned int getTargetSectionOrder(const LDSection& pSectHdr) const {
+ return (unsigned int)-1;
+ }
/// elfSegmentTable - return the reference of the elf segment table
- ELFSegmentFactory& elfSegmentTable();
+ ELFSegmentFactory& elfSegmentTable();
/// elfSegmentTable - return the reference of the elf segment table
const ELFSegmentFactory& elfSegmentTable() const;
@@ -247,7 +246,6 @@ public:
int64_t pAddend) const;
/// symbolNeedsPLT - return whether the symbol needs a PLT entry
- /// @ref Google gold linker, symtab.h:596
bool symbolNeedsPLT(const ResolveInfo& pSym) const;
/// symbolNeedsCopyReloc - return whether the symbol needs a copy relocation
@@ -255,14 +253,12 @@ public:
const ResolveInfo& pSym) const;
/// symbolNeedsDynRel - return whether the symbol needs a dynamic relocation
- /// @ref Google gold linker, symtab.h:645
bool symbolNeedsDynRel(const ResolveInfo& pSym,
bool pSymHasPLT,
bool isAbsReloc) const;
/// isSymbolPreemptible - whether the symbol can be preemted by other link
/// units
- /// @ref Google gold linker, symtab.h:551
bool isSymbolPreemptible(const ResolveInfo& pSym) const;
/// symbolHasFinalValue - return true if the symbol's value can be decided at
@@ -270,22 +266,20 @@ public:
bool symbolFinalValueIsKnown(const ResolveInfo& pSym) const;
/// isDynamicSymbol
- /// @ref Google gold linker: symtab.cc:311
bool isDynamicSymbol(const LDSymbol& pSymbol) const;
/// isDynamicSymbol
- /// @ref Google gold linker: symtab.cc:311
bool isDynamicSymbol(const ResolveInfo& pResolveInfo) const;
virtual ResolveInfo::Desc getSymDesc(uint16_t pShndx) const {
return ResolveInfo::Define;
}
- bool hasTDATASymbol() const { return (NULL != f_pTDATA); }
- bool hasTBSSSymbol() const { return (NULL != f_pTBSS); }
+ bool hasTDATASymbol() const { return (f_pTDATA != NULL); }
+ bool hasTBSSSymbol() const { return (f_pTBSS != NULL); }
void setTDATASymbol(LDSymbol& pTDATA) { f_pTDATA = &pTDATA; }
- void setTBSSSymbol(LDSymbol& pTBSS) { f_pTBSS = &pTBSS; }
+ void setTBSSSymbol(LDSymbol& pTBSS) { f_pTBSS = &pTBSS; }
// getTDATASymbol - get section symbol of .tdata
LDSymbol& getTDATASymbol();
@@ -309,7 +303,7 @@ public:
BranchIslandFactory* getBRIslandFactory() { return m_pBRIslandFactory; }
/// getStubFactory
- StubFactory* getStubFactory() { return m_pStubFactory; }
+ StubFactory* getStubFactory() { return m_pStubFactory; }
/// maxFwdBranchOffset - return the max forward branch offset of the backend.
/// Target can override this function if needed.
@@ -340,7 +334,7 @@ public:
/// function pointer access
bool mayHaveUnsafeFunctionPointerAccess(const LDSection& pSection) const;
-protected:
+ protected:
/// getRelEntrySize - the size in BYTE of rel type relocation
virtual size_t getRelEntrySize() = 0;
@@ -359,11 +353,9 @@ protected:
virtual bool isTemporary(const LDSymbol& pSymbol) const;
/// getHashBucketCount - calculate hash bucket count.
- /// @ref Google gold linker, dynobj.cc:791
static unsigned getHashBucketCount(unsigned pNumOfSymbols, bool pIsGNUStyle);
/// getGNUHashMaskbitslog2 - calculate the number of mask bits in log2
- /// @ref binutils gold, dynobj.cc:1165
unsigned getGNUHashMaskbitslog2(unsigned pNumOfSymbols) const;
/// emitSymbol32 - emit an ELF32 symbol
@@ -380,7 +372,7 @@ protected:
size_t pStrtabsize,
size_t pSymtabIdx);
-private:
+ private:
/// createProgramHdrs - base on output sections to create the program headers
void createProgramHdrs(Module& pModule);
@@ -442,71 +434,66 @@ private:
/// implementation. Return true if the output (e.g., .text) is "relaxed"
/// (i.e. layout is changed), and set pFinished to true if everything is fit,
/// otherwise set it to false.
- virtual bool doRelax(Module& pModule, IRBuilder& pBuilder, bool& pFinished)
- { return false; }
+ virtual bool doRelax(Module& pModule, IRBuilder& pBuilder, bool& pFinished) {
+ return false;
+ }
-protected:
- // Based on Kind in LDFileFormat to define basic section orders for ELF, and
- // refer gold linker to add more enumerations to handle Regular and BSS kind
+ protected:
+ // Based on Kind in LDFileFormat to define basic section orders for ELF.
enum SectionOrder {
- SHO_NULL = 0, // NULL
- SHO_INTERP, // .interp
- SHO_RO_NOTE, // .note.ABI-tag, .note.gnu.build-id
- SHO_NAMEPOOL, // *.hash, .dynsym, .dynstr
- SHO_RELOCATION, // .rel.*, .rela.*
- SHO_REL_PLT, // .rel.plt should come after other .rel.*
- SHO_INIT, // .init
- SHO_PLT, // .plt
- SHO_TEXT, // .text
- SHO_FINI, // .fini
- SHO_RO, // .rodata
- SHO_EXCEPTION, // .eh_frame_hdr, .eh_frame, .gcc_except_table
- SHO_TLS_DATA, // .tdata
- SHO_TLS_BSS, // .tbss
- SHO_RELRO_LOCAL, // .data.rel.ro.local
- SHO_RELRO, // .data.rel.ro,
- SHO_RELRO_LAST, // for x86 to adjust .got if needed
- SHO_NON_RELRO_FIRST, // for x86 to adjust .got.plt if needed
- SHO_DATA, // .data
- SHO_LARGE_DATA, // .ldata
- SHO_RW_NOTE, //
- SHO_SMALL_DATA, // .sdata
- SHO_SMALL_BSS, // .sbss
- SHO_BSS, // .bss
- SHO_LARGE_BSS, // .lbss
- SHO_UNDEFINED, // default order
- SHO_STRTAB // .strtab
+ SHO_NULL = 0, // NULL
+ SHO_INTERP, // .interp
+ SHO_RO_NOTE, // .note.ABI-tag, .note.gnu.build-id
+ SHO_NAMEPOOL, // *.hash, .dynsym, .dynstr
+ SHO_RELOCATION, // .rel.*, .rela.*
+ SHO_REL_PLT, // .rel.plt should come after other .rel.*
+ SHO_INIT, // .init
+ SHO_PLT, // .plt
+ SHO_TEXT, // .text
+ SHO_FINI, // .fini
+ SHO_RO, // .rodata
+ SHO_EXCEPTION, // .eh_frame_hdr, .eh_frame, .gcc_except_table
+ SHO_TLS_DATA, // .tdata
+ SHO_TLS_BSS, // .tbss
+ SHO_RELRO_LOCAL, // .data.rel.ro.local
+ SHO_RELRO, // .data.rel.ro,
+ SHO_RELRO_LAST, // for x86 to adjust .got if needed
+ SHO_NON_RELRO_FIRST, // for x86 to adjust .got.plt if needed
+ SHO_DATA, // .data
+ SHO_LARGE_DATA, // .ldata
+ SHO_RW_NOTE, //
+ SHO_SMALL_DATA, // .sdata
+ SHO_SMALL_BSS, // .sbss
+ SHO_BSS, // .bss
+ SHO_LARGE_BSS, // .lbss
+ SHO_UNDEFINED, // default order
+ SHO_STRTAB // .strtab
};
// for -z combreloc
- struct RelocCompare
- {
- RelocCompare(const GNULDBackend& pBackend)
- : m_Backend(pBackend) {
- }
+ struct RelocCompare {
+ explicit RelocCompare(const GNULDBackend& pBackend) : m_Backend(pBackend) {}
bool operator()(const Relocation* X, const Relocation* Y) const;
- private:
+
+ private:
const GNULDBackend& m_Backend;
};
// for gnu style hash table
- struct DynsymCompare
- {
+ struct DynsymCompare {
bool needGNUHash(const LDSymbol& X) const;
bool operator()(const LDSymbol* X, const LDSymbol* Y) const;
};
- struct SymCompare
- {
- bool operator()(const LDSymbol* X, const LDSymbol* Y) const
- { return (X==Y); }
+ struct SymCompare {
+ bool operator()(const LDSymbol* X, const LDSymbol* Y) const {
+ return (X == Y);
+ }
};
- struct SymPtrHash
- {
- size_t operator()(const LDSymbol* pKey) const
- {
+ struct SymPtrHash {
+ size_t operator()(const LDSymbol* pKey) const {
return (unsigned((uintptr_t)pKey) >> 4) ^
(unsigned((uintptr_t)pKey) >> 9);
}
@@ -517,13 +504,12 @@ protected:
SymPtrHash,
EntryFactory<SymHashEntryType> > HashTableType;
-
-protected:
+ protected:
ELFObjectReader* m_pObjectReader;
// ----- file formats ----- //
ELFDynObjFileFormat* m_pDynObjFileFormat;
- ELFExecFileFormat* m_pExecFileFormat;
+ ELFExecFileFormat* m_pExecFileFormat;
ELFObjectFileFormat* m_pObjectFileFormat;
// GNUInfo
@@ -581,7 +567,6 @@ protected:
LDSymbol* f_p_End;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_TARGET_GNULDBACKEND_H_
diff --git a/include/mcld/Target/GOT.h b/include/mcld/Target/GOT.h
index 01d540f..f458644 100644
--- a/include/mcld/Target/GOT.h
+++ b/include/mcld/Target/GOT.h
@@ -6,12 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGET_GOT_H
-#define MCLD_TARGET_GOT_H
+#ifndef MCLD_TARGET_GOT_H_
+#define MCLD_TARGET_GOT_H_
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Fragment/TargetFragment.h>
+#include "mcld/Fragment/TargetFragment.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
namespace mcld {
@@ -22,44 +22,37 @@ class ResolveInfo;
/** \class GOT
* \brief The Global Offset Table
*/
-class GOT
-{
-protected:
- GOT(LDSection& pSection);
+class GOT {
+ protected:
+ explicit GOT(LDSection& pSection);
-public:
+ public:
typedef SectionData::iterator iterator;
typedef SectionData::const_iterator const_iterator;
- template<size_t SIZE>
- class Entry : public TargetFragment
- {
- public:
+ template <size_t SIZE>
+ class Entry : public TargetFragment {
+ public:
enum { EntrySize = SIZE };
- public:
+ public:
Entry(uint64_t pValue, SectionData* pParent)
- : TargetFragment(Fragment::Target, pParent),
- f_Value(pValue) {
- }
+ : TargetFragment(Fragment::Target, pParent), f_Value(pValue) {}
virtual ~Entry() {}
- uint64_t getValue() const
- { return f_Value; }
+ uint64_t getValue() const { return f_Value; }
- void setValue(uint64_t pValue)
- { f_Value = pValue; }
+ void setValue(uint64_t pValue) { f_Value = pValue; }
// Override pure virtual function
- size_t size() const
- { return EntrySize; }
+ size_t size() const { return EntrySize; }
- protected:
+ protected:
uint64_t f_Value;
};
-public:
+ public:
virtual ~GOT();
// ----- observers -----//
@@ -67,22 +60,20 @@ public:
uint64_t size() const { return m_Section.size(); }
const_iterator begin() const { return m_SectionData->begin(); }
- iterator begin() { return m_SectionData->begin(); }
- const_iterator end () const { return m_SectionData->end(); }
- iterator end () { return m_SectionData->end(); }
+ iterator begin() { return m_SectionData->begin(); }
+ const_iterator end() const { return m_SectionData->end(); }
+ iterator end() { return m_SectionData->end(); }
- bool empty() const
- { return m_SectionData->empty(); }
+ bool empty() const { return m_SectionData->empty(); }
// finalizeSectionSize - set LDSection size
virtual void finalizeSectionSize();
-protected:
+ protected:
LDSection& m_Section;
SectionData* m_SectionData;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_TARGET_GOT_H_
diff --git a/include/mcld/Target/KeyEntryMap.h b/include/mcld/Target/KeyEntryMap.h
index ac11a22..6ff9656 100644
--- a/include/mcld/Target/KeyEntryMap.h
+++ b/include/mcld/Target/KeyEntryMap.h
@@ -6,29 +6,27 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGET_KEYENTRYMAP_H
-#define MCLD_TARGET_KEYENTRYMAP_H
+#ifndef MCLD_TARGET_KEYENTRYMAP_H_
+#define MCLD_TARGET_KEYENTRYMAP_H_
-#include <vector>
#include <list>
+#include <vector>
namespace mcld {
/** \class KeyEntryMap
* \brief KeyEntryMap is a <const KeyType*, ENTRY*> map.
*/
-template<typename KEY, typename ENTRY>
-class KeyEntryMap
-{
-public:
- typedef KEY KeyType;
+template <typename KEY, typename ENTRY>
+class KeyEntryMap {
+ public:
+ typedef KEY KeyType;
typedef ENTRY EntryType;
-private:
+ private:
struct EntryPair {
EntryPair(EntryType* pEntry1, EntryType* pEntry2)
- : entry1(pEntry1), entry2(pEntry2)
- {}
+ : entry1(pEntry1), entry2(pEntry2) {}
EntryType* entry1;
EntryType* entry2;
@@ -49,49 +47,46 @@ private:
typedef std::vector<Mapping> KeyEntryPool;
typedef std::list<EntryPair> PairListType;
-public:
+ public:
typedef typename KeyEntryPool::iterator iterator;
typedef typename KeyEntryPool::const_iterator const_iterator;
-public:
+ public:
/// lookUp - look up the entry mapping to pKey
const EntryType* lookUp(const KeyType& pKey) const;
- EntryType* lookUp(const KeyType& pKey);
+ EntryType* lookUp(const KeyType& pKey);
/// lookUpFirstEntry - look up the first entry mapping to pKey
const EntryType* lookUpFirstEntry(const KeyType& pKey) const;
- EntryType* lookUpFirstEntry(const KeyType& pKey);
+ EntryType* lookUpFirstEntry(const KeyType& pKey);
/// lookUpSecondEntry - look up the second entry mapping to pKey
const EntryType* lookUpSecondEntry(const KeyType& pKey) const;
- EntryType* lookUpSecondEntry(const KeyType& pKey);
+ EntryType* lookUpSecondEntry(const KeyType& pKey);
void record(const KeyType& pKey, EntryType& pEntry);
- void record(const KeyType& pKey,
- EntryType& pEntry1,
- EntryType& pEntry2);
+ void record(const KeyType& pKey, EntryType& pEntry1, EntryType& pEntry2);
- bool empty() const { return m_Pool.empty(); }
- size_t size () const { return m_Pool.size(); }
+ bool empty() const { return m_Pool.empty(); }
+ size_t size() const { return m_Pool.size(); }
const_iterator begin() const { return m_Pool.begin(); }
- iterator begin() { return m_Pool.begin(); }
- const_iterator end () const { return m_Pool.end(); }
- iterator end () { return m_Pool.end(); }
+ iterator begin() { return m_Pool.begin(); }
+ const_iterator end() const { return m_Pool.end(); }
+ iterator end() { return m_Pool.end(); }
void reserve(size_t pSize) { m_Pool.reserve(pSize); }
-private:
+ private:
KeyEntryPool m_Pool;
/// m_Pairs - the EntryPairs
PairListType m_Pairs;
};
-template<typename KeyType, typename EntryType>
-const EntryType*
-KeyEntryMap<KeyType, EntryType>::lookUp(const KeyType& pKey) const
-{
+template <typename KeyType, typename EntryType>
+const EntryType* KeyEntryMap<KeyType, EntryType>::lookUp(
+ const KeyType& pKey) const {
const_iterator mapping, mEnd = m_Pool.end();
for (mapping = m_Pool.begin(); mapping != mEnd; ++mapping) {
if (mapping->key == &pKey) {
@@ -102,10 +97,8 @@ KeyEntryMap<KeyType, EntryType>::lookUp(const KeyType& pKey) const
return NULL;
}
-template<typename KeyType, typename EntryType>
-EntryType*
-KeyEntryMap<KeyType, EntryType>::lookUp(const KeyType& pKey)
-{
+template <typename KeyType, typename EntryType>
+EntryType* KeyEntryMap<KeyType, EntryType>::lookUp(const KeyType& pKey) {
iterator mapping, mEnd = m_Pool.end();
for (mapping = m_Pool.begin(); mapping != mEnd; ++mapping) {
if (mapping->key == &pKey) {
@@ -116,10 +109,9 @@ KeyEntryMap<KeyType, EntryType>::lookUp(const KeyType& pKey)
return NULL;
}
-template<typename KeyType, typename EntryType>
-const EntryType*
-KeyEntryMap<KeyType, EntryType>::lookUpFirstEntry(const KeyType& pKey) const
-{
+template <typename KeyType, typename EntryType>
+const EntryType* KeyEntryMap<KeyType, EntryType>::lookUpFirstEntry(
+ const KeyType& pKey) const {
const_iterator mapping, mEnd = m_Pool.end();
for (mapping = m_Pool.begin(); mapping != mEnd; ++mapping) {
if (mapping->key == &pKey) {
@@ -130,10 +122,9 @@ KeyEntryMap<KeyType, EntryType>::lookUpFirstEntry(const KeyType& pKey) const
return NULL;
}
-template<typename KeyType, typename EntryType>
-EntryType*
-KeyEntryMap<KeyType, EntryType>::lookUpFirstEntry(const KeyType& pKey)
-{
+template <typename KeyType, typename EntryType>
+EntryType* KeyEntryMap<KeyType, EntryType>::lookUpFirstEntry(
+ const KeyType& pKey) {
const_iterator mapping, mEnd = m_Pool.end();
for (mapping = m_Pool.begin(); mapping != mEnd; ++mapping) {
if (mapping->key == &pKey) {
@@ -144,10 +135,9 @@ KeyEntryMap<KeyType, EntryType>::lookUpFirstEntry(const KeyType& pKey)
return NULL;
}
-template<typename KeyType, typename EntryType>
-const EntryType*
-KeyEntryMap<KeyType, EntryType>::lookUpSecondEntry(const KeyType& pKey) const
-{
+template <typename KeyType, typename EntryType>
+const EntryType* KeyEntryMap<KeyType, EntryType>::lookUpSecondEntry(
+ const KeyType& pKey) const {
const_iterator mapping, mEnd = m_Pool.end();
for (mapping = m_Pool.begin(); mapping != mEnd; ++mapping) {
if (mapping->key == &pKey) {
@@ -158,10 +148,9 @@ KeyEntryMap<KeyType, EntryType>::lookUpSecondEntry(const KeyType& pKey) const
return NULL;
}
-template<typename KeyType, typename EntryType>
-EntryType*
-KeyEntryMap<KeyType, EntryType>::lookUpSecondEntry(const KeyType& pKey)
-{
+template <typename KeyType, typename EntryType>
+EntryType* KeyEntryMap<KeyType, EntryType>::lookUpSecondEntry(
+ const KeyType& pKey) {
const_iterator mapping, mEnd = m_Pool.end();
for (mapping = m_Pool.begin(); mapping != mEnd; ++mapping) {
if (mapping->key == &pKey) {
@@ -172,22 +161,19 @@ KeyEntryMap<KeyType, EntryType>::lookUpSecondEntry(const KeyType& pKey)
return NULL;
}
-template<typename KeyType, typename EntryType>
-void
-KeyEntryMap<KeyType, EntryType>::record(const KeyType& pKey, EntryType& pEntry)
-{
+template <typename KeyType, typename EntryType>
+void KeyEntryMap<KeyType, EntryType>::record(const KeyType& pKey,
+ EntryType& pEntry) {
Mapping mapping;
mapping.key = &pKey;
mapping.entry.entry_ptr = &pEntry;
m_Pool.push_back(mapping);
}
-template<typename KeyType, typename EntryType>
-void
-KeyEntryMap<KeyType, EntryType>::record(const KeyType& pKey,
- EntryType& pEntry1,
- EntryType& pEntry2)
-{
+template <typename KeyType, typename EntryType>
+void KeyEntryMap<KeyType, EntryType>::record(const KeyType& pKey,
+ EntryType& pEntry1,
+ EntryType& pEntry2) {
Mapping mapping;
mapping.key = &pKey;
m_Pairs.push_back(EntryPair(&pEntry1, &pEntry2));
@@ -195,7 +181,6 @@ KeyEntryMap<KeyType, EntryType>::record(const KeyType& pKey,
m_Pool.push_back(mapping);
}
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_TARGET_KEYENTRYMAP_H_
diff --git a/include/mcld/Target/OutputRelocSection.h b/include/mcld/Target/OutputRelocSection.h
index 9bf31cc..77cf6c8 100644
--- a/include/mcld/Target/OutputRelocSection.h
+++ b/include/mcld/Target/OutputRelocSection.h
@@ -6,13 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGET_OUTPUTRELOCSECTION_H
-#define MCLD_TARGET_OUTPUTRELOCSECTION_H
+#ifndef MCLD_TARGET_OUTPUTRELOCSECTION_H_
+#define MCLD_TARGET_OUTPUTRELOCSECTION_H_
-#include <mcld/LD/RelocData.h>
+#include "mcld/LD/RelocData.h"
-namespace mcld
-{
+namespace mcld {
class LDSymbol;
class Module;
@@ -22,9 +21,8 @@ class RelocationFactory;
/** \class OutputRelocSection
* \brief Dynamic relocation section for ARM .rel.dyn and .rel.plt
*/
-class OutputRelocSection
-{
-public:
+class OutputRelocSection {
+ public:
OutputRelocSection(Module& pModule, LDSection& pSection);
~OutputRelocSection();
@@ -32,7 +30,7 @@ public:
/// create - create an dynamic relocation entry
Relocation* create();
- void reserveEntry(size_t pNum=1);
+ void reserveEntry(size_t pNum = 1);
Relocation* consumeEntry();
@@ -41,15 +39,14 @@ public:
bool addSymbolToDynSym(LDSymbol& pSymbol);
// ----- observers ----- //
- bool empty()
- { return m_pRelocData->empty(); }
+ bool empty() { return m_pRelocData->empty(); }
size_t numOfRelocs();
-private:
+ private:
typedef RelocData::iterator RelocIterator;
-private:
+ private:
Module& m_Module;
/// m_RelocData - the output RelocData which contains the dynamic
@@ -63,7 +60,6 @@ private:
RelocIterator m_ValidEntryIterator;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_TARGET_OUTPUTRELOCSECTION_H_
diff --git a/include/mcld/Target/PLT.h b/include/mcld/Target/PLT.h
index da6d86f..58f7676 100644
--- a/include/mcld/Target/PLT.h
+++ b/include/mcld/Target/PLT.h
@@ -6,12 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGET_PLT_H
-#define MCLD_TARGET_PLT_H
+#ifndef MCLD_TARGET_PLT_H_
+#define MCLD_TARGET_PLT_H_
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Fragment/TargetFragment.h>
+#include "mcld/Fragment/TargetFragment.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
namespace mcld {
@@ -21,60 +21,47 @@ class ResolveInfo;
/** \class PLTEntryDefaultBase
* \brief PLTEntryDefaultBase provides the default interface for PLT Entry
*/
-class PLTEntryBase : public TargetFragment
-{
-public:
- PLTEntryBase(SectionData& pParent)
- : TargetFragment(Fragment::Target, &pParent), m_pValue(NULL)
- {}
+class PLTEntryBase : public TargetFragment {
+ public:
+ explicit PLTEntryBase(SectionData& pParent)
+ : TargetFragment(Fragment::Target, &pParent), m_pValue(NULL) {}
- virtual ~PLTEntryBase()
- {
- free(m_pValue);
- }
+ virtual ~PLTEntryBase() { free(m_pValue); }
- void setValue(unsigned char* pValue)
- { m_pValue = pValue; }
+ void setValue(unsigned char* pValue) { m_pValue = pValue; }
- const unsigned char* getValue() const
- { return m_pValue; }
+ const unsigned char* getValue() const { return m_pValue; }
- //Used by llvm::cast<>.
- static bool classof(const Fragment *O)
- { return true; }
+ // Used by llvm::cast<>.
+ static bool classof(const Fragment* O) { return true; }
-protected:
+ protected:
unsigned char* m_pValue;
};
/** \class PLT
* \brief Procedure linkage table
*/
-class PLT
-{
-public:
+class PLT {
+ public:
typedef SectionData::iterator iterator;
typedef SectionData::const_iterator const_iterator;
- template<size_t SIZE, typename EntryBase = PLTEntryBase>
- class Entry : public EntryBase
- {
- public:
+ template <size_t SIZE, typename EntryBase = PLTEntryBase>
+ class Entry : public EntryBase {
+ public:
enum { EntrySize = SIZE };
- public:
- Entry(SectionData& pParent)
- : EntryBase(pParent)
- {}
+ public:
+ explicit Entry(SectionData& pParent) : EntryBase(pParent) {}
virtual ~Entry() {}
- size_t size() const
- { return EntrySize; }
+ size_t size() const { return EntrySize; }
};
-public:
- PLT(LDSection& pSection);
+ public:
+ explicit PLT(LDSection& pSection);
virtual ~PLT();
@@ -84,16 +71,15 @@ public:
uint64_t addr() const { return m_Section.addr(); }
const_iterator begin() const { return m_pSectionData->begin(); }
- iterator begin() { return m_pSectionData->begin(); }
- const_iterator end () const { return m_pSectionData->end(); }
- iterator end () { return m_pSectionData->end(); }
+ iterator begin() { return m_pSectionData->begin(); }
+ const_iterator end() const { return m_pSectionData->end(); }
+ iterator end() { return m_pSectionData->end(); }
-protected:
+ protected:
LDSection& m_Section;
SectionData* m_pSectionData;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_TARGET_PLT_H_
diff --git a/include/mcld/Target/TargetLDBackend.h b/include/mcld/Target/TargetLDBackend.h
index a1a5f1c..858c66e 100644
--- a/include/mcld/Target/TargetLDBackend.h
+++ b/include/mcld/Target/TargetLDBackend.h
@@ -6,29 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGET_TARGETLDBACKEND_H
-#define MCLD_TARGET_TARGETLDBACKEND_H
+#ifndef MCLD_TARGET_TARGETLDBACKEND_H_
+#define MCLD_TARGET_TARGETLDBACKEND_H_
+#include "mcld/LD/GarbageCollection.h"
+#include "mcld/Support/Compiler.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/DataTypes.h>
-#include <mcld/LD/GarbageCollection.h>
namespace mcld {
class ArchiveReader;
+class BranchIslandFactory;
class BinaryReader;
class BinaryWriter;
-class BranchIslandFactory;
class DynObjReader;
class DynObjWriter;
class ExecWriter;
class FileOutputBuffer;
-class SectionReachedListMap;
class IRBuilder;
class Input;
class LDSection;
class LDSymbol;
-class Layout;
class LinkerConfig;
class Module;
class ObjectBuilder;
@@ -37,27 +36,24 @@ class ObjectWriter;
class Relocator;
class ResolveInfo;
class SectionData;
+class SectionReachedListMap;
class StubFactory;
//===----------------------------------------------------------------------===//
/// TargetLDBackend - Generic interface to target specific assembler backends.
//===----------------------------------------------------------------------===//
-class TargetLDBackend
-{
- TargetLDBackend(const TargetLDBackend &); // DO NOT IMPLEMENT
- void operator=(const TargetLDBackend &); // DO NOT IMPLEMENT
-
-protected:
- TargetLDBackend(const LinkerConfig& pConfig);
+class TargetLDBackend {
+ protected:
+ explicit TargetLDBackend(const LinkerConfig& pConfig);
-public:
+ public:
virtual ~TargetLDBackend();
// ----- target dependent ----- //
- virtual void initTargetSegments(IRBuilder& pBuilder) { }
- virtual void initTargetSections(Module& pModule, ObjectBuilder& pBuilder) { }
- virtual void initTargetSymbols(IRBuilder& pBuilder, Module& pModule) { }
- virtual void initTargetRelocation(IRBuilder& pBuilder) { }
+ virtual void initTargetSegments(IRBuilder& pBuilder) {}
+ virtual void initTargetSections(Module& pModule, ObjectBuilder& pBuilder) {}
+ virtual void initTargetSymbols(IRBuilder& pBuilder, Module& pModule) {}
+ virtual void initTargetRelocation(IRBuilder& pBuilder) {}
virtual bool initStandardSymbols(IRBuilder& pBuilder, Module& pModule) = 0;
virtual bool initRelocator() = 0;
@@ -67,10 +63,10 @@ public:
// ----- format dependent ----- //
virtual ArchiveReader* createArchiveReader(Module&) = 0;
- virtual ObjectReader* createObjectReader(IRBuilder&) = 0;
- virtual DynObjReader* createDynObjReader(IRBuilder&) = 0;
- virtual BinaryReader* createBinaryReader(IRBuilder&) = 0;
- virtual ObjectWriter* createWriter() = 0;
+ virtual ObjectReader* createObjectReader(IRBuilder&) = 0;
+ virtual DynObjReader* createDynObjReader(IRBuilder&) = 0;
+ virtual BinaryReader* createBinaryReader(IRBuilder&) = 0;
+ virtual ObjectWriter* createWriter() = 0;
virtual bool initStdSections(ObjectBuilder& pBuilder) = 0;
@@ -114,25 +110,27 @@ public:
/// mergeSection - merge target dependent sections.
virtual bool mergeSection(Module& pModule,
const Input& pInputFile,
- LDSection& pInputSection)
- { return true; }
+ LDSection& pInputSection) {
+ return true;
+ }
/// setUpReachedSectionsForGC - set the reference between two sections for
/// some special target sections. GC will set up the reference for the Regular
/// and BSS sections. Backends can also set up the reference if need.
- virtual void setUpReachedSectionsForGC(const Module& pModule,
- GarbageCollection::SectionReachedListMap& pSectReachedListMap) const { }
+ virtual void setUpReachedSectionsForGC(
+ const Module& pModule,
+ GarbageCollection::SectionReachedListMap& pSectReachedListMap) const {}
/// updateSectionFlags - update pTo's flags when merging pFrom
/// update the output section flags based on input section flags.
/// FIXME: (Luba) I know ELF need to merge flags, but I'm not sure if
/// MachO and COFF also need this.
- virtual bool updateSectionFlags(LDSection& pTo, const LDSection& pFrom)
- { return true; }
+ virtual bool updateSectionFlags(LDSection& pTo, const LDSection& pFrom) {
+ return true;
+ }
/// readSection - read a target dependent section
- virtual bool readSection(Input& pInput, SectionData& pSD)
- { return true; }
+ virtual bool readSection(Input& pInput, SectionData& pSD) { return true; }
/// sizeInterp - compute the size of program interpreter's name
/// In ELF executables, this is the length of dynamic linker's path name
@@ -147,7 +145,7 @@ public:
virtual bool initTargetStubs() { return true; }
virtual BranchIslandFactory* getBRIslandFactory() = 0;
- virtual StubFactory* getStubFactory() = 0;
+ virtual StubFactory* getStubFactory() = 0;
/// relax - the relaxation pass
virtual bool relax(Module& pModule, IRBuilder& pBuilder) = 0;
@@ -175,16 +173,19 @@ public:
/// mayHaveUnsafeFunctionPointerAccess - check if the section may have unsafe
/// function pointer access
- virtual bool mayHaveUnsafeFunctionPointerAccess(const LDSection& pSection)
- const = 0;
+ virtual bool mayHaveUnsafeFunctionPointerAccess(
+ const LDSection& pSection) const = 0;
-protected:
+ protected:
const LinkerConfig& config() const { return m_Config; }
-private:
+ private:
const LinkerConfig& m_Config;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TargetLDBackend);
};
-} // End mcld namespace
+} // namespace mcld
-#endif
+#endif // MCLD_TARGET_TARGETLDBACKEND_H_
diff --git a/include/mcld/TargetOptions.h b/include/mcld/TargetOptions.h
index c856104..9672054 100644
--- a/include/mcld/TargetOptions.h
+++ b/include/mcld/TargetOptions.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef MCLD_TARGETOPTIONS_H
-#define MCLD_TARGETOPTIONS_H
+#ifndef MCLD_TARGETOPTIONS_H_
+#define MCLD_TARGETOPTIONS_H_
#include <llvm/ADT/Triple.h>
@@ -19,19 +19,14 @@ namespace mcld {
* \brief TargetOptions collects the options that dependent on a target
* backend.
*/
-class TargetOptions
-{
-public:
- enum Endian {
- Little,
- Big,
- Unknown
- };
-
-public:
+class TargetOptions {
+ public:
+ enum Endian { Little, Big, Unknown };
+
+ public:
TargetOptions();
- TargetOptions(const std::string& pTriple);
+ explicit TargetOptions(const std::string& pTriple);
~TargetOptions();
@@ -58,7 +53,7 @@ public:
void setEndian(Endian pEndian) { m_Endian = pEndian; }
bool isLittleEndian() const { return (Little == m_Endian); }
- bool isBigEndian () const { return (Big == m_Endian); }
+ bool isBigEndian() const { return (Big == m_Endian); }
unsigned int bitclass() const { return m_BitClass; }
@@ -67,17 +62,15 @@ public:
bool is32Bits() const { return (32 == m_BitClass); }
bool is64Bits() const { return (64 == m_BitClass); }
-private:
+ private:
llvm::Triple m_Triple;
std::string m_ArchName;
std::string m_TargetCPU;
std::string m_TargetFS;
Endian m_Endian;
unsigned int m_BitClass;
-
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // MCLD_TARGETOPTIONS_H_
diff --git a/lib/ADT/GraphLite/Digraph.cpp b/lib/ADT/GraphLite/Digraph.cpp
deleted file mode 100644
index 301f9fa..0000000
--- a/lib/ADT/GraphLite/Digraph.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-//===- Digraph.cpp --------------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/ADT/GraphLite/Digraph.h>
-
-using namespace mcld::graph;
-
-//===----------------------------------------------------------------------===//
-// Digraph::Arc
-//===----------------------------------------------------------------------===//
-Digraph::Arc::Arc()
-{
-}
-
-bool Digraph::Arc::operator==(const Digraph::Node& pOther) const
-{
- return true;
-}
-
-bool Digraph::Arc::operator!=(const Digraph::Node& pOther) const
-{
- return true;
-}
-
-Digraph::Node Digraph::Arc::source() const
-{
- return Node();
-}
-
-Digraph::Node Digraph::Arc::target() const
-{
- return Node();
-}
-
-Digraph::Arc::Arc(Digraph& pParent)
-{
-}
-
-
-//===----------------------------------------------------------------------===//
-// Digraph
-//===----------------------------------------------------------------------===//
-Digraph::Digraph()
-{
-}
-
-
-Digraph::Node Digraph::addNode()
-{
- return Node();
-}
-
-
-Digraph::Arc
-Digraph::addArc(const Digraph::Node& pSource, const Digraph::Node& pTarget)
-{
- return Arc();
-}
-
-
-void Digraph::erase(const Digraph::Node& pNode)
-{
-}
-
-
-void Digraph::erase(const Digraph::Arc& pArc)
-{
-}
-
-
-void Digraph::clear()
-{
-}
-
-unsigned int Digraph::numOfNodes() const
-{
- return 0;
-}
-
-unsigned int Digraph::numOfArcs() const
-{
- return 0;
-}
diff --git a/lib/ADT/GraphLite/ListDigraph.cpp b/lib/ADT/GraphLite/ListDigraph.cpp
deleted file mode 100644
index fcf957b..0000000
--- a/lib/ADT/GraphLite/ListDigraph.cpp
+++ /dev/null
@@ -1,178 +0,0 @@
-//===- ListDigraph.cpp ----------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/ADT/GraphLite/ListDigraph.h>
-
-using namespace mcld::graph;
-
-//===----------------------------------------------------------------------===//
-// ListDigraph::Node
-//===----------------------------------------------------------------------===//
-ListDigraph::Node::Node()
- : prev(NULL), next(NULL), first_in(NULL), first_out(NULL) {
-}
-
-//===----------------------------------------------------------------------===//
-// ListDigraph::Arc
-//===----------------------------------------------------------------------===//
-ListDigraph::Arc::Arc()
- : target(NULL), source(NULL),
- prev_in(NULL), next_in(NULL), prev_out(NULL), next_out(NULL) {
-}
-
-//===----------------------------------------------------------------------===//
-// ListDigraph
-//===----------------------------------------------------------------------===//
-ListDigraph::ListDigraph()
- : m_pNodeHead(NULL), m_pFreeNodeHead(NULL), m_pFreeArcHead(NULL),
- m_NodeList(32), m_ArcList(32) {
-}
-
-
-ListDigraph::Node* ListDigraph::addNode()
-{
- // 1. find an available free node
- Node* result = NULL;
- if (NULL == m_pFreeNodeHead) {
- result = m_NodeList.allocate();
- new (result) Node();
- }
- else {
- result = m_pFreeNodeHead;
- m_pFreeNodeHead = m_pFreeNodeHead->next;
- }
-
- // 2. set up linkages
- result->prev = NULL;
- result->next = m_pNodeHead;
-
- // 3. reset head node
- if (NULL != m_pNodeHead) {
- m_pNodeHead->prev = result;
- }
- m_pNodeHead = result;
-
- return result;
-}
-
-
-ListDigraph::Arc* ListDigraph::addArc(Node& pU, Node& pV)
-{
- // 1. find an available free arc
- Arc* result = NULL;
- if (NULL == m_pFreeArcHead) {
- result = m_ArcList.allocate();
- new (result) Arc();
- }
- else {
- result = m_pFreeArcHead;
- m_pFreeArcHead = m_pFreeArcHead->next_in;
- }
-
- // 2. set up arc
- result->source = &pU;
- result->target = &pV;
-
- // 3. set up fan-out linked list
- result->next_out = pU.first_out;
- if (NULL != pU.first_out) {
- pU.first_out->prev_out = result;
- }
- pU.first_out = result;
-
- // 4. set up fan-in linked list
- result->next_in = pV.first_in;
- if (NULL != pV.first_in) {
- pV.first_in->prev_in = result;
- }
- pV.first_in = result;
-
- return result;
-}
-
-void ListDigraph::erase(ListDigraph::Node& pNode)
-{
- // 1. connect previous node and next node.
- if (NULL != pNode.next) {
- pNode.next->prev = pNode.prev;
- }
-
- if (NULL != pNode.prev) {
- pNode.prev->next = pNode.next;
- }
- else { // pNode.prev is NULL => pNode is the head
- m_pNodeHead = pNode.next;
- }
-
- // 2. remove all fan-in arcs
- Arc* fan_in = pNode.first_in;
- while(NULL != fan_in) {
- Arc* next_in = fan_in->next_in;
- erase(*fan_in);
- fan_in = next_in;
- }
-
- // 3. remove all fan-out arcs
- Arc* fan_out = pNode.first_out;
- while(NULL != fan_out) {
- Arc* next_out = fan_out->next_out;
- erase(*fan_out);
- fan_out = next_out;
- }
-
- // 4. put pNode in the free node list
- pNode.next = m_pFreeNodeHead;
- pNode.prev = NULL;
- if (NULL != m_pFreeNodeHead)
- m_pFreeNodeHead->prev = &pNode;
- m_pFreeNodeHead = &pNode;
-}
-
-
-void ListDigraph::erase(ListDigraph::Arc& pArc)
-{
- // 1. remove from the fan-out list
- if (NULL != pArc.prev_out) {
- pArc.prev_out->next_out = pArc.next_out;
- }
- else { // pArc.prev_out is NULL => pArc is the first_out of the source
- pArc.source->first_out = pArc.next_out;
- }
-
- if (NULL != pArc.next_out) {
- pArc.next_out->prev_out = pArc.prev_out;
- }
-
- // 2. remove from the fan-in list
- if (NULL != pArc.prev_in) {
- pArc.prev_in->next_in = pArc.next_in;
- }
- else {
- pArc.target->first_in = pArc.next_in;
- }
-
- if (NULL != pArc.next_in) {
- pArc.next_in->prev_in = pArc.prev_in;
- }
-
- // 3. put pArc in the free arc list
- // Use fan-in links to chain the free list
- pArc.next_in = m_pFreeArcHead;
- m_pFreeArcHead = &pArc;
-}
-
-
-void ListDigraph::clear()
-{
- m_pNodeHead = NULL;
- m_pFreeNodeHead = NULL;
- m_pFreeArcHead = NULL;
- m_NodeList.clear();
- m_ArcList.clear();
-}
-
diff --git a/lib/ADT/StringEntry.cpp b/lib/ADT/StringEntry.cpp
index e824804..405396e 100644
--- a/lib/ADT/StringEntry.cpp
+++ b/lib/ADT/StringEntry.cpp
@@ -1,4 +1,4 @@
-//===- StringEntry.cpp -----------------------------------------------------===//
+//===- StringEntry.cpp ----------------------------------------------------===//
//
// The MCLinker Project
//
@@ -6,44 +6,40 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/ADT/StringEntry.h>
+#include "mcld/ADT/StringEntry.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// StringEntry<llvm::StringRef>
//===----------------------------------------------------------------------===//
-StringEntry<llvm::StringRef>::StringEntry()
-{
+StringEntry<llvm::StringRef>::StringEntry() {
}
-StringEntry<llvm::StringRef>::StringEntry(const StringEntry::key_type& pKey)
-{
+StringEntry<llvm::StringRef>::StringEntry(const StringEntry::key_type& pKey) {
}
-StringEntry<llvm::StringRef>::StringEntry(const StringEntry<llvm::StringRef>& pCopy)
-{
+StringEntry<llvm::StringRef>::StringEntry(
+ const StringEntry<llvm::StringRef>& pCopy) {
assert("Copy constructor of StringEntry should not be called!");
}
-StringEntry<llvm::StringRef>::~StringEntry()
-{
+StringEntry<llvm::StringRef>::~StringEntry() {
if (!m_Value.empty())
free(const_cast<char*>(m_Value.data()));
}
-void StringEntry<llvm::StringRef>::setValue(llvm::StringRef& pVal)
-{
- char* data = (char*)malloc(pVal.size()+1);
- strcpy(data, pVal.data());
+void StringEntry<llvm::StringRef>::setValue(llvm::StringRef pVal) {
+ char* data = reinterpret_cast<char*>(malloc(pVal.size() + 1));
+ ::memcpy(data, pVal.data(), pVal.size());
m_Value = llvm::StringRef(data, pVal.size());
}
-void StringEntry<llvm::StringRef>::setValue(const char* pVal)
-{
+void StringEntry<llvm::StringRef>::setValue(const char* pVal) {
size_t length = strlen(pVal);
- char* data = (char*)malloc(length+1);
- strcpy(data, pVal);
+ char* data = reinterpret_cast<char*>(malloc(length + 1));
+ ::memcpy(data, pVal, length);
m_Value = llvm::StringRef(data, length);
}
+} // namespace mcld
diff --git a/lib/CodeGen/Android.mk b/lib/CodeGen/Android.mk
deleted file mode 100644
index 9954552..0000000
--- a/lib/CodeGen/Android.mk
+++ /dev/null
@@ -1,29 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-mcld_codegen_SRC_FILES := \
- MCLDTargetMachine.cpp \
- MCLinker.cpp
-
-# For the host
-# =====================================================
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(mcld_codegen_SRC_FILES)
-LOCAL_MODULE:= libmcldCodeGen
-
-LOCAL_MODULE_TAGS := optional
-
-include $(MCLD_HOST_BUILD_MK)
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-# For the device
-# =====================================================
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(mcld_codegen_SRC_FILES)
-LOCAL_MODULE:= libmcldCodeGen
-
-LOCAL_MODULE_TAGS := optional
-
-include $(MCLD_DEVICE_BUILD_MK)
-include $(BUILD_STATIC_LIBRARY)
diff --git a/lib/CodeGen/MCLDTargetMachine.cpp b/lib/CodeGen/MCLDTargetMachine.cpp
deleted file mode 100644
index 7749748..0000000
--- a/lib/CodeGen/MCLDTargetMachine.cpp
+++ /dev/null
@@ -1,382 +0,0 @@
-//===- MCLDTargetMachine.cpp ----------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/CodeGen/TargetMachine.h>
-
-#include <mcld/Module.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/CodeGen/MCLinker.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Support/ToolOutputFile.h>
-#include <mcld/Target/TargetLDBackend.h>
-
-#include <llvm/Analysis/Passes.h>
-#include <llvm/CodeGen/AsmPrinter.h>
-#include <llvm/CodeGen/MachineFunctionAnalysis.h>
-#include <llvm/CodeGen/MachineModuleInfo.h>
-#include <llvm/CodeGen/GCStrategy.h>
-#include <llvm/CodeGen/Passes.h>
-#include <llvm/IR/DataLayout.h>
-#include <llvm/IR/IRPrintingPasses.h>
-#include <llvm/IR/Verifier.h>
-#include <llvm/MC/MCAsmInfo.h>
-#include <llvm/MC/MCStreamer.h>
-#include <llvm/MC/MCInstrInfo.h>
-#include <llvm/MC/MCSubtargetInfo.h>
-#include <llvm/MC/MCObjectStreamer.h>
-#include <llvm/MC/MCAssembler.h>
-#include <llvm/MC/MCObjectWriter.h>
-#include <llvm/MC/MCContext.h>
-#include <llvm/PassManager.h>
-#include <llvm/Support/CommandLine.h>
-#include <llvm/Support/Debug.h>
-#include <llvm/Support/TargetRegistry.h>
-#include <llvm/Support/FormattedStream.h>
-#include <llvm/Target/TargetInstrInfo.h>
-#include <llvm/Target/TargetLowering.h>
-#include <llvm/Target/TargetOptions.h>
-#include <llvm/Target/TargetSubtargetInfo.h>
-#include <llvm/Target/TargetLoweringObjectFile.h>
-#include <llvm/Target/TargetRegisterInfo.h>
-#include <llvm/Transforms/Scalar.h>
-
-#include <string>
-
-using namespace mcld;
-using namespace llvm;
-
-//===----------------------------------------------------------------------===//
-/// Arguments
-//===----------------------------------------------------------------------===//
-// Enable or disable FastISel. Both options are needed, because
-// FastISel is enabled by default with -fast, and we wish to be
-// able to enable or disable fast-isel independently from -O0.
-static cl::opt<cl::boolOrDefault>
-ArgEnableFastISelOption("lfast-isel", cl::Hidden,
- cl::desc("Enable the \"fast\" instruction selector"));
-
-static cl::opt<bool>
-ArgShowMCEncoding("lshow-mc-encoding",
- cl::Hidden,
- cl::desc("Show encoding in .s output"));
-
-static cl::opt<bool>
-ArgShowMCInst("lshow-mc-inst",
- cl::Hidden,
- cl::desc("Show instruction structure in .s output"));
-
-static cl::opt<cl::boolOrDefault>
-ArgAsmVerbose("fverbose-asm",
- cl::desc("Put extra commentary information in the \
- generated assembly code to make it more readable."),
- cl::init(cl::BOU_UNSET));
-
-static bool getVerboseAsm(TargetMachine &TM) {
- switch (ArgAsmVerbose) {
- default:
- case cl::BOU_UNSET: return TM.getAsmVerbosityDefault();
- case cl::BOU_TRUE: return true;
- case cl::BOU_FALSE: return false;
- }
-}
-
-
-//===----------------------------------------------------------------------===//
-// MCLDTargetMachine
-//===----------------------------------------------------------------------===//
-mcld::MCLDTargetMachine::MCLDTargetMachine(llvm::TargetMachine &pTM,
- const llvm::Target& pLLVMTarget,
- const mcld::Target& pMCLDTarget,
- const std::string& pTriple)
- : m_TM(pTM),
- m_pLLVMTarget(&pLLVMTarget),
- m_pMCLDTarget(&pMCLDTarget),
- m_Triple(pTriple) {
-}
-
-mcld::MCLDTargetMachine::~MCLDTargetMachine()
-{
- m_pLLVMTarget = NULL;
- m_pMCLDTarget = NULL;
-}
-
-const mcld::Target& mcld::MCLDTargetMachine::getTarget() const
-{
- return *m_pMCLDTarget;
-}
-
-/// Turn exception handling constructs into something the code generators can
-/// handle.
-static void addPassesToHandleExceptions(llvm::TargetMachine *TM,
- llvm::legacy::PassManagerBase &PM) {
- switch (TM->getMCAsmInfo()->getExceptionHandlingType()) {
- case llvm::ExceptionHandling::SjLj:
- // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
- // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
- // catch info can get misplaced when a selector ends up more than one block
- // removed from the parent invoke(s). This could happen when a landing
- // pad is shared by multiple invokes and is also a target of a normal
- // edge from elsewhere.
- PM.add(createSjLjEHPreparePass(TM));
- // FALLTHROUGH
- case llvm::ExceptionHandling::DwarfCFI:
- case llvm::ExceptionHandling::ARM:
- case llvm::ExceptionHandling::WinEH:
- PM.add(createDwarfEHPass(TM));
- break;
- case llvm::ExceptionHandling::None:
- PM.add(createLowerInvokePass());
-
- // The lower invoke pass may create unreachable code. Remove it.
- PM.add(createUnreachableBlockEliminationPass());
- break;
- }
-}
-
-
-static llvm::MCContext *
-addPassesToGenerateCode(llvm::LLVMTargetMachine *TM,
- llvm::legacy::PassManagerBase &PM,
- bool DisableVerify)
-{
- // Targets may override createPassConfig to provide a target-specific sublass.
- TargetPassConfig *PassConfig = TM->createPassConfig(PM);
-
- // Set PassConfig options provided by TargetMachine.
- PassConfig->setDisableVerify(DisableVerify);
-
- PM.add(PassConfig);
-
- PassConfig->addIRPasses();
-
- addPassesToHandleExceptions(TM, PM);
-
- PassConfig->addISelPrepare();
-
- // Install a MachineModuleInfo class, which is an immutable pass that holds
- // all the per-module stuff we're generating, including MCContext.
- MachineModuleInfo *MMI =
- new MachineModuleInfo(*TM->getMCAsmInfo(), *TM->getRegisterInfo(),
- &TM->getTargetLowering()->getObjFileLowering());
- PM.add(MMI);
- MCContext *Context = &MMI->getContext(); // Return the MCContext by-ref.
-
- // Set up a MachineFunction for the rest of CodeGen to work on.
- PM.add(new MachineFunctionAnalysis(*TM));
-
- // Enable FastISel with -fast, but allow that to be overridden.
- if (ArgEnableFastISelOption == cl::BOU_TRUE ||
- (TM->getOptLevel() == CodeGenOpt::None &&
- ArgEnableFastISelOption != cl::BOU_FALSE))
- TM->setFastISel(true);
-
- // Ask the target for an isel.
- if (PassConfig->addInstSelector())
- return NULL;
-
- PassConfig->addMachinePasses();
-
- PassConfig->setInitialized();
-
- return Context;
-
-}
-
-bool
-mcld::MCLDTargetMachine::addPassesToEmitFile(llvm::legacy::PassManagerBase &pPM,
- mcld::ToolOutputFile& pOutput,
- mcld::CodeGenFileType pFileType,
- CodeGenOpt::Level pOptLvl,
- mcld::Module& pModule,
- LinkerConfig& pConfig,
- bool pDisableVerify)
-{
-
- llvm::MCContext* Context =
- addPassesToGenerateCode(static_cast<llvm::LLVMTargetMachine*>(&m_TM),
- pPM, pDisableVerify);
- if (!Context)
- return true;
-
- switch(pFileType) {
- default:
- case mcld::CGFT_NULLFile:
- assert(0 && "fatal: file type is not set!");
- break;
- case CGFT_ASMFile: {
- assert(Context != 0 && "Failed to get MCContext");
-
- if (getTM().Options.MCOptions.MCSaveTempLabels)
- Context->setAllowTemporaryLabels(false);
-
- if (addCompilerPasses(pPM,
- pOutput.formatted_os(),
- Context))
- return true;
- break;
- }
- case CGFT_OBJFile: {
- assert(Context != 0 && "Failed to get MCContext");
-
- if (getTM().Options.MCOptions.MCSaveTempLabels)
- Context->setAllowTemporaryLabels(false);
- if (addAssemblerPasses(pPM,
- pOutput.formatted_os(),
- Context))
- return true;
- break;
- }
- case CGFT_EXEFile: {
- pConfig.setCodeGenType(LinkerConfig::Exec);
- if (addLinkerPasses(pPM,
- pConfig,
- pModule,
- pOutput.fd(),
- Context))
- return true;
- break;
- }
- case CGFT_BINARY: {
- pConfig.setCodeGenType(LinkerConfig::Binary);
- if (addLinkerPasses(pPM,
- pConfig,
- pModule,
- pOutput.fd(),
- Context))
- return true;
- break;
- }
- case CGFT_DSOFile: {
- pConfig.setCodeGenType(LinkerConfig::DynObj);
- if (addLinkerPasses(pPM,
- pConfig,
- pModule,
- pOutput.fd(),
- Context))
- return true;
- break;
- }
- case CGFT_PARTIAL: {
- pConfig.setCodeGenType(LinkerConfig::Object);
- if (addLinkerPasses(pPM,
- pConfig,
- pModule,
- pOutput.fd(),
- Context))
- return true;
- break;
- }
- } // switch
- return false;
-}
-
-bool
-mcld::MCLDTargetMachine::addCompilerPasses(llvm::legacy::PassManagerBase &pPM,
- llvm::formatted_raw_ostream &pOutput,
- llvm::MCContext *&Context)
-{
- const MCAsmInfo &MAI = *getTM().getMCAsmInfo();
- const MCInstrInfo &MII = *getTM().getInstrInfo();
- const MCRegisterInfo &MRI = *getTM().getRegisterInfo();
- const MCSubtargetInfo &STI = getTM().getSubtarget<MCSubtargetInfo>();
-
- MCInstPrinter *InstPrinter =
- m_pLLVMTarget->createMCInstPrinter(MAI.getAssemblerDialect(), MAI,
- MII, *Context->getRegisterInfo(), STI);
-
- MCCodeEmitter* MCE = 0;
- MCAsmBackend *MAB = 0;
- if (ArgShowMCEncoding) {
- MCE = m_pLLVMTarget->createMCCodeEmitter(MII, MRI, STI, *Context);
- MAB = m_pLLVMTarget->createMCAsmBackend(MRI, m_Triple,
- getTM().getTargetCPU());
- }
-
-
- // now, we have MCCodeEmitter and MCAsmBackend, we can create AsmStreamer.
- std::unique_ptr<MCStreamer> AsmStreamer(
- m_pLLVMTarget->createAsmStreamer(*Context, pOutput,
- getVerboseAsm(getTM()),
- getTM().Options.MCOptions.MCUseDwarfDirectory,
- InstPrinter,
- MCE, MAB,
- ArgShowMCInst));
-
- llvm::MachineFunctionPass* funcPass =
- m_pLLVMTarget->createAsmPrinter(getTM(), *AsmStreamer.get());
-
- if (funcPass == 0)
- return true;
- // If successful, createAsmPrinter took ownership of AsmStreamer
- AsmStreamer.release();
- pPM.add(funcPass);
- return false;
-}
-
-bool
-mcld::MCLDTargetMachine::addAssemblerPasses(llvm::legacy::PassManagerBase &pPM,
- llvm::raw_ostream &pOutput,
- llvm::MCContext *&Context)
-{
- // MCCodeEmitter
- const MCInstrInfo &MII = *getTM().getInstrInfo();
- const MCRegisterInfo &MRI = *getTM().getRegisterInfo();
- const MCSubtargetInfo &STI = getTM().getSubtarget<MCSubtargetInfo>();
- MCCodeEmitter* MCE =
- m_pLLVMTarget->createMCCodeEmitter(MII, MRI, STI, *Context);
-
- // MCAsmBackend
- MCAsmBackend* MAB =
- m_pLLVMTarget->createMCAsmBackend(MRI, m_Triple, getTM().getTargetCPU());
- if (MCE == 0 || MAB == 0)
- return true;
-
- // now, we have MCCodeEmitter and MCAsmBackend, we can create AsmStreamer.
- std::unique_ptr<MCStreamer> AsmStreamer(m_pLLVMTarget->createMCObjectStreamer(
- m_Triple, *Context, *MAB, pOutput, MCE, STI,
- getTM().Options.MCOptions.MCRelaxAll, getTM().Options.MCOptions.MCNoExecStack));
-
- AsmStreamer.get()->InitSections();
- MachineFunctionPass *funcPass =
- m_pLLVMTarget->createAsmPrinter(getTM(), *AsmStreamer.get());
- if (funcPass == 0)
- return true;
- // If successful, createAsmPrinter took ownership of AsmStreamer
- AsmStreamer.release();
- pPM.add(funcPass);
- return false;
-}
-
-bool
-mcld::MCLDTargetMachine::addLinkerPasses(llvm::legacy::PassManagerBase &pPM,
- LinkerConfig& pConfig,
- mcld::Module& pModule,
- mcld::FileHandle& pFileHandle,
- llvm::MCContext *&Context)
-{
- // set up output's SOName
- if (pConfig.options().soname().empty()) {
- // if the output is a shared object, and the option -soname was not
- // enable, set soname as the output file name. soname must be UTF-8 string.
- pConfig.options().setSOName(pFileHandle.path().filename().native());
- }
-
- // set up output module name
- pModule.setName(pFileHandle.path().filename().native());
-
- MachineFunctionPass* funcPass = m_pMCLDTarget->createMCLinker(m_Triple,
- pConfig,
- pModule,
- pFileHandle);
- if (NULL == funcPass)
- return true;
-
- pPM.add(funcPass);
- return false;
-}
-
diff --git a/lib/CodeGen/MCLinker.cpp b/lib/CodeGen/MCLinker.cpp
deleted file mode 100644
index 471b0af..0000000
--- a/lib/CodeGen/MCLinker.cpp
+++ /dev/null
@@ -1,424 +0,0 @@
-//===- MCLinker.cpp -------------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the MCLinker class.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/CodeGen/MCLinker.h>
-
-#include <mcld/Module.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/InputTree.h>
-#include <mcld/Linker.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/MC/InputBuilder.h>
-#include <mcld/MC/FileAction.h>
-#include <mcld/MC/CommandAction.h>
-#include <mcld/Object/ObjectLinker.h>
-#include <mcld/Support/CommandLine.h>
-#include <mcld/Support/FileSystem.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/raw_ostream.h>
-
-#include <llvm/IR/Module.h>
-#include <llvm/Support/CommandLine.h>
-
-#include <algorithm>
-#include <vector>
-#include <string>
-
-using namespace mcld;
-using namespace llvm;
-
-char MCLinker::m_ID = 0;
-
-//===----------------------------------------------------------------------===//
-// Help Functions
-//===----------------------------------------------------------------------===//
-static inline bool CompareAction(const InputAction* X, const InputAction* Y)
-{
- return (X->position() < Y->position());
-}
-
-//===----------------------------------------------------------------------===//
-// Positional Options
-// There are four kinds of positional options:
-// 1. Inputs, object files, such as /tmp/XXXX.o
-// 2. Namespecs, short names of libraries. A namespec may refer to an archive
-// or a shared library. For example, -lm.
-// 3. Attributes of inputs. Attributes describe inputs appears after them.
-// For example, --as-needed and --whole-archive.
-// 4. Groups. A Group is a set of archives. Linkers repeatedly read archives
-// in groups until there is no new undefined symbols.
-// 5. Bitcode. Bitcode is a kind of object files. MCLinker compiles it to
-// object file first, then link it as a object file. (Bitcode is recorded
-// in BitcodeOption, not be read by LLVM Command Line library.)
-//===----------------------------------------------------------------------===//
-// Inputs
-//===----------------------------------------------------------------------===//
-static cl::list<mcld::sys::fs::Path>
-ArgInputObjectFiles(cl::Positional,
- cl::desc("[input object files]"),
- cl::ZeroOrMore);
-
-//===----------------------------------------------------------------------===//
-// Namespecs
-//===----------------------------------------------------------------------===//
-static cl::list<std::string>
-ArgNameSpecList("l",
- cl::ZeroOrMore,
- cl::desc("Add the archive or object file specified by namespec to "
- "the list of files to link."),
- cl::value_desc("namespec"),
- cl::Prefix);
-
-static cl::alias
-ArgNameSpecListAlias("library",
- cl::desc("alias for -l"),
- cl::aliasopt(ArgNameSpecList));
-
-//===----------------------------------------------------------------------===//
-// Attributes
-//===----------------------------------------------------------------------===//
-static cl::list<bool>
-ArgWholeArchiveList("whole-archive",
- cl::ValueDisallowed,
- cl::desc("For each archive mentioned on the command line after "
- "the --whole-archive option, include all object files "
- "in the archive."));
-
-static cl::list<bool>
-ArgNoWholeArchiveList("no-whole-archive",
- cl::ValueDisallowed,
- cl::desc("Turn off the effect of the --whole-archive option for "
- "subsequent archive files."));
-
-static cl::list<bool>
-ArgAsNeededList("as-needed",
- cl::ValueDisallowed,
- cl::desc("This option affects ELF DT_NEEDED tags for dynamic "
- "libraries mentioned on the command line after the "
- "--as-needed option."));
-
-static cl::list<bool>
-ArgNoAsNeededList("no-as-needed",
- cl::ValueDisallowed,
- cl::desc("Turn off the effect of the --as-needed option for "
- "subsequent dynamic libraries"));
-
-static cl::list<bool>
-ArgAddNeededList("add-needed",
- cl::ValueDisallowed,
- cl::desc("--add-needed causes DT_NEEDED tags are always "
- "emitted for those libraries from DT_NEEDED tags. "
- "This is the default behavior."));
-
-static cl::list<bool>
-ArgNoAddNeededList("no-add-needed",
- cl::ValueDisallowed,
- cl::desc("--no-add-needed causes DT_NEEDED tags will never be "
- "emitted for those libraries from DT_NEEDED tags"));
-
-static cl::list<bool>
-ArgBDynamicList("Bdynamic",
- cl::ValueDisallowed,
- cl::desc("Link against dynamic library"));
-
-static cl::alias
-ArgBDynamicListAlias1("dy",
- cl::desc("alias for --Bdynamic"),
- cl::aliasopt(ArgBDynamicList));
-
-static cl::alias
-ArgBDynamicListAlias2("call_shared",
- cl::desc("alias for --Bdynamic"),
- cl::aliasopt(ArgBDynamicList));
-
-static cl::list<bool>
-ArgBStaticList("Bstatic",
- cl::ValueDisallowed,
- cl::desc("Link against static library"));
-
-static cl::alias
-ArgBStaticListAlias1("dn",
- cl::desc("alias for --Bstatic"),
- cl::aliasopt(ArgBStaticList));
-
-static cl::alias
-ArgBStaticListAlias2("static",
- cl::desc("alias for --Bstatic"),
- cl::aliasopt(ArgBStaticList));
-
-static cl::alias
-ArgBStaticListAlias3("non_shared",
- cl::desc("alias for --Bstatic"),
- cl::aliasopt(ArgBStaticList));
-
-//===----------------------------------------------------------------------===//
-// Groups
-//===----------------------------------------------------------------------===//
-static cl::list<bool>
-ArgStartGroupList("start-group",
- cl::ValueDisallowed,
- cl::desc("start to record a group of archives"));
-
-static cl::alias
-ArgStartGroupListAlias("(",
- cl::desc("alias for --start-group"),
- cl::aliasopt(ArgStartGroupList));
-
-static cl::list<bool>
-ArgEndGroupList("end-group",
- cl::ValueDisallowed,
- cl::desc("stop recording a group of archives"));
-
-static cl::alias
-ArgEndGroupListAlias(")",
- cl::desc("alias for --end-group"),
- cl::aliasopt(ArgEndGroupList));
-
-//===----------------------------------------------------------------------===//
-// --defsym
-//===----------------------------------------------------------------------===//
-static cl::list<std::string>
-ArgDefSymList("defsym",
- cl::ZeroOrMore,
- cl::desc("Define a symbol"),
- cl::value_desc("symbol=expression"));
-
-//===----------------------------------------------------------------------===//
-// MCLinker
-//===----------------------------------------------------------------------===//
-MCLinker::MCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
- : MachineFunctionPass(m_ID),
- m_Config(pConfig),
- m_Module(pModule),
- m_FileHandle(pFileHandle),
- m_pBuilder(NULL),
- m_pLinker(NULL) {
-}
-
-MCLinker::~MCLinker()
-{
- delete m_pLinker;
- delete m_pBuilder;
-}
-
-bool MCLinker::doInitialization(llvm::Module &pM)
-{
- // Now, all input arguments are prepared well, send it into ObjectLinker
- m_pLinker = new Linker();
-
- if (!m_pLinker->emulate(m_Module.getScript(), m_Config))
- return false;
-
- m_pBuilder = new IRBuilder(m_Module, m_Config);
-
- initializeInputTree(*m_pBuilder);
-
- return true;
-}
-
-bool MCLinker::doFinalization(llvm::Module &pM)
-{
- if (!m_pLinker->link(m_Module, *m_pBuilder))
- return true;
-
- if (!m_pLinker->emit(m_Module, m_FileHandle.handler()))
- return true;
-
- return false;
-}
-
-bool MCLinker::runOnMachineFunction(MachineFunction& pF)
-{
- // basically, linkers do nothing during function is generated.
- return false;
-}
-
-void MCLinker::initializeInputTree(IRBuilder& pBuilder)
-{
- if (0 == ArgInputObjectFiles.size() &&
- 0 == ArgNameSpecList.size() &&
- !m_Config.bitcode().hasDefined()) {
- fatal(diag::err_no_inputs);
- return;
- }
-
- size_t num_actions = ArgInputObjectFiles.size() +
- ArgNameSpecList.size() +
- ArgWholeArchiveList.size() +
- ArgNoWholeArchiveList.size() +
- ArgAsNeededList.size() +
- ArgNoAsNeededList.size() +
- ArgAddNeededList.size() +
- ArgNoAddNeededList.size() +
- ArgBDynamicList.size() +
- ArgBStaticList.size() +
- ArgStartGroupList.size() +
- ArgEndGroupList.size() +
- ArgDefSymList.size() +
- 1; // bitcode
- std::vector<InputAction*> actions;
- actions.reserve(num_actions);
-
- // ----- scripts ----- //
- /// -T
- if (!m_Config.options().getScriptList().empty()) {
- GeneralOptions::const_script_iterator ii, ie = m_Config.options().script_end();
- for (ii = m_Config.options().script_begin(); ii != ie; ++ii) {
- actions.push_back(new ScriptAction(0x0,
- *ii,
- ScriptFile::LDScript,
- m_Module.getScript().directories()));
- actions.push_back(new ContextAction(0x0));
- actions.push_back(new MemoryAreaAction(0x0, FileHandle::ReadOnly));
- }
- }
-
- /// --defsym
- cl::list<std::string>::iterator defsym, dsBegin, dsEnd;
- dsBegin = ArgDefSymList.begin();
- dsEnd = ArgDefSymList.end();
- for (defsym = dsBegin; defsym != dsEnd; ++defsym) {
- unsigned int pos = ArgDefSymList.getPosition(defsym - dsBegin);
- actions.push_back(new DefSymAction(pos, *defsym));
- }
-
- // ----- inputs ----- //
- cl::list<mcld::sys::fs::Path>::iterator input, inBegin, inEnd;
- inBegin = ArgInputObjectFiles.begin();
- inEnd = ArgInputObjectFiles.end();
- for (input = inBegin; input != inEnd; ++input) {
- unsigned int pos = ArgInputObjectFiles.getPosition(input - inBegin);
- actions.push_back(new InputFileAction(pos, *input));
- actions.push_back(new ContextAction(pos));
- actions.push_back(new MemoryAreaAction(pos, FileHandle::ReadOnly));
- }
-
- // ----- namespecs ----- //
- cl::list<std::string>::iterator namespec, nsBegin, nsEnd;
- nsBegin = ArgNameSpecList.begin();
- nsEnd = ArgNameSpecList.end();
- for (namespec = nsBegin; namespec != nsEnd; ++namespec) {
- unsigned int pos = ArgNameSpecList.getPosition(namespec - nsBegin);
- actions.push_back(new NamespecAction(pos, *namespec,
- m_Module.getScript().directories()));
- actions.push_back(new ContextAction(pos));
- actions.push_back(new MemoryAreaAction(pos, FileHandle::ReadOnly));
- }
-
- // ----- attributes ----- //
- /// --whole-archive
- cl::list<bool>::iterator attr, attrBegin, attrEnd;
- attrBegin = ArgWholeArchiveList.begin();
- attrEnd = ArgWholeArchiveList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgWholeArchiveList.getPosition(attr - attrBegin);
- actions.push_back(new WholeArchiveAction(pos));
- }
-
- /// --no-whole-archive
- attrBegin = ArgNoWholeArchiveList.begin();
- attrEnd = ArgNoWholeArchiveList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgNoWholeArchiveList.getPosition(attr - attrBegin);
- actions.push_back(new NoWholeArchiveAction(pos));
- }
-
- /// --as-needed
- attrBegin = ArgAsNeededList.begin();
- attrEnd = ArgAsNeededList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgAsNeededList.getPosition(attr - attrBegin);
- actions.push_back(new AsNeededAction(pos));
- }
-
- /// --no-as-needed
- attrBegin = ArgNoAsNeededList.begin();
- attrEnd = ArgNoAsNeededList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgNoAsNeededList.getPosition(attr - attrBegin);
- actions.push_back(new NoAsNeededAction(pos));
- }
-
- /// --add--needed
- attrBegin = ArgAddNeededList.begin();
- attrEnd = ArgAddNeededList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgAddNeededList.getPosition(attr - attrBegin);
- actions.push_back(new AddNeededAction(pos));
- }
-
- /// --no-add--needed
- attrBegin = ArgNoAddNeededList.begin();
- attrEnd = ArgNoAddNeededList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgNoAddNeededList.getPosition(attr - attrBegin);
- actions.push_back(new NoAddNeededAction(pos));
- }
-
- /// --Bdynamic
- attrBegin = ArgBDynamicList.begin();
- attrEnd = ArgBDynamicList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgBDynamicList.getPosition(attr - attrBegin);
- actions.push_back(new BDynamicAction(pos));
- }
-
- /// --Bstatic
- attrBegin = ArgBStaticList.begin();
- attrEnd = ArgBStaticList.end();
- for (attr = attrBegin; attr != attrEnd; ++attr) {
- unsigned int pos = ArgBStaticList.getPosition(attr - attrBegin);
- actions.push_back(new BStaticAction(pos));
- }
-
- // ----- groups ----- //
- /// --start-group
- cl::list<bool>::iterator group, gsBegin, gsEnd;
- gsBegin = ArgStartGroupList.begin();
- gsEnd = ArgStartGroupList.end();
- for (group = gsBegin; group != gsEnd; ++group) {
- unsigned int pos = ArgStartGroupList.getPosition(group - gsBegin);
- actions.push_back(new StartGroupAction(pos));
- }
-
- /// --end-group
- gsBegin = ArgEndGroupList.begin();
- gsEnd = ArgEndGroupList.end();
- for (group = gsBegin; group != gsEnd; ++group) {
- unsigned int pos = ArgEndGroupList.getPosition(group - gsBegin);
- actions.push_back(new EndGroupAction(pos));
- }
-
- // ----- bitcode ----- //
- if (m_Config.bitcode().hasDefined()) {
- actions.push_back(new BitcodeAction(m_Config.bitcode().getPosition(),
- m_Config.bitcode().getPath()));
- }
-
- // stable sort
- std::stable_sort(actions.begin(), actions.end(), CompareAction);
-
- // build up input tree
- std::vector<InputAction*>::iterator action, actionEnd = actions.end();
- for (action = actions.begin(); action != actionEnd; ++action) {
- (*action)->activate(pBuilder.getInputBuilder());
- delete *action;
- }
-
- if (pBuilder.getInputBuilder().isInGroup())
- report_fatal_error("no matched --start-group and --end-group");
-}
-
diff --git a/lib/Core/Android.mk b/lib/Core/Android.mk
index 8036cc5..f75025b 100644
--- a/lib/Core/Android.mk
+++ b/lib/Core/Android.mk
@@ -2,14 +2,13 @@ LOCAL_PATH:= $(call my-dir)
mcld_core_SRC_FILES := \
AttributeOption.cpp \
- BitcodeOption.cpp \
Environment.cpp \
GeneralOptions.cpp \
- IRBuilder.cpp \
InputTree.cpp \
- LinkerConfig.cpp \
- LinkerScript.cpp \
+ IRBuilder.cpp \
+ LinkerConfig.cpp \
Linker.cpp \
+ LinkerScript.cpp \
Module.cpp \
TargetOptions.cpp
diff --git a/lib/Core/AttributeOption.cpp b/lib/Core/AttributeOption.cpp
index d2a7947..cedfc0f 100644
--- a/lib/Core/AttributeOption.cpp
+++ b/lib/Core/AttributeOption.cpp
@@ -6,17 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/AttributeOption.h>
+#include "mcld/AttributeOption.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// AttributeOption
//===----------------------------------------------------------------------===//
-AttributeOption::AttributeOption()
-{
+AttributeOption::AttributeOption() {
}
-AttributeOption::~AttributeOption()
-{
+AttributeOption::~AttributeOption() {
}
+
+} // namespace mcld
diff --git a/lib/Core/BitcodeOption.cpp b/lib/Core/BitcodeOption.cpp
deleted file mode 100644
index 47d6667..0000000
--- a/lib/Core/BitcodeOption.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-//===- BitcodeOption.cpp --------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/BitcodeOption.h>
-
-using namespace mcld;
-
-//===----------------------------------------------------------------------===//
-// BitcodeOption
-//===----------------------------------------------------------------------===//
-BitcodeOption::BitcodeOption()
- : m_Position(-1) {
-}
-
-BitcodeOption::~BitcodeOption()
-{
-}
-
-bool BitcodeOption::hasDefined() const
-{
- return (m_Position != -1);
-}
diff --git a/lib/Core/Environment.cpp b/lib/Core/Environment.cpp
index 5755fe7..153704b 100644
--- a/lib/Core/Environment.cpp
+++ b/lib/Core/Environment.cpp
@@ -6,11 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Environment.h>
-#include <mcld/Support/TargetSelect.h>
+#include "mcld/Environment.h"
+#include "mcld/Support/TargetSelect.h"
-void mcld::Initialize()
-{
+void mcld::Initialize() {
static bool is_initialized = false;
if (is_initialized)
@@ -23,7 +22,5 @@ void mcld::Initialize()
is_initialized = true;
}
-void mcld::Finalize()
-{
+void mcld::Finalize() {
}
-
diff --git a/lib/Core/GeneralOptions.cpp b/lib/Core/GeneralOptions.cpp
index f6e86b9..521ffa5 100644
--- a/lib/Core/GeneralOptions.cpp
+++ b/lib/Core/GeneralOptions.cpp
@@ -6,71 +6,69 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/GeneralOptions.h>
-#include <mcld/MC/Input.h>
-#include <mcld/MC/ZOption.h>
+#include "mcld/GeneralOptions.h"
+#include "mcld/MC/Input.h"
+#include "mcld/MC/ZOption.h"
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// GeneralOptions
//===----------------------------------------------------------------------===//
GeneralOptions::GeneralOptions()
- : m_Verbose(-1),
- m_MaxErrorNum(-1),
- m_MaxWarnNum(-1),
- m_ExecStack(Unknown),
- m_NoUndefined(Unknown),
- m_MulDefs(Unknown),
- m_CommPageSize(0x0),
- m_MaxPageSize(0x0),
- m_bCombReloc(true),
- m_bInitFirst(false),
- m_bInterPose(false),
- m_bLoadFltr(false),
- m_bNoCopyReloc(false),
- m_bNoDefaultLib(false),
- m_bNoDelete(false),
- m_bNoDLOpen(false),
- m_bNoDump(false),
- m_bRelro(false),
- m_bNow(false),
- m_bOrigin(false),
- m_bTrace(false),
- m_Bsymbolic(false),
- m_Bgroup(false),
- m_bPIE(false),
- m_bColor(true),
- m_bCreateEhFrameHdr(false),
- m_bNMagic(false),
- m_bOMagic(false),
- m_bStripDebug(false),
- m_bExportDynamic(false),
- m_bWarnSharedTextrel(false),
- m_bBinaryInput(false),
- m_bDefineCommon(false),
- m_bFatalWarnings(false),
- m_bNewDTags(false),
- m_bNoStdlib(false),
- m_bWarnMismatch(true),
- m_bGCSections(false),
- m_bPrintGCSections(false),
- m_bGenUnwindInfo(true),
- m_bPrintICFSections(false),
- m_ICF(ICF_None),
- m_ICFIterations(0) ,
- m_GPSize(8),
- m_StripSymbols(KeepAllSymbols),
- m_HashStyle(SystemV) {
+ : m_Verbose(-1),
+ m_MaxErrorNum(-1),
+ m_MaxWarnNum(-1),
+ m_ExecStack(Unknown),
+ m_NoUndefined(Unknown),
+ m_MulDefs(Unknown),
+ m_CommPageSize(0x0),
+ m_MaxPageSize(0x0),
+ m_bCombReloc(true),
+ m_bInitFirst(false),
+ m_bInterPose(false),
+ m_bLoadFltr(false),
+ m_bNoCopyReloc(false),
+ m_bNoDefaultLib(false),
+ m_bNoDelete(false),
+ m_bNoDLOpen(false),
+ m_bNoDump(false),
+ m_bRelro(false),
+ m_bNow(false),
+ m_bOrigin(false),
+ m_bTrace(false),
+ m_Bsymbolic(false),
+ m_Bgroup(false),
+ m_bPIE(false),
+ m_bColor(true),
+ m_bCreateEhFrameHdr(false),
+ m_bNMagic(false),
+ m_bOMagic(false),
+ m_bStripDebug(false),
+ m_bExportDynamic(false),
+ m_bWarnSharedTextrel(false),
+ m_bBinaryInput(false),
+ m_bDefineCommon(false),
+ m_bFatalWarnings(false),
+ m_bNewDTags(false),
+ m_bNoStdlib(false),
+ m_bWarnMismatch(true),
+ m_bGCSections(false),
+ m_bPrintGCSections(false),
+ m_bGenUnwindInfo(true),
+ m_bPrintICFSections(false),
+ m_ICF(ICF_None),
+ m_ICFIterations(0),
+ m_GPSize(8),
+ m_StripSymbols(KeepAllSymbols),
+ m_HashStyle(SystemV) {
}
-GeneralOptions::~GeneralOptions()
-{
+GeneralOptions::~GeneralOptions() {
}
-void GeneralOptions::setSOName(const std::string& pName)
-{
+void GeneralOptions::setSOName(const std::string& pName) {
size_t pos = pName.find_last_of(sys::fs::separator);
if (std::string::npos == pos)
m_SOName = pName;
@@ -78,8 +76,7 @@ void GeneralOptions::setSOName(const std::string& pName)
m_SOName = pName.substr(pos + 1);
}
-void GeneralOptions::addZOption(const ZOption& pOption)
-{
+void GeneralOptions::addZOption(const ZOption& pOption) {
switch (pOption.kind()) {
case ZOption::CombReloc:
m_bCombReloc = true;
@@ -151,8 +148,7 @@ void GeneralOptions::addZOption(const ZOption& pOption)
}
}
-bool GeneralOptions::isInExcludeLIBS(const Input& pInput) const
-{
+bool GeneralOptions::isInExcludeLIBS(const Input& pInput) const {
assert(pInput.type() == Input::Archive);
if (m_ExcludeLIBS.empty()) {
@@ -173,3 +169,5 @@ bool GeneralOptions::isInExcludeLIBS(const Input& pInput) const
return false;
}
+
+} // namespace mcld
diff --git a/lib/Core/IRBuilder.cpp b/lib/Core/IRBuilder.cpp
index bc44990..252fc43 100644
--- a/lib/Core/IRBuilder.cpp
+++ b/lib/Core/IRBuilder.cpp
@@ -6,28 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/IRBuilder.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/LD/ELFReader.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/ELF.h>
-#include <mcld/Fragment/FragmentRef.h>
+#include "mcld/IRBuilder.h"
+
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/LD/DebugString.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/ELFReader.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/ELF.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <llvm/ADT/StringRef.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Helper Functions
//===----------------------------------------------------------------------===//
-LDFileFormat::Kind GetELFSectionKind(uint32_t pType, const char* pName,
- uint32_t pFlag)
-{
- if (pFlag & mcld::ELF::SHF_EXCLUDE)
+LDFileFormat::Kind GetELFSectionKind(uint32_t pType,
+ const char* pName,
+ uint32_t pFlag) {
+ if (pFlag & llvm::ELF::SHF_EXCLUDE)
return LDFileFormat::Exclude;
if (pFlag & llvm::ELF::SHF_MASKPROC)
@@ -35,11 +39,12 @@ LDFileFormat::Kind GetELFSectionKind(uint32_t pType, const char* pName,
// name rules
llvm::StringRef name(pName);
- if (name.startswith(".debug") ||
- name.startswith(".zdebug") ||
- name.startswith(".line") ||
- name.startswith(".stab"))
+ if (name.startswith(".debug") || name.startswith(".zdebug") ||
+ name.startswith(".line") || name.startswith(".stab")) {
+ if (name.startswith(".debug_str"))
+ return LDFileFormat::DebugString;
return LDFileFormat::Debug;
+ }
if (name.startswith(".comment"))
return LDFileFormat::MetaData;
if (name.startswith(".interp") || name.startswith(".dynamic"))
@@ -56,46 +61,46 @@ LDFileFormat::Kind GetELFSectionKind(uint32_t pType, const char* pName,
return LDFileFormat::LinkOnce;
// type rules
- switch(pType) {
- case llvm::ELF::SHT_NULL:
- return LDFileFormat::Null;
- case llvm::ELF::SHT_INIT_ARRAY:
- case llvm::ELF::SHT_FINI_ARRAY:
- case llvm::ELF::SHT_PREINIT_ARRAY:
- case llvm::ELF::SHT_PROGBITS: {
- if ((pFlag & llvm::ELF::SHF_EXECINSTR) != 0)
- return LDFileFormat::TEXT;
- else
- return LDFileFormat::DATA;
- }
- case llvm::ELF::SHT_SYMTAB:
- case llvm::ELF::SHT_DYNSYM:
- case llvm::ELF::SHT_STRTAB:
- case llvm::ELF::SHT_HASH:
- case llvm::ELF::SHT_DYNAMIC:
- case llvm::ELF::SHT_SYMTAB_SHNDX:
- return LDFileFormat::NamePool;
- case llvm::ELF::SHT_RELA:
- case llvm::ELF::SHT_REL:
- return LDFileFormat::Relocation;
- case llvm::ELF::SHT_NOBITS:
- return LDFileFormat::BSS;
- case llvm::ELF::SHT_NOTE:
- return LDFileFormat::Note;
- case llvm::ELF::SHT_GROUP:
- return LDFileFormat::Group;
- case llvm::ELF::SHT_GNU_versym:
- case llvm::ELF::SHT_GNU_verdef:
- case llvm::ELF::SHT_GNU_verneed:
- return LDFileFormat::Version;
- case llvm::ELF::SHT_SHLIB:
- return LDFileFormat::Target;
- default:
- if ((pType >= llvm::ELF::SHT_LOPROC && pType <= llvm::ELF::SHT_HIPROC) ||
- (pType >= llvm::ELF::SHT_LOOS && pType <= llvm::ELF::SHT_HIOS) ||
- (pType >= llvm::ELF::SHT_LOUSER && pType <= llvm::ELF::SHT_HIUSER))
+ switch (pType) {
+ case llvm::ELF::SHT_NULL:
+ return LDFileFormat::Null;
+ case llvm::ELF::SHT_INIT_ARRAY:
+ case llvm::ELF::SHT_FINI_ARRAY:
+ case llvm::ELF::SHT_PREINIT_ARRAY:
+ case llvm::ELF::SHT_PROGBITS: {
+ if ((pFlag & llvm::ELF::SHF_EXECINSTR) != 0)
+ return LDFileFormat::TEXT;
+ else
+ return LDFileFormat::DATA;
+ }
+ case llvm::ELF::SHT_SYMTAB:
+ case llvm::ELF::SHT_DYNSYM:
+ case llvm::ELF::SHT_STRTAB:
+ case llvm::ELF::SHT_HASH:
+ case llvm::ELF::SHT_DYNAMIC:
+ case llvm::ELF::SHT_SYMTAB_SHNDX:
+ return LDFileFormat::NamePool;
+ case llvm::ELF::SHT_RELA:
+ case llvm::ELF::SHT_REL:
+ return LDFileFormat::Relocation;
+ case llvm::ELF::SHT_NOBITS:
+ return LDFileFormat::BSS;
+ case llvm::ELF::SHT_NOTE:
+ return LDFileFormat::Note;
+ case llvm::ELF::SHT_GROUP:
+ return LDFileFormat::Group;
+ case llvm::ELF::SHT_GNU_versym:
+ case llvm::ELF::SHT_GNU_verdef:
+ case llvm::ELF::SHT_GNU_verneed:
+ return LDFileFormat::Version;
+ case llvm::ELF::SHT_SHLIB:
return LDFileFormat::Target;
- fatal(diag::err_unsupported_section) << pName << pType;
+ default:
+ if ((pType >= llvm::ELF::SHT_LOPROC && pType <= llvm::ELF::SHT_HIPROC) ||
+ (pType >= llvm::ELF::SHT_LOOS && pType <= llvm::ELF::SHT_HIOS) ||
+ (pType >= llvm::ELF::SHT_LOUSER && pType <= llvm::ELF::SHT_HIUSER))
+ return LDFileFormat::Target;
+ fatal(diag::err_unsupported_section) << pName << pType;
}
return LDFileFormat::MetaData;
}
@@ -104,21 +109,20 @@ LDFileFormat::Kind GetELFSectionKind(uint32_t pType, const char* pName,
// IRBuilder
//===----------------------------------------------------------------------===//
IRBuilder::IRBuilder(Module& pModule, const LinkerConfig& pConfig)
- : m_Module(pModule), m_Config(pConfig), m_InputBuilder(pConfig) {
+ : m_Module(pModule), m_Config(pConfig), m_InputBuilder(pConfig) {
m_InputBuilder.setCurrentTree(m_Module.getInputTree());
// FIXME: where to set up Relocation?
Relocation::SetUp(m_Config);
}
-IRBuilder::~IRBuilder()
-{
+IRBuilder::~IRBuilder() {
}
/// CreateInput - To create an input file and append it to the input tree.
Input* IRBuilder::CreateInput(const std::string& pName,
- const sys::fs::Path& pPath, Input::Type pType)
-{
+ const sys::fs::Path& pPath,
+ Input::Type pType) {
if (Input::Unknown == pType)
return ReadInput(pName, pPath);
@@ -132,24 +136,24 @@ Input* IRBuilder::CreateInput(const std::string& pName,
}
/// ReadInput - To read an input file and append it to the input tree.
-Input*
-IRBuilder::ReadInput(const std::string& pName, const sys::fs::Path& pPath)
-{
- m_InputBuilder.createNode<InputTree::Positional>(pName, pPath, Input::Unknown);
+Input* IRBuilder::ReadInput(const std::string& pName,
+ const sys::fs::Path& pPath) {
+ m_InputBuilder.createNode<InputTree::Positional>(
+ pName, pPath, Input::Unknown);
Input* input = *m_InputBuilder.getCurrentNode();
if (!input->hasContext())
m_InputBuilder.setContext(*input);
if (!input->hasMemArea())
- m_InputBuilder.setMemory(*input, FileHandle::ReadOnly, FileHandle::System);
+ m_InputBuilder.setMemory(*input, FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System));
return input;
}
/// ReadInput - To read an input file and append it to the input tree.
-Input* IRBuilder::ReadInput(const std::string& pNameSpec)
-{
+Input* IRBuilder::ReadInput(const std::string& pNameSpec) {
const sys::fs::Path* path = NULL;
// find out the real path of the namespec.
if (m_InputBuilder.getConstraint().isSharedSystem()) {
@@ -159,19 +163,17 @@ Input* IRBuilder::ReadInput(const std::string& pNameSpec)
if (m_InputBuilder.getAttributes().isStatic()) {
// with --static, we must search an archive.
path = m_Module.getScript().directories().find(pNameSpec, Input::Archive);
- }
- else {
+ } else {
// otherwise, with --Bdynamic, we can find either an archive or a
// shared object.
path = m_Module.getScript().directories().find(pNameSpec, Input::DynObj);
}
- }
- else {
+ } else {
// In the system without shared object support, we only look for an archive
path = m_Module.getScript().directories().find(pNameSpec, Input::Archive);
}
- if (NULL == path) {
+ if (path == NULL) {
fatal(diag::err_cannot_find_namespec) << pNameSpec;
return NULL;
}
@@ -183,42 +185,41 @@ Input* IRBuilder::ReadInput(const std::string& pNameSpec)
m_InputBuilder.setContext(*input);
if (!input->hasMemArea())
- m_InputBuilder.setMemory(*input, FileHandle::ReadOnly, FileHandle::System);
+ m_InputBuilder.setMemory(*input, FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System));
return input;
}
/// ReadInput - To read an input file and append it to the input tree.
-Input* IRBuilder::ReadInput(FileHandle& pFileHandle)
-{
+Input* IRBuilder::ReadInput(FileHandle& pFileHandle) {
m_InputBuilder.createNode<InputTree::Positional>("file handler",
pFileHandle.path());
Input* input = *m_InputBuilder.getCurrentNode();
if (pFileHandle.path().empty()) {
m_InputBuilder.setContext(*input, false);
- m_InputBuilder.setMemory(*input, pFileHandle.handler(), FileHandle::ReadOnly);
- }
- else {
+ } else {
m_InputBuilder.setContext(*input, true);
- m_InputBuilder.setMemory(*input, FileHandle::ReadOnly, FileHandle::System);
}
+ m_InputBuilder.setMemory(*input, FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System));
return input;
}
/// ReadInput - To read an input file and append it to the input tree.
-Input* IRBuilder::ReadInput(const std::string& pName, void* pRawMemory, size_t pSize)
-{
- m_InputBuilder.createNode<InputTree::Positional>(pName, "NAN");
+Input* IRBuilder::ReadInput(const std::string& pName,
+ void* pRawMemory,
+ size_t pSize) {
+ m_InputBuilder.createNode<InputTree::Positional>(pName, sys::fs::Path("NAN"));
Input* input = *m_InputBuilder.getCurrentNode();
m_InputBuilder.setContext(*input, false);
m_InputBuilder.setMemory(*input, pRawMemory, pSize);
return input;
}
-bool IRBuilder::StartGroup()
-{
+bool IRBuilder::StartGroup() {
if (m_InputBuilder.isInGroup()) {
fatal(diag::fatal_forbid_nest_group);
return false;
@@ -227,49 +228,40 @@ bool IRBuilder::StartGroup()
return true;
}
-bool IRBuilder::EndGroup()
-{
+bool IRBuilder::EndGroup() {
m_InputBuilder.exitGroup();
return true;
}
-void IRBuilder::WholeArchive()
-{
+void IRBuilder::WholeArchive() {
m_InputBuilder.getAttributes().setWholeArchive();
}
-void IRBuilder::NoWholeArchive()
-{
+void IRBuilder::NoWholeArchive() {
m_InputBuilder.getAttributes().unsetWholeArchive();
}
-void IRBuilder::AsNeeded()
-{
+void IRBuilder::AsNeeded() {
m_InputBuilder.getAttributes().setAsNeeded();
}
-void IRBuilder::NoAsNeeded()
-{
+void IRBuilder::NoAsNeeded() {
m_InputBuilder.getAttributes().unsetAsNeeded();
}
-void IRBuilder::CopyDTNeeded()
-{
+void IRBuilder::CopyDTNeeded() {
m_InputBuilder.getAttributes().setAddNeeded();
}
-void IRBuilder::NoCopyDTNeeded()
-{
+void IRBuilder::NoCopyDTNeeded() {
m_InputBuilder.getAttributes().unsetAddNeeded();
}
-void IRBuilder::AgainstShared()
-{
+void IRBuilder::AgainstShared() {
m_InputBuilder.getAttributes().setDynamic();
}
-void IRBuilder::AgainstStatic()
-{
+void IRBuilder::AgainstStatic() {
m_InputBuilder.getAttributes().setStatic();
}
@@ -277,8 +269,7 @@ LDSection* IRBuilder::CreateELFHeader(Input& pInput,
const std::string& pName,
uint32_t pType,
uint32_t pFlag,
- uint32_t pAlign)
-{
+ uint32_t pAlign) {
// Create section header
LDFileFormat::Kind kind = GetELFSectionKind(pType, pName.c_str(), pFlag);
LDSection* header = LDSection::Create(pName, kind, pType, pFlag);
@@ -290,8 +281,7 @@ LDSection* IRBuilder::CreateELFHeader(Input& pInput,
}
/// CreateSectionData - To create a section data for given pSection.
-SectionData* IRBuilder::CreateSectionData(LDSection& pSection)
-{
+SectionData* IRBuilder::CreateSectionData(LDSection& pSection) {
assert(!pSection.hasSectionData() && "pSection already has section data.");
SectionData* sect_data = SectionData::Create(pSection);
@@ -300,8 +290,7 @@ SectionData* IRBuilder::CreateSectionData(LDSection& pSection)
}
/// CreateRelocData - To create a relocation data for given pSection.
-RelocData* IRBuilder::CreateRelocData(LDSection &pSection)
-{
+RelocData* IRBuilder::CreateRelocData(LDSection& pSection) {
assert(!pSection.hasRelocData() && "pSection already has relocation data.");
RelocData* reloc_data = RelocData::Create(pSection);
@@ -310,8 +299,7 @@ RelocData* IRBuilder::CreateRelocData(LDSection &pSection)
}
/// CreateEhFrame - To create a eh_frame for given pSection
-EhFrame* IRBuilder::CreateEhFrame(LDSection& pSection)
-{
+EhFrame* IRBuilder::CreateEhFrame(LDSection& pSection) {
assert(!pSection.hasEhFrame() && "pSection already has eh_frame.");
EhFrame* eh_frame = EhFrame::Create(pSection);
@@ -319,16 +307,25 @@ EhFrame* IRBuilder::CreateEhFrame(LDSection& pSection)
return eh_frame;
}
+/// CreateDebugString - To create a DebugString for given pSection
+DebugString* IRBuilder::CreateDebugString(LDSection& pSection) {
+ assert(!pSection.hasDebugString() && "pSection already has debug_str.");
+
+ DebugString* debug_str = DebugString::Create(pSection);
+ pSection.setDebugString(debug_str);
+ return debug_str;
+}
+
/// CreateBSS - To create a bss section for given pSection
-SectionData* IRBuilder::CreateBSS(LDSection& pSection)
-{
+SectionData* IRBuilder::CreateBSS(LDSection& pSection) {
assert(!pSection.hasSectionData() && "pSection already has section data.");
- assert((pSection.kind() == LDFileFormat::BSS) && "pSection is not a BSS section.");
+ assert((pSection.kind() == LDFileFormat::BSS) &&
+ "pSection is not a BSS section.");
SectionData* sect_data = SectionData::Create(pSection);
pSection.setSectionData(sect_data);
- /* value, valsize, size*/
+ /* value, valsize, size*/
FillFragment* frag = new FillFragment(0x0, 1, pSection.size());
ObjectBuilder::AppendFragment(*frag, *sect_data);
@@ -336,8 +333,9 @@ SectionData* IRBuilder::CreateBSS(LDSection& pSection)
}
/// CreateRegion - To create a region fragment in the input file.
-Fragment* IRBuilder::CreateRegion(Input& pInput, size_t pOffset, size_t pLength)
-{
+Fragment* IRBuilder::CreateRegion(Input& pInput,
+ size_t pOffset,
+ size_t pLength) {
if (!pInput.hasMemArea()) {
fatal(diag::fatal_cannot_read_input) << pInput.path();
return NULL;
@@ -351,8 +349,7 @@ Fragment* IRBuilder::CreateRegion(Input& pInput, size_t pOffset, size_t pLength)
}
/// CreateRegion - To create a region fragment wrapping the given memory
-Fragment* IRBuilder::CreateRegion(void* pMemory, size_t pLength)
-{
+Fragment* IRBuilder::CreateRegion(void* pMemory, size_t pLength) {
if (0 == pLength)
return new FillFragment(0x0, 0, 0);
@@ -361,42 +358,35 @@ Fragment* IRBuilder::CreateRegion(void* pMemory, size_t pLength)
}
/// AppendFragment - To append pFrag to the given SectionData pSD
-uint64_t IRBuilder::AppendFragment(Fragment& pFrag, SectionData& pSD)
-{
- uint64_t size = ObjectBuilder::AppendFragment(pFrag,
- pSD,
- pSD.getSection().align());
+uint64_t IRBuilder::AppendFragment(Fragment& pFrag, SectionData& pSD) {
+ uint64_t size =
+ ObjectBuilder::AppendFragment(pFrag, pSD, pSD.getSection().align());
pSD.getSection().setSize(pSD.getSection().size() + size);
return size;
}
/// AppendRelocation - To append an relocation to the given RelocData pRD.
-void IRBuilder::AppendRelocation(Relocation& pRelocation, RelocData& pRD)
-{
+void IRBuilder::AppendRelocation(Relocation& pRelocation, RelocData& pRD) {
pRD.append(pRelocation);
}
/// AppendEhFrame - To append a fragment to EhFrame.
-uint64_t IRBuilder::AppendEhFrame(Fragment& pFrag, EhFrame& pEhFrame)
-{
- uint64_t size = ObjectBuilder::AppendFragment(pFrag,
- *pEhFrame.getSectionData(),
- pEhFrame.getSection().align());
+uint64_t IRBuilder::AppendEhFrame(Fragment& pFrag, EhFrame& pEhFrame) {
+ uint64_t size = ObjectBuilder::AppendFragment(
+ pFrag, *pEhFrame.getSectionData(), pEhFrame.getSection().align());
pEhFrame.getSection().setSize(pEhFrame.getSection().size() + size);
return size;
}
/// AppendEhFrame - To append a FDE to the given EhFrame pEhFram.
-uint64_t IRBuilder::AppendEhFrame(EhFrame::FDE& pFDE, EhFrame& pEhFrame)
-{
+uint64_t IRBuilder::AppendEhFrame(EhFrame::FDE& pFDE, EhFrame& pEhFrame) {
pEhFrame.addFDE(pFDE);
pEhFrame.getSection().setSize(pEhFrame.getSection().size() + pFDE.size());
return pFDE.size();
}
/// AppendEhFrame - To append a CIE to the given EhFrame pEhFram.
-uint64_t IRBuilder::AppendEhFrame(EhFrame::CIE& pCIE, EhFrame& pEhFrame)
-{
+uint64_t IRBuilder::AppendEhFrame(EhFrame::CIE& pCIE, EhFrame& pEhFrame) {
pEhFrame.addCIE(pCIE);
pEhFrame.getSection().setSize(pEhFrame.getSection().size() + pCIE.size());
return pCIE.size();
@@ -412,8 +402,7 @@ LDSymbol* IRBuilder::AddSymbol(Input& pInput,
ResolveInfo::SizeType pSize,
LDSymbol::ValueType pValue,
LDSection* pSection,
- ResolveInfo::Visibility pVis)
-{
+ ResolveInfo::Visibility pVis) {
// rename symbols
std::string name = pName;
if (!m_Module.getScript().renameMap().empty() &&
@@ -422,7 +411,7 @@ LDSymbol* IRBuilder::AddSymbol(Input& pInput,
// --wrap and --portable defines the symbol rename map.
const LinkerScript& script = m_Module.getScript();
LinkerScript::SymbolRenameMap::const_iterator renameSym =
- script.renameMap().find(pName);
+ script.renameMap().find(pName);
if (script.renameMap().end() != renameSym)
name = renameSym.getEntry()->value();
}
@@ -436,24 +425,23 @@ LDSymbol* IRBuilder::AddSymbol(Input& pInput,
switch (pInput.type()) {
case Input::Object: {
-
FragmentRef* frag = NULL;
- if (NULL == pSection ||
- ResolveInfo::Undefined == pDesc ||
- ResolveInfo::Common == pDesc ||
- ResolveInfo::Absolute == pBind ||
- LDFileFormat::Ignore == pSection->kind() ||
- LDFileFormat::Group == pSection->kind())
+ if (pSection == NULL || ResolveInfo::Undefined == pDesc ||
+ ResolveInfo::Common == pDesc || ResolveInfo::Absolute == pBind ||
+ LDFileFormat::Ignore == pSection->kind() ||
+ LDFileFormat::Group == pSection->kind())
frag = FragmentRef::Null();
else
frag = FragmentRef::Create(*pSection, pValue);
- LDSymbol* input_sym = addSymbolFromObject(name, pType, pDesc, pBind, pSize, pValue, frag, pVis);
+ LDSymbol* input_sym = addSymbolFromObject(
+ name, pType, pDesc, pBind, pSize, pValue, frag, pVis);
pInput.context()->addSymbol(input_sym);
return input_sym;
}
case Input::DynObj: {
- return addSymbolFromDynObj(pInput, name, pType, pDesc, pBind, pSize, pValue, pVis);
+ return addSymbolFromDynObj(
+ pInput, name, pType, pDesc, pBind, pSize, pValue, pVis);
}
default: {
return NULL;
@@ -470,38 +458,38 @@ LDSymbol* IRBuilder::addSymbolFromObject(const std::string& pName,
ResolveInfo::SizeType pSize,
LDSymbol::ValueType pValue,
FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility)
-{
+ ResolveInfo::Visibility pVisibility) {
// Step 1. calculate a Resolver::Result
// resolved_result is a triple <resolved_info, existent, override>
Resolver::Result resolved_result;
- ResolveInfo old_info; // used for arrange output symbols
+ ResolveInfo old_info; // used for arrange output symbols
if (pBinding == ResolveInfo::Local) {
// if the symbol is a local symbol, create a LDSymbol for input, but do not
// resolve them.
- resolved_result.info = m_Module.getNamePool().createSymbol(pName,
- false,
- pType,
- pDesc,
- pBinding,
- pSize,
- pVisibility);
+ resolved_result.info = m_Module.getNamePool().createSymbol(
+ pName, false, pType, pDesc, pBinding, pSize, pVisibility);
// No matter if there is a symbol with the same name, insert the symbol
// into output symbol table. So, we let the existent false.
- resolved_result.existent = false;
+ resolved_result.existent = false;
resolved_result.overriden = true;
- }
- else {
+ } else {
// if the symbol is not local, insert and resolve it immediately
- m_Module.getNamePool().insertSymbol(pName, false, pType, pDesc, pBinding,
- pSize, pValue, pVisibility,
- &old_info, resolved_result);
+ m_Module.getNamePool().insertSymbol(pName,
+ false,
+ pType,
+ pDesc,
+ pBinding,
+ pSize,
+ pValue,
+ pVisibility,
+ &old_info,
+ resolved_result);
}
// the return ResolveInfo should not NULL
- assert(NULL != resolved_result.info);
+ assert(resolved_result.info != NULL);
/// Step 2. create an input LDSymbol.
// create a LDSymbol for the input file.
@@ -511,16 +499,15 @@ LDSymbol* IRBuilder::addSymbolFromObject(const std::string& pName,
// Step 3. Set up corresponding output LDSymbol
LDSymbol* output_sym = resolved_result.info->outSymbol();
- bool has_output_sym = (NULL != output_sym);
+ bool has_output_sym = (output_sym != NULL);
if (!resolved_result.existent || !has_output_sym) {
// it is a new symbol, the output_sym should be NULL.
- assert(NULL == output_sym);
+ assert(output_sym == NULL);
if (pType == ResolveInfo::Section) {
// if it is a section symbol, its output LDSymbol is the input LDSymbol.
output_sym = input_sym;
- }
- else {
+ } else {
// if it is a new symbol, create a LDSymbol for the output
output_sym = LDSymbol::Create(*resolved_result.info);
}
@@ -545,16 +532,14 @@ LDSymbol* IRBuilder::addSymbolFromDynObj(Input& pInput,
ResolveInfo::Binding pBinding,
ResolveInfo::SizeType pSize,
LDSymbol::ValueType pValue,
- ResolveInfo::Visibility pVisibility)
-{
+ ResolveInfo::Visibility pVisibility) {
// We don't need sections of dynamic objects. So we ignore section symbols.
if (pType == ResolveInfo::Section)
return NULL;
// ignore symbols with local binding or that have internal or hidden
// visibility
- if (pBinding == ResolveInfo::Local ||
- pVisibility == ResolveInfo::Internal ||
+ if (pBinding == ResolveInfo::Local || pVisibility == ResolveInfo::Internal ||
pVisibility == ResolveInfo::Hidden)
return NULL;
@@ -566,12 +551,19 @@ LDSymbol* IRBuilder::addSymbolFromDynObj(Input& pInput,
// insert symbol and resolve it immediately
// resolved_result is a triple <resolved_info, existent, override>
Resolver::Result resolved_result;
- m_Module.getNamePool().insertSymbol(pName, true, pType, pDesc,
- pBinding, pSize, pValue, pVisibility,
- NULL, resolved_result);
+ m_Module.getNamePool().insertSymbol(pName,
+ true,
+ pType,
+ pDesc,
+ pBinding,
+ pSize,
+ pValue,
+ pVisibility,
+ NULL,
+ resolved_result);
// the return ResolveInfo should not NULL
- assert(NULL != resolved_result.info);
+ assert(resolved_result.info != NULL);
if (resolved_result.overriden || !resolved_result.existent)
pInput.setNeeded();
@@ -598,8 +590,7 @@ Relocation* IRBuilder::AddRelocation(LDSection& pSection,
Relocation::Type pType,
LDSymbol& pSym,
uint32_t pOffset,
- Relocation::Address pAddend)
-{
+ Relocation::Address pAddend) {
FragmentRef* frag_ref = FragmentRef::Create(*pSection.getLink(), pOffset);
Relocation* relocation = Relocation::Create(pType, *frag_ref, pAddend);
@@ -611,26 +602,32 @@ Relocation* IRBuilder::AddRelocation(LDSection& pSection,
}
/// AddSymbol - define an output symbol and override it immediately
-template<> LDSymbol*
-IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- const llvm::StringRef& pName,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility)
-{
+template <>
+LDSymbol* IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
+ const llvm::StringRef& pName,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ FragmentRef* pFragmentRef,
+ ResolveInfo::Visibility pVisibility) {
ResolveInfo* info = m_Module.getNamePool().findInfo(pName);
LDSymbol* output_sym = NULL;
- if (NULL == info) {
+ if (info == NULL) {
// the symbol is not in the pool, create a new one.
// create a ResolveInfo
Resolver::Result result;
- m_Module.getNamePool().insertSymbol(pName, false, pType, pDesc,
- pBinding, pSize, pValue, pVisibility,
- NULL, result);
+ m_Module.getNamePool().insertSymbol(pName,
+ false,
+ pType,
+ pDesc,
+ pBinding,
+ pSize,
+ pValue,
+ pVisibility,
+ NULL,
+ result);
assert(!result.existent);
// create a output LDSymbol
@@ -641,8 +638,7 @@ IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
m_Module.getSymbolTable().forceLocal(*output_sym);
else
m_Module.getSymbolTable().add(*output_sym);
- }
- else {
+ } else {
// the symbol is already in the pool, override it
ResolveInfo old_info;
old_info.override(*info);
@@ -656,7 +652,7 @@ IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
info->setSize(pSize);
output_sym = info->outSymbol();
- if (NULL != output_sym)
+ if (output_sym != NULL)
m_Module.getSymbolTable().arrange(*output_sym, old_info);
else {
// create a output LDSymbol
@@ -667,7 +663,7 @@ IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
}
}
- if (NULL != output_sym) {
+ if (output_sym != NULL) {
output_sym->setFragmentRef(pFragmentRef);
output_sym->setValue(pValue);
}
@@ -676,20 +672,19 @@ IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
}
/// AddSymbol - define an output symbol and override it immediately
-template<> LDSymbol*
-IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>(
- const llvm::StringRef& pName,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility)
-{
+template <>
+LDSymbol* IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>(
+ const llvm::StringRef& pName,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ FragmentRef* pFragmentRef,
+ ResolveInfo::Visibility pVisibility) {
ResolveInfo* info = m_Module.getNamePool().findInfo(pName);
- if (NULL == info || !(info->isUndef() || info->isDyn())) {
+ if (info == NULL || !(info->isUndef() || info->isDyn())) {
// only undefined symbol and dynamic symbol can make a reference.
return NULL;
}
@@ -707,12 +702,11 @@ IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>(
info->setSize(pSize);
LDSymbol* output_sym = info->outSymbol();
- if (NULL != output_sym) {
+ if (output_sym != NULL) {
output_sym->setFragmentRef(pFragmentRef);
output_sym->setValue(pValue);
m_Module.getSymbolTable().arrange(*output_sym, old_info);
- }
- else {
+ } else {
// create a output LDSymbol
output_sym = LDSymbol::Create(*info);
info->setSymPtr(output_sym);
@@ -725,26 +719,32 @@ IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>(
/// AddSymbol - define an output symbol and resolve it
/// immediately
-template<> LDSymbol*
-IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- const llvm::StringRef& pName,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility)
-{
+template <>
+LDSymbol* IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
+ const llvm::StringRef& pName,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ FragmentRef* pFragmentRef,
+ ResolveInfo::Visibility pVisibility) {
// Result is <info, existent, override>
Resolver::Result result;
ResolveInfo old_info;
- m_Module.getNamePool().insertSymbol(pName, false, pType, pDesc, pBinding,
- pSize, pValue, pVisibility,
- &old_info, result);
+ m_Module.getNamePool().insertSymbol(pName,
+ false,
+ pType,
+ pDesc,
+ pBinding,
+ pSize,
+ pValue,
+ pVisibility,
+ &old_info,
+ result);
LDSymbol* output_sym = result.info->outSymbol();
- bool has_output_sym = (NULL != output_sym);
+ bool has_output_sym = (output_sym != NULL);
if (!result.existent || !has_output_sym) {
output_sym = LDSymbol::Create(*result.info);
@@ -769,31 +769,25 @@ IRBuilder::AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
}
/// defineSymbol - define an output symbol and resolve it immediately.
-template<> LDSymbol*
-IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- const llvm::StringRef& pName,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- FragmentRef* pFragmentRef,
- ResolveInfo::Visibility pVisibility)
-{
+template <>
+LDSymbol* IRBuilder::AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ const llvm::StringRef& pName,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ FragmentRef* pFragmentRef,
+ ResolveInfo::Visibility pVisibility) {
ResolveInfo* info = m_Module.getNamePool().findInfo(pName);
- if (NULL == info || !(info->isUndef() || info->isDyn())) {
+ if (info == NULL || !(info->isUndef() || info->isDyn())) {
// only undefined symbol and dynamic symbol can make a reference.
return NULL;
}
- return AddSymbol<Force, Resolve>(pName,
- pType,
- pDesc,
- pBinding,
- pSize,
- pValue,
- pFragmentRef,
- pVisibility);
+ return AddSymbol<Force, Resolve>(
+ pName, pType, pDesc, pBinding, pSize, pValue, pFragmentRef, pVisibility);
}
+} // namespace mcld
diff --git a/lib/Core/InputTree.cpp b/lib/Core/InputTree.cpp
index 5df91d8..6e65add 100644
--- a/lib/Core/InputTree.cpp
+++ b/lib/Core/InputTree.cpp
@@ -6,27 +6,25 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/InputTree.h>
+#include "mcld/InputTree.h"
-using namespace mcld;
+namespace mcld {
InputTree::Succeeder InputTree::Afterward;
-InputTree::Includer InputTree::Downward;
+InputTree::Includer InputTree::Downward;
//===----------------------------------------------------------------------===//
// InputTree
//===----------------------------------------------------------------------===//
InputTree& InputTree::merge(TreeIteratorBase pRoot,
const InputTree::Mover& pMover,
- InputTree& pTree)
-{
+ InputTree& pTree) {
if (this == &pTree)
return *this;
if (!pTree.empty()) {
pMover.connect(pRoot, pTree.m_Root.node.right);
- BinaryTreeBase<Input>::m_Root.summon(
- pTree.BinaryTreeBase<Input>::m_Root);
+ BinaryTreeBase<Input>::m_Root.summon(pTree.BinaryTreeBase<Input>::m_Root);
BinaryTreeBase<Input>::m_Root.delegate(pTree.m_Root);
pTree.m_Root.node.left = pTree.m_Root.node.right = &pTree.m_Root.node;
}
@@ -34,8 +32,7 @@ InputTree& InputTree::merge(TreeIteratorBase pRoot,
}
InputTree& InputTree::enterGroup(TreeIteratorBase pRoot,
- const InputTree::Mover& pMover)
-{
+ const InputTree::Mover& pMover) {
NodeBase* node = createNode();
pMover.connect(pRoot, node);
return *this;
@@ -43,8 +40,7 @@ InputTree& InputTree::enterGroup(TreeIteratorBase pRoot,
InputTree& InputTree::insert(TreeIteratorBase pRoot,
const InputTree::Mover& pMover,
- mcld::Input& pInput)
-{
+ Input& pInput) {
BinaryTree<Input>::node_type* node = createNode();
node->data = &pInput;
pMover.connect(pRoot, node);
@@ -54,33 +50,28 @@ InputTree& InputTree::insert(TreeIteratorBase pRoot,
//===----------------------------------------------------------------------===//
// non-member functions
//===----------------------------------------------------------------------===//
-bool mcld::isGroup(const InputTree::iterator& pos)
-{
+bool isGroup(const InputTree::iterator& pos) {
return !pos.hasData() && !pos.isRoot();
}
-bool mcld::isGroup(const InputTree::const_iterator& pos)
-{
+bool isGroup(const InputTree::const_iterator& pos) {
return !pos.hasData() && !pos.isRoot();
}
-bool mcld::isGroup(const InputTree::dfs_iterator& pos)
-{
+bool isGroup(const InputTree::dfs_iterator& pos) {
return !pos.hasData() && !pos.isRoot();
}
-bool mcld::isGroup(const InputTree::const_dfs_iterator& pos)
-{
+bool isGroup(const InputTree::const_dfs_iterator& pos) {
return !pos.hasData() && !pos.isRoot();
}
-bool mcld::isGroup(const InputTree::bfs_iterator& pos)
-{
+bool isGroup(const InputTree::bfs_iterator& pos) {
return !pos.hasData() && !pos.isRoot();
}
-bool mcld::isGroup(const InputTree::const_bfs_iterator& pos)
-{
+bool isGroup(const InputTree::const_bfs_iterator& pos) {
return !pos.hasData() && !pos.isRoot();
}
+} // namespace mcld
diff --git a/lib/Core/Linker.cpp b/lib/Core/Linker.cpp
index c8638a7..b499b80 100644
--- a/lib/Core/Linker.cpp
+++ b/lib/Core/Linker.cpp
@@ -6,46 +6,46 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Linker.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Module.h>
-#include <mcld/IRBuilder.h>
-
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/FileOutputBuffer.h>
-#include <mcld/Support/raw_ostream.h>
-
-#include <mcld/Object/ObjectLinker.h>
-#include <mcld/MC/InputBuilder.h>
-#include <mcld/Target/TargetLDBackend.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/ObjectWriter.h>
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/Fragment/FragmentRef.h>
+#include "mcld/Linker.h"
+
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Module.h"
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ObjectWriter.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/Object/ObjectLinker.h"
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/FileOutputBuffer.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/Target/TargetLDBackend.h"
#include <cassert>
-using namespace mcld;
+namespace mcld {
Linker::Linker()
- : m_pConfig(NULL), m_pIRBuilder(NULL),
- m_pTarget(NULL), m_pBackend(NULL), m_pObjLinker(NULL) {
+ : m_pConfig(NULL),
+ m_pIRBuilder(NULL),
+ m_pTarget(NULL),
+ m_pBackend(NULL),
+ m_pObjLinker(NULL) {
}
-Linker::~Linker()
-{
+Linker::~Linker() {
reset();
}
/// emulate - To set up target-dependent options and default linker script.
/// Follow GNU ld quirks.
-bool Linker::emulate(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+bool Linker::emulate(LinkerScript& pScript, LinkerConfig& pConfig) {
m_pConfig = &pConfig;
if (!initTarget())
@@ -63,8 +63,7 @@ bool Linker::emulate(LinkerScript& pScript, LinkerConfig& pConfig)
return true;
}
-bool Linker::link(Module& pModule, IRBuilder& pBuilder)
-{
+bool Linker::link(Module& pModule, IRBuilder& pBuilder) {
if (!normalize(pModule, pBuilder))
return false;
@@ -75,9 +74,8 @@ bool Linker::link(Module& pModule, IRBuilder& pBuilder)
}
/// normalize - to convert the command line language to the input tree.
-bool Linker::normalize(Module& pModule, IRBuilder& pBuilder)
-{
- assert(NULL != m_pConfig);
+bool Linker::normalize(Module& pModule, IRBuilder& pBuilder) {
+ assert(m_pConfig != NULL);
m_pIRBuilder = &pBuilder;
@@ -107,30 +105,32 @@ bool Linker::normalize(Module& pModule, IRBuilder& pBuilder)
if (m_pConfig->options().trace()) {
static int counter = 0;
- mcld::outs() << "** name\ttype\tpath\tsize (" << pModule.getInputTree().size() << ")\n";
- InputTree::const_dfs_iterator input, inEnd = pModule.getInputTree().dfs_end();
- for (input=pModule.getInputTree().dfs_begin(); input!=inEnd; ++input) {
+ mcld::outs() << "** name\ttype\tpath\tsize ("
+ << pModule.getInputTree().size() << ")\n";
+
+ InputTree::const_dfs_iterator input,
+ inEnd = pModule.getInputTree().dfs_end();
+ for (input = pModule.getInputTree().dfs_begin(); input != inEnd; ++input) {
mcld::outs() << counter++ << " * " << (*input)->name();
- switch((*input)->type()) {
- case Input::Archive:
- mcld::outs() << "\tarchive\t(";
- break;
- case Input::Object:
- mcld::outs() << "\tobject\t(";
- break;
- case Input::DynObj:
- mcld::outs() << "\tshared\t(";
- break;
- case Input::Script:
- mcld::outs() << "\tscript\t(";
- break;
- case Input::External:
- mcld::outs() << "\textern\t(";
- break;
- default:
- unreachable(diag::err_cannot_trace_file) << (*input)->type()
- << (*input)->name()
- << (*input)->path();
+ switch ((*input)->type()) {
+ case Input::Archive:
+ mcld::outs() << "\tarchive\t(";
+ break;
+ case Input::Object:
+ mcld::outs() << "\tobject\t(";
+ break;
+ case Input::DynObj:
+ mcld::outs() << "\tshared\t(";
+ break;
+ case Input::Script:
+ mcld::outs() << "\tscript\t(";
+ break;
+ case Input::External:
+ mcld::outs() << "\textern\t(";
+ break;
+ default:
+ unreachable(diag::err_cannot_trace_file)
+ << (*input)->type() << (*input)->name() << (*input)->path();
}
mcld::outs() << (*input)->path() << ")\n";
}
@@ -140,20 +140,19 @@ bool Linker::normalize(Module& pModule, IRBuilder& pBuilder)
if (LinkerConfig::DynObj == m_pConfig->codeGenType() ||
m_pConfig->options().isPIE()) {
m_pConfig->setCodePosition(LinkerConfig::Independent);
- }
- else if (pModule.getLibraryList().empty()) {
+ } else if (pModule.getLibraryList().empty()) {
// If the output is dependent on its loaded address, and it does not need
// to call outside functions, then we can treat the output static dependent
// and perform better optimizations.
m_pConfig->setCodePosition(LinkerConfig::StaticDependent);
if (LinkerConfig::Exec == m_pConfig->codeGenType()) {
- // Since the output is static dependent, there should not have any undefined
+ // Since the output is static dependent, there should not have any
+ // undefined
// references in the output module.
m_pConfig->options().setNoUndefined();
}
- }
- else {
+ } else {
m_pConfig->setCodePosition(LinkerConfig::DynamicDependent);
}
@@ -163,9 +162,8 @@ bool Linker::normalize(Module& pModule, IRBuilder& pBuilder)
return true;
}
-bool Linker::resolve(Module& pModule)
-{
- assert(NULL != m_pConfig);
+bool Linker::resolve(Module& pModule) {
+ assert(m_pConfig != NULL);
assert(m_pObjLinker != NULL);
// 6. - read all relocation entries from input files
@@ -176,7 +174,6 @@ bool Linker::resolve(Module& pModule)
// To collect all edges in the reference graph.
m_pObjLinker->readRelocations();
-
// 7. - data stripping optimizations
m_pObjLinker->dataStrippingOpt();
@@ -202,14 +199,12 @@ bool Linker::resolve(Module& pModule)
return true;
}
-bool Linker::layout()
-{
- assert(NULL != m_pConfig && NULL != m_pObjLinker);
+bool Linker::layout() {
+ assert(m_pConfig != NULL && m_pObjLinker != NULL);
// 10. - add standard symbols, target-dependent symbols and script symbols
if (!m_pObjLinker->addStandardSymbols() ||
- !m_pObjLinker->addTargetSymbols() ||
- !m_pObjLinker->addScriptSymbols())
+ !m_pObjLinker->addTargetSymbols() || !m_pObjLinker->addScriptSymbols())
return false;
// 11. - scan all relocation entries by output symbols.
@@ -244,8 +239,7 @@ bool Linker::layout()
return true;
}
-bool Linker::emit(FileOutputBuffer& pOutput)
-{
+bool Linker::emit(FileOutputBuffer& pOutput) {
// 15. - write out output
m_pObjLinker->emitOutput(pOutput);
@@ -258,57 +252,52 @@ bool Linker::emit(FileOutputBuffer& pOutput)
return true;
}
-bool Linker::emit(const Module& pModule, const std::string& pPath)
-{
+bool Linker::emit(const Module& pModule, const std::string& pPath) {
FileHandle file;
- FileHandle::Permission perm;
+ FileHandle::OpenMode open_mode(
+ FileHandle::ReadWrite | FileHandle::Truncate | FileHandle::Create);
+ FileHandle::Permission permission;
switch (m_pConfig->codeGenType()) {
case mcld::LinkerConfig::Unknown:
case mcld::LinkerConfig::Object:
- perm = mcld::FileHandle::Permission(0x644);
+ permission = FileHandle::Permission(0x644);
break;
case mcld::LinkerConfig::DynObj:
case mcld::LinkerConfig::Exec:
case mcld::LinkerConfig::Binary:
- perm = mcld::FileHandle::Permission(0x755);
+ permission = FileHandle::Permission(0x755);
break;
- default: assert(0 && "Unknown file type");
+ default:
+ assert(0 && "Unknown file type");
}
- if (!file.open(pPath,
- FileHandle::ReadWrite | FileHandle::Truncate | FileHandle::Create,
- perm)) {
+ bool result = file.open(sys::fs::Path(pPath), open_mode, permission);
+ if (!result) {
error(diag::err_cannot_open_output_file) << "Linker::emit()" << pPath;
return false;
}
std::unique_ptr<FileOutputBuffer> output;
- FileOutputBuffer::create(file,
- m_pObjLinker->getWriter()->getOutputSize(pModule),
- output);
+ FileOutputBuffer::create(
+ file, m_pObjLinker->getWriter()->getOutputSize(pModule), output);
- bool result = emit(*output.get());
+ result = emit(*output.get());
file.close();
return result;
}
-bool Linker::emit(const Module& pModule, int pFileDescriptor)
-{
+bool Linker::emit(const Module& pModule, int pFileDescriptor) {
FileHandle file;
file.delegate(pFileDescriptor);
std::unique_ptr<FileOutputBuffer> output;
- FileOutputBuffer::create(file,
- m_pObjLinker->getWriter()->getOutputSize(pModule),
- output);
-
- bool result = emit(*output.get());
+ FileOutputBuffer::create(
+ file, m_pObjLinker->getWriter()->getOutputSize(pModule), output);
- return result;
+ return emit(*output.get());
}
-bool Linker::reset()
-{
+bool Linker::reset() {
m_pConfig = NULL;
m_pIRBuilder = NULL;
m_pTarget = NULL;
@@ -332,38 +321,36 @@ bool Linker::reset()
return true;
}
-bool Linker::initTarget()
-{
- assert(NULL != m_pConfig);
+bool Linker::initTarget() {
+ assert(m_pConfig != NULL);
std::string error;
llvm::Triple triple(m_pConfig->targets().triple());
- m_pTarget = mcld::TargetRegistry::lookupTarget(m_pConfig->targets().getArch(),
- triple, error);
+ m_pTarget = mcld::TargetRegistry::lookupTarget(
+ m_pConfig->targets().getArch(), triple, error);
m_pConfig->targets().setTriple(triple);
- if (NULL == m_pTarget) {
+ if (m_pTarget == NULL) {
fatal(diag::fatal_cannot_init_target) << triple.str() << error;
return false;
}
return true;
}
-bool Linker::initBackend()
-{
- assert(NULL != m_pTarget);
+bool Linker::initBackend() {
+ assert(m_pTarget != NULL);
m_pBackend = m_pTarget->createLDBackend(*m_pConfig);
- if (NULL == m_pBackend) {
- fatal(diag::fatal_cannot_init_backend) << m_pConfig->targets().triple().str();
+ if (m_pBackend == NULL) {
+ fatal(diag::fatal_cannot_init_backend)
+ << m_pConfig->targets().triple().str();
return false;
}
return true;
}
-bool Linker::initOStream()
-{
- assert(NULL != m_pConfig);
+bool Linker::initOStream() {
+ assert(m_pConfig != NULL);
mcld::outs().setColor(m_pConfig->options().color());
mcld::errs().setColor(m_pConfig->options().color());
@@ -371,9 +358,9 @@ bool Linker::initOStream()
return true;
}
-bool Linker::initEmulator(LinkerScript& pScript)
-{
- assert(NULL != m_pTarget && NULL != m_pConfig);
+bool Linker::initEmulator(LinkerScript& pScript) {
+ assert(m_pTarget != NULL && m_pConfig != NULL);
return m_pTarget->emulate(pScript, *m_pConfig);
}
+} // namespace mcld
diff --git a/lib/Core/LinkerConfig.cpp b/lib/Core/LinkerConfig.cpp
index b40cda5..d252066 100644
--- a/lib/Core/LinkerConfig.cpp
+++ b/lib/Core/LinkerConfig.cpp
@@ -6,47 +6,43 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LinkerConfig.h>
-#include <mcld/Config/Config.h>
+#include "mcld/LinkerConfig.h"
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/Config/Config.h"
+#include "mcld/Support/MsgHandling.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// LinkerConfig
//===----------------------------------------------------------------------===//
LinkerConfig::LinkerConfig()
- : m_Options(),
- m_Targets(),
- m_Bitcode(),
- m_Attribute(),
- m_CodeGenType(Unknown),
- m_CodePosition(Unset)
-{
+ : m_Options(),
+ m_Targets(),
+ m_Attribute(),
+ m_CodeGenType(Unknown),
+ m_CodePosition(Unset) {
// FIXME: is here the right place to hold this?
InitializeDiagnosticEngine(*this);
}
LinkerConfig::LinkerConfig(const std::string& pTripleString)
- : m_Options(),
- m_Targets(pTripleString),
- m_Bitcode(),
- m_Attribute(),
- m_CodeGenType(Unknown),
- m_CodePosition(Unset)
-{
+ : m_Options(),
+ m_Targets(pTripleString),
+ m_Attribute(),
+ m_CodeGenType(Unknown),
+ m_CodePosition(Unset) {
// FIXME: is here the right place to hold this?
InitializeDiagnosticEngine(*this);
}
-LinkerConfig::~LinkerConfig()
-{
+LinkerConfig::~LinkerConfig() {
// FIXME: is here the right place to hold this?
FinalizeDiagnosticEngine();
}
-const char* LinkerConfig::version()
-{
+const char* LinkerConfig::version() {
return MCLD_VERSION;
}
+
+} // namespace mcld
diff --git a/lib/Core/LinkerScript.cpp b/lib/Core/LinkerScript.cpp
index 2e891e2..7bb26a7 100644
--- a/lib/Core/LinkerScript.cpp
+++ b/lib/Core/LinkerScript.cpp
@@ -6,62 +6,53 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LinkerScript.h>
+#include "mcld/LinkerScript.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// LinkerScript
//===----------------------------------------------------------------------===//
-LinkerScript::LinkerScript()
-{
+LinkerScript::LinkerScript() {
}
-LinkerScript::~LinkerScript()
-{
+LinkerScript::~LinkerScript() {
}
-const mcld::sys::fs::Path& LinkerScript::sysroot() const
-{
+const mcld::sys::fs::Path& LinkerScript::sysroot() const {
return m_SearchDirs.sysroot();
}
-void LinkerScript::setSysroot(const mcld::sys::fs::Path &pSysroot)
-{
+void LinkerScript::setSysroot(const mcld::sys::fs::Path& pSysroot) {
m_SearchDirs.setSysRoot(pSysroot);
}
-bool LinkerScript::hasSysroot() const
-{
+bool LinkerScript::hasSysroot() const {
return !sysroot().empty();
}
-const std::string& LinkerScript::entry() const
-{
+const std::string& LinkerScript::entry() const {
return m_Entry;
}
-void LinkerScript::setEntry(const std::string& pEntry)
-{
+void LinkerScript::setEntry(const std::string& pEntry) {
m_Entry = pEntry;
}
-bool LinkerScript::hasEntry() const
-{
+bool LinkerScript::hasEntry() const {
return !m_Entry.empty();
}
-const std::string& LinkerScript::outputFile() const
-{
+const std::string& LinkerScript::outputFile() const {
return m_OutputFile;
}
-void LinkerScript::setOutputFile(const std::string& pOutputFile)
-{
+void LinkerScript::setOutputFile(const std::string& pOutputFile) {
m_OutputFile = pOutputFile;
}
-bool LinkerScript::hasOutputFile() const
-{
+bool LinkerScript::hasOutputFile() const {
return !m_OutputFile.empty();
}
+
+} // namespace mcld
diff --git a/lib/Core/Module.cpp b/lib/Core/Module.cpp
index 0f9a24d..dce8e31 100644
--- a/lib/Core/Module.cpp
+++ b/lib/Core/Module.cpp
@@ -6,38 +6,36 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Module.h>
-#include <mcld/Fragment/FragmentRef.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/NamePool.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/StaticResolver.h>
+#include "mcld/Module.h"
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/NamePool.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/LD/StaticResolver.h"
-using namespace mcld;
+namespace mcld {
-static GCFactory<Module::AliasList, MCLD_SECTIONS_PER_INPUT> gc_aliaslist_factory;
+static GCFactory<Module::AliasList, MCLD_SECTIONS_PER_INPUT>
+ gc_aliaslist_factory;
//===----------------------------------------------------------------------===//
// Module
//===----------------------------------------------------------------------===//
-Module::Module(LinkerScript& pScript)
- : m_Script(pScript), m_NamePool(1024) {
+Module::Module(LinkerScript& pScript) : m_Script(pScript), m_NamePool(1024) {
}
Module::Module(const std::string& pName, LinkerScript& pScript)
- : m_Name(pName), m_Script(pScript), m_NamePool(1024) {
+ : m_Name(pName), m_Script(pScript), m_NamePool(1024) {
}
-Module::~Module()
-{
+Module::~Module() {
}
// Following two functions will be obsolette when we have new section merger.
-LDSection* Module::getSection(const std::string& pName)
-{
+LDSection* Module::getSection(const std::string& pName) {
iterator sect, sectEnd = end();
for (sect = begin(); sect != sectEnd; ++sect) {
if ((*sect)->name() == pName)
@@ -46,8 +44,7 @@ LDSection* Module::getSection(const std::string& pName)
return NULL;
}
-const LDSection* Module::getSection(const std::string& pName) const
-{
+const LDSection* Module::getSection(const std::string& pName) const {
const_iterator sect, sectEnd = end();
for (sect = begin(); sect != sectEnd; ++sect) {
if ((*sect)->name() == pName)
@@ -56,29 +53,26 @@ const LDSection* Module::getSection(const std::string& pName) const
return NULL;
}
-void Module::CreateAliasList(const ResolveInfo& pSym)
-{
+void Module::CreateAliasList(const ResolveInfo& pSym) {
AliasList* result = gc_aliaslist_factory.allocate();
new (result) AliasList();
m_AliasLists.push_back(result);
result->push_back(&pSym);
}
-void Module::addAlias(const ResolveInfo& pAlias)
-{
- assert(0!=m_AliasLists.size());
- uint32_t last_pos = m_AliasLists.size()-1;
+void Module::addAlias(const ResolveInfo& pAlias) {
+ assert(m_AliasLists.size() != 0);
+ uint32_t last_pos = m_AliasLists.size() - 1;
m_AliasLists[last_pos]->push_back(&pAlias);
}
-Module::AliasList* Module::getAliasList(const ResolveInfo& pSym)
-{
- std::vector<AliasList*>::iterator list_it, list_it_e=m_AliasLists.end();
- for (list_it=m_AliasLists.begin(); list_it!=list_it_e; ++list_it) {
+Module::AliasList* Module::getAliasList(const ResolveInfo& pSym) {
+ std::vector<AliasList*>::iterator list_it, list_it_e = m_AliasLists.end();
+ for (list_it = m_AliasLists.begin(); list_it != list_it_e; ++list_it) {
AliasList& list = **list_it;
- alias_iterator alias_it, alias_it_e=list.end();
- for (alias_it=list.begin(); alias_it!=alias_it_e; ++alias_it) {
- if ( 0==strcmp((*alias_it)->name(), pSym.name()) ) {
+ alias_iterator alias_it, alias_it_e = list.end();
+ for (alias_it = list.begin(); alias_it != alias_it_e; ++alias_it) {
+ if (strcmp((*alias_it)->name(), pSym.name()) == 0) {
return &list;
}
}
@@ -86,3 +80,4 @@ Module::AliasList* Module::getAliasList(const ResolveInfo& pSym)
return NULL;
}
+} // namespace mcld
diff --git a/lib/Core/TargetOptions.cpp b/lib/Core/TargetOptions.cpp
index 710899c..57a2eb9 100644
--- a/lib/Core/TargetOptions.cpp
+++ b/lib/Core/TargetOptions.cpp
@@ -6,50 +6,41 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/TargetOptions.h>
+#include "mcld/TargetOptions.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// TargetOptions
//===----------------------------------------------------------------------===//
-TargetOptions::TargetOptions()
- : m_Endian(Unknown),
- m_BitClass(0) {
+TargetOptions::TargetOptions() : m_Endian(Unknown), m_BitClass(0) {
}
TargetOptions::TargetOptions(const std::string& pTriple)
- : m_Triple(pTriple),
- m_Endian(Unknown),
- m_BitClass(0) {
+ : m_Triple(pTriple), m_Endian(Unknown), m_BitClass(0) {
}
-TargetOptions::~TargetOptions()
-{
+TargetOptions::~TargetOptions() {
}
-void TargetOptions::setTriple(const llvm::Triple& pTriple)
-{
+void TargetOptions::setTriple(const llvm::Triple& pTriple) {
m_Triple = pTriple;
}
-void TargetOptions::setTriple(const std::string& pTriple)
-{
+void TargetOptions::setTriple(const std::string& pTriple) {
m_Triple.setTriple(pTriple);
}
-void TargetOptions::setArch(const std::string& pArchName)
-{
+void TargetOptions::setArch(const std::string& pArchName) {
m_ArchName = pArchName;
}
-void TargetOptions::setTargetCPU(const std::string& pCPU)
-{
+void TargetOptions::setTargetCPU(const std::string& pCPU) {
m_TargetCPU = pCPU;
}
-void TargetOptions::setTargetFeatureString(const std::string& pFS)
-{
+void TargetOptions::setTargetFeatureString(const std::string& pFS) {
m_TargetFS = pFS;
}
+} // namespace mcld
diff --git a/lib/Fragment/AlignFragment.cpp b/lib/Fragment/AlignFragment.cpp
index 7cc1065..de2425f 100644
--- a/lib/Fragment/AlignFragment.cpp
+++ b/lib/Fragment/AlignFragment.cpp
@@ -6,12 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/AlignFragment.h>
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/LD/SectionData.h"
#include <llvm/Support/MathExtras.h>
-#include <mcld/LD/SectionData.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// AlignFragment
@@ -20,15 +20,18 @@ AlignFragment::AlignFragment(unsigned int pAlignment,
int64_t pValue,
unsigned int pValueSize,
unsigned int pMaxBytesToEmit,
- SectionData *pSD)
- : Fragment(Fragment::Alignment, pSD), m_Alignment(pAlignment),
- m_Value(pValue), m_ValueSize(pValueSize), m_MaxBytesToEmit(pMaxBytesToEmit),
- m_bEmitNops(false) {
+ SectionData* pSD)
+ : Fragment(Fragment::Alignment, pSD),
+ m_Alignment(pAlignment),
+ m_Value(pValue),
+ m_ValueSize(pValueSize),
+ m_MaxBytesToEmit(pMaxBytesToEmit),
+ m_bEmitNops(false) {
}
-size_t AlignFragment::size() const
-{
- assert(hasOffset() && "AlignFragment::size() should not be called before layout.");
+size_t AlignFragment::size() const {
+ assert(hasOffset() &&
+ "AlignFragment::size() should not be called before layout.");
uint64_t size = llvm::OffsetToAlignment(getOffset(), m_Alignment);
if (size > m_MaxBytesToEmit)
return 0;
@@ -36,3 +39,4 @@ size_t AlignFragment::size() const
return size;
}
+} // namespace mcld
diff --git a/lib/Fragment/FillFragment.cpp b/lib/Fragment/FillFragment.cpp
index 16de4f0..05175e8 100644
--- a/lib/Fragment/FillFragment.cpp
+++ b/lib/Fragment/FillFragment.cpp
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/LD/SectionData.h>
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/LD/SectionData.h"
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// FillFragment
@@ -19,9 +19,12 @@ FillFragment::FillFragment(int64_t pValue,
unsigned int pValueSize,
uint64_t pSize,
SectionData* pSD)
- : Fragment(Fragment::Fillment, pSD), m_Value(pValue), m_ValueSize(pValueSize),
- m_Size(pSize) {
+ : Fragment(Fragment::Fillment, pSD),
+ m_Value(pValue),
+ m_ValueSize(pValueSize),
+ m_Size(pSize) {
assert((!m_ValueSize || (m_Size % m_ValueSize) == 0) &&
- "Fill size must be a multiple of the value size!");
+ "Fill size must be a multiple of the value size!");
}
+} // namespace mcld
diff --git a/lib/Fragment/Fragment.cpp b/lib/Fragment/Fragment.cpp
index df66694..f46f264 100644
--- a/lib/Fragment/Fragment.cpp
+++ b/lib/Fragment/Fragment.cpp
@@ -7,39 +7,36 @@
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/Fragment.h>
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/LD/SectionData.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/LD/SectionData.h>
-
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Fragment
//===----------------------------------------------------------------------===//
Fragment::Fragment()
- : m_Kind(Type(~0)), m_pParent(NULL), m_Offset(~uint64_t(0)) {
+ : m_Kind(Type(~0)), m_pParent(NULL), m_Offset(~uint64_t(0)) {
}
-Fragment::Fragment(Type pKind, SectionData *pParent)
- : m_Kind(pKind), m_pParent(pParent), m_Offset(~uint64_t(0)) {
- if (NULL != m_pParent)
+Fragment::Fragment(Type pKind, SectionData* pParent)
+ : m_Kind(pKind), m_pParent(pParent), m_Offset(~uint64_t(0)) {
+ if (m_pParent != NULL)
m_pParent->getFragmentList().push_back(this);
}
-Fragment::~Fragment()
-{
+Fragment::~Fragment() {
}
-uint64_t Fragment::getOffset() const
-{
+uint64_t Fragment::getOffset() const {
assert(hasOffset() && "Cannot getOffset() before setting it up.");
return m_Offset;
}
-bool Fragment::hasOffset() const
-{
+bool Fragment::hasOffset() const {
return (m_Offset != ~uint64_t(0));
}
+} // namespace mcld
diff --git a/lib/Fragment/FragmentRef.cpp b/lib/Fragment/FragmentRef.cpp
index a22beca..efe3868 100644
--- a/lib/Fragment/FragmentRef.cpp
+++ b/lib/Fragment/FragmentRef.cpp
@@ -6,15 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/FragmentRef.h>
+#include "mcld/Fragment/FragmentRef.h"
-#include <mcld/Fragment/Fragment.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/Support/GCFactory.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Fragment/Stub.h>
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Support/GCFactory.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/Casting.h>
@@ -22,7 +22,7 @@
#include <cassert>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<FragmentRef, MCLD_SECTIONS_PER_INPUT> FragRefFactory;
@@ -33,13 +33,11 @@ FragmentRef FragmentRef::g_NullFragmentRef;
//===----------------------------------------------------------------------===//
// FragmentRef
//===----------------------------------------------------------------------===//
-FragmentRef::FragmentRef()
- : m_pFragment(NULL), m_Offset(0) {
+FragmentRef::FragmentRef() : m_pFragment(NULL), m_Offset(0) {
}
-FragmentRef::FragmentRef(Fragment& pFrag,
- FragmentRef::Offset pOffset)
- : m_pFragment(&pFrag), m_Offset(pOffset) {
+FragmentRef::FragmentRef(Fragment& pFrag, FragmentRef::Offset pOffset)
+ : m_pFragment(&pFrag), m_Offset(pOffset) {
}
/// Create - create a fragment reference for a given fragment.
@@ -49,12 +47,11 @@ FragmentRef::FragmentRef(Fragment& pFrag,
/// be larger than the section size.
/// @return if the offset is legal, return the fragment reference. Otherwise,
/// return NULL.
-FragmentRef* FragmentRef::Create(Fragment& pFrag, uint64_t pOffset)
-{
+FragmentRef* FragmentRef::Create(Fragment& pFrag, uint64_t pOffset) {
int64_t offset = pOffset;
Fragment* frag = &pFrag;
- while (NULL != frag) {
+ while (frag != NULL) {
offset -= frag->size();
if (offset <= 0)
break;
@@ -67,7 +64,7 @@ FragmentRef* FragmentRef::Create(Fragment& pFrag, uint64_t pOffset)
offset += frag->size();
}
- if (NULL == frag)
+ if (frag == NULL)
return Null();
FragmentRef* result = g_FragRefFactory->allocate();
@@ -76,8 +73,7 @@ FragmentRef* FragmentRef::Create(Fragment& pFrag, uint64_t pOffset)
return result;
}
-FragmentRef* FragmentRef::Create(LDSection& pSection, uint64_t pOffset)
-{
+FragmentRef* FragmentRef::Create(LDSection& pSection, uint64_t pOffset) {
SectionData* data = NULL;
switch (pSection.kind()) {
case LDFileFormat::Relocation:
@@ -92,57 +88,54 @@ FragmentRef* FragmentRef::Create(LDSection& pSection, uint64_t pOffset)
break;
}
- if (NULL == data || data->empty()) {
+ if (data == NULL || data->empty()) {
return Null();
}
return Create(data->front(), pOffset);
}
-void FragmentRef::Clear()
-{
+void FragmentRef::Clear() {
g_FragRefFactory->clear();
}
-FragmentRef* FragmentRef::Null()
-{
+FragmentRef* FragmentRef::Null() {
return &g_NullFragmentRef;
}
-FragmentRef& FragmentRef::assign(const FragmentRef& pCopy)
-{
+FragmentRef& FragmentRef::assign(const FragmentRef& pCopy) {
m_pFragment = const_cast<Fragment*>(pCopy.m_pFragment);
m_Offset = pCopy.m_Offset;
return *this;
}
-FragmentRef& FragmentRef::assign(Fragment& pFrag, FragmentRef::Offset pOffset)
-{
+FragmentRef& FragmentRef::assign(Fragment& pFrag, FragmentRef::Offset pOffset) {
m_pFragment = &pFrag;
m_Offset = pOffset;
return *this;
}
-void FragmentRef::memcpy(void* pDest, size_t pNBytes, Offset pOffset) const
-{
+void FragmentRef::memcpy(void* pDest, size_t pNBytes, Offset pOffset) const {
// check if the offset is still in a legal range.
- if (NULL == m_pFragment)
+ if (m_pFragment == NULL)
return;
+
unsigned int total_offset = m_Offset + pOffset;
- switch(m_pFragment->getKind()) {
+ switch (m_pFragment->getKind()) {
case Fragment::Region: {
RegionFragment* region_frag = static_cast<RegionFragment*>(m_pFragment);
unsigned int total_length = region_frag->getRegion().size();
- if (total_length < (total_offset+pNBytes))
+ if (total_length < (total_offset + pNBytes))
pNBytes = total_length - total_offset;
- std::memcpy(pDest, region_frag->getRegion().begin() + total_offset, pNBytes);
+ std::memcpy(
+ pDest, region_frag->getRegion().begin() + total_offset, pNBytes);
return;
}
case Fragment::Stub: {
Stub* stub_frag = static_cast<Stub*>(m_pFragment);
unsigned int total_length = stub_frag->size();
- if (total_length < (total_offset+pNBytes))
+ if (total_length < (total_offset + pNBytes))
pNBytes = total_length - total_offset;
std::memcpy(pDest, stub_frag->getContent() + total_offset, pNBytes);
return;
@@ -154,10 +147,11 @@ void FragmentRef::memcpy(void* pDest, size_t pNBytes, Offset pOffset) const
}
}
-FragmentRef::Offset FragmentRef::getOutputOffset() const
-{
+FragmentRef::Offset FragmentRef::getOutputOffset() const {
Offset result = 0;
- if (NULL != m_pFragment)
+ if (m_pFragment != NULL)
result = m_pFragment->getOffset();
return (result + m_Offset);
}
+
+} // namespace mcld
diff --git a/lib/Fragment/NullFragment.cpp b/lib/Fragment/NullFragment.cpp
index a1d1626..702b3a6 100644
--- a/lib/Fragment/NullFragment.cpp
+++ b/lib/Fragment/NullFragment.cpp
@@ -6,15 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/NullFragment.h>
+#include "mcld/Fragment/NullFragment.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// NullFragment
//===----------------------------------------------------------------------===//
-NullFragment::NullFragment(SectionData* pSD)
- : Fragment(Fragment::Null, pSD)
-{
+NullFragment::NullFragment(SectionData* pSD) : Fragment(Fragment::Null, pSD) {
}
+} // namespace mcld
diff --git a/lib/Fragment/RegionFragment.cpp b/lib/Fragment/RegionFragment.cpp
index c8971b8..37945a2 100644
--- a/lib/Fragment/RegionFragment.cpp
+++ b/lib/Fragment/RegionFragment.cpp
@@ -6,23 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/RegionFragment.h>
+#include "mcld/Fragment/RegionFragment.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// RegionFragment
//===----------------------------------------------------------------------===//
RegionFragment::RegionFragment(llvm::StringRef pRegion, SectionData* pSD)
- : Fragment(Fragment::Region, pSD), m_Region(pRegion) {
+ : Fragment(Fragment::Region, pSD), m_Region(pRegion) {
}
-RegionFragment::~RegionFragment()
-{
+RegionFragment::~RegionFragment() {
}
-size_t RegionFragment::size() const
-{
+size_t RegionFragment::size() const {
return m_Region.size();
}
+} // namespace mcld
diff --git a/lib/Fragment/Relocation.cpp b/lib/Fragment/Relocation.cpp
index 1537c0c..68c13a0 100644
--- a/lib/Fragment/Relocation.cpp
+++ b/lib/Fragment/Relocation.cpp
@@ -6,18 +6,19 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/LD/Relocator.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/LD/RelocationFactory.h>
+#include "mcld/Fragment/Relocation.h"
+
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/RelocationFactory.h"
+#include "mcld/LD/Relocator.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Support/MsgHandling.h"
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
static llvm::ManagedStatic<RelocationFactory> g_RelocationFactory;
@@ -25,20 +26,17 @@ static llvm::ManagedStatic<RelocationFactory> g_RelocationFactory;
// Relocation Factory Methods
//===----------------------------------------------------------------------===//
/// Initialize - set up the relocation factory
-void Relocation::SetUp(const LinkerConfig& pConfig)
-{
+void Relocation::SetUp(const LinkerConfig& pConfig) {
g_RelocationFactory->setConfig(pConfig);
}
/// Clear - Clean up the relocation factory
-void Relocation::Clear()
-{
+void Relocation::Clear() {
g_RelocationFactory->clear();
}
/// Create - produce an empty relocation entry
-Relocation* Relocation::Create()
-{
+Relocation* Relocation::Create() {
return g_RelocationFactory->produceEmptyEntry();
}
@@ -46,14 +44,14 @@ Relocation* Relocation::Create()
/// @param pType [in] the type of the relocation entry
/// @param pFragRef [in] the place to apply the relocation
/// @param pAddend [in] the addend of the relocation entry
-Relocation* Relocation::Create(Type pType, FragmentRef& pFragRef, Address pAddend)
-{
+Relocation* Relocation::Create(Type pType,
+ FragmentRef& pFragRef,
+ Address pAddend) {
return g_RelocationFactory->produce(pType, pFragRef, pAddend);
}
/// Destroy - destroy a relocation entry
-void Relocation::Destroy(Relocation*& pRelocation)
-{
+void Relocation::Destroy(Relocation*& pRelocation) {
g_RelocationFactory->destroy(pRelocation);
pRelocation = NULL;
}
@@ -62,34 +60,30 @@ void Relocation::Destroy(Relocation*& pRelocation)
// Relocation
//===----------------------------------------------------------------------===//
Relocation::Relocation()
- : m_Type(0x0), m_TargetData(0x0), m_pSymInfo(NULL), m_Addend(0x0) {
+ : m_Type(0x0), m_TargetData(0x0), m_pSymInfo(NULL), m_Addend(0x0) {
}
Relocation::Relocation(Relocation::Type pType,
FragmentRef* pTargetRef,
Relocation::Address pAddend,
Relocation::DWord pTargetData)
- : m_Type(pType),
- m_TargetData(pTargetData),
- m_pSymInfo(NULL),
- m_Addend(pAddend)
-{
- if(NULL != pTargetRef)
- m_TargetAddress.assign(*pTargetRef->frag(), pTargetRef->offset()) ;
+ : m_Type(pType),
+ m_TargetData(pTargetData),
+ m_pSymInfo(NULL),
+ m_Addend(pAddend) {
+ if (pTargetRef != NULL)
+ m_TargetAddress.assign(*pTargetRef->frag(), pTargetRef->offset());
}
-Relocation::~Relocation()
-{
+Relocation::~Relocation() {
}
-Relocation::Address Relocation::place() const
-{
+Relocation::Address Relocation::place() const {
Address sect_addr = m_TargetAddress.frag()->getParent()->getSection().addr();
return sect_addr + m_TargetAddress.getOutputOffset();
}
-Relocation::Address Relocation::symValue() const
-{
+Relocation::Address Relocation::symValue() const {
if (m_pSymInfo->type() == ResolveInfo::Section &&
m_pSymInfo->outSymbol()->hasFragRef()) {
const FragmentRef* fragRef = m_pSymInfo->outSymbol()->fragRef();
@@ -99,8 +93,7 @@ Relocation::Address Relocation::symValue() const
return m_pSymInfo->outSymbol()->value();
}
-void Relocation::apply(Relocator& pRelocator)
-{
+void Relocation::apply(Relocator& pRelocator) {
Relocator::Result result = pRelocator.applyRelocation(*this);
switch (result) {
@@ -118,7 +111,7 @@ void Relocation::apply(Relocator& pRelocator)
<< symInfo()->name();
return;
}
- case Relocator::Unsupport: {
+ case Relocator::Unsupported: {
fatal(diag::unsupported_relocation) << type()
<< "mclinker@googlegroups.com";
return;
@@ -127,34 +120,31 @@ void Relocation::apply(Relocator& pRelocator)
fatal(diag::unknown_relocation) << type() << symInfo()->name();
return;
}
- } // end of switch
+ } // end of switch
}
-void Relocation::setType(Type pType)
-{
+void Relocation::setType(Type pType) {
m_Type = pType;
}
-void Relocation::setAddend(Address pAddend)
-{
+void Relocation::setAddend(Address pAddend) {
m_Addend = pAddend;
}
-void Relocation::setSymInfo(ResolveInfo* pSym)
-{
+void Relocation::setSymInfo(ResolveInfo* pSym) {
m_pSymInfo = pSym;
}
-Relocation::Size Relocation::size(Relocator& pRelocator) const
-{
+Relocation::Size Relocation::size(Relocator& pRelocator) const {
return pRelocator.getSize(m_Type);
}
-void Relocation::updateAddend()
-{
+void Relocation::updateAddend() {
// Update value keep in addend if we meet a section symbol
if (m_pSymInfo->type() == ResolveInfo::Section) {
uint32_t offset = m_pSymInfo->outSymbol()->fragRef()->getOutputOffset();
m_Addend += offset;
}
}
+
+} // namespace mcld
diff --git a/lib/Fragment/Stub.cpp b/lib/Fragment/Stub.cpp
index b7122bd..b658ece 100644
--- a/lib/Fragment/Stub.cpp
+++ b/lib/Fragment/Stub.cpp
@@ -6,37 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "mcld/Fragment/Stub.h"
-#include <mcld/Fragment/Stub.h>
+namespace mcld {
-using namespace mcld;
-
-Stub::Stub()
- : Fragment(Fragment::Stub),
- m_pSymInfo(NULL)
-{
+Stub::Stub() : Fragment(Fragment::Stub), m_pSymInfo(NULL) {
}
-Stub::~Stub()
-{
- for (fixup_iterator fixup= fixup_begin(); fixup != fixup_end(); ++fixup)
- delete(*fixup);
+Stub::~Stub() {
+ for (fixup_iterator fixup = fixup_begin(); fixup != fixup_end(); ++fixup)
+ delete (*fixup);
}
-void Stub::setSymInfo(ResolveInfo* pSymInfo)
-{
+void Stub::setSymInfo(ResolveInfo* pSymInfo) {
m_pSymInfo = pSymInfo;
}
-void Stub::addFixup(DWord pOffset, SWord pAddend, Type pType)
-{
+void Stub::addFixup(DWord pOffset, SWord pAddend, Type pType) {
assert(pOffset < size());
m_FixupList.push_back(new Fixup(pOffset, pAddend, pType));
}
-void Stub::addFixup(const Fixup& pFixup)
-{
+void Stub::addFixup(const Fixup& pFixup) {
assert(pFixup.offset() < size());
m_FixupList.push_back(new Fixup(pFixup));
}
+} // namespace mcld
diff --git a/lib/LD/Archive.cpp b/lib/LD/Archive.cpp
index c555e67..9217519 100644
--- a/lib/LD/Archive.cpp
+++ b/lib/LD/Archive.cpp
@@ -6,87 +6,78 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/Archive.h>
-#include <mcld/MC/InputBuilder.h>
-#include <mcld/MC/Input.h>
+#include "mcld/LD/Archive.h"
+#include "mcld/MC/Input.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <llvm/ADT/StringRef.h>
-#include <mcld/Support/MsgHandling.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Archive
-const char Archive::MAGIC[] = "!<arch>\n";
-const char Archive::THIN_MAGIC[] = "!<thin>\n";
-const size_t Archive::MAGIC_LEN = sizeof(Archive::MAGIC) - 1;
-const char Archive::SVR4_SYMTAB_NAME[] = "/ ";
-const char Archive::IRIX6_SYMTAB_NAME[]= "/SYM64/ ";
-const char Archive::STRTAB_NAME[] = "// ";
-const char Archive::PAD[] = "\n";
-const char Archive::MEMBER_MAGIC[] = "`\n";
+const char Archive::MAGIC[] = "!<arch>\n";
+const char Archive::THIN_MAGIC[] = "!<thin>\n";
+const size_t Archive::MAGIC_LEN = sizeof(Archive::MAGIC) - 1;
+const char Archive::SVR4_SYMTAB_NAME[] = "/ ";
+const char Archive::IRIX6_SYMTAB_NAME[] = "/SYM64/ ";
+const char Archive::STRTAB_NAME[] = "// ";
+const char Archive::PAD[] = "\n";
+const char Archive::MEMBER_MAGIC[] = "`\n";
Archive::Archive(Input& pInputFile, InputBuilder& pBuilder)
- : m_ArchiveFile(pInputFile),
- m_pInputTree(NULL),
- m_SymbolFactory(32),
- m_Builder(pBuilder)
-{
+ : m_ArchiveFile(pInputFile),
+ m_pInputTree(NULL),
+ m_SymbolFactory(32),
+ m_Builder(pBuilder) {
// FIXME: move creation of input tree out of Archive.
m_pInputTree = new InputTree();
}
-Archive::~Archive()
-{
+Archive::~Archive() {
delete m_pInputTree;
}
/// getARFile - get the Input& of the archive file
-Input& Archive::getARFile()
-{
+Input& Archive::getARFile() {
return m_ArchiveFile;
}
/// getARFile - get the Input& of the archive file
-const Input& Archive::getARFile() const
-{
+const Input& Archive::getARFile() const {
return m_ArchiveFile;
}
/// inputs - get the input tree built from this archive
-InputTree& Archive::inputs()
-{
+InputTree& Archive::inputs() {
return *m_pInputTree;
}
/// inputs - get the input tree built from this archive
-const InputTree& Archive::inputs() const
-{
+const InputTree& Archive::inputs() const {
return *m_pInputTree;
}
/// getObjectMemberMap - get the map that contains the included object files
-Archive::ObjectMemberMapType& Archive::getObjectMemberMap()
-{
+Archive::ObjectMemberMapType& Archive::getObjectMemberMap() {
return m_ObjectMemberMap;
}
/// getObjectMemberMap - get the map that contains the included object files
-const Archive::ObjectMemberMapType& Archive::getObjectMemberMap() const
-{
+const Archive::ObjectMemberMapType& Archive::getObjectMemberMap() const {
return m_ObjectMemberMap;
}
/// numOfObjectMember - return the number of included object files
-size_t Archive::numOfObjectMember() const
-{
+size_t Archive::numOfObjectMember() const {
return m_ObjectMemberMap.numOfEntries();
}
/// addObjectMember - add a object in the object member map
/// @param pFileOffset - file offset in symtab represents a object file
/// @param pIter - the iterator in the input tree built from this archive
-bool Archive::addObjectMember(uint32_t pFileOffset, InputTree::iterator pIter)
-{
+bool Archive::addObjectMember(uint32_t pFileOffset, InputTree::iterator pIter) {
bool exist;
ObjectMemberEntryType* entry = m_ObjectMemberMap.insert(pFileOffset, exist);
if (!exist)
@@ -96,20 +87,17 @@ bool Archive::addObjectMember(uint32_t pFileOffset, InputTree::iterator pIter)
/// hasObjectMember - check if a object file is included or not
/// @param pFileOffset - file offset in symtab represents a object file
-bool Archive::hasObjectMember(uint32_t pFileOffset) const
-{
+bool Archive::hasObjectMember(uint32_t pFileOffset) const {
return (m_ObjectMemberMap.find(pFileOffset) != m_ObjectMemberMap.end());
}
/// getArchiveMemberMap - get the map that contains the included archive files
-Archive::ArchiveMemberMapType& Archive::getArchiveMemberMap()
-{
+Archive::ArchiveMemberMapType& Archive::getArchiveMemberMap() {
return m_ArchiveMemberMap;
}
/// getArchiveMemberMap - get the map that contains the included archive files
-const Archive::ArchiveMemberMapType& Archive::getArchiveMemberMap() const
-{
+const Archive::ArchiveMemberMapType& Archive::getArchiveMemberMap() const {
return m_ArchiveMemberMap;
}
@@ -121,8 +109,7 @@ const Archive::ArchiveMemberMapType& Archive::getArchiveMemberMap() const
/// subtree of this archive member
bool Archive::addArchiveMember(const llvm::StringRef& pName,
InputTree::iterator pLastPos,
- InputTree::Mover* pMove)
-{
+ InputTree::Mover* pMove) {
bool exist;
ArchiveMemberEntryType* entry = m_ArchiveMemberMap.insert(pName, exist);
if (!exist) {
@@ -138,14 +125,13 @@ bool Archive::addArchiveMember(const llvm::StringRef& pName,
}
/// hasArchiveMember - check if an archive file is included or not
-bool Archive::hasArchiveMember(const llvm::StringRef& pName) const
-{
+bool Archive::hasArchiveMember(const llvm::StringRef& pName) const {
return (m_ArchiveMemberMap.find(pName) != m_ArchiveMemberMap.end());
}
/// getArchiveMember - get a archive member
-Archive::ArchiveMember* Archive::getArchiveMember(const llvm::StringRef& pName)
-{
+Archive::ArchiveMember* Archive::getArchiveMember(
+ const llvm::StringRef& pName) {
ArchiveMemberMapType::iterator it = m_ArchiveMemberMap.find(pName);
if (it != m_ArchiveMemberMap.end())
return &(it.getEntry()->value());
@@ -153,32 +139,27 @@ Archive::ArchiveMember* Archive::getArchiveMember(const llvm::StringRef& pName)
}
/// getSymbolTable - get the symtab
-Archive::SymTabType& Archive::getSymbolTable()
-{
+Archive::SymTabType& Archive::getSymbolTable() {
return m_SymTab;
}
/// getSymbolTable - get the symtab
-const Archive::SymTabType& Archive::getSymbolTable() const
-{
+const Archive::SymTabType& Archive::getSymbolTable() const {
return m_SymTab;
}
/// setSymTabSize - set the memory size of symtab
-void Archive::setSymTabSize(size_t pSize)
-{
+void Archive::setSymTabSize(size_t pSize) {
m_SymTabSize = pSize;
}
/// getSymTabSize - get the memory size of symtab
-size_t Archive::getSymTabSize() const
-{
+size_t Archive::getSymTabSize() const {
return m_SymTabSize;
}
/// numOfSymbols - return the number of symbols in symtab
-size_t Archive::numOfSymbols() const
-{
+size_t Archive::numOfSymbols() const {
return m_SymTab.size();
}
@@ -187,57 +168,49 @@ size_t Archive::numOfSymbols() const
/// @param pFileOffset - file offset in symtab represents a object file
void Archive::addSymbol(const char* pName,
uint32_t pFileOffset,
- enum Archive::Symbol::Status pStatus)
-{
+ enum Archive::Symbol::Status pStatus) {
Symbol* entry = m_SymbolFactory.allocate();
new (entry) Symbol(pName, pFileOffset, pStatus);
m_SymTab.push_back(entry);
}
/// getSymbolName - get the symbol name with the given index
-const std::string& Archive::getSymbolName(size_t pSymIdx) const
-{
+const std::string& Archive::getSymbolName(size_t pSymIdx) const {
assert(pSymIdx < numOfSymbols());
return m_SymTab[pSymIdx]->name;
}
/// getObjFileOffset - get the file offset that represent a object file
-uint32_t Archive::getObjFileOffset(size_t pSymIdx) const
-{
+uint32_t Archive::getObjFileOffset(size_t pSymIdx) const {
assert(pSymIdx < numOfSymbols());
return m_SymTab[pSymIdx]->fileOffset;
}
/// getSymbolStatus - get the status of a symbol
-enum Archive::Symbol::Status Archive::getSymbolStatus(size_t pSymIdx) const
-{
+enum Archive::Symbol::Status Archive::getSymbolStatus(size_t pSymIdx) const {
assert(pSymIdx < numOfSymbols());
return m_SymTab[pSymIdx]->status;
}
/// setSymbolStatus - set the status of a symbol
void Archive::setSymbolStatus(size_t pSymIdx,
- enum Archive::Symbol::Status pStatus)
-{
+ enum Archive::Symbol::Status pStatus) {
assert(pSymIdx < numOfSymbols());
m_SymTab[pSymIdx]->status = pStatus;
}
/// getStrTable - get the extended name table
-std::string& Archive::getStrTable()
-{
+std::string& Archive::getStrTable() {
return m_StrTab;
}
/// getStrTable - get the extended name table
-const std::string& Archive::getStrTable() const
-{
+const std::string& Archive::getStrTable() const {
return m_StrTab;
}
/// hasStrTable()
-bool Archive::hasStrTable() const
-{
+bool Archive::hasStrTable() const {
return (m_StrTab.size() > 0);
}
@@ -252,19 +225,19 @@ Input* Archive::getMemberFile(Input& pArchiveFile,
bool isThinAR,
const std::string& pName,
const sys::fs::Path& pPath,
- off_t pFileOffset)
-{
+ off_t pFileOffset) {
Input* member = NULL;
if (!isThinAR) {
member = m_Builder.createInput(pName, pPath, Input::Unknown, pFileOffset);
assert(member != NULL);
member->setMemArea(pArchiveFile.memArea());
m_Builder.setContext(*member);
- }
- else {
+ } else {
member = m_Builder.createInput(pName, pPath, Input::Unknown);
assert(member != NULL);
- if (!m_Builder.setMemory(*member, FileHandle::ReadOnly)) {
+ if (!m_Builder.setMemory(*member,
+ FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System))) {
error(diag::err_cannot_open_input) << member->name() << member->path();
return NULL;
}
@@ -273,3 +246,4 @@ Input* Archive::getMemberFile(Input& pArchiveFile,
return member;
}
+} // namespace mcld
diff --git a/lib/LD/ArchiveReader.cpp b/lib/LD/ArchiveReader.cpp
index 88957bc..29568c0 100644
--- a/lib/LD/ArchiveReader.cpp
+++ b/lib/LD/ArchiveReader.cpp
@@ -8,14 +8,14 @@
//===----------------------------------------------------------------------===//
#include "mcld/LD/ArchiveReader.h"
-using namespace mcld;
+namespace mcld {
//==========================
// MCELFArchiveReader
-ArchiveReader::ArchiveReader()
-{
+ArchiveReader::ArchiveReader() {
}
-ArchiveReader::~ArchiveReader()
-{
+ArchiveReader::~ArchiveReader() {
}
+
+} // namespace mcld
diff --git a/lib/LD/BSDArchiveReader.cpp b/lib/LD/BSDArchiveReader.cpp
index 57d3a52..00e1ed4 100644
--- a/lib/LD/BSDArchiveReader.cpp
+++ b/lib/LD/BSDArchiveReader.cpp
@@ -6,31 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/Input.h>
-#include <mcld/LD/BSDArchiveReader.h>
-#include <mcld/LD/Archive.h>
+#include "mcld/LD/BSDArchiveReader.h"
+#include "mcld/LD/Archive.h"
+#include "mcld/MC/Input.h"
-using namespace mcld;
+namespace mcld {
-BSDArchiveReader::BSDArchiveReader()
-{
+BSDArchiveReader::BSDArchiveReader() {
}
-BSDArchiveReader::~BSDArchiveReader()
-{
+BSDArchiveReader::~BSDArchiveReader() {
}
bool BSDArchiveReader::readArchive(const LinkerConfig& pConfig,
- Archive& pArchive)
-{
+ Archive& pArchive) {
// TODO
return true;
}
-bool BSDArchiveReader::isMyFormat(Input& pInput, bool &pContinue) const
-{
+bool BSDArchiveReader::isMyFormat(Input& pInput, bool& pContinue) const {
pContinue = true;
// TODO
return false;
}
+} // namespace mcld
diff --git a/lib/LD/BinaryReader.cpp b/lib/LD/BinaryReader.cpp
index f5c439f..914c3ca 100644
--- a/lib/LD/BinaryReader.cpp
+++ b/lib/LD/BinaryReader.cpp
@@ -6,14 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/BinaryReader.h>
+#include "mcld/LD/BinaryReader.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// BinaryReader
//===----------------------------------------------------------------------===//
-BinaryReader::~BinaryReader()
-{
+BinaryReader::~BinaryReader() {
}
+} // namespace mcld
diff --git a/lib/LD/BranchIsland.cpp b/lib/LD/BranchIsland.cpp
index c6f5b02..0405263 100644
--- a/lib/LD/BranchIsland.cpp
+++ b/lib/LD/BranchIsland.cpp
@@ -6,101 +6,88 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/BranchIsland.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Fragment/Stub.h>
-#include <mcld/Fragment/AlignFragment.h>
+#include "mcld/LD/BranchIsland.h"
+
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/ResolveInfo.h"
#include <sstream>
-using namespace mcld;
+namespace mcld {
//==========================
// BranchIsland
-BranchIsland::BranchIsland(Fragment& pEntryFrag,
- size_t pMaxSize,
- size_t pIndex)
- : m_Entry(pEntryFrag),
- m_pExit(pEntryFrag.getNextNode()),
- m_pRear(NULL),
- m_MaxSize(pMaxSize),
- m_Name("island-")
-{
+BranchIsland::BranchIsland(Fragment& pEntryFrag, size_t pMaxSize, size_t pIndex)
+ : m_Entry(pEntryFrag),
+ m_pExit(pEntryFrag.getNextNode()),
+ m_pRear(NULL),
+ m_MaxSize(pMaxSize),
+ m_Name("island-") {
// island name
std::ostringstream index;
index << pIndex;
m_Name.append(index.str());
}
-BranchIsland::~BranchIsland()
-{
+BranchIsland::~BranchIsland() {
}
/// fragment iterators of the island
-SectionData::iterator BranchIsland::begin()
-{
+SectionData::iterator BranchIsland::begin() {
return ++iterator(&m_Entry);
}
-SectionData::const_iterator BranchIsland::begin() const
-{
+SectionData::const_iterator BranchIsland::begin() const {
return ++iterator(&m_Entry);
}
-SectionData::iterator BranchIsland::end()
-{
- if (NULL != m_pExit)
+SectionData::iterator BranchIsland::end() {
+ if (m_pExit != NULL)
return iterator(m_pExit);
return m_Entry.getParent()->end();
}
-SectionData::const_iterator BranchIsland::end() const
-{
- if (NULL != m_pExit)
+SectionData::const_iterator BranchIsland::end() const {
+ if (m_pExit != NULL)
return iterator(m_pExit);
return m_Entry.getParent()->end();
}
-uint64_t BranchIsland::offset() const
-{
+uint64_t BranchIsland::offset() const {
return m_Entry.getOffset() + m_Entry.size();
}
-size_t BranchIsland::size() const
-{
+size_t BranchIsland::size() const {
size_t size = 0x0;
- if (0x0 != numOfStubs()) {
+ if (numOfStubs() != 0x0) {
size = m_pRear->getOffset() + m_pRear->size() -
m_Entry.getNextNode()->getOffset();
}
return size;
}
-size_t BranchIsland::maxSize() const
-{
+size_t BranchIsland::maxSize() const {
return m_MaxSize;
}
-const std::string& BranchIsland::name() const
-{
+const std::string& BranchIsland::name() const {
return m_Name;
}
-size_t BranchIsland::numOfStubs() const
-{
+size_t BranchIsland::numOfStubs() const {
return m_StubMap.numOfEntries();
}
/// findStub - return true if there is a stub built from the given prototype
/// for the given relocation
-Stub* BranchIsland::findStub(const Stub* pPrototype, const Relocation& pReloc)
-{
+Stub* BranchIsland::findStub(const Stub* pPrototype, const Relocation& pReloc) {
Key key(pPrototype, pReloc.symInfo()->outSymbol(), pReloc.addend());
StubMapType::iterator it = m_StubMap.find(key);
if (it != m_StubMap.end()) {
- assert(NULL != it.getEntry()->value());
+ assert(it.getEntry()->value() != NULL);
return it.getEntry()->value();
}
return NULL;
@@ -109,8 +96,7 @@ Stub* BranchIsland::findStub(const Stub* pPrototype, const Relocation& pReloc)
/// addStub - add a stub into the island
bool BranchIsland::addStub(const Stub* pPrototype,
const Relocation& pReloc,
- Stub& pStub)
-{
+ Stub& pStub) {
bool exist = false;
Key key(pPrototype, pReloc.symInfo()->outSymbol(), pReloc.addend());
StubEntryType* entry = m_StubMap.insert(key, exist);
@@ -121,10 +107,8 @@ bool BranchIsland::addStub(const Stub* pPrototype,
// insert alignment fragment
// TODO: check if we can reduce this alignment fragment for some cases
- AlignFragment* align_frag = new AlignFragment(pStub.alignment(),
- 0x0,
- 1u,
- pStub.alignment() - 1);
+ AlignFragment* align_frag =
+ new AlignFragment(pStub.alignment(), 0x0, 1u, pStub.alignment() - 1);
align_frag->setParent(sd);
sd->getFragmentList().insert(end(), align_frag);
align_frag->setOffset(align_frag->getPrevNode()->getOffset() +
@@ -140,9 +124,9 @@ bool BranchIsland::addStub(const Stub* pPrototype,
}
/// addRelocation - add a relocation into island
-bool BranchIsland::addRelocation(Relocation& pReloc)
-{
+bool BranchIsland::addRelocation(Relocation& pReloc) {
m_Relocations.push_back(&pReloc);
return true;
}
+} // namespace mcld
diff --git a/lib/LD/BranchIslandFactory.cpp b/lib/LD/BranchIslandFactory.cpp
index 0147e5f..cace800 100644
--- a/lib/LD/BranchIslandFactory.cpp
+++ b/lib/LD/BranchIslandFactory.cpp
@@ -6,13 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/Fragment/Fragment.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Module.h>
+#include "mcld/LD/BranchIslandFactory.h"
-using namespace mcld;
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Module.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// BranchIslandFactory
@@ -25,21 +26,18 @@ using namespace mcld;
BranchIslandFactory::BranchIslandFactory(int64_t pMaxFwdBranchRange,
int64_t pMaxBwdBranchRange,
size_t pMaxIslandSize)
- : GCFactory<BranchIsland, 0>(1u), // magic number
+ : GCFactory<BranchIsland, 0>(1u), // magic number
m_MaxFwdBranchRange(pMaxFwdBranchRange - pMaxIslandSize),
m_MaxBwdBranchRange(pMaxBwdBranchRange + pMaxIslandSize),
- m_MaxIslandSize(pMaxIslandSize)
-{
+ m_MaxIslandSize(pMaxIslandSize) {
}
-BranchIslandFactory::~BranchIslandFactory()
-{
+BranchIslandFactory::~BranchIslandFactory() {
}
/// group - group fragments and create islands when needed
/// @param pSectionData - the SectionData holds fragments need to be grouped
-void BranchIslandFactory::group(Module& pModule)
-{
+void BranchIslandFactory::group(Module& pModule) {
/* FIXME: Currently only support relaxing .text section! */
LDSection* text = pModule.getSection(".text");
if (text != NULL && text->hasSectionData()) {
@@ -64,33 +62,30 @@ void BranchIslandFactory::group(Module& pModule)
/// produce - produce a island for the given fragment
/// @param pFragment - the fragment needs a branch island
-BranchIsland* BranchIslandFactory::produce(Fragment& pFragment)
-{
- BranchIsland *island = allocate();
- new (island) BranchIsland(pFragment, // entry fragment to the island
- m_MaxIslandSize, // the max size of the island
- size() - 1u); // index in the island factory
+BranchIsland* BranchIslandFactory::produce(Fragment& pFragment) {
+ BranchIsland* island = allocate();
+ new (island) BranchIsland(pFragment, // entry fragment to the island
+ m_MaxIslandSize, // the max size of the island
+ size() - 1u); // index in the island factory
return island;
}
/// getIsland - find fwd and bwd islands for the fragment
/// @param pFragment - the fragment needs a branch island
-std::pair<BranchIsland*, BranchIsland*>
-BranchIslandFactory::getIslands(const Fragment& pFragment)
-{
+std::pair<BranchIsland*, BranchIsland*> BranchIslandFactory::getIslands(
+ const Fragment& pFragment) {
BranchIsland* fwd = NULL;
BranchIsland* bwd = NULL;
for (iterator it = begin(), ie = end(), prev = ie; it != ie;
prev = it, ++it) {
if ((pFragment.getOffset() < (*it).offset()) &&
((pFragment.getOffset() + m_MaxFwdBranchRange) >= (*it).offset())) {
-
fwd = &*it;
if (prev != ie) {
int64_t bwd_off = (int64_t)pFragment.getOffset() + m_MaxBwdBranchRange;
if ((pFragment.getOffset() > (*prev).offset()) &&
- (bwd_off <= (int64_t) (*prev).offset())) {
+ (bwd_off <= (int64_t)(*prev).offset())) {
bwd = &*prev;
}
}
@@ -99,3 +94,5 @@ BranchIslandFactory::getIslands(const Fragment& pFragment)
}
return std::make_pair(fwd, bwd);
}
+
+} // namespace mcld
diff --git a/lib/LD/DWARFLineInfo.cpp b/lib/LD/DWARFLineInfo.cpp
index 63c588d..1df686e 100644
--- a/lib/LD/DWARFLineInfo.cpp
+++ b/lib/LD/DWARFLineInfo.cpp
@@ -6,10 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/DWARFLineInfo.h>
+#include "mcld/LD/DWARFLineInfo.h"
-using namespace mcld;
+namespace mcld {
//==========================
// DWARFLineInfo
+} // namespace mcld
diff --git a/lib/LD/DebugString.cpp b/lib/LD/DebugString.cpp
new file mode 100644
index 0000000..3a8f9af
--- /dev/null
+++ b/lib/LD/DebugString.cpp
@@ -0,0 +1,95 @@
+//===- DebugString.cpp ----------------------------------------------------===//
+//
+// The MCLinker Project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "mcld/LD/DebugString.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/Target/TargetLDBackend.h"
+#include "mcld/LD/Relocator.h"
+
+#include <llvm/Support/Casting.h>
+#include <llvm/Support/ManagedStatic.h>
+
+namespace mcld {
+
+// DebugString represents the output .debug_str section, which is at most on
+// in each linking
+static llvm::ManagedStatic<DebugString> g_DebugString;
+
+static inline size_t string_length(const char* pStr) {
+ const char* p = pStr;
+ size_t len = 0;
+ for (; *p != 0; ++p)
+ ++len;
+ return len;
+}
+
+//==========================
+// DebugString
+void DebugString::merge(LDSection& pSection) {
+ // get the fragment contents
+ llvm::StringRef strings;
+ SectionData::iterator it, end = pSection.getSectionData()->end();
+ for (it = pSection.getSectionData()->begin(); it != end; ++it) {
+ if ((*it).getKind() == Fragment::Region) {
+ RegionFragment* frag = llvm::cast<RegionFragment>(&(*it));
+ strings = frag->getRegion().data();
+ }
+ }
+
+ // get the debug strings and add them into merged string table
+ const char* str = strings.data();
+ const char* str_end = str + pSection.size();
+ while (str < str_end) {
+ size_t len = string_length(str);
+ m_StringTable.insertString(llvm::StringRef(str, len));
+ str = str + len + 1;
+ }
+}
+
+size_t DebugString::computeOffsetSize() {
+ size_t size = m_StringTable.finalizeOffset();
+ m_pSection->setSize(size);
+ return size;
+}
+
+void DebugString::applyOffset(Relocation& pReloc, TargetLDBackend& pBackend) {
+ // get the refered string
+ ResolveInfo* info = pReloc.symInfo();
+ // the symbol should point to the first region fragment in the debug
+ // string section, get the input .debut_str region
+ llvm::StringRef d_str;
+ if (info->outSymbol()->fragRef()->frag()->getKind() == Fragment::Region) {
+ RegionFragment* frag =
+ llvm::cast<RegionFragment>(info->outSymbol()->fragRef()->frag());
+ d_str = frag->getRegion();
+ }
+ uint32_t offset = pBackend.getRelocator()->getDebugStringOffset(pReloc);
+ const char* str = d_str.data() + offset;
+
+ // apply the relocation
+ pBackend.getRelocator()->applyDebugStringOffset(pReloc,
+ m_StringTable.getOutputOffset(llvm::StringRef(str, string_length(str))));
+}
+
+void DebugString::emit(MemoryRegion& pRegion) {
+ return m_StringTable.emit(pRegion);
+}
+
+DebugString* DebugString::Create(LDSection& pSection) {
+ g_DebugString->setOutputSection(pSection);
+ return &(*g_DebugString);
+}
+
+} // namespace mcld
diff --git a/lib/LD/Diagnostic.cpp b/lib/LD/Diagnostic.cpp
index 5d57f29..a55a9c1 100644
--- a/lib/LD/Diagnostic.cpp
+++ b/lib/LD/Diagnostic.cpp
@@ -6,29 +6,29 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/Diagnostic.h>
+#include "mcld/LD/Diagnostic.h"
+
#include <llvm/Support/ErrorHandling.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/ADT/Twine.h>
-#include <ctype.h>
+
#include <algorithm>
-using namespace mcld;
+#include <ctype.h>
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// Diagnostic
-Diagnostic::Diagnostic(DiagnosticEngine& pEngine)
- : m_Engine(pEngine) {
+Diagnostic::Diagnostic(DiagnosticEngine& pEngine) : m_Engine(pEngine) {
}
-Diagnostic::~Diagnostic()
-{
+Diagnostic::~Diagnostic() {
}
// format - format this diagnostic into string, subsituting the formal
// arguments. The result is appended at on the pOutStr.
-void Diagnostic::format(std::string& pOutStr) const
-{
+void Diagnostic::format(std::string& pOutStr) const {
// we've not implemented DWARF LOC messages yet. So, keep pIsLoC false
llvm::StringRef desc = m_Engine.infoMap().getDescription(getID(), false);
@@ -36,16 +36,16 @@ void Diagnostic::format(std::string& pOutStr) const
}
const char* Diagnostic::findMatch(char pVal,
- const char* pBegin, const char* pEnd ) const
-{
+ const char* pBegin,
+ const char* pEnd) const {
unsigned int depth = 0;
for (; pBegin != pEnd; ++pBegin) {
- if (0 == depth && *pBegin == pVal)
+ if (depth == 0 && *pBegin == pVal)
return pBegin;
- if (0 != depth && *pBegin == '}')
+ if (depth != 0 && *pBegin == '}')
--depth;
- if ('%' == *pBegin) {
+ if (*pBegin == '%') {
++pBegin;
if (pBegin == pEnd)
break;
@@ -57,28 +57,27 @@ const char* Diagnostic::findMatch(char pVal,
if (pBegin == pEnd)
break;
- if ('{' == *pBegin)
+ if (*pBegin == '{')
++depth;
}
}
- } // end of for
+ } // end of for
return pEnd;
}
// format - format the given formal string, subsituting the formal
// arguments. The result is appended at on the pOutStr.
-void Diagnostic::format(const char* pBegin, const char* pEnd,
- std::string& pOutStr) const
-{
+void Diagnostic::format(const char* pBegin,
+ const char* pEnd,
+ std::string& pOutStr) const {
const char* cur_char = pBegin;
while (cur_char != pEnd) {
- if ('%' != *cur_char) {
+ if (*cur_char != '%') {
const char* new_end = std::find(cur_char, pEnd, '%');
pOutStr.append(cur_char, new_end);
cur_char = new_end;
continue;
- }
- else if (ispunct(cur_char[1])) {
+ } else if (ispunct(cur_char[1])) {
pOutStr.push_back(cur_char[1]); // %% -> %.
cur_char += 2;
continue;
@@ -98,17 +97,18 @@ void Diagnostic::format(const char* pBegin, const char* pEnd,
modifier_len = cur_char - modifier;
// we get an argument
- if ('{' == *cur_char) {
- ++cur_char; // skip '{'
+ if (*cur_char == '{') {
+ ++cur_char; // skip '{'
cur_char = findMatch('}', cur_char, pEnd);
if (cur_char == pEnd) {
// DIAG's format error
- llvm::report_fatal_error(llvm::Twine("Mismatched {} in the diagnostic: ") +
- llvm::Twine(getID()));
+ llvm::report_fatal_error(
+ llvm::Twine("Mismatched {} in the diagnostic: ") +
+ llvm::Twine(getID()));
}
- ++cur_char; // skip '}'
+ ++cur_char; // skip '}'
}
}
if (!isdigit(*cur_char)) {
@@ -119,30 +119,30 @@ void Diagnostic::format(const char* pBegin, const char* pEnd,
}
unsigned int arg_no = *cur_char - '0';
- ++cur_char; // skip argument number
+ ++cur_char; // skip argument number
DiagnosticEngine::ArgumentKind kind = getArgKind(arg_no);
switch (kind) {
case DiagnosticEngine::ak_std_string: {
- if (0 != modifier_len) {
- llvm::report_fatal_error(llvm::Twine("In diagnostic: ") +
- llvm::Twine(getID()) +
- llvm::Twine(": ") + llvm::Twine(pBegin) +
- llvm::Twine("\nNo modifiers for strings yet\n"));
+ if (modifier_len != 0) {
+ llvm::report_fatal_error(
+ llvm::Twine("In diagnostic: ") + llvm::Twine(getID()) +
+ llvm::Twine(": ") + llvm::Twine(pBegin) +
+ llvm::Twine("\nNo modifiers for strings yet\n"));
}
const std::string& str = getArgStdStr(arg_no);
pOutStr.append(str.begin(), str.end());
break;
}
case DiagnosticEngine::ak_c_string: {
- if (0 != modifier_len) {
- llvm::report_fatal_error(llvm::Twine("In diagnostic: ") +
- llvm::Twine(getID()) +
- llvm::Twine(": ") + llvm::Twine(pBegin) +
- llvm::Twine("\nNo modifiers for strings yet\n"));
+ if (modifier_len != 0) {
+ llvm::report_fatal_error(
+ llvm::Twine("In diagnostic: ") + llvm::Twine(getID()) +
+ llvm::Twine(": ") + llvm::Twine(pBegin) +
+ llvm::Twine("\nNo modifiers for strings yet\n"));
}
const char* str = getArgCStr(arg_no);
- if (NULL == str)
+ if (str == NULL)
str = "(null)";
pOutStr.append(str);
break;
@@ -170,7 +170,8 @@ void Diagnostic::format(const char* pBegin, const char* pEnd,
pOutStr.append("false");
break;
}
- } // end of switch
- } // end of while
+ } // end of switch
+ } // end of while
}
+} // namespace mcld
diff --git a/lib/LD/DiagnosticEngine.cpp b/lib/LD/DiagnosticEngine.cpp
index ac51080..ca0f2bd 100644
--- a/lib/LD/DiagnosticEngine.cpp
+++ b/lib/LD/DiagnosticEngine.cpp
@@ -6,26 +6,29 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/DiagnosticEngine.h>
-#include <mcld/LD/DiagnosticPrinter.h>
-#include <mcld/LD/DiagnosticLineInfo.h>
-#include <mcld/LD/MsgHandler.h>
-#include <mcld/LinkerConfig.h>
+#include "mcld/LD/DiagnosticEngine.h"
+
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/DiagnosticLineInfo.h"
+#include "mcld/LD/DiagnosticPrinter.h"
+#include "mcld/LD/MsgHandler.h"
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// DiagnosticEngine
//===----------------------------------------------------------------------===//
DiagnosticEngine::DiagnosticEngine()
- : m_pConfig(NULL), m_pLineInfo(NULL), m_pPrinter(NULL),
- m_pInfoMap(NULL), m_OwnPrinter(false) {
+ : m_pConfig(NULL),
+ m_pLineInfo(NULL),
+ m_pPrinter(NULL),
+ m_pInfoMap(NULL),
+ m_OwnPrinter(false) {
}
-DiagnosticEngine::~DiagnosticEngine()
-{
+DiagnosticEngine::~DiagnosticEngine() {
if (m_OwnPrinter && m_pPrinter != NULL)
delete m_pPrinter;
@@ -35,40 +38,35 @@ DiagnosticEngine::~DiagnosticEngine()
delete m_pLineInfo;
}
-void DiagnosticEngine::reset(const LinkerConfig& pConfig)
-{
+void DiagnosticEngine::reset(const LinkerConfig& pConfig) {
m_pConfig = &pConfig;
delete m_pInfoMap;
m_pInfoMap = new DiagnosticInfos(*m_pConfig);
m_State.reset();
}
-void DiagnosticEngine::setLineInfo(DiagnosticLineInfo& pLineInfo)
-{
+void DiagnosticEngine::setLineInfo(DiagnosticLineInfo& pLineInfo) {
m_pLineInfo = &pLineInfo;
}
void DiagnosticEngine::setPrinter(DiagnosticPrinter& pPrinter,
- bool pShouldOwnPrinter)
-{
- if (m_OwnPrinter && NULL != m_pPrinter)
+ bool pShouldOwnPrinter) {
+ if (m_OwnPrinter && m_pPrinter != NULL)
delete m_pPrinter;
m_pPrinter = &pPrinter;
m_OwnPrinter = pShouldOwnPrinter;
}
// emit - process current diagnostic.
-bool DiagnosticEngine::emit()
-{
- assert(NULL != m_pInfoMap);
+bool DiagnosticEngine::emit() {
+ assert(m_pInfoMap != NULL);
bool emitted = m_pInfoMap->process(*this);
m_State.reset();
return emitted;
}
-MsgHandler
-DiagnosticEngine::report(uint16_t pID, DiagnosticEngine::Severity pSeverity)
-{
+MsgHandler DiagnosticEngine::report(uint16_t pID,
+ DiagnosticEngine::Severity pSeverity) {
m_State.ID = pID;
m_State.severity = pSeverity;
@@ -76,3 +74,4 @@ DiagnosticEngine::report(uint16_t pID, DiagnosticEngine::Severity pSeverity)
return result;
}
+} // namespace mcld
diff --git a/lib/LD/DiagnosticInfos.cpp b/lib/LD/DiagnosticInfos.cpp
index aed389a..080c318 100644
--- a/lib/LD/DiagnosticInfos.cpp
+++ b/lib/LD/DiagnosticInfos.cpp
@@ -6,83 +6,85 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "mcld/LD/DiagnosticInfos.h"
+
+#include "mcld/LinkerConfig.h"
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/LD/Diagnostic.h"
+#include "mcld/LD/DiagnosticPrinter.h"
+
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/DataTypes.h>
-#include <mcld/ADT/SizeTraits.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LD/Diagnostic.h>
-#include <mcld/LD/DiagnosticInfos.h>
-#include <mcld/LD/DiagnosticPrinter.h>
-
#include <algorithm>
-using namespace mcld;
+namespace mcld {
namespace {
-struct DiagStaticInfo
-{
-public:
+struct DiagStaticInfo {
+ public:
uint16_t ID;
DiagnosticEngine::Severity Severity;
uint16_t DescriptionLen;
const char* DescriptionStr;
-public:
- llvm::StringRef getDescription() const
- { return llvm::StringRef(DescriptionStr, DescriptionLen); }
+ public:
+ llvm::StringRef getDescription() const {
+ return llvm::StringRef(DescriptionStr, DescriptionLen);
+ }
- bool operator<(const DiagStaticInfo& pRHS) const
- { return (ID < pRHS.ID); }
+ bool operator<(const DiagStaticInfo& pRHS) const { return (ID < pRHS.ID); }
};
-} // namespace anonymous
+} // anonymous namespace
static const DiagStaticInfo DiagCommonInfo[] = {
-#define DIAG(ENUM, CLASS, ADDRDESC, LOCDESC) \
- { diag::ENUM, CLASS, STR_SIZE(ADDRDESC, uint16_t), ADDRDESC },
-#include "mcld/LD/DiagAttribute.inc"
-#include "mcld/LD/DiagCommonKinds.inc"
-#include "mcld/LD/DiagReaders.inc"
-#include "mcld/LD/DiagSymbolResolutions.inc"
-#include "mcld/LD/DiagRelocations.inc"
-#include "mcld/LD/DiagLayouts.inc"
-#include "mcld/LD/DiagGOTPLT.inc"
-#include "mcld/LD/DiagLDScript.inc"
+#define DIAG(ENUM, CLASS, ADDRDESC, LOCDESC) \
+ { diag::ENUM, CLASS, STR_SIZE(ADDRDESC, uint16_t), ADDRDESC } \
+ ,
+#include "mcld/LD/DiagAttribute.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagCommonKinds.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagReaders.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagSymbolResolutions.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagRelocations.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagLayouts.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagGOTPLT.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagLDScript.inc" // NOLINT [build/include] [4]
#undef DIAG
- { 0, DiagnosticEngine::None, 0, 0}
-};
+ {0, DiagnosticEngine::None, 0, 0}};
static const unsigned int DiagCommonInfoSize =
- sizeof(DiagCommonInfo)/sizeof(DiagCommonInfo[0])-1;
+ sizeof(DiagCommonInfo) / sizeof(DiagCommonInfo[0]) - 1;
static const DiagStaticInfo DiagLoCInfo[] = {
-#define DIAG(ENUM, CLASS, ADDRDESC, LOCDESC) \
- { diag::ENUM, CLASS, STR_SIZE(LOCDESC, uint16_t), LOCDESC },
-#include "mcld/LD/DiagAttribute.inc"
-#include "mcld/LD/DiagCommonKinds.inc"
-#include "mcld/LD/DiagReaders.inc"
-#include "mcld/LD/DiagSymbolResolutions.inc"
-#include "mcld/LD/DiagRelocations.inc"
-#include "mcld/LD/DiagLayouts.inc"
-#include "mcld/LD/DiagGOTPLT.inc"
-#include "mcld/LD/DiagLDScript.inc"
+#define DIAG(ENUM, CLASS, ADDRDESC, LOCDESC) \
+ { diag::ENUM, CLASS, STR_SIZE(LOCDESC, uint16_t), LOCDESC } \
+ ,
+#include "mcld/LD/DiagAttribute.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagCommonKinds.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagReaders.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagSymbolResolutions.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagRelocations.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagLayouts.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagGOTPLT.inc" // NOLINT [build/include] [4]
+#include "mcld/LD/DiagLDScript.inc" // NOLINT [build/include] [4]
#undef DIAG
- { 0, DiagnosticEngine::None, 0, 0}
-};
+ {0, DiagnosticEngine::None, 0, 0}};
static const unsigned int DiagLoCInfoSize =
- sizeof(DiagLoCInfo)/sizeof(DiagLoCInfo[0])-1;
+ sizeof(DiagLoCInfo) / sizeof(DiagLoCInfo[0]) - 1;
+static const DiagStaticInfo* getDiagInfo(unsigned int pID,
+ bool pInLoC = false) {
+ const DiagStaticInfo* static_info = (pInLoC) ? DiagLoCInfo : DiagCommonInfo;
+ unsigned int info_size = (pInLoC) ? DiagLoCInfoSize : DiagCommonInfoSize;
-static const DiagStaticInfo* getDiagInfo(unsigned int pID, bool pInLoC = false)
-{
- const DiagStaticInfo* static_info = (pInLoC)?DiagLoCInfo:DiagCommonInfo;
- unsigned int info_size = (pInLoC)?DiagLoCInfoSize:DiagCommonInfoSize;
+ DiagStaticInfo key = {
+ static_cast<uint16_t>(pID), DiagnosticEngine::None, 0, 0};
- DiagStaticInfo key = { static_cast<uint16_t>(pID), DiagnosticEngine::None, 0, 0 };
- const DiagStaticInfo *result = std::lower_bound(static_info, static_info + info_size, key);
+ const DiagStaticInfo* result =
+ std::lower_bound(static_info, static_info + info_size, key);
if (result == (static_info + info_size) || result->ID != pID)
return NULL;
@@ -94,20 +96,18 @@ static const DiagStaticInfo* getDiagInfo(unsigned int pID, bool pInLoC = false)
// DiagnosticInfos
//===----------------------------------------------------------------------===//
DiagnosticInfos::DiagnosticInfos(const LinkerConfig& pConfig)
- : m_Config(pConfig) {
+ : m_Config(pConfig) {
}
-DiagnosticInfos::~DiagnosticInfos()
-{
+DiagnosticInfos::~DiagnosticInfos() {
}
-llvm::StringRef DiagnosticInfos::getDescription(unsigned int pID, bool pInLoC) const
-{
+llvm::StringRef DiagnosticInfos::getDescription(unsigned int pID,
+ bool pInLoC) const {
return getDiagInfo(pID, pInLoC)->getDescription();
}
-bool DiagnosticInfos::process(DiagnosticEngine& pEngine) const
-{
+bool DiagnosticInfos::process(DiagnosticEngine& pEngine) const {
Diagnostic info(pEngine);
unsigned int ID = info.getID();
@@ -127,8 +127,9 @@ bool DiagnosticInfos::process(DiagnosticEngine& pEngine) const
case diag::undefined_reference:
case diag::undefined_reference_text: {
// we have not implement --unresolved-symbols=method yet. So far, MCLinker
- // provides the easier --allow-shlib-undefined and --no-undefined (i.e. -z defs)
- switch(m_Config.codeGenType()) {
+ // provides the easier --allow-shlib-undefined and --no-undefined (i.e.
+ // -z defs)
+ switch (m_Config.codeGenType()) {
case LinkerConfig::Object:
if (m_Config.options().isNoUndefined())
severity = DiagnosticEngine::Error;
@@ -154,7 +155,7 @@ bool DiagnosticInfos::process(DiagnosticEngine& pEngine) const
}
default:
break;
- } // end of switch
+ } // end of switch
// If --fatal-warnings is turned on, then switch warnings and errors to fatal
if (m_Config.options().isFatalWarnings()) {
@@ -169,3 +170,4 @@ bool DiagnosticInfos::process(DiagnosticEngine& pEngine) const
return true;
}
+} // namespace mcld
diff --git a/lib/LD/DiagnosticLineInfo.cpp b/lib/LD/DiagnosticLineInfo.cpp
index d3c9190..b1c3a84 100644
--- a/lib/LD/DiagnosticLineInfo.cpp
+++ b/lib/LD/DiagnosticLineInfo.cpp
@@ -6,10 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/DiagnosticLineInfo.h>
+#include "mcld/LD/DiagnosticLineInfo.h"
-using namespace mcld;
+namespace mcld {
//==========================
// DiagnosticLineInfo
+} // namespace mcld
diff --git a/lib/LD/DiagnosticPrinter.cpp b/lib/LD/DiagnosticPrinter.cpp
index 6eee86a..9978b1e 100644
--- a/lib/LD/DiagnosticPrinter.cpp
+++ b/lib/LD/DiagnosticPrinter.cpp
@@ -6,27 +6,24 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/DiagnosticPrinter.h>
+#include "mcld/LD/DiagnosticPrinter.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// DiagnosticPrinter
//===----------------------------------------------------------------------===//
-DiagnosticPrinter::DiagnosticPrinter()
- : m_NumErrors(0), m_NumWarnings(0) {
+DiagnosticPrinter::DiagnosticPrinter() : m_NumErrors(0), m_NumWarnings(0) {
}
-DiagnosticPrinter::~DiagnosticPrinter()
-{
+DiagnosticPrinter::~DiagnosticPrinter() {
clear();
}
/// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
/// capturing it to a log as needed.
void DiagnosticPrinter::handleDiagnostic(DiagnosticEngine::Severity pSeverity,
- const Diagnostic& pInfo)
-{
+ const Diagnostic& pInfo) {
if (pSeverity == DiagnosticEngine::Warning)
++m_NumWarnings;
@@ -34,3 +31,4 @@ void DiagnosticPrinter::handleDiagnostic(DiagnosticEngine::Severity pSeverity,
++m_NumErrors;
}
+} // namespace mcld
diff --git a/lib/LD/DynObjReader.cpp b/lib/LD/DynObjReader.cpp
index 552e893..a040cf1 100644
--- a/lib/LD/DynObjReader.cpp
+++ b/lib/LD/DynObjReader.cpp
@@ -7,10 +7,13 @@
//
//===----------------------------------------------------------------------===//
#include "mcld/LD/DynObjReader.h"
-#include "mcld/Target/TargetLDBackend.h"
+
#include "mcld/MC/Input.h"
+#include "mcld/Target/TargetLDBackend.h"
-using namespace mcld;
+namespace mcld {
//==========================
// ObjectReader
+
+} // namespace mcld
diff --git a/lib/LD/ELFBinaryReader.cpp b/lib/LD/ELFBinaryReader.cpp
index c72fa58..5b53d3a 100644
--- a/lib/LD/ELFBinaryReader.cpp
+++ b/lib/LD/ELFBinaryReader.cpp
@@ -6,18 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFBinaryReader.h>
+#include "mcld/LD/ELFBinaryReader.h"
-#include <mcld/IRBuilder.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Support/MemoryArea.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Support/MemoryArea.h"
#include <llvm/Support/ELF.h>
#include <cctype>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFBinaryReader
@@ -25,37 +25,30 @@ using namespace mcld;
/// constructor
ELFBinaryReader::ELFBinaryReader(IRBuilder& pBuilder,
const LinkerConfig& pConfig)
- : m_Builder(pBuilder), m_Config(pConfig) {
+ : m_Builder(pBuilder), m_Config(pConfig) {
}
/// destructor
-ELFBinaryReader::~ELFBinaryReader()
-{
+ELFBinaryReader::~ELFBinaryReader() {
}
-bool ELFBinaryReader::isMyFormat(Input& pInput, bool &pContinue) const
-{
+bool ELFBinaryReader::isMyFormat(Input& pInput, bool& pContinue) const {
pContinue = true;
return m_Config.options().isBinaryInput();
}
-bool ELFBinaryReader::readBinary(Input& pInput)
-{
+bool ELFBinaryReader::readBinary(Input& pInput) {
// section: NULL
- m_Builder.CreateELFHeader(pInput,
- "",
- LDFileFormat::Null,
- llvm::ELF::SHT_NULL,
- 0x0);
+ m_Builder.CreateELFHeader(
+ pInput, "", LDFileFormat::Null, llvm::ELF::SHT_NULL, 0x0);
// section: .data
LDSection* data_sect =
- m_Builder.CreateELFHeader(pInput,
- ".data",
- LDFileFormat::DATA,
- llvm::ELF::SHF_WRITE | llvm::ELF::SHF_ALLOC,
- 0x1);
-
+ m_Builder.CreateELFHeader(pInput,
+ ".data",
+ LDFileFormat::DATA,
+ llvm::ELF::SHF_WRITE | llvm::ELF::SHF_ALLOC,
+ 0x1);
SectionData* data = m_Builder.CreateSectionData(*data_sect);
size_t data_size = pInput.memArea()->size();
@@ -63,11 +56,8 @@ bool ELFBinaryReader::readBinary(Input& pInput)
m_Builder.AppendFragment(*frag, *data);
// section: .shstrtab
- m_Builder.CreateELFHeader(pInput,
- ".shstrtab",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_STRTAB,
- 0x1);
+ m_Builder.CreateELFHeader(
+ pInput, ".shstrtab", LDFileFormat::NamePool, llvm::ELF::SHT_STRTAB, 0x1);
// section: .symtab
m_Builder.CreateELFHeader(pInput,
@@ -89,8 +79,9 @@ bool ELFBinaryReader::readBinary(Input& pInput)
// Note: in Win32, the filename is wstring. Is it correct to convert
// filename to std::string?
std::string mangled_name = pInput.path().filename().native();
- for (std::string::iterator it = mangled_name.begin(),
- ie = mangled_name.end(); it != ie; ++it) {
+ for (std::string::iterator it = mangled_name.begin(), ie = mangled_name.end();
+ it != ie;
+ ++it) {
if (isalnum(*it) == 0)
*it = '_';
}
@@ -126,11 +117,10 @@ bool ELFBinaryReader::readBinary(Input& pInput)
data_sect);
// section: .strtab
- m_Builder.CreateELFHeader(pInput,
- ".strtab",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_STRTAB,
- 0x1);
+ m_Builder.CreateELFHeader(
+ pInput, ".strtab", LDFileFormat::NamePool, llvm::ELF::SHT_STRTAB, 0x1);
return true;
}
+
+} // namespace mcld
diff --git a/lib/LD/ELFDynObjFileFormat.cpp b/lib/LD/ELFDynObjFileFormat.cpp
index e89f48b..4812091 100644
--- a/lib/LD/ELFDynObjFileFormat.cpp
+++ b/lib/LD/ELFDynObjFileFormat.cpp
@@ -6,86 +6,89 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFDynObjFileFormat.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/LD/ELFDynObjFileFormat.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Object/ObjectBuilder.h"
#include <llvm/Support/ELF.h>
-using namespace mcld;
+namespace mcld {
void ELFDynObjFileFormat::initObjectFormat(ObjectBuilder& pBuilder,
- unsigned int pBitClass)
-{
- f_pDynSymTab = pBuilder.CreateSection(".dynsym",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_DYNSYM,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pDynStrTab = pBuilder.CreateSection(".dynstr",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_STRTAB,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pInterp = pBuilder.CreateSection(".interp",
- LDFileFormat::Note,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pHashTab = pBuilder.CreateSection(".hash",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_HASH,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pDynamic = pBuilder.CreateSection(".dynamic",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_DYNAMIC,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- pBitClass / 8);
- f_pRelaDyn = pBuilder.CreateSection(".rela.dyn",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_RELA,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pRelaPlt = pBuilder.CreateSection(".rela.plt",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_RELA,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pRelDyn = pBuilder.CreateSection(".rel.dyn",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_REL,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pRelPlt = pBuilder.CreateSection(".rel.plt",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_REL,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pGOT = pBuilder.CreateSection(".got",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- pBitClass / 8);
- f_pPLT = pBuilder.CreateSection(".plt",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
- pBitClass / 8);
- f_pGOTPLT = pBuilder.CreateSection(".got.plt",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- pBitClass / 8);
- f_pEhFrameHdr = pBuilder.CreateSection(".eh_frame_hdr",
- LDFileFormat::EhFrameHdr,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x4);
- f_pGNUHashTab = pBuilder.CreateSection(".gnu.hash",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_GNU_HASH,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
+ unsigned int pBitClass) {
+ f_pDynSymTab = pBuilder.CreateSection(".dynsym",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_DYNSYM,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pDynStrTab = pBuilder.CreateSection(".dynstr",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_STRTAB,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pInterp = pBuilder.CreateSection(".interp",
+ LDFileFormat::Note,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pHashTab = pBuilder.CreateSection(".hash",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_HASH,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pDynamic =
+ pBuilder.CreateSection(".dynamic",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_DYNAMIC,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ pBitClass / 8);
+ f_pRelaDyn = pBuilder.CreateSection(".rela.dyn",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_RELA,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pRelaPlt = pBuilder.CreateSection(".rela.plt",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_RELA,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pRelDyn = pBuilder.CreateSection(".rel.dyn",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_REL,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pRelPlt = pBuilder.CreateSection(".rel.plt",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_REL,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pGOT = pBuilder.CreateSection(".got",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ pBitClass / 8);
+ f_pPLT =
+ pBuilder.CreateSection(".plt",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
+ pBitClass / 8);
+ f_pGOTPLT =
+ pBuilder.CreateSection(".got.plt",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ pBitClass / 8);
+ f_pEhFrameHdr = pBuilder.CreateSection(".eh_frame_hdr",
+ LDFileFormat::EhFrameHdr,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x4);
+ f_pGNUHashTab = pBuilder.CreateSection(".gnu.hash",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_GNU_HASH,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
}
+} // namespace mcld
diff --git a/lib/LD/ELFDynObjReader.cpp b/lib/LD/ELFDynObjReader.cpp
index 94eef58..f18d6c6 100644
--- a/lib/LD/ELFDynObjReader.cpp
+++ b/lib/LD/ELFDynObjReader.cpp
@@ -6,14 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFDynObjReader.h>
+#include "mcld/LD/ELFDynObjReader.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/LD/ELFReader.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Support/MemoryArea.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/ELFReader.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/Twine.h>
@@ -21,7 +22,7 @@
#include <string>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFDynObjReader
@@ -29,23 +30,19 @@ using namespace mcld;
ELFDynObjReader::ELFDynObjReader(GNULDBackend& pBackend,
IRBuilder& pBuilder,
const LinkerConfig& pConfig)
- : DynObjReader(),
- m_pELFReader(0),
- m_Builder(pBuilder) {
+ : DynObjReader(), m_pELFReader(0), m_Builder(pBuilder) {
if (pConfig.targets().is32Bits() && pConfig.targets().isLittleEndian())
m_pELFReader = new ELFReader<32, true>(pBackend);
else if (pConfig.targets().is64Bits() && pConfig.targets().isLittleEndian())
m_pELFReader = new ELFReader<64, true>(pBackend);
}
-ELFDynObjReader::~ELFDynObjReader()
-{
+ELFDynObjReader::~ELFDynObjReader() {
delete m_pELFReader;
}
/// isMyFormat
-bool ELFDynObjReader::isMyFormat(Input &pInput, bool &pContinue) const
-{
+bool ELFDynObjReader::isMyFormat(Input& pInput, bool& pContinue) const {
assert(pInput.hasMemArea());
// Don't warning about the frequently requests.
@@ -54,8 +51,8 @@ bool ELFDynObjReader::isMyFormat(Input &pInput, bool &pContinue) const
if (pInput.memArea()->size() < hdr_size)
return false;
- llvm::StringRef region = pInput.memArea()->request(pInput.fileOffset(),
- hdr_size);
+ llvm::StringRef region =
+ pInput.memArea()->request(pInput.fileOffset(), hdr_size);
const char* ELF_hdr = region.begin();
bool result = true;
@@ -76,13 +73,12 @@ bool ELFDynObjReader::isMyFormat(Input &pInput, bool &pContinue) const
}
/// readHeader
-bool ELFDynObjReader::readHeader(Input& pInput)
-{
+bool ELFDynObjReader::readHeader(Input& pInput) {
assert(pInput.hasMemArea());
size_t hdr_size = m_pELFReader->getELFHeaderSize();
- llvm::StringRef region = pInput.memArea()->request(pInput.fileOffset(),
- hdr_size);
+ llvm::StringRef region =
+ pInput.memArea()->request(pInput.fileOffset(), hdr_size);
const char* ELF_hdr = region.begin();
bool shdr_result = m_pELFReader->readSectionHeaders(pInput, ELF_hdr);
@@ -94,22 +90,19 @@ bool ELFDynObjReader::readHeader(Input& pInput)
}
/// readSymbols
-bool ELFDynObjReader::readSymbols(Input& pInput)
-{
+bool ELFDynObjReader::readSymbols(Input& pInput) {
assert(pInput.hasMemArea());
LDSection* symtab_shdr = pInput.context()->getSection(".dynsym");
- if (NULL == symtab_shdr) {
- note(diag::note_has_no_symtab) << pInput.name()
- << pInput.path()
+ if (symtab_shdr == NULL) {
+ note(diag::note_has_no_symtab) << pInput.name() << pInput.path()
<< ".dynsym";
return true;
}
LDSection* strtab_shdr = symtab_shdr->getLink();
- if (NULL == strtab_shdr) {
- fatal(diag::fatal_cannot_read_strtab) << pInput.name()
- << pInput.path()
+ if (strtab_shdr == NULL) {
+ fatal(diag::fatal_cannot_read_strtab) << pInput.name() << pInput.path()
<< ".dynsym";
return false;
}
@@ -120,8 +113,9 @@ bool ELFDynObjReader::readSymbols(Input& pInput)
llvm::StringRef strtab_region = pInput.memArea()->request(
pInput.fileOffset() + strtab_shdr->offset(), strtab_shdr->size());
const char* strtab = strtab_region.begin();
- bool result = m_pELFReader->readSymbols(pInput, m_Builder,
- symtab_region, strtab);
+ bool result =
+ m_pELFReader->readSymbols(pInput, m_Builder, symtab_region, strtab);
return result;
}
+} // namespace mcld
diff --git a/lib/LD/ELFExecFileFormat.cpp b/lib/LD/ELFExecFileFormat.cpp
index 6a81f72..3e94295 100644
--- a/lib/LD/ELFExecFileFormat.cpp
+++ b/lib/LD/ELFExecFileFormat.cpp
@@ -6,86 +6,90 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFExecFileFormat.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/LD/ELFExecFileFormat.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Object/ObjectBuilder.h"
#include <llvm/Support/ELF.h>
-using namespace mcld;
+namespace mcld {
void ELFExecFileFormat::initObjectFormat(ObjectBuilder& pBuilder,
- unsigned int pBitClass)
-{
+ unsigned int pBitClass) {
// FIXME: make sure ELF executable files has these sections.
- f_pDynSymTab = pBuilder.CreateSection(".dynsym",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_DYNSYM,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pDynStrTab = pBuilder.CreateSection(".dynstr",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_STRTAB,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pInterp = pBuilder.CreateSection(".interp",
- LDFileFormat::Note,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pHashTab = pBuilder.CreateSection(".hash",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_HASH,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pDynamic = pBuilder.CreateSection(".dynamic",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_DYNAMIC,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- pBitClass / 8);
- f_pRelaDyn = pBuilder.CreateSection(".rela.dyn",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_RELA,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pRelaPlt = pBuilder.CreateSection(".rela.plt",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_RELA,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pRelDyn = pBuilder.CreateSection(".rel.dyn",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_REL,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pRelPlt = pBuilder.CreateSection(".rel.plt",
- LDFileFormat::Relocation,
- llvm::ELF::SHT_REL,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
- f_pGOT = pBuilder.CreateSection(".got",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- pBitClass / 8);
- f_pPLT = pBuilder.CreateSection(".plt",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
- pBitClass / 8);
- f_pGOTPLT = pBuilder.CreateSection(".got.plt",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- pBitClass / 8);
- f_pEhFrameHdr = pBuilder.CreateSection(".eh_frame_hdr",
- LDFileFormat::EhFrameHdr,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x4);
- f_pGNUHashTab = pBuilder.CreateSection(".gnu.hash",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_GNU_HASH,
- llvm::ELF::SHF_ALLOC,
- pBitClass / 8);
+ f_pDynSymTab = pBuilder.CreateSection(".dynsym",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_DYNSYM,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pDynStrTab = pBuilder.CreateSection(".dynstr",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_STRTAB,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pInterp = pBuilder.CreateSection(".interp",
+ LDFileFormat::Note,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pHashTab = pBuilder.CreateSection(".hash",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_HASH,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pDynamic =
+ pBuilder.CreateSection(".dynamic",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_DYNAMIC,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ pBitClass / 8);
+ f_pRelaDyn = pBuilder.CreateSection(".rela.dyn",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_RELA,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pRelaPlt = pBuilder.CreateSection(".rela.plt",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_RELA,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pRelDyn = pBuilder.CreateSection(".rel.dyn",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_REL,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pRelPlt = pBuilder.CreateSection(".rel.plt",
+ LDFileFormat::Relocation,
+ llvm::ELF::SHT_REL,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
+ f_pGOT = pBuilder.CreateSection(".got",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ pBitClass / 8);
+ f_pPLT =
+ pBuilder.CreateSection(".plt",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
+ pBitClass / 8);
+ f_pGOTPLT =
+ pBuilder.CreateSection(".got.plt",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ pBitClass / 8);
+ f_pEhFrameHdr = pBuilder.CreateSection(".eh_frame_hdr",
+ LDFileFormat::EhFrameHdr,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x4);
+ f_pGNUHashTab = pBuilder.CreateSection(".gnu.hash",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_GNU_HASH,
+ llvm::ELF::SHF_ALLOC,
+ pBitClass / 8);
}
+
+} // namespace mcld
diff --git a/lib/LD/ELFFileFormat.cpp b/lib/LD/ELFFileFormat.cpp
index 318e595..0a8d2c8 100644
--- a/lib/LD/ELFFileFormat.cpp
+++ b/lib/LD/ELFFileFormat.cpp
@@ -6,247 +6,232 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/Target/GNULDBackend.h>
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/Support/ELF.h>
-using namespace mcld;
+namespace mcld {
ELFFileFormat::ELFFileFormat()
- : f_pNULLSection(NULL),
- f_pGOT(NULL),
- f_pPLT(NULL),
- f_pRelDyn(NULL),
- f_pRelPlt(NULL),
- f_pRelaDyn(NULL),
- f_pRelaPlt(NULL),
- f_pComment(NULL),
- f_pData1(NULL),
- f_pDebug(NULL),
- f_pDynamic(NULL),
- f_pDynStrTab(NULL),
- f_pDynSymTab(NULL),
- f_pFini(NULL),
- f_pFiniArray(NULL),
- f_pHashTab(NULL),
- f_pInit(NULL),
- f_pInitArray(NULL),
- f_pInterp(NULL),
- f_pLine(NULL),
- f_pNote(NULL),
- f_pPreInitArray(NULL),
- f_pROData1(NULL),
- f_pShStrTab(NULL),
- f_pStrTab(NULL),
- f_pSymTab(NULL),
- f_pTBSS(NULL),
- f_pTData(NULL),
- f_pCtors(NULL),
- f_pDataRelRo(NULL),
- f_pDtors(NULL),
- f_pEhFrame(NULL),
- f_pEhFrameHdr(NULL),
- f_pGCCExceptTable(NULL),
- f_pGNUVersion(NULL),
- f_pGNUVersionD(NULL),
- f_pGNUVersionR(NULL),
- f_pGOTPLT(NULL),
- f_pJCR(NULL),
- f_pNoteABITag(NULL),
- f_pStab(NULL),
- f_pStabStr(NULL),
- f_pStack(NULL),
- f_pStackNote(NULL),
- f_pDataRelRoLocal(NULL),
- f_pGNUHashTab(NULL) {
-
+ : f_pNULLSection(NULL),
+ f_pGOT(NULL),
+ f_pPLT(NULL),
+ f_pRelDyn(NULL),
+ f_pRelPlt(NULL),
+ f_pRelaDyn(NULL),
+ f_pRelaPlt(NULL),
+ f_pComment(NULL),
+ f_pData1(NULL),
+ f_pDebug(NULL),
+ f_pDynamic(NULL),
+ f_pDynStrTab(NULL),
+ f_pDynSymTab(NULL),
+ f_pFini(NULL),
+ f_pFiniArray(NULL),
+ f_pHashTab(NULL),
+ f_pInit(NULL),
+ f_pInitArray(NULL),
+ f_pInterp(NULL),
+ f_pLine(NULL),
+ f_pNote(NULL),
+ f_pPreInitArray(NULL),
+ f_pROData1(NULL),
+ f_pShStrTab(NULL),
+ f_pStrTab(NULL),
+ f_pSymTab(NULL),
+ f_pTBSS(NULL),
+ f_pTData(NULL),
+ f_pCtors(NULL),
+ f_pDataRelRo(NULL),
+ f_pDtors(NULL),
+ f_pEhFrame(NULL),
+ f_pEhFrameHdr(NULL),
+ f_pGCCExceptTable(NULL),
+ f_pGNUVersion(NULL),
+ f_pGNUVersionD(NULL),
+ f_pGNUVersionR(NULL),
+ f_pGOTPLT(NULL),
+ f_pJCR(NULL),
+ f_pNoteABITag(NULL),
+ f_pStab(NULL),
+ f_pStabStr(NULL),
+ f_pStack(NULL),
+ f_pStackNote(NULL),
+ f_pDataRelRoLocal(NULL),
+ f_pGNUHashTab(NULL) {
}
-void ELFFileFormat::initStdSections(ObjectBuilder& pBuilder, unsigned int pBitClass)
-{
- f_pTextSection = pBuilder.CreateSection(".text",
- LDFileFormat::TEXT,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
- 0x1);
- f_pNULLSection = pBuilder.CreateSection("",
- LDFileFormat::Null,
- llvm::ELF::SHT_NULL,
- 0x0);
+void ELFFileFormat::initStdSections(ObjectBuilder& pBuilder,
+ unsigned int pBitClass) {
+ f_pTextSection =
+ pBuilder.CreateSection(".text",
+ LDFileFormat::TEXT,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
+ 0x1);
+ f_pNULLSection =
+ pBuilder.CreateSection("", LDFileFormat::Null, llvm::ELF::SHT_NULL, 0x0);
f_pReadOnlySection = pBuilder.CreateSection(".rodata",
LDFileFormat::TEXT,
llvm::ELF::SHT_PROGBITS,
llvm::ELF::SHF_ALLOC,
0x1);
- f_pBSSSection = pBuilder.CreateSection(".bss",
- LDFileFormat::BSS,
- llvm::ELF::SHT_NOBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pComment = pBuilder.CreateSection(".comment",
- LDFileFormat::MetaData,
- llvm::ELF::SHT_PROGBITS,
- 0x0,
- 0x1);
- f_pDataSection = pBuilder.CreateSection(".data",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pData1 = pBuilder.CreateSection(".data1",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pDebug = pBuilder.CreateSection(".debug",
- LDFileFormat::Debug,
- llvm::ELF::SHT_PROGBITS,
- 0x0,
- 0x1);
- f_pInit = pBuilder.CreateSection(".init",
- LDFileFormat::TEXT,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
- 0x1);
- f_pInitArray = pBuilder.CreateSection(".init_array",
- LDFileFormat::DATA,
- llvm::ELF::SHT_INIT_ARRAY,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pFini = pBuilder.CreateSection(".fini",
- LDFileFormat::TEXT,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
- 0x1);
- f_pFiniArray = pBuilder.CreateSection(".fini_array",
- LDFileFormat::DATA,
- llvm::ELF::SHT_FINI_ARRAY,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pLine = pBuilder.CreateSection(".line",
- LDFileFormat::Debug,
- llvm::ELF::SHT_PROGBITS,
- 0x0,
- 0x1);
- f_pPreInitArray = pBuilder.CreateSection(".preinit_array",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PREINIT_ARRAY,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
+ f_pBSSSection =
+ pBuilder.CreateSection(".bss",
+ LDFileFormat::BSS,
+ llvm::ELF::SHT_NOBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pComment = pBuilder.CreateSection(
+ ".comment", LDFileFormat::MetaData, llvm::ELF::SHT_PROGBITS, 0x0, 0x1);
+ f_pDataSection =
+ pBuilder.CreateSection(".data",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pData1 = pBuilder.CreateSection(".data1",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pDebug = pBuilder.CreateSection(
+ ".debug", LDFileFormat::Debug, llvm::ELF::SHT_PROGBITS, 0x0, 0x1);
+ f_pInit =
+ pBuilder.CreateSection(".init",
+ LDFileFormat::TEXT,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
+ 0x1);
+ f_pInitArray =
+ pBuilder.CreateSection(".init_array",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_INIT_ARRAY,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pFini =
+ pBuilder.CreateSection(".fini",
+ LDFileFormat::TEXT,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
+ 0x1);
+ f_pFiniArray =
+ pBuilder.CreateSection(".fini_array",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_FINI_ARRAY,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pLine = pBuilder.CreateSection(
+ ".line", LDFileFormat::Debug, llvm::ELF::SHT_PROGBITS, 0x0, 0x1);
+ f_pPreInitArray =
+ pBuilder.CreateSection(".preinit_array",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PREINIT_ARRAY,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
// the definition of SHF_XXX attributes of rodata in Linux Standard Base
// conflicts with System V standard. We follow System V standard.
- f_pROData1 = pBuilder.CreateSection(".rodata1",
- LDFileFormat::TEXT,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pShStrTab = pBuilder.CreateSection(".shstrtab",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_STRTAB,
- 0x0,
- 0x1);
+ f_pROData1 = pBuilder.CreateSection(".rodata1",
+ LDFileFormat::TEXT,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pShStrTab = pBuilder.CreateSection(
+ ".shstrtab", LDFileFormat::NamePool, llvm::ELF::SHT_STRTAB, 0x0, 0x1);
// In ELF Spec Book I, p1-16. If symbol table and string table are in
// loadable segments, set the attribute to SHF_ALLOC bit. But in the
// real world, this bit always turn off.
- f_pSymTab = pBuilder.CreateSection(".symtab",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_SYMTAB,
- 0x0,
- pBitClass / 8);
+ f_pSymTab = pBuilder.CreateSection(".symtab",
+ LDFileFormat::NamePool,
+ llvm::ELF::SHT_SYMTAB,
+ 0x0,
+ pBitClass / 8);
- f_pStrTab = pBuilder.CreateSection(".strtab",
- LDFileFormat::NamePool,
- llvm::ELF::SHT_STRTAB,
- 0x0,
- 0x1);
- f_pTBSS = pBuilder.CreateSection(".tbss",
- LDFileFormat::BSS,
- llvm::ELF::SHT_NOBITS,
- llvm::ELF::SHF_ALLOC |
- llvm::ELF::SHF_WRITE |
- llvm::ELF::SHF_TLS,
- 0x1);
- f_pTData = pBuilder.CreateSection(".tdata",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC |
- llvm::ELF::SHF_WRITE |
- llvm::ELF::SHF_TLS,
- 0x1);
+ f_pStrTab = pBuilder.CreateSection(
+ ".strtab", LDFileFormat::NamePool, llvm::ELF::SHT_STRTAB, 0x0, 0x1);
+ f_pTBSS = pBuilder.CreateSection(
+ ".tbss",
+ LDFileFormat::BSS,
+ llvm::ELF::SHT_NOBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE | llvm::ELF::SHF_TLS,
+ 0x1);
+ f_pTData = pBuilder.CreateSection(
+ ".tdata",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE | llvm::ELF::SHF_TLS,
+ 0x1);
/// @ref 10.3.1.2, ISO/IEC 23360, Part 1:2010(E), p. 24.
- f_pCtors = pBuilder.CreateSection(".ctors",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pDataRelRo = pBuilder.CreateSection(".data.rel.ro",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pDtors = pBuilder.CreateSection(".dtors",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pEhFrame = pBuilder.CreateSection(".eh_frame",
- LDFileFormat::EhFrame,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x4);
- f_pGCCExceptTable = pBuilder.CreateSection(".gcc_except_table",
- LDFileFormat::GCCExceptTable,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x4);
- f_pGNUVersion = pBuilder.CreateSection(".gnu.version",
- LDFileFormat::Version,
- llvm::ELF::SHT_GNU_versym,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pGNUVersionD = pBuilder.CreateSection(".gnu.version_d",
- LDFileFormat::Version,
- llvm::ELF::SHT_GNU_verdef,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pGNUVersionR = pBuilder.CreateSection(".gnu.version_r",
- LDFileFormat::Version,
- llvm::ELF::SHT_GNU_verneed,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- f_pJCR = pBuilder.CreateSection(".jcr",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
- f_pStab = pBuilder.CreateSection(".stab",
- LDFileFormat::Debug,
- llvm::ELF::SHT_PROGBITS,
- 0x0,
- 0x1);
- f_pStabStr = pBuilder.CreateSection(".stabstr",
- LDFileFormat::Debug,
- llvm::ELF::SHT_STRTAB,
- 0x0,
- 0x1);
- f_pStackNote = pBuilder.CreateSection(".note.GNU-stack",
- LDFileFormat::StackNote,
- llvm::ELF::SHT_PROGBITS,
- 0x0,
- 0x1);
+ f_pCtors = pBuilder.CreateSection(".ctors",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pDataRelRo =
+ pBuilder.CreateSection(".data.rel.ro",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pDtors = pBuilder.CreateSection(".dtors",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pEhFrame = pBuilder.CreateSection(".eh_frame",
+ LDFileFormat::EhFrame,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x4);
+ f_pGCCExceptTable = pBuilder.CreateSection(".gcc_except_table",
+ LDFileFormat::GCCExceptTable,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x4);
+ f_pGNUVersion = pBuilder.CreateSection(".gnu.version",
+ LDFileFormat::Version,
+ llvm::ELF::SHT_GNU_versym,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pGNUVersionD = pBuilder.CreateSection(".gnu.version_d",
+ LDFileFormat::Version,
+ llvm::ELF::SHT_GNU_verdef,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pGNUVersionR = pBuilder.CreateSection(".gnu.version_r",
+ LDFileFormat::Version,
+ llvm::ELF::SHT_GNU_verneed,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ f_pJCR = pBuilder.CreateSection(".jcr",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
+ f_pStab = pBuilder.CreateSection(
+ ".stab", LDFileFormat::Debug, llvm::ELF::SHT_PROGBITS, 0x0, 0x1);
+ f_pStabStr = pBuilder.CreateSection(
+ ".stabstr", LDFileFormat::Debug, llvm::ELF::SHT_STRTAB, 0x0, 0x1);
+ f_pStackNote = pBuilder.CreateSection(".note.GNU-stack",
+ LDFileFormat::StackNote,
+ llvm::ELF::SHT_PROGBITS,
+ 0x0,
+ 0x1);
/// @ref GCC convention, see http://www.airs.com/blog/archives/189
- f_pDataRelRoLocal = pBuilder.CreateSection(".data.rel.ro.local",
- LDFileFormat::DATA,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 0x1);
+ f_pDataRelRoLocal =
+ pBuilder.CreateSection(".data.rel.ro.local",
+ LDFileFormat::DATA,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 0x1);
/// Initialize format dependent sections. (sections for executable and shared
/// objects)
initObjectFormat(pBuilder, pBitClass);
}
+} // namespace mcld
diff --git a/lib/LD/ELFObjectReader.cpp b/lib/LD/ELFObjectReader.cpp
index a0ece0f..aeefd37 100644
--- a/lib/LD/ELFObjectReader.cpp
+++ b/lib/LD/ELFObjectReader.cpp
@@ -6,17 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFObjectReader.h>
+#include "mcld/LD/ELFObjectReader.h"
-#include <mcld/IRBuilder.h>
-#include <mcld/MC/Input.h>
-#include <mcld/LD/ELFReader.h>
-#include <mcld/LD/EhFrameReader.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/MC/Input.h"
+#include "mcld/LD/ELFReader.h"
+#include "mcld/LD/EhFrameReader.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/Target/GNULDBackend.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Object/ObjectBuilder.h"
#include <llvm/Support/ELF.h>
#include <llvm/ADT/Twine.h>
@@ -25,7 +26,7 @@
#include <string>
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFObjectReader
@@ -34,17 +35,17 @@ using namespace mcld;
ELFObjectReader::ELFObjectReader(GNULDBackend& pBackend,
IRBuilder& pBuilder,
const LinkerConfig& pConfig)
- : ObjectReader(),
- m_pELFReader(NULL),
- m_pEhFrameReader(NULL),
- m_Builder(pBuilder),
- m_ReadFlag(ParseEhFrame),
- m_Backend(pBackend),
- m_Config(pConfig) {
+ : ObjectReader(),
+ m_pELFReader(NULL),
+ m_pEhFrameReader(NULL),
+ m_Builder(pBuilder),
+ m_ReadFlag(ParseEhFrame),
+ m_Backend(pBackend),
+ m_Config(pConfig) {
if (pConfig.targets().is32Bits() && pConfig.targets().isLittleEndian()) {
m_pELFReader = new ELFReader<32, true>(pBackend);
- }
- else if (pConfig.targets().is64Bits() && pConfig.targets().isLittleEndian()) {
+ } else if (pConfig.targets().is64Bits() &&
+ pConfig.targets().isLittleEndian()) {
m_pELFReader = new ELFReader<64, true>(pBackend);
}
@@ -52,15 +53,13 @@ ELFObjectReader::ELFObjectReader(GNULDBackend& pBackend,
}
/// destructor
-ELFObjectReader::~ELFObjectReader()
-{
+ELFObjectReader::~ELFObjectReader() {
delete m_pELFReader;
delete m_pEhFrameReader;
}
/// isMyFormat
-bool ELFObjectReader::isMyFormat(Input &pInput, bool &pContinue) const
-{
+bool ELFObjectReader::isMyFormat(Input& pInput, bool& pContinue) const {
assert(pInput.hasMemArea());
// Don't warning about the frequently requests.
@@ -69,8 +68,8 @@ bool ELFObjectReader::isMyFormat(Input &pInput, bool &pContinue) const
if (pInput.memArea()->size() < hdr_size)
return false;
- llvm::StringRef region = pInput.memArea()->request(pInput.fileOffset(),
- hdr_size);
+ llvm::StringRef region =
+ pInput.memArea()->request(pInput.fileOffset(), hdr_size);
const char* ELF_hdr = region.begin();
bool result = true;
@@ -91,42 +90,38 @@ bool ELFObjectReader::isMyFormat(Input &pInput, bool &pContinue) const
}
/// readHeader - read section header and create LDSections.
-bool ELFObjectReader::readHeader(Input& pInput)
-{
+bool ELFObjectReader::readHeader(Input& pInput) {
assert(pInput.hasMemArea());
size_t hdr_size = m_pELFReader->getELFHeaderSize();
if (pInput.memArea()->size() < hdr_size)
return false;
- llvm::StringRef region = pInput.memArea()->request(pInput.fileOffset(),
- hdr_size);
+ llvm::StringRef region =
+ pInput.memArea()->request(pInput.fileOffset(), hdr_size);
const char* ELF_hdr = region.begin();
bool result = m_pELFReader->readSectionHeaders(pInput, ELF_hdr);
return result;
}
/// readSections - read all regular sections.
-bool ELFObjectReader::readSections(Input& pInput)
-{
+bool ELFObjectReader::readSections(Input& pInput) {
// handle sections
LDContext::sect_iterator section, sectEnd = pInput.context()->sectEnd();
for (section = pInput.context()->sectBegin(); section != sectEnd; ++section) {
// ignore the section if the LDSection* in input context is NULL
- if (NULL == *section)
- continue;
+ if (*section == NULL)
+ continue;
- switch((*section)->kind()) {
+ switch ((*section)->kind()) {
/** group sections **/
case LDFileFormat::Group: {
- assert(NULL != (*section)->getLink());
- ResolveInfo* signature =
- m_pELFReader->readSignature(pInput,
- *(*section)->getLink(),
- (*section)->getInfo());
+ assert((*section)->getLink() != NULL);
+ ResolveInfo* signature = m_pELFReader->readSignature(
+ pInput, *(*section)->getLink(), (*section)->getInfo());
bool exist = false;
- if (0 == signature->nameSize() &&
+ if (signature->nameSize() == 0 &&
ResolveInfo::Section == signature->type()) {
// if the signature is a section symbol in input object, we use the
// section name as group signature.
@@ -139,14 +134,15 @@ bool ELFObjectReader::readSections(Input& pInput)
// if this is not the first time we see this group signature, then
// ignore all the members in this group (set Ignore)
llvm::StringRef region = pInput.memArea()->request(
- pInput.fileOffset() + (*section)->offset(), (*section)->size());
+ pInput.fileOffset() + (*section)->offset(), (*section)->size());
const llvm::ELF::Elf32_Word* value =
reinterpret_cast<const llvm::ELF::Elf32_Word*>(region.begin());
size_t size = region.size() / sizeof(llvm::ELF::Elf32_Word);
if (llvm::ELF::GRP_COMDAT == *value) {
for (size_t index = 1; index < size; ++index) {
- pInput.context()->getSection(value[index])->setKind(LDFileFormat::Ignore);
+ pInput.context()->getSection(value[index])->setKind(
+ LDFileFormat::Ignore);
}
}
}
@@ -157,7 +153,8 @@ bool ELFObjectReader::readSections(Input& pInput)
case LDFileFormat::LinkOnce: {
bool exist = false;
// .gnu.linkonce + "." + type + "." + name
- llvm::StringRef name(llvm::StringRef((*section)->name()).drop_front(14));
+ llvm::StringRef name(
+ llvm::StringRef((*section)->name()).drop_front(14));
signatures().insert(name.split(".").second, exist);
if (!exist) {
if (name.startswith("wi")) {
@@ -185,10 +182,10 @@ bool ELFObjectReader::readSections(Input& pInput)
}
/** relocation sections **/
case LDFileFormat::Relocation: {
- assert(NULL != (*section)->getLink());
+ assert((*section)->getLink() != NULL);
size_t link_index = (*section)->getLink()->index();
LDSection* link_sect = pInput.context()->getSection(link_index);
- if (NULL == link_sect || LDFileFormat::Ignore == link_sect->kind()) {
+ if (link_sect == NULL || link_sect->kind() == LDFileFormat::Ignore) {
// Relocation sections of group members should also be part of the
// group. Thus, if the associated member sections are ignored, the
// related relocations should be also ignored.
@@ -211,11 +208,11 @@ bool ELFObjectReader::readSections(Input& pInput)
fatal(diag::err_cannot_read_section) << (*section)->name();
break;
}
- case LDFileFormat::Debug: {
+ case LDFileFormat::Debug:
+ case LDFileFormat::DebugString: {
if (m_Config.options().stripDebug()) {
(*section)->setKind(LDFileFormat::Ignore);
- }
- else {
+ } else {
SectionData* sd = IRBuilder::CreateSectionData(**section);
if (!m_pELFReader->readRegularSection(pInput, *sd)) {
fatal(diag::err_cannot_read_section) << (*section)->name();
@@ -234,8 +231,7 @@ bool ELFObjectReader::readSections(Input& pInput)
// .eh_frame.
m_ReadFlag ^= ParseEhFrame;
}
- }
- else {
+ } else {
if (!m_pELFReader->readRegularSection(pInput,
*eh_frame->getSectionData())) {
fatal(diag::err_cannot_read_section) << (*section)->name();
@@ -265,34 +261,30 @@ bool ELFObjectReader::readSections(Input& pInput)
// warning
case LDFileFormat::EhFrameHdr:
default: {
- warning(diag::warn_illegal_input_section) << (*section)->name()
- << pInput.name()
- << pInput.path();
+ warning(diag::warn_illegal_input_section)
+ << (*section)->name() << pInput.name() << pInput.path();
break;
}
}
- } // end of for all sections
+ } // end of for all sections
return true;
}
/// readSymbols - read symbols from the input relocatable object.
-bool ELFObjectReader::readSymbols(Input& pInput)
-{
+bool ELFObjectReader::readSymbols(Input& pInput) {
assert(pInput.hasMemArea());
LDSection* symtab_shdr = pInput.context()->getSection(".symtab");
- if (NULL == symtab_shdr) {
- note(diag::note_has_no_symtab) << pInput.name()
- << pInput.path()
+ if (symtab_shdr == NULL) {
+ note(diag::note_has_no_symtab) << pInput.name() << pInput.path()
<< ".symtab";
return true;
}
LDSection* strtab_shdr = symtab_shdr->getLink();
- if (NULL == strtab_shdr) {
- fatal(diag::fatal_cannot_read_strtab) << pInput.name()
- << pInput.path()
+ if (strtab_shdr == NULL) {
+ fatal(diag::fatal_cannot_read_strtab) << pInput.name() << pInput.path()
<< ".symtab";
return false;
}
@@ -302,15 +294,12 @@ bool ELFObjectReader::readSymbols(Input& pInput)
llvm::StringRef strtab_region = pInput.memArea()->request(
pInput.fileOffset() + strtab_shdr->offset(), strtab_shdr->size());
const char* strtab = strtab_region.begin();
- bool result = m_pELFReader->readSymbols(pInput,
- m_Builder,
- symtab_region,
- strtab);
+ bool result =
+ m_pELFReader->readSymbols(pInput, m_Builder, symtab_region, strtab);
return result;
}
-bool ELFObjectReader::readRelocations(Input& pInput)
-{
+bool ELFObjectReader::readRelocations(Input& pInput) {
assert(pInput.hasMemArea());
MemoryArea* mem = pInput.memArea();
@@ -322,7 +311,8 @@ bool ELFObjectReader::readRelocations(Input& pInput)
uint32_t offset = pInput.fileOffset() + (*rs)->offset();
uint32_t size = (*rs)->size();
llvm::StringRef region = mem->request(offset, size);
- IRBuilder::CreateRelocData(**rs); ///< create relocation data for the header
+ IRBuilder::CreateRelocData(
+ **rs); ///< create relocation data for the header
switch ((*rs)->type()) {
case llvm::ELF::SHT_RELA: {
if (!m_pELFReader->readRela(pInput, **rs, region)) {
@@ -336,13 +326,13 @@ bool ELFObjectReader::readRelocations(Input& pInput)
}
break;
}
- default: { ///< should not enter
+ default: { ///< should not enter
return false;
}
- } // end of switch
-
- } // end of for all relocation data
+ } // end of switch
+ } // end of for all relocation data
return true;
}
+} // namespace mcld
diff --git a/lib/LD/ELFObjectWriter.cpp b/lib/LD/ELFObjectWriter.cpp
index c90efdf..4d11132 100644
--- a/lib/LD/ELFObjectWriter.cpp
+++ b/lib/LD/ELFObjectWriter.cpp
@@ -6,121 +6,118 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFObjectWriter.h>
-
-#include <mcld/Module.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/ADT/SizeTraits.h>
-#include <mcld/Fragment/AlignFragment.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Fragment/Stub.h>
-#include <mcld/Fragment/NullFragment.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/Target/GNUInfo.h>
+#include "mcld/LD/ELFObjectWriter.h"
+
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/DebugString.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/GNUInfo.h"
+#include "mcld/Target/GNULDBackend.h"
+#include <llvm/Support/Casting.h>
+#include <llvm/Support/ELF.h>
#include <llvm/Support/Errc.h>
#include <llvm/Support/ErrorHandling.h>
-#include <llvm/Support/ELF.h>
-#include <llvm/Support/Casting.h>
-using namespace llvm;
-using namespace llvm::ELF;
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFObjectWriter
//===----------------------------------------------------------------------===//
ELFObjectWriter::ELFObjectWriter(GNULDBackend& pBackend,
const LinkerConfig& pConfig)
- : ObjectWriter(), m_Backend(pBackend), m_Config(pConfig)
-{
+ : ObjectWriter(), m_Backend(pBackend), m_Config(pConfig) {
}
-ELFObjectWriter::~ELFObjectWriter()
-{
+ELFObjectWriter::~ELFObjectWriter() {
}
void ELFObjectWriter::writeSection(Module& pModule,
- FileOutputBuffer& pOutput, LDSection *section)
-{
+ FileOutputBuffer& pOutput,
+ LDSection* section) {
MemoryRegion region;
// Request output region
switch (section->kind()) {
- case LDFileFormat::Note:
- if (section->getSectionData() == NULL)
- return;
+ case LDFileFormat::Note:
+ if (section->getSectionData() == NULL)
+ return;
// Fall through
- case LDFileFormat::TEXT:
- case LDFileFormat::DATA:
- case LDFileFormat::Relocation:
- case LDFileFormat::Target:
- case LDFileFormat::Debug:
- case LDFileFormat::GCCExceptTable:
- case LDFileFormat::EhFrame: {
- region = pOutput.request(section->offset(), section->size());
- if (region.size() == 0) {
- return;
+ case LDFileFormat::TEXT:
+ case LDFileFormat::DATA:
+ case LDFileFormat::Relocation:
+ case LDFileFormat::Target:
+ case LDFileFormat::Debug:
+ case LDFileFormat::DebugString:
+ case LDFileFormat::GCCExceptTable:
+ case LDFileFormat::EhFrame: {
+ region = pOutput.request(section->offset(), section->size());
+ if (region.size() == 0) {
+ return;
+ }
+ break;
}
- break;
- }
- case LDFileFormat::Null:
- case LDFileFormat::NamePool:
- case LDFileFormat::BSS:
- case LDFileFormat::MetaData:
- case LDFileFormat::Version:
- case LDFileFormat::EhFrameHdr:
- case LDFileFormat::StackNote:
- // Ignore these sections
- return;
- default:
- llvm::errs() << "WARNING: unsupported section kind: "
- << section->kind()
- << " of section "
- << section->name()
- << ".\n";
- return;
+ case LDFileFormat::Null:
+ case LDFileFormat::NamePool:
+ case LDFileFormat::BSS:
+ case LDFileFormat::MetaData:
+ case LDFileFormat::Version:
+ case LDFileFormat::EhFrameHdr:
+ case LDFileFormat::StackNote:
+ // Ignore these sections
+ return;
+ default:
+ llvm::errs() << "WARNING: unsupported section kind: " << section->kind()
+ << " of section " << section->name() << ".\n";
+ return;
}
// Write out sections with data
- switch(section->kind()) {
- case LDFileFormat::GCCExceptTable:
- case LDFileFormat::TEXT:
- case LDFileFormat::DATA:
- case LDFileFormat::Debug:
- case LDFileFormat::Note:
- emitSectionData(*section, region);
- break;
- case LDFileFormat::EhFrame:
- emitEhFrame(pModule, *section->getEhFrame(), region);
- break;
- case LDFileFormat::Relocation:
- // sort relocation for the benefit of the dynamic linker.
- target().sortRelocation(*section);
-
- emitRelocation(m_Config, *section, region);
- break;
- case LDFileFormat::Target:
- target().emitSectionData(*section, region);
- break;
- default:
- llvm_unreachable("invalid section kind");
+ switch (section->kind()) {
+ case LDFileFormat::GCCExceptTable:
+ case LDFileFormat::TEXT:
+ case LDFileFormat::DATA:
+ case LDFileFormat::Debug:
+ case LDFileFormat::Note:
+ emitSectionData(*section, region);
+ break;
+ case LDFileFormat::EhFrame:
+ emitEhFrame(pModule, *section->getEhFrame(), region);
+ break;
+ case LDFileFormat::Relocation:
+ // sort relocation for the benefit of the dynamic linker.
+ target().sortRelocation(*section);
+
+ emitRelocation(m_Config, *section, region);
+ break;
+ case LDFileFormat::Target:
+ target().emitSectionData(*section, region);
+ break;
+ case LDFileFormat::DebugString:
+ section->getDebugString()->emit(region);
+ break;
+ default:
+ llvm_unreachable("invalid section kind");
}
}
std::error_code ELFObjectWriter::writeObject(Module& pModule,
- FileOutputBuffer& pOutput)
-{
+ FileOutputBuffer& pOutput) {
bool is_dynobj = m_Config.codeGenType() == LinkerConfig::DynObj;
bool is_exec = m_Config.codeGenType() == LinkerConfig::Exec;
bool is_binary = m_Config.codeGenType() == LinkerConfig::Binary;
@@ -171,8 +168,7 @@ std::error_code ELFObjectWriter::writeObject(Module& pModule,
emitProgramHeader<32>(pOutput);
emitSectionHeader<32>(pModule, m_Config, pOutput);
- }
- else if (m_Config.targets().is64Bits()) {
+ } else if (m_Config.targets().is64Bits()) {
// Write out ELF header
// Write out section header table
writeELFHeader<64>(m_Config, pModule, pOutput);
@@ -180,17 +176,16 @@ std::error_code ELFObjectWriter::writeObject(Module& pModule,
emitProgramHeader<64>(pOutput);
emitSectionHeader<64>(pModule, m_Config, pOutput);
- }
- else
+ } else {
return llvm::make_error_code(llvm::errc::function_not_supported);
+ }
}
return std::error_code();
}
// getOutputSize - count the final output size
-size_t ELFObjectWriter::getOutputSize(const Module& pModule) const
-{
+size_t ELFObjectWriter::getOutputSize(const Module& pModule) const {
if (m_Config.targets().is32Bits()) {
return getLastStartOffset<32>(pModule) +
sizeof(ELFSizeTraits<32>::Shdr) * pModule.size();
@@ -204,66 +199,67 @@ size_t ELFObjectWriter::getOutputSize(const Module& pModule) const
}
// writeELFHeader - emit ElfXX_Ehdr
-template<size_t SIZE>
+template <size_t SIZE>
void ELFObjectWriter::writeELFHeader(const LinkerConfig& pConfig,
const Module& pModule,
- FileOutputBuffer& pOutput) const
-{
+ FileOutputBuffer& pOutput) const {
typedef typename ELFSizeTraits<SIZE>::Ehdr ElfXX_Ehdr;
typedef typename ELFSizeTraits<SIZE>::Shdr ElfXX_Shdr;
typedef typename ELFSizeTraits<SIZE>::Phdr ElfXX_Phdr;
// ELF header must start from 0x0
MemoryRegion region = pOutput.request(0, sizeof(ElfXX_Ehdr));
- ElfXX_Ehdr* header = (ElfXX_Ehdr*)region.begin();
+ ElfXX_Ehdr* header = reinterpret_cast<ElfXX_Ehdr*>(region.begin());
- memcpy(header->e_ident, ElfMagic, EI_MAG3+1);
+ memcpy(header->e_ident, llvm::ELF::ElfMagic, llvm::ELF::EI_MAG3 + 1);
- header->e_ident[EI_CLASS] = (SIZE == 32) ? ELFCLASS32 : ELFCLASS64;
- header->e_ident[EI_DATA] = pConfig.targets().isLittleEndian()?
- ELFDATA2LSB : ELFDATA2MSB;
- header->e_ident[EI_VERSION] = target().getInfo().ELFVersion();
- header->e_ident[EI_OSABI] = target().getInfo().OSABI();
- header->e_ident[EI_ABIVERSION] = target().getInfo().ABIVersion();
+ header->e_ident[llvm::ELF::EI_CLASS] =
+ (SIZE == 32) ? llvm::ELF::ELFCLASS32 : llvm::ELF::ELFCLASS64;
+ header->e_ident[llvm::ELF::EI_DATA] =
+ pConfig.targets().isLittleEndian()
+ ? llvm::ELF::ELFDATA2LSB : llvm::ELF::ELFDATA2MSB;
+ header->e_ident[llvm::ELF::EI_VERSION] = target().getInfo().ELFVersion();
+ header->e_ident[llvm::ELF::EI_OSABI] = target().getInfo().OSABI();
+ header->e_ident[llvm::ELF::EI_ABIVERSION] = target().getInfo().ABIVersion();
// FIXME: add processor-specific and core file types.
- switch(pConfig.codeGenType()) {
+ switch (pConfig.codeGenType()) {
case LinkerConfig::Object:
- header->e_type = ET_REL;
+ header->e_type = llvm::ELF::ET_REL;
break;
case LinkerConfig::DynObj:
- header->e_type = ET_DYN;
+ header->e_type = llvm::ELF::ET_DYN;
break;
case LinkerConfig::Exec:
- header->e_type = ET_EXEC;
+ header->e_type = llvm::ELF::ET_EXEC;
break;
default:
- llvm::errs() << "unspported output file type: " << pConfig.codeGenType() << ".\n";
- header->e_type = ET_NONE;
+ llvm::errs() << "unspported output file type: " << pConfig.codeGenType()
+ << ".\n";
+ header->e_type = llvm::ELF::ET_NONE;
}
- header->e_machine = target().getInfo().machine();
- header->e_version = header->e_ident[EI_VERSION];
- header->e_entry = getEntryPoint(pConfig, pModule);
+ header->e_machine = target().getInfo().machine();
+ header->e_version = header->e_ident[llvm::ELF::EI_VERSION];
+ header->e_entry = getEntryPoint(pConfig, pModule);
if (LinkerConfig::Object != pConfig.codeGenType())
- header->e_phoff = sizeof(ElfXX_Ehdr);
+ header->e_phoff = sizeof(ElfXX_Ehdr);
else
- header->e_phoff = 0x0;
+ header->e_phoff = 0x0;
- header->e_shoff = getLastStartOffset<SIZE>(pModule);
- header->e_flags = target().getInfo().flags();
- header->e_ehsize = sizeof(ElfXX_Ehdr);
+ header->e_shoff = getLastStartOffset<SIZE>(pModule);
+ header->e_flags = target().getInfo().flags();
+ header->e_ehsize = sizeof(ElfXX_Ehdr);
header->e_phentsize = sizeof(ElfXX_Phdr);
- header->e_phnum = target().elfSegmentTable().size();
+ header->e_phnum = target().elfSegmentTable().size();
header->e_shentsize = sizeof(ElfXX_Shdr);
- header->e_shnum = pModule.size();
- header->e_shstrndx = pModule.getSection(".shstrtab")->index();
+ header->e_shnum = pModule.size();
+ header->e_shstrndx = pModule.getSection(".shstrtab")->index();
}
/// getEntryPoint
uint64_t ELFObjectWriter::getEntryPoint(const LinkerConfig& pConfig,
- const Module& pModule) const
-{
+ const Module& pModule) const {
llvm::StringRef entry_name = target().getEntry(pModule);
uint64_t result = 0x0;
@@ -274,24 +270,21 @@ uint64_t ELFObjectWriter::getEntryPoint(const LinkerConfig& pConfig,
const LDSymbol* entry_symbol = pModule.getNamePool().findSymbol(entry_name);
// found the symbol
- if (NULL != entry_symbol) {
+ if (entry_symbol != NULL) {
if (entry_symbol->desc() != ResolveInfo::Define && issue_warning) {
- llvm::errs() << "WARNING: entry symbol '"
- << entry_symbol->name()
+ llvm::errs() << "WARNING: entry symbol '" << entry_symbol->name()
<< "' exists but is not defined.\n";
}
result = entry_symbol->value();
- }
- // not in the symbol pool
- else {
+ } else {
+ // not in the symbol pool
// We should parse entry as a number.
// @ref GNU ld manual, Options -e. e.g., -e 0x1000.
char* endptr;
result = strtoull(entry_name.data(), &endptr, 0);
if (*endptr != '\0') {
if (issue_warning) {
- llvm::errs() << "cannot find entry symbol '"
- << entry_name.data()
+ llvm::errs() << "cannot find entry symbol '" << entry_name.data()
<< "'.\n";
}
result = 0x0;
@@ -301,35 +294,34 @@ uint64_t ELFObjectWriter::getEntryPoint(const LinkerConfig& pConfig,
}
// emitSectionHeader - emit ElfXX_Shdr
-template<size_t SIZE>
+template <size_t SIZE>
void ELFObjectWriter::emitSectionHeader(const Module& pModule,
const LinkerConfig& pConfig,
- FileOutputBuffer& pOutput) const
-{
+ FileOutputBuffer& pOutput) const {
typedef typename ELFSizeTraits<SIZE>::Shdr ElfXX_Shdr;
// emit section header
unsigned int sectNum = pModule.size();
unsigned int header_size = sizeof(ElfXX_Shdr) * sectNum;
- MemoryRegion region = pOutput.request(getLastStartOffset<SIZE>(pModule),
- header_size);
- ElfXX_Shdr* shdr = (ElfXX_Shdr*)region.begin();
+ MemoryRegion region =
+ pOutput.request(getLastStartOffset<SIZE>(pModule), header_size);
+ ElfXX_Shdr* shdr = reinterpret_cast<ElfXX_Shdr*>(region.begin());
// Iterate the SectionTable in LDContext
unsigned int sectIdx = 0;
- unsigned int shstridx = 0; // NULL section has empty name
+ unsigned int shstridx = 0; // NULL section has empty name
for (; sectIdx < sectNum; ++sectIdx) {
- const LDSection *ld_sect = pModule.getSectionTable().at(sectIdx);
- shdr[sectIdx].sh_name = shstridx;
- shdr[sectIdx].sh_type = ld_sect->type();
- shdr[sectIdx].sh_flags = ld_sect->flag();
- shdr[sectIdx].sh_addr = ld_sect->addr();
- shdr[sectIdx].sh_offset = ld_sect->offset();
- shdr[sectIdx].sh_size = ld_sect->size();
+ const LDSection* ld_sect = pModule.getSectionTable().at(sectIdx);
+ shdr[sectIdx].sh_name = shstridx;
+ shdr[sectIdx].sh_type = ld_sect->type();
+ shdr[sectIdx].sh_flags = ld_sect->flag();
+ shdr[sectIdx].sh_addr = ld_sect->addr();
+ shdr[sectIdx].sh_offset = ld_sect->offset();
+ shdr[sectIdx].sh_size = ld_sect->size();
shdr[sectIdx].sh_addralign = ld_sect->align();
- shdr[sectIdx].sh_entsize = getSectEntrySize<SIZE>(*ld_sect);
- shdr[sectIdx].sh_link = getSectLink(*ld_sect, pConfig);
- shdr[sectIdx].sh_info = getSectInfo(*ld_sect);
+ shdr[sectIdx].sh_entsize = getSectEntrySize<SIZE>(*ld_sect);
+ shdr[sectIdx].sh_link = getSectLink(*ld_sect, pConfig);
+ shdr[sectIdx].sh_info = getSectInfo(*ld_sect);
// adjust strshidx
shstridx += ld_sect->name().size() + 1;
@@ -337,9 +329,8 @@ void ELFObjectWriter::emitSectionHeader(const Module& pModule,
}
// emitProgramHeader - emit ElfXX_Phdr
-template<size_t SIZE>
-void ELFObjectWriter::emitProgramHeader(FileOutputBuffer& pOutput) const
-{
+template <size_t SIZE>
+void ELFObjectWriter::emitProgramHeader(FileOutputBuffer& pOutput) const {
typedef typename ELFSizeTraits<SIZE>::Ehdr ElfXX_Ehdr;
typedef typename ELFSizeTraits<SIZE>::Phdr ElfXX_Phdr;
@@ -348,49 +339,47 @@ void ELFObjectWriter::emitProgramHeader(FileOutputBuffer& pOutput) const
start_offset = sizeof(ElfXX_Ehdr);
phdr_size = sizeof(ElfXX_Phdr);
// Program header must start directly after ELF header
- MemoryRegion region = pOutput.request(start_offset,
- target().elfSegmentTable().size() * phdr_size);
+ MemoryRegion region = pOutput.request(
+ start_offset, target().elfSegmentTable().size() * phdr_size);
- ElfXX_Phdr* phdr = (ElfXX_Phdr*)region.begin();
+ ElfXX_Phdr* phdr = reinterpret_cast<ElfXX_Phdr*>(region.begin());
// Iterate the elf segment table in GNULDBackend
size_t index = 0;
ELFSegmentFactory::const_iterator seg = target().elfSegmentTable().begin(),
- segEnd = target().elfSegmentTable().end();
+ segEnd = target().elfSegmentTable().end();
for (; seg != segEnd; ++seg, ++index) {
- phdr[index].p_type = (*seg)->type();
- phdr[index].p_flags = (*seg)->flag();
+ phdr[index].p_type = (*seg)->type();
+ phdr[index].p_flags = (*seg)->flag();
phdr[index].p_offset = (*seg)->offset();
- phdr[index].p_vaddr = (*seg)->vaddr();
- phdr[index].p_paddr = (*seg)->paddr();
+ phdr[index].p_vaddr = (*seg)->vaddr();
+ phdr[index].p_paddr = (*seg)->paddr();
phdr[index].p_filesz = (*seg)->filesz();
- phdr[index].p_memsz = (*seg)->memsz();
- phdr[index].p_align = (*seg)->align();
+ phdr[index].p_memsz = (*seg)->memsz();
+ phdr[index].p_align = (*seg)->align();
}
}
/// emitShStrTab - emit section string table
-void
-ELFObjectWriter::emitShStrTab(const LDSection& pShStrTab,
- const Module& pModule,
- FileOutputBuffer& pOutput)
-{
+void ELFObjectWriter::emitShStrTab(const LDSection& pShStrTab,
+ const Module& pModule,
+ FileOutputBuffer& pOutput) {
// write out data
MemoryRegion region = pOutput.request(pShStrTab.offset(), pShStrTab.size());
- char* data = (char*)region.begin();
+ char* data = reinterpret_cast<char*>(region.begin());
size_t shstrsize = 0;
Module::const_iterator section, sectEnd = pModule.end();
for (section = pModule.begin(); section != sectEnd; ++section) {
- strcpy((char*)(data + shstrsize), (*section)->name().data());
+ ::memcpy(reinterpret_cast<char*>(data + shstrsize),
+ (*section)->name().data(),
+ (*section)->name().size());
shstrsize += (*section)->name().size() + 1;
}
}
/// emitSectionData
-void
-ELFObjectWriter::emitSectionData(const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+void ELFObjectWriter::emitSectionData(const LDSection& pSection,
+ MemoryRegion& pRegion) const {
const SectionData* sd = NULL;
switch (pSection.kind()) {
case LDFileFormat::Relocation:
@@ -410,21 +399,22 @@ ELFObjectWriter::emitSectionData(const LDSection& pSection,
/// emitEhFrame
void ELFObjectWriter::emitEhFrame(Module& pModule,
- EhFrame& pFrame, MemoryRegion& pRegion) const
-{
+ EhFrame& pFrame,
+ MemoryRegion& pRegion) const {
emitSectionData(*pFrame.getSectionData(), pRegion);
// Patch FDE field (offset to CIE)
for (EhFrame::cie_iterator i = pFrame.cie_begin(), e = pFrame.cie_end();
- i != e; ++i) {
+ i != e;
+ ++i) {
EhFrame::CIE& cie = **i;
- for (EhFrame::fde_iterator fi = cie.begin(), fe = cie.end();
- fi != fe; ++fi) {
+ for (EhFrame::fde_iterator fi = cie.begin(), fe = cie.end(); fi != fe;
+ ++fi) {
EhFrame::FDE& fde = **fi;
if (fde.getRecordType() == EhFrame::RECORD_GENERATED) {
// Patch PLT offset
LDSection* plt_sect = pModule.getSection(".plt");
- assert (plt_sect && "We have no plt but have corresponding eh_frame?");
+ assert(plt_sect && "We have no plt but have corresponding eh_frame?");
uint64_t plt_offset = plt_sect->offset();
// FDE entry for PLT is always 32-bit
uint64_t fde_offset = pFrame.getSection().offset() + fde.getOffset() +
@@ -433,34 +423,35 @@ void ELFObjectWriter::emitEhFrame(Module& pModule,
if (plt_offset < fde_offset)
offset = -offset;
memcpy(pRegion.begin() + fde.getOffset() +
- EhFrame::getDataStartOffset<32>(),
- &offset, 4);
+ EhFrame::getDataStartOffset<32>(),
+ &offset,
+ 4);
uint32_t size = plt_sect->size();
memcpy(pRegion.begin() + fde.getOffset() +
- EhFrame::getDataStartOffset<32>() + 4,
- &size, 4);
+ EhFrame::getDataStartOffset<32>() + 4,
+ &size,
+ 4);
}
uint64_t fde_cie_ptr_offset = fde.getOffset() +
EhFrame::getDataStartOffset<32>() -
- /*ID*/4;
+ /*ID*/ 4;
uint64_t cie_start_offset = cie.getOffset();
int32_t offset = fde_cie_ptr_offset - cie_start_offset;
if (fde_cie_ptr_offset < cie_start_offset)
offset = -offset;
memcpy(pRegion.begin() + fde_cie_ptr_offset, &offset, 4);
- } // for loop fde_iterator
- } // for loop cie_iterator
+ } // for loop fde_iterator
+ } // for loop cie_iterator
}
/// emitRelocation
void ELFObjectWriter::emitRelocation(const LinkerConfig& pConfig,
const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
const RelocData* sect_data = pSection.getRelocData();
- assert(NULL != sect_data && "SectionData is NULL in emitRelocation!");
+ assert(sect_data != NULL && "SectionData is NULL in emitRelocation!");
- if (pSection.type() == SHT_REL) {
+ if (pSection.type() == llvm::ELF::SHT_REL) {
if (pConfig.targets().is32Bits())
emitRel<32>(pConfig, *sect_data, pRegion);
else if (pConfig.targets().is64Bits())
@@ -469,7 +460,7 @@ void ELFObjectWriter::emitRelocation(const LinkerConfig& pConfig,
fatal(diag::unsupported_bitclass) << pConfig.targets().triple().str()
<< pConfig.targets().bitclass();
}
- } else if (pSection.type() == SHT_RELA) {
+ } else if (pSection.type() == llvm::ELF::SHT_RELA) {
if (pConfig.targets().is32Bits())
emitRela<32>(pConfig, *sect_data, pRegion);
else if (pConfig.targets().is64Bits())
@@ -482,14 +473,12 @@ void ELFObjectWriter::emitRelocation(const LinkerConfig& pConfig,
llvm::report_fatal_error("unsupported relocation section type!");
}
-
// emitRel - emit ElfXX_Rel
-template<size_t SIZE>
+template <size_t SIZE>
void ELFObjectWriter::emitRel(const LinkerConfig& pConfig,
const RelocData& pRelocData,
- MemoryRegion& pRegion) const
-{
- typedef typename ELFSizeTraits<SIZE>::Rel ElfXX_Rel;
+ MemoryRegion& pRegion) const {
+ typedef typename ELFSizeTraits<SIZE>::Rel ElfXX_Rel;
typedef typename ELFSizeTraits<SIZE>::Addr ElfXX_Addr;
typedef typename ELFSizeTraits<SIZE>::Word ElfXX_Word;
@@ -498,40 +487,39 @@ void ELFObjectWriter::emitRel(const LinkerConfig& pConfig,
const Relocation* relocation = 0;
const FragmentRef* frag_ref = 0;
- for (RelocData::const_iterator it = pRelocData.begin(),
- ie = pRelocData.end(); it != ie; ++it, ++rel) {
+ for (RelocData::const_iterator it = pRelocData.begin(), ie = pRelocData.end();
+ it != ie;
+ ++it, ++rel) {
ElfXX_Addr r_offset = 0;
ElfXX_Word r_sym = 0;
relocation = &(llvm::cast<Relocation>(*it));
frag_ref = &(relocation->targetRef());
- if(LinkerConfig::DynObj == pConfig.codeGenType() ||
- LinkerConfig::Exec == pConfig.codeGenType()) {
+ if (LinkerConfig::DynObj == pConfig.codeGenType() ||
+ LinkerConfig::Exec == pConfig.codeGenType()) {
r_offset = static_cast<ElfXX_Addr>(
- frag_ref->frag()->getParent()->getSection().addr() +
- frag_ref->getOutputOffset());
- }
- else {
+ frag_ref->frag()->getParent()->getSection().addr() +
+ frag_ref->getOutputOffset());
+ } else {
r_offset = static_cast<ElfXX_Addr>(frag_ref->getOutputOffset());
}
- if( relocation->symInfo() == NULL )
+ if (relocation->symInfo() == NULL)
r_sym = 0;
else
r_sym = static_cast<ElfXX_Word>(
- target().getSymbolIdx(relocation->symInfo()->outSymbol()));
+ target().getSymbolIdx(relocation->symInfo()->outSymbol()));
target().emitRelocation(*rel, relocation->type(), r_sym, r_offset);
}
}
// emitRela - emit ElfXX_Rela
-template<size_t SIZE>
+template <size_t SIZE>
void ELFObjectWriter::emitRela(const LinkerConfig& pConfig,
const RelocData& pRelocData,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
typedef typename ELFSizeTraits<SIZE>::Rela ElfXX_Rela;
typedef typename ELFSizeTraits<SIZE>::Addr ElfXX_Addr;
typedef typename ELFSizeTraits<SIZE>::Word ElfXX_Word;
@@ -541,45 +529,43 @@ void ELFObjectWriter::emitRela(const LinkerConfig& pConfig,
const Relocation* relocation = 0;
const FragmentRef* frag_ref = 0;
- for (RelocData::const_iterator it = pRelocData.begin(),
- ie = pRelocData.end(); it != ie; ++it, ++rel) {
+ for (RelocData::const_iterator it = pRelocData.begin(), ie = pRelocData.end();
+ it != ie;
+ ++it, ++rel) {
ElfXX_Addr r_offset = 0;
ElfXX_Word r_sym = 0;
relocation = &(llvm::cast<Relocation>(*it));
frag_ref = &(relocation->targetRef());
- if(LinkerConfig::DynObj == pConfig.codeGenType() ||
- LinkerConfig::Exec == pConfig.codeGenType()) {
+ if (LinkerConfig::DynObj == pConfig.codeGenType() ||
+ LinkerConfig::Exec == pConfig.codeGenType()) {
r_offset = static_cast<ElfXX_Addr>(
- frag_ref->frag()->getParent()->getSection().addr() +
- frag_ref->getOutputOffset());
- }
- else {
+ frag_ref->frag()->getParent()->getSection().addr() +
+ frag_ref->getOutputOffset());
+ } else {
r_offset = static_cast<ElfXX_Addr>(frag_ref->getOutputOffset());
}
- if( relocation->symInfo() == NULL )
+ if (relocation->symInfo() == NULL)
r_sym = 0;
else
r_sym = static_cast<ElfXX_Word>(
- target().getSymbolIdx(relocation->symInfo()->outSymbol()));
+ target().getSymbolIdx(relocation->symInfo()->outSymbol()));
- target().emitRelocation(*rel, relocation->type(),
- r_sym, r_offset, relocation->addend());
+ target().emitRelocation(
+ *rel, relocation->type(), r_sym, r_offset, relocation->addend());
}
}
-
/// getSectEntrySize - compute ElfXX_Shdr::sh_entsize
-template<size_t SIZE>
-uint64_t ELFObjectWriter::getSectEntrySize(const LDSection& pSection) const
-{
+template <size_t SIZE>
+uint64_t ELFObjectWriter::getSectEntrySize(const LDSection& pSection) const {
typedef typename ELFSizeTraits<SIZE>::Word ElfXX_Word;
- typedef typename ELFSizeTraits<SIZE>::Sym ElfXX_Sym;
- typedef typename ELFSizeTraits<SIZE>::Rel ElfXX_Rel;
+ typedef typename ELFSizeTraits<SIZE>::Sym ElfXX_Sym;
+ typedef typename ELFSizeTraits<SIZE>::Rel ElfXX_Rel;
typedef typename ELFSizeTraits<SIZE>::Rela ElfXX_Rela;
- typedef typename ELFSizeTraits<SIZE>::Dyn ElfXX_Dyn;
+ typedef typename ELFSizeTraits<SIZE>::Dyn ElfXX_Dyn;
if (llvm::ELF::SHT_DYNSYM == pSection.type() ||
llvm::ELF::SHT_SYMTAB == pSection.type())
@@ -588,7 +574,7 @@ uint64_t ELFObjectWriter::getSectEntrySize(const LDSection& pSection) const
return sizeof(ElfXX_Rel);
if (llvm::ELF::SHT_RELA == pSection.type())
return sizeof(ElfXX_Rela);
- if (llvm::ELF::SHT_HASH == pSection.type() ||
+ if (llvm::ELF::SHT_HASH == pSection.type() ||
llvm::ELF::SHT_GNU_HASH == pSection.type())
return sizeof(ElfXX_Word);
if (llvm::ELF::SHT_DYNAMIC == pSection.type())
@@ -604,15 +590,14 @@ uint64_t ELFObjectWriter::getSectEntrySize(const LDSection& pSection) const
/// getSectLink - compute ElfXX_Shdr::sh_link
uint64_t ELFObjectWriter::getSectLink(const LDSection& pSection,
- const LinkerConfig& pConfig) const
-{
+ const LinkerConfig& pConfig) const {
if (llvm::ELF::SHT_SYMTAB == pSection.type())
return target().getOutputFormat()->getStrTab().index();
if (llvm::ELF::SHT_DYNSYM == pSection.type())
return target().getOutputFormat()->getDynStrTab().index();
if (llvm::ELF::SHT_DYNAMIC == pSection.type())
return target().getOutputFormat()->getDynStrTab().index();
- if (llvm::ELF::SHT_HASH == pSection.type() ||
+ if (llvm::ELF::SHT_HASH == pSection.type() ||
llvm::ELF::SHT_GNU_HASH == pSection.type())
return target().getOutputFormat()->getDynSymTab().index();
if (llvm::ELF::SHT_REL == pSection.type() ||
@@ -629,8 +614,7 @@ uint64_t ELFObjectWriter::getSectLink(const LDSection& pSection,
}
/// getSectInfo - compute ElfXX_Shdr::sh_info
-uint64_t ELFObjectWriter::getSectInfo(const LDSection& pSection) const
-{
+uint64_t ELFObjectWriter::getSectInfo(const LDSection& pSection) const {
if (llvm::ELF::SHT_SYMTAB == pSection.type() ||
llvm::ELF::SHT_DYNSYM == pSection.type())
return pSection.getInfo();
@@ -638,7 +622,7 @@ uint64_t ELFObjectWriter::getSectInfo(const LDSection& pSection) const
if (llvm::ELF::SHT_REL == pSection.type() ||
llvm::ELF::SHT_RELA == pSection.type()) {
const LDSection* info_link = pSection.getLink();
- if (NULL != info_link)
+ if (info_link != NULL)
return info_link->index();
}
@@ -646,18 +630,16 @@ uint64_t ELFObjectWriter::getSectInfo(const LDSection& pSection) const
}
/// getLastStartOffset
-template<>
-uint64_t ELFObjectWriter::getLastStartOffset<32>(const Module& pModule) const
-{
+template <>
+uint64_t ELFObjectWriter::getLastStartOffset<32>(const Module& pModule) const {
const LDSection* lastSect = pModule.back();
assert(lastSect != NULL);
return Align<32>(lastSect->offset() + lastSect->size());
}
/// getLastStartOffset
-template<>
-uint64_t ELFObjectWriter::getLastStartOffset<64>(const Module& pModule) const
-{
+template <>
+uint64_t ELFObjectWriter::getLastStartOffset<64>(const Module& pModule) const {
const LDSection* lastSect = pModule.back();
assert(lastSect != NULL);
return Align<64>(lastSect->offset() + lastSect->size());
@@ -665,15 +647,15 @@ uint64_t ELFObjectWriter::getLastStartOffset<64>(const Module& pModule) const
/// emitSectionData
void ELFObjectWriter::emitSectionData(const SectionData& pSD,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
SectionData::const_iterator fragIter, fragEnd = pSD.end();
size_t cur_offset = 0;
for (fragIter = pSD.begin(); fragIter != fragEnd; ++fragIter) {
size_t size = fragIter->size();
- switch(fragIter->getKind()) {
+ switch (fragIter->getKind()) {
case Fragment::Region: {
- const RegionFragment& region_frag = llvm::cast<RegionFragment>(*fragIter);
+ const RegionFragment& region_frag =
+ llvm::cast<RegionFragment>(*fragIter);
const char* from = region_frag.getRegion().begin();
memcpy(pRegion.begin() + cur_offset, from, size);
break;
@@ -684,20 +666,19 @@ void ELFObjectWriter::emitSectionData(const SectionData& pSD,
uint64_t count = size / align_frag.getValueSize();
switch (align_frag.getValueSize()) {
case 1u:
- std::memset(pRegion.begin() + cur_offset,
- align_frag.getValue(),
- count);
+ std::memset(
+ pRegion.begin() + cur_offset, align_frag.getValue(), count);
break;
default:
- llvm::report_fatal_error("unsupported value size for align fragment emission yet.\n");
+ llvm::report_fatal_error(
+ "unsupported value size for align fragment emission yet.\n");
break;
}
break;
}
case Fragment::Fillment: {
const FillFragment& fill_frag = llvm::cast<FillFragment>(*fragIter);
- if (0 == size ||
- 0 == fill_frag.getValueSize() ||
+ if (0 == size || 0 == fill_frag.getValueSize() ||
0 == fill_frag.size()) {
// ignore virtual fillment
break;
@@ -721,13 +702,16 @@ void ELFObjectWriter::emitSectionData(const SectionData& pSD,
break;
}
case Fragment::Target:
- llvm::report_fatal_error("Target fragment should not be in a regular section.\n");
+ llvm::report_fatal_error(
+ "Target fragment should not be in a regular section.\n");
break;
default:
- llvm::report_fatal_error("invalid fragment should not be in a regular section.\n");
+ llvm::report_fatal_error(
+ "invalid fragment should not be in a regular section.\n");
break;
}
cur_offset += size;
}
}
+} // namespace mcld
diff --git a/lib/LD/ELFReader.cpp b/lib/LD/ELFReader.cpp
index 119f8a7..526d2ad 100644
--- a/lib/LD/ELFReader.cpp
+++ b/lib/LD/ELFReader.cpp
@@ -6,19 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFReader.h>
-
-#include <mcld/IRBuilder.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Target/GNUInfo.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Object/ObjectBuilder.h>
-
-#include <cstring>
+#include "mcld/LD/ELFReader.h"
+
+#include "mcld/IRBuilder.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/GNUInfo.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/Twine.h>
@@ -27,35 +26,33 @@
#include <iostream>
-using namespace mcld;
+#include <cstring>
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFReader<32, true>
//===----------------------------------------------------------------------===//
/// constructor
-ELFReader<32, true>::ELFReader(GNULDBackend& pBackend)
- : ELFReaderIF(pBackend) {
+ELFReader<32, true>::ELFReader(GNULDBackend& pBackend) : ELFReaderIF(pBackend) {
}
/// destructor
-ELFReader<32, true>::~ELFReader()
-{
+ELFReader<32, true>::~ELFReader() {
}
/// isELF - is this a ELF file
-bool ELFReader<32, true>::isELF(const void* pELFHeader) const
-{
+bool ELFReader<32, true>::isELF(const void* pELFHeader) const {
const llvm::ELF::Elf32_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf32_Ehdr*>(pELFHeader);
- if (0 == memcmp(llvm::ELF::ElfMagic, hdr, 4))
+ if (memcmp(llvm::ELF::ElfMagic, hdr, 4) == 0)
return true;
return false;
}
/// readRegularSection - read a regular section and create fragments.
-bool
-ELFReader<32, true>::readRegularSection(Input& pInput, SectionData& pSD) const
-{
+bool ELFReader<32, true>::readRegularSection(Input& pInput,
+ SectionData& pSD) const {
uint32_t offset = pInput.fileOffset() + pSD.getSection().offset();
uint32_t size = pSD.getSection().size();
@@ -68,18 +65,17 @@ ELFReader<32, true>::readRegularSection(Input& pInput, SectionData& pSD) const
bool ELFReader<32, true>::readSymbols(Input& pInput,
IRBuilder& pBuilder,
llvm::StringRef pRegion,
- const char* pStrTab) const
-{
+ const char* pStrTab) const {
// get number of symbols
- size_t entsize = pRegion.size()/sizeof(llvm::ELF::Elf32_Sym);
+ size_t entsize = pRegion.size() / sizeof(llvm::ELF::Elf32_Sym);
const llvm::ELF::Elf32_Sym* symtab =
reinterpret_cast<const llvm::ELF::Elf32_Sym*>(pRegion.begin());
- uint32_t st_name = 0x0;
+ uint32_t st_name = 0x0;
uint32_t st_value = 0x0;
- uint32_t st_size = 0x0;
- uint8_t st_info = 0x0;
- uint8_t st_other = 0x0;
+ uint32_t st_size = 0x0;
+ uint8_t st_info = 0x0;
+ uint8_t st_other = 0x0;
uint16_t st_shndx = 0x0;
// skip the first NULL symbol
@@ -87,30 +83,28 @@ bool ELFReader<32, true>::readSymbols(Input& pInput,
/// recording symbols added from DynObj to analyze weak alias
std::vector<AliasInfo> potential_aliases;
- bool is_dyn_obj = (pInput.type()==Input::DynObj);
+ bool is_dyn_obj = (pInput.type() == Input::DynObj);
for (size_t idx = 1; idx < entsize; ++idx) {
- st_info = symtab[idx].st_info;
+ st_info = symtab[idx].st_info;
st_other = symtab[idx].st_other;
if (llvm::sys::IsLittleEndianHost) {
- st_name = symtab[idx].st_name;
+ st_name = symtab[idx].st_name;
st_value = symtab[idx].st_value;
- st_size = symtab[idx].st_size;
+ st_size = symtab[idx].st_size;
st_shndx = symtab[idx].st_shndx;
- }
- else {
- st_name = mcld::bswap32(symtab[idx].st_name);
+ } else {
+ st_name = mcld::bswap32(symtab[idx].st_name);
st_value = mcld::bswap32(symtab[idx].st_value);
- st_size = mcld::bswap32(symtab[idx].st_size);
+ st_size = mcld::bswap32(symtab[idx].st_size);
st_shndx = mcld::bswap16(symtab[idx].st_shndx);
}
// If the section should not be included, set the st_shndx SHN_UNDEF
// - A section in interrelated groups are not included.
- if (pInput.type() == Input::Object &&
- st_shndx < llvm::ELF::SHN_LORESERVE &&
+ if (pInput.type() == Input::Object && st_shndx < llvm::ELF::SHN_LORESERVE &&
st_shndx != llvm::ELF::SHN_UNDEF) {
- if (NULL == pInput.context()->getSection(st_shndx))
+ if (pInput.context()->getSection(st_shndx) == NULL)
st_shndx = llvm::ELF::SHN_UNDEF;
}
@@ -121,7 +115,8 @@ bool ELFReader<32, true>::readSymbols(Input& pInput,
ResolveInfo::Desc ld_desc = getSymDesc(st_shndx, pInput);
// get ld_binding
- ResolveInfo::Binding ld_binding = getSymBinding((st_info >> 4), st_shndx, st_other);
+ ResolveInfo::Binding ld_binding =
+ getSymBinding((st_info >> 4), st_shndx, st_other);
// get ld_value - ld_value must be section relative.
uint64_t ld_value = getSymValue(st_value, st_shndx, pInput);
@@ -131,17 +126,16 @@ bool ELFReader<32, true>::readSymbols(Input& pInput,
// get section
LDSection* section = NULL;
- if (st_shndx < llvm::ELF::SHN_LORESERVE) // including ABS and COMMON
+ if (st_shndx < llvm::ELF::SHN_LORESERVE) // including ABS and COMMON
section = pInput.context()->getSection(st_shndx);
// get ld_name
std::string ld_name;
if (ResolveInfo::Section == ld_type) {
// Section symbol's st_name is the section index.
- assert(NULL != section && "get a invalid section");
+ assert(section != NULL && "get a invalid section");
ld_name = section->name();
- }
- else {
+ } else {
ld_name = std::string(pStrTab + st_name);
}
@@ -155,20 +149,17 @@ bool ELFReader<32, true>::readSymbols(Input& pInput,
section,
ld_vis);
- if (is_dyn_obj
- && NULL != psym
- && ResolveInfo::Undefined != ld_desc
- && (ResolveInfo::Global == ld_binding ||
- ResolveInfo::Weak == ld_binding)
- && ResolveInfo::Object == ld_type) {
+ if (is_dyn_obj && psym != NULL && ResolveInfo::Undefined != ld_desc &&
+ (ResolveInfo::Global == ld_binding ||
+ ResolveInfo::Weak == ld_binding) &&
+ ResolveInfo::Object == ld_type) {
AliasInfo p;
p.pt_alias = psym;
p.ld_binding = ld_binding;
p.ld_value = ld_value;
potential_aliases.push_back(p);
}
-
- } // end of for loop
+ } // end of for loop
// analyze weak alias
// FIXME: it is better to let IRBuilder handle alias anlysis.
@@ -183,13 +174,13 @@ bool ELFReader<32, true>::readSymbols(Input& pInput,
// then link them as a circular list in Module
std::vector<AliasInfo>::iterator sym_it, sym_e;
sym_e = potential_aliases.end();
- for (sym_it = potential_aliases.begin(); sym_it!=sym_e; ++sym_it) {
- if (ResolveInfo::Weak!=sym_it->ld_binding)
+ for (sym_it = potential_aliases.begin(); sym_it != sym_e; ++sym_it) {
+ if (ResolveInfo::Weak != sym_it->ld_binding)
continue;
Module& pModule = pBuilder.getModule();
- std::vector<AliasInfo>::iterator alias_it = sym_it+1;
- while(alias_it!=sym_e) {
+ std::vector<AliasInfo>::iterator alias_it = sym_it + 1;
+ while (alias_it != sym_e) {
if (sym_it->ld_value != alias_it->ld_value)
break;
@@ -200,7 +191,7 @@ bool ELFReader<32, true>::readSymbols(Input& pInput,
}
sym_it = alias_it - 1;
- }// end of for loop
+ } // end of for loop
}
return true;
@@ -212,42 +203,42 @@ bool ELFReader<32, true>::readSymbols(Input& pInput,
/// ELFReader::readRela - read ELF rela and create Relocation
bool ELFReader<32, true>::readRela(Input& pInput,
LDSection& pSection,
- llvm::StringRef pRegion) const
-{
+ llvm::StringRef pRegion) const {
// get the number of rela
size_t entsize = pRegion.size() / sizeof(llvm::ELF::Elf32_Rela);
const llvm::ELF::Elf32_Rela* relaTab =
reinterpret_cast<const llvm::ELF::Elf32_Rela*>(pRegion.begin());
- for (size_t idx=0; idx < entsize; ++idx) {
+ for (size_t idx = 0; idx < entsize; ++idx) {
Relocation::Type r_type = 0x0;
uint32_t r_sym = 0x0;
uint32_t r_offset = 0x0;
- int32_t r_addend = 0;
- if (!target().readRelocation(relaTab[idx], r_type, r_sym, r_offset, r_addend))
+ int32_t r_addend = 0;
+ if (!target()
+ .readRelocation(relaTab[idx], r_type, r_sym, r_offset, r_addend)) {
return false;
+ }
LDSymbol* symbol = pInput.context()->getSymbol(r_sym);
- if (NULL == symbol) {
+ if (symbol == NULL) {
fatal(diag::err_cannot_read_symbol) << r_sym << pInput.path();
}
IRBuilder::AddRelocation(pSection, r_type, *symbol, r_offset, r_addend);
- } // end of for
+ } // end of for
return true;
}
/// readRel - read ELF rel and create Relocation
bool ELFReader<32, true>::readRel(Input& pInput,
LDSection& pSection,
- llvm::StringRef pRegion) const
-{
+ llvm::StringRef pRegion) const {
// get the number of rel
size_t entsize = pRegion.size() / sizeof(llvm::ELF::Elf32_Rel);
const llvm::ELF::Elf32_Rel* relTab =
reinterpret_cast<const llvm::ELF::Elf32_Rel*>(pRegion.begin());
- for (size_t idx=0; idx < entsize; ++idx) {
+ for (size_t idx = 0; idx < entsize; ++idx) {
Relocation::Type r_type = 0x0;
uint32_t r_sym = 0x0;
uint32_t r_offset = 0x0;
@@ -256,18 +247,17 @@ bool ELFReader<32, true>::readRel(Input& pInput,
return false;
LDSymbol* symbol = pInput.context()->getSymbol(r_sym);
- if (NULL == symbol) {
+ if (symbol == NULL) {
fatal(diag::err_cannot_read_symbol) << r_sym << pInput.path();
}
IRBuilder::AddRelocation(pSection, r_type, *symbol, r_offset);
- } // end of for
+ } // end of for
return true;
}
/// isMyEndian - is this ELF file in the same endian to me?
-bool ELFReader<32, true>::isMyEndian(const void* pELFHeader) const
-{
+bool ELFReader<32, true>::isMyEndian(const void* pELFHeader) const {
const llvm::ELF::Elf32_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf32_Ehdr*>(pELFHeader);
@@ -275,8 +265,7 @@ bool ELFReader<32, true>::isMyEndian(const void* pELFHeader) const
}
/// isMyMachine - is this ELF file generated for the same machine.
-bool ELFReader<32, true>::isMyMachine(const void* pELFHeader) const
-{
+bool ELFReader<32, true>::isMyMachine(const void* pELFHeader) const {
const llvm::ELF::Elf32_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf32_Ehdr*>(pELFHeader);
@@ -286,8 +275,7 @@ bool ELFReader<32, true>::isMyMachine(const void* pELFHeader) const
}
/// fileType - return the file type
-Input::Type ELFReader<32, true>::fileType(const void* pELFHeader) const
-{
+Input::Type ELFReader<32, true>::fileType(const void* pELFHeader) const {
const llvm::ELF::Elf32_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf32_Ehdr*>(pELFHeader);
uint32_t type = 0x0;
@@ -296,72 +284,69 @@ Input::Type ELFReader<32, true>::fileType(const void* pELFHeader) const
else
type = mcld::bswap16(hdr->e_type);
- switch(type) {
- case llvm::ELF::ET_REL:
- return Input::Object;
- case llvm::ELF::ET_EXEC:
- return Input::Exec;
- case llvm::ELF::ET_DYN:
- return Input::DynObj;
- case llvm::ELF::ET_CORE:
- return Input::CoreFile;
- case llvm::ELF::ET_NONE:
- default:
- return Input::Unknown;
+ switch (type) {
+ case llvm::ELF::ET_REL:
+ return Input::Object;
+ case llvm::ELF::ET_EXEC:
+ return Input::Exec;
+ case llvm::ELF::ET_DYN:
+ return Input::DynObj;
+ case llvm::ELF::ET_CORE:
+ return Input::CoreFile;
+ case llvm::ELF::ET_NONE:
+ default:
+ return Input::Unknown;
}
}
/// readSectionHeaders - read ELF section header table and create LDSections
bool ELFReader<32, true>::readSectionHeaders(Input& pInput,
- const void* pELFHeader) const
-{
+ const void* pELFHeader) const {
const llvm::ELF::Elf32_Ehdr* ehdr =
reinterpret_cast<const llvm::ELF::Elf32_Ehdr*>(pELFHeader);
- uint32_t shoff = 0x0;
+ uint32_t shoff = 0x0;
uint16_t shentsize = 0x0;
- uint32_t shnum = 0x0;
- uint32_t shstrtab = 0x0;
+ uint32_t shnum = 0x0;
+ uint32_t shstrtab = 0x0;
if (llvm::sys::IsLittleEndianHost) {
- shoff = ehdr->e_shoff;
+ shoff = ehdr->e_shoff;
shentsize = ehdr->e_shentsize;
- shnum = ehdr->e_shnum;
- shstrtab = ehdr->e_shstrndx;
- }
- else {
- shoff = mcld::bswap32(ehdr->e_shoff);
+ shnum = ehdr->e_shnum;
+ shstrtab = ehdr->e_shstrndx;
+ } else {
+ shoff = mcld::bswap32(ehdr->e_shoff);
shentsize = mcld::bswap16(ehdr->e_shentsize);
- shnum = mcld::bswap16(ehdr->e_shnum);
- shstrtab = mcld::bswap16(ehdr->e_shstrndx);
+ shnum = mcld::bswap16(ehdr->e_shnum);
+ shstrtab = mcld::bswap16(ehdr->e_shstrndx);
}
// If the file has no section header table, e_shoff holds zero.
- if (0x0 == shoff)
+ if (shoff == 0x0)
return true;
- const llvm::ELF::Elf32_Shdr *shdr = NULL;
+ const llvm::ELF::Elf32_Shdr* shdr = NULL;
llvm::StringRef shdr_region;
- uint32_t sh_name = 0x0;
- uint32_t sh_type = 0x0;
- uint32_t sh_flags = 0x0;
- uint32_t sh_offset = 0x0;
- uint32_t sh_size = 0x0;
- uint32_t sh_link = 0x0;
- uint32_t sh_info = 0x0;
+ uint32_t sh_name = 0x0;
+ uint32_t sh_type = 0x0;
+ uint32_t sh_flags = 0x0;
+ uint32_t sh_offset = 0x0;
+ uint32_t sh_size = 0x0;
+ uint32_t sh_link = 0x0;
+ uint32_t sh_info = 0x0;
uint32_t sh_addralign = 0x0;
// if shnum and shstrtab overflow, the actual values are in the 1st shdr
if (shnum == llvm::ELF::SHN_UNDEF || shstrtab == llvm::ELF::SHN_XINDEX) {
- shdr_region = pInput.memArea()->request(pInput.fileOffset() + shoff,
- shentsize);
+ shdr_region =
+ pInput.memArea()->request(pInput.fileOffset() + shoff, shentsize);
shdr = reinterpret_cast<const llvm::ELF::Elf32_Shdr*>(shdr_region.begin());
if (llvm::sys::IsLittleEndianHost) {
sh_size = shdr->sh_size;
sh_link = shdr->sh_link;
- }
- else {
+ } else {
sh_size = mcld::bswap32(shdr->sh_size);
sh_link = mcld::bswap32(shdr->sh_link);
}
@@ -374,8 +359,8 @@ bool ELFReader<32, true>::readSectionHeaders(Input& pInput,
shoff += shentsize;
}
- shdr_region = pInput.memArea()->request(pInput.fileOffset() + shoff,
- shnum * shentsize);
+ shdr_region =
+ pInput.memArea()->request(pInput.fileOffset() + shoff, shnum * shentsize);
const llvm::ELF::Elf32_Shdr* shdrTab =
reinterpret_cast<const llvm::ELF::Elf32_Shdr*>(shdr_region.begin());
@@ -383,15 +368,14 @@ bool ELFReader<32, true>::readSectionHeaders(Input& pInput,
shdr = &shdrTab[shstrtab];
if (llvm::sys::IsLittleEndianHost) {
sh_offset = shdr->sh_offset;
- sh_size = shdr->sh_size;
- }
- else {
+ sh_size = shdr->sh_size;
+ } else {
sh_offset = mcld::bswap32(shdr->sh_offset);
- sh_size = mcld::bswap32(shdr->sh_size);
+ sh_size = mcld::bswap32(shdr->sh_size);
}
- llvm::StringRef sect_name_region = pInput.memArea()->request(
- pInput.fileOffset() + sh_offset, sh_size);
+ llvm::StringRef sect_name_region =
+ pInput.memArea()->request(pInput.fileOffset() + sh_offset, sh_size);
const char* sect_name = sect_name_region.begin();
LinkInfoList link_info_list;
@@ -399,40 +383,36 @@ bool ELFReader<32, true>::readSectionHeaders(Input& pInput,
// create all LDSections, including first NULL section.
for (size_t idx = 0; idx < shnum; ++idx) {
if (llvm::sys::IsLittleEndianHost) {
- sh_name = shdrTab[idx].sh_name;
- sh_type = shdrTab[idx].sh_type;
- sh_flags = shdrTab[idx].sh_flags;
- sh_offset = shdrTab[idx].sh_offset;
- sh_size = shdrTab[idx].sh_size;
- sh_link = shdrTab[idx].sh_link;
- sh_info = shdrTab[idx].sh_info;
+ sh_name = shdrTab[idx].sh_name;
+ sh_type = shdrTab[idx].sh_type;
+ sh_flags = shdrTab[idx].sh_flags;
+ sh_offset = shdrTab[idx].sh_offset;
+ sh_size = shdrTab[idx].sh_size;
+ sh_link = shdrTab[idx].sh_link;
+ sh_info = shdrTab[idx].sh_info;
sh_addralign = shdrTab[idx].sh_addralign;
- }
- else {
- sh_name = mcld::bswap32(shdrTab[idx].sh_name);
- sh_type = mcld::bswap32(shdrTab[idx].sh_type);
- sh_flags = mcld::bswap32(shdrTab[idx].sh_flags);
- sh_offset = mcld::bswap32(shdrTab[idx].sh_offset);
- sh_size = mcld::bswap32(shdrTab[idx].sh_size);
- sh_link = mcld::bswap32(shdrTab[idx].sh_link);
- sh_info = mcld::bswap32(shdrTab[idx].sh_info);
+ } else {
+ sh_name = mcld::bswap32(shdrTab[idx].sh_name);
+ sh_type = mcld::bswap32(shdrTab[idx].sh_type);
+ sh_flags = mcld::bswap32(shdrTab[idx].sh_flags);
+ sh_offset = mcld::bswap32(shdrTab[idx].sh_offset);
+ sh_size = mcld::bswap32(shdrTab[idx].sh_size);
+ sh_link = mcld::bswap32(shdrTab[idx].sh_link);
+ sh_info = mcld::bswap32(shdrTab[idx].sh_info);
sh_addralign = mcld::bswap32(shdrTab[idx].sh_addralign);
}
- LDSection* section = IRBuilder::CreateELFHeader(pInput,
- sect_name+sh_name,
- sh_type,
- sh_flags,
- sh_addralign);
+ LDSection* section = IRBuilder::CreateELFHeader(
+ pInput, sect_name + sh_name, sh_type, sh_flags, sh_addralign);
section->setSize(sh_size);
section->setOffset(sh_offset);
section->setInfo(sh_info);
if (sh_link != 0x0 || sh_info != 0x0) {
- LinkInfo link_info = { section, sh_link, sh_info };
+ LinkInfo link_info = {section, sh_link, sh_info};
link_info_list.push_back(link_info);
}
- } // end of for
+ } // end of for
// set up InfoLink
LinkInfoList::iterator info, infoEnd = link_info_list.end();
@@ -450,31 +430,29 @@ bool ELFReader<32, true>::readSectionHeaders(Input& pInput,
/// This is used to get the signature of a group section.
ResolveInfo* ELFReader<32, true>::readSignature(Input& pInput,
LDSection& pSymTab,
- uint32_t pSymIdx) const
-{
+ uint32_t pSymIdx) const {
LDSection* symtab = &pSymTab;
LDSection* strtab = symtab->getLink();
- assert(NULL != symtab && NULL != strtab);
+ assert(symtab != NULL && strtab != NULL);
uint32_t offset = pInput.fileOffset() + symtab->offset() +
- sizeof(llvm::ELF::Elf32_Sym) * pSymIdx;
+ sizeof(llvm::ELF::Elf32_Sym) * pSymIdx;
llvm::StringRef symbol_region =
pInput.memArea()->request(offset, sizeof(llvm::ELF::Elf32_Sym));
const llvm::ELF::Elf32_Sym* entry =
reinterpret_cast<const llvm::ELF::Elf32_Sym*>(symbol_region.begin());
- uint32_t st_name = 0x0;
- uint8_t st_info = 0x0;
- uint8_t st_other = 0x0;
+ uint32_t st_name = 0x0;
+ uint8_t st_info = 0x0;
+ uint8_t st_other = 0x0;
uint16_t st_shndx = 0x0;
- st_info = entry->st_info;
+ st_info = entry->st_info;
st_other = entry->st_other;
if (llvm::sys::IsLittleEndianHost) {
- st_name = entry->st_name;
+ st_name = entry->st_name;
st_shndx = entry->st_shndx;
- }
- else {
- st_name = mcld::bswap32(entry->st_name);
+ } else {
+ st_name = mcld::bswap32(entry->st_name);
st_shndx = mcld::bswap16(entry->st_shndx);
}
@@ -495,15 +473,14 @@ ResolveInfo* ELFReader<32, true>::readSignature(Input& pInput,
}
/// readDynamic - read ELF .dynamic in input dynobj
-bool ELFReader<32, true>::readDynamic(Input& pInput) const
-{
+bool ELFReader<32, true>::readDynamic(Input& pInput) const {
assert(pInput.type() == Input::DynObj);
const LDSection* dynamic_sect = pInput.context()->getSection(".dynamic");
- if (NULL == dynamic_sect) {
+ if (dynamic_sect == NULL) {
fatal(diag::err_cannot_read_section) << ".dynamic";
}
const LDSection* dynstr_sect = dynamic_sect->getLink();
- if (NULL == dynstr_sect) {
+ if (dynstr_sect == NULL) {
fatal(diag::err_cannot_read_section) << ".dynstr";
}
@@ -520,7 +497,6 @@ bool ELFReader<32, true>::readDynamic(Input& pInput) const
size_t numOfEntries = dynamic_sect->size() / sizeof(llvm::ELF::Elf32_Dyn);
for (size_t idx = 0; idx < numOfEntries; ++idx) {
-
llvm::ELF::Elf32_Sword d_tag = 0x0;
llvm::ELF::Elf32_Word d_val = 0x0;
@@ -558,29 +534,25 @@ bool ELFReader<32, true>::readDynamic(Input& pInput) const
// ELFReader<64, true>
//===----------------------------------------------------------------------===//
/// constructor
-ELFReader<64, true>::ELFReader(GNULDBackend& pBackend)
- : ELFReaderIF(pBackend) {
+ELFReader<64, true>::ELFReader(GNULDBackend& pBackend) : ELFReaderIF(pBackend) {
}
/// destructor
-ELFReader<64, true>::~ELFReader()
-{
+ELFReader<64, true>::~ELFReader() {
}
/// isELF - is this a ELF file
-bool ELFReader<64, true>::isELF(const void* pELFHeader) const
-{
+bool ELFReader<64, true>::isELF(const void* pELFHeader) const {
const llvm::ELF::Elf64_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf64_Ehdr*>(pELFHeader);
- if (0 == memcmp(llvm::ELF::ElfMagic, hdr, 4))
+ if (memcmp(llvm::ELF::ElfMagic, hdr, 4) == 0)
return true;
return false;
}
/// readRegularSection - read a regular section and create fragments.
-bool
-ELFReader<64, true>::readRegularSection(Input& pInput, SectionData& pSD) const
-{
+bool ELFReader<64, true>::readRegularSection(Input& pInput,
+ SectionData& pSD) const {
uint64_t offset = pInput.fileOffset() + pSD.getSection().offset();
uint64_t size = pSD.getSection().size();
@@ -593,18 +565,17 @@ ELFReader<64, true>::readRegularSection(Input& pInput, SectionData& pSD) const
bool ELFReader<64, true>::readSymbols(Input& pInput,
IRBuilder& pBuilder,
llvm::StringRef pRegion,
- const char* pStrTab) const
-{
+ const char* pStrTab) const {
// get number of symbols
size_t entsize = pRegion.size() / sizeof(llvm::ELF::Elf64_Sym);
const llvm::ELF::Elf64_Sym* symtab =
reinterpret_cast<const llvm::ELF::Elf64_Sym*>(pRegion.begin());
- uint32_t st_name = 0x0;
+ uint32_t st_name = 0x0;
uint64_t st_value = 0x0;
- uint64_t st_size = 0x0;
- uint8_t st_info = 0x0;
- uint8_t st_other = 0x0;
+ uint64_t st_size = 0x0;
+ uint8_t st_info = 0x0;
+ uint8_t st_other = 0x0;
uint16_t st_shndx = 0x0;
// skip the first NULL symbol
@@ -612,30 +583,28 @@ bool ELFReader<64, true>::readSymbols(Input& pInput,
/// recording symbols added from DynObj to analyze weak alias
std::vector<AliasInfo> potential_aliases;
- bool is_dyn_obj = (pInput.type()==Input::DynObj);
+ bool is_dyn_obj = (pInput.type() == Input::DynObj);
for (size_t idx = 1; idx < entsize; ++idx) {
- st_info = symtab[idx].st_info;
+ st_info = symtab[idx].st_info;
st_other = symtab[idx].st_other;
if (llvm::sys::IsLittleEndianHost) {
- st_name = symtab[idx].st_name;
+ st_name = symtab[idx].st_name;
st_value = symtab[idx].st_value;
- st_size = symtab[idx].st_size;
+ st_size = symtab[idx].st_size;
st_shndx = symtab[idx].st_shndx;
- }
- else {
- st_name = mcld::bswap32(symtab[idx].st_name);
+ } else {
+ st_name = mcld::bswap32(symtab[idx].st_name);
st_value = mcld::bswap64(symtab[idx].st_value);
- st_size = mcld::bswap64(symtab[idx].st_size);
+ st_size = mcld::bswap64(symtab[idx].st_size);
st_shndx = mcld::bswap16(symtab[idx].st_shndx);
}
// If the section should not be included, set the st_shndx SHN_UNDEF
// - A section in interrelated groups are not included.
- if (pInput.type() == Input::Object &&
- st_shndx < llvm::ELF::SHN_LORESERVE &&
+ if (pInput.type() == Input::Object && st_shndx < llvm::ELF::SHN_LORESERVE &&
st_shndx != llvm::ELF::SHN_UNDEF) {
- if (NULL == pInput.context()->getSection(st_shndx))
+ if (pInput.context()->getSection(st_shndx) == NULL)
st_shndx = llvm::ELF::SHN_UNDEF;
}
@@ -646,7 +615,8 @@ bool ELFReader<64, true>::readSymbols(Input& pInput,
ResolveInfo::Desc ld_desc = getSymDesc(st_shndx, pInput);
// get ld_binding
- ResolveInfo::Binding ld_binding = getSymBinding((st_info >> 4), st_shndx, st_other);
+ ResolveInfo::Binding ld_binding =
+ getSymBinding((st_info >> 4), st_shndx, st_other);
// get ld_value - ld_value must be section relative.
uint64_t ld_value = getSymValue(st_value, st_shndx, pInput);
@@ -656,17 +626,16 @@ bool ELFReader<64, true>::readSymbols(Input& pInput,
// get section
LDSection* section = NULL;
- if (st_shndx < llvm::ELF::SHN_LORESERVE) // including ABS and COMMON
+ if (st_shndx < llvm::ELF::SHN_LORESERVE) // including ABS and COMMON
section = pInput.context()->getSection(st_shndx);
// get ld_name
std::string ld_name;
if (ResolveInfo::Section == ld_type) {
// Section symbol's st_name is the section index.
- assert(NULL != section && "get a invalid section");
+ assert(section != NULL && "get a invalid section");
ld_name = section->name();
- }
- else {
+ } else {
ld_name = std::string(pStrTab + st_name);
}
@@ -680,20 +649,17 @@ bool ELFReader<64, true>::readSymbols(Input& pInput,
section,
ld_vis);
- if (is_dyn_obj
- && NULL != psym
- && ResolveInfo::Undefined != ld_desc
- && (ResolveInfo::Global == ld_binding ||
- ResolveInfo::Weak == ld_binding)
- && ResolveInfo::Object == ld_type ) {
+ if (is_dyn_obj && psym != NULL && ResolveInfo::Undefined != ld_desc &&
+ (ResolveInfo::Global == ld_binding ||
+ ResolveInfo::Weak == ld_binding) &&
+ ResolveInfo::Object == ld_type) {
AliasInfo p;
p.pt_alias = psym;
p.ld_binding = ld_binding;
p.ld_value = ld_value;
potential_aliases.push_back(p);
}
-
- } // end of for loop
+ } // end of for loop
// analyze weak alias here
if (is_dyn_obj) {
@@ -704,13 +670,13 @@ bool ELFReader<64, true>::readSymbols(Input& pInput,
// then link them as a circular list in Module
std::vector<AliasInfo>::iterator sym_it, sym_e;
sym_e = potential_aliases.end();
- for (sym_it = potential_aliases.begin(); sym_it!=sym_e; ++sym_it) {
- if (ResolveInfo::Weak!=sym_it->ld_binding)
+ for (sym_it = potential_aliases.begin(); sym_it != sym_e; ++sym_it) {
+ if (ResolveInfo::Weak != sym_it->ld_binding)
continue;
Module& pModule = pBuilder.getModule();
- std::vector<AliasInfo>::iterator alias_it = sym_it+1;
- while(alias_it!=sym_e) {
+ std::vector<AliasInfo>::iterator alias_it = sym_it + 1;
+ while (alias_it != sym_e) {
if (sym_it->ld_value != alias_it->ld_value)
break;
@@ -721,7 +687,7 @@ bool ELFReader<64, true>::readSymbols(Input& pInput,
}
sym_it = alias_it - 1;
- }// end of for loop
+ } // end of for loop
}
return true;
}
@@ -732,44 +698,42 @@ bool ELFReader<64, true>::readSymbols(Input& pInput,
/// ELFReader::readRela - read ELF rela and create Relocation
bool ELFReader<64, true>::readRela(Input& pInput,
LDSection& pSection,
- llvm::StringRef pRegion) const
-{
+ llvm::StringRef pRegion) const {
// get the number of rela
size_t entsize = pRegion.size() / sizeof(llvm::ELF::Elf64_Rela);
const llvm::ELF::Elf64_Rela* relaTab =
reinterpret_cast<const llvm::ELF::Elf64_Rela*>(pRegion.begin());
- for (size_t idx=0; idx < entsize; ++idx) {
+ for (size_t idx = 0; idx < entsize; ++idx) {
Relocation::Type r_type = 0x0;
uint32_t r_sym = 0x0;
uint64_t r_offset = 0x0;
- int64_t r_addend = 0;
- if (!target().readRelocation(relaTab[idx],
- r_type, r_sym, r_offset, r_addend)) {
+ int64_t r_addend = 0;
+ if (!target()
+ .readRelocation(relaTab[idx], r_type, r_sym, r_offset, r_addend)) {
return false;
}
LDSymbol* symbol = pInput.context()->getSymbol(r_sym);
- if (NULL == symbol) {
+ if (symbol == NULL) {
fatal(diag::err_cannot_read_symbol) << r_sym << pInput.path();
}
IRBuilder::AddRelocation(pSection, r_type, *symbol, r_offset, r_addend);
- } // end of for
+ } // end of for
return true;
}
/// readRel - read ELF rel and create Relocation
bool ELFReader<64, true>::readRel(Input& pInput,
LDSection& pSection,
- llvm::StringRef pRegion) const
-{
+ llvm::StringRef pRegion) const {
// get the number of rel
size_t entsize = pRegion.size() / sizeof(llvm::ELF::Elf64_Rel);
const llvm::ELF::Elf64_Rel* relTab =
reinterpret_cast<const llvm::ELF::Elf64_Rel*>(pRegion.begin());
- for (size_t idx=0; idx < entsize; ++idx) {
+ for (size_t idx = 0; idx < entsize; ++idx) {
Relocation::Type r_type = 0x0;
uint32_t r_sym = 0x0;
uint64_t r_offset = 0x0;
@@ -777,18 +741,17 @@ bool ELFReader<64, true>::readRel(Input& pInput,
return false;
LDSymbol* symbol = pInput.context()->getSymbol(r_sym);
- if (NULL == symbol) {
+ if (symbol == NULL) {
fatal(diag::err_cannot_read_symbol) << r_sym << pInput.path();
}
IRBuilder::AddRelocation(pSection, r_type, *symbol, r_offset);
- } // end of for
+ } // end of for
return true;
}
/// isMyEndian - is this ELF file in the same endian to me?
-bool ELFReader<64, true>::isMyEndian(const void* pELFHeader) const
-{
+bool ELFReader<64, true>::isMyEndian(const void* pELFHeader) const {
const llvm::ELF::Elf64_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf64_Ehdr*>(pELFHeader);
@@ -796,8 +759,7 @@ bool ELFReader<64, true>::isMyEndian(const void* pELFHeader) const
}
/// isMyMachine - is this ELF file generated for the same machine.
-bool ELFReader<64, true>::isMyMachine(const void* pELFHeader) const
-{
+bool ELFReader<64, true>::isMyMachine(const void* pELFHeader) const {
const llvm::ELF::Elf64_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf64_Ehdr*>(pELFHeader);
@@ -807,8 +769,7 @@ bool ELFReader<64, true>::isMyMachine(const void* pELFHeader) const
}
/// fileType - return the file type
-Input::Type ELFReader<64, true>::fileType(const void* pELFHeader) const
-{
+Input::Type ELFReader<64, true>::fileType(const void* pELFHeader) const {
const llvm::ELF::Elf64_Ehdr* hdr =
reinterpret_cast<const llvm::ELF::Elf64_Ehdr*>(pELFHeader);
uint32_t type = 0x0;
@@ -817,72 +778,69 @@ Input::Type ELFReader<64, true>::fileType(const void* pELFHeader) const
else
type = mcld::bswap16(hdr->e_type);
- switch(type) {
- case llvm::ELF::ET_REL:
- return Input::Object;
- case llvm::ELF::ET_EXEC:
- return Input::Exec;
- case llvm::ELF::ET_DYN:
- return Input::DynObj;
- case llvm::ELF::ET_CORE:
- return Input::CoreFile;
- case llvm::ELF::ET_NONE:
- default:
- return Input::Unknown;
+ switch (type) {
+ case llvm::ELF::ET_REL:
+ return Input::Object;
+ case llvm::ELF::ET_EXEC:
+ return Input::Exec;
+ case llvm::ELF::ET_DYN:
+ return Input::DynObj;
+ case llvm::ELF::ET_CORE:
+ return Input::CoreFile;
+ case llvm::ELF::ET_NONE:
+ default:
+ return Input::Unknown;
}
}
/// readSectionHeaders - read ELF section header table and create LDSections
bool ELFReader<64, true>::readSectionHeaders(Input& pInput,
- const void* pELFHeader) const
-{
+ const void* pELFHeader) const {
const llvm::ELF::Elf64_Ehdr* ehdr =
reinterpret_cast<const llvm::ELF::Elf64_Ehdr*>(pELFHeader);
- uint64_t shoff = 0x0;
+ uint64_t shoff = 0x0;
uint16_t shentsize = 0x0;
- uint32_t shnum = 0x0;
- uint32_t shstrtab = 0x0;
+ uint32_t shnum = 0x0;
+ uint32_t shstrtab = 0x0;
if (llvm::sys::IsLittleEndianHost) {
- shoff = ehdr->e_shoff;
+ shoff = ehdr->e_shoff;
shentsize = ehdr->e_shentsize;
- shnum = ehdr->e_shnum;
- shstrtab = ehdr->e_shstrndx;
- }
- else {
- shoff = mcld::bswap64(ehdr->e_shoff);
+ shnum = ehdr->e_shnum;
+ shstrtab = ehdr->e_shstrndx;
+ } else {
+ shoff = mcld::bswap64(ehdr->e_shoff);
shentsize = mcld::bswap16(ehdr->e_shentsize);
- shnum = mcld::bswap16(ehdr->e_shnum);
- shstrtab = mcld::bswap16(ehdr->e_shstrndx);
+ shnum = mcld::bswap16(ehdr->e_shnum);
+ shstrtab = mcld::bswap16(ehdr->e_shstrndx);
}
// If the file has no section header table, e_shoff holds zero.
- if (0x0 == shoff)
+ if (shoff == 0x0)
return true;
- const llvm::ELF::Elf64_Shdr *shdr = NULL;
+ const llvm::ELF::Elf64_Shdr* shdr = NULL;
llvm::StringRef shdr_region;
- uint32_t sh_name = 0x0;
- uint32_t sh_type = 0x0;
- uint64_t sh_flags = 0x0;
- uint64_t sh_offset = 0x0;
- uint64_t sh_size = 0x0;
- uint32_t sh_link = 0x0;
- uint32_t sh_info = 0x0;
+ uint32_t sh_name = 0x0;
+ uint32_t sh_type = 0x0;
+ uint64_t sh_flags = 0x0;
+ uint64_t sh_offset = 0x0;
+ uint64_t sh_size = 0x0;
+ uint32_t sh_link = 0x0;
+ uint32_t sh_info = 0x0;
uint64_t sh_addralign = 0x0;
// if shnum and shstrtab overflow, the actual values are in the 1st shdr
if (shnum == llvm::ELF::SHN_UNDEF || shstrtab == llvm::ELF::SHN_XINDEX) {
- shdr_region = pInput.memArea()->request(pInput.fileOffset() + shoff,
- shentsize);
+ shdr_region =
+ pInput.memArea()->request(pInput.fileOffset() + shoff, shentsize);
shdr = reinterpret_cast<const llvm::ELF::Elf64_Shdr*>(shdr_region.begin());
if (llvm::sys::IsLittleEndianHost) {
sh_size = shdr->sh_size;
sh_link = shdr->sh_link;
- }
- else {
+ } else {
sh_size = mcld::bswap64(shdr->sh_size);
sh_link = mcld::bswap32(shdr->sh_link);
}
@@ -895,8 +853,8 @@ bool ELFReader<64, true>::readSectionHeaders(Input& pInput,
shoff += shentsize;
}
- shdr_region = pInput.memArea()->request(pInput.fileOffset() + shoff,
- shnum * shentsize);
+ shdr_region =
+ pInput.memArea()->request(pInput.fileOffset() + shoff, shnum * shentsize);
const llvm::ELF::Elf64_Shdr* shdrTab =
reinterpret_cast<const llvm::ELF::Elf64_Shdr*>(shdr_region.begin());
@@ -904,15 +862,14 @@ bool ELFReader<64, true>::readSectionHeaders(Input& pInput,
shdr = &shdrTab[shstrtab];
if (llvm::sys::IsLittleEndianHost) {
sh_offset = shdr->sh_offset;
- sh_size = shdr->sh_size;
- }
- else {
+ sh_size = shdr->sh_size;
+ } else {
sh_offset = mcld::bswap64(shdr->sh_offset);
- sh_size = mcld::bswap64(shdr->sh_size);
+ sh_size = mcld::bswap64(shdr->sh_size);
}
- llvm::StringRef sect_name_region = pInput.memArea()->request(
- pInput.fileOffset() + sh_offset, sh_size);
+ llvm::StringRef sect_name_region =
+ pInput.memArea()->request(pInput.fileOffset() + sh_offset, sh_size);
const char* sect_name = sect_name_region.begin();
LinkInfoList link_info_list;
@@ -920,40 +877,36 @@ bool ELFReader<64, true>::readSectionHeaders(Input& pInput,
// create all LDSections, including first NULL section.
for (size_t idx = 0; idx < shnum; ++idx) {
if (llvm::sys::IsLittleEndianHost) {
- sh_name = shdrTab[idx].sh_name;
- sh_type = shdrTab[idx].sh_type;
- sh_flags = shdrTab[idx].sh_flags;
- sh_offset = shdrTab[idx].sh_offset;
- sh_size = shdrTab[idx].sh_size;
- sh_link = shdrTab[idx].sh_link;
- sh_info = shdrTab[idx].sh_info;
+ sh_name = shdrTab[idx].sh_name;
+ sh_type = shdrTab[idx].sh_type;
+ sh_flags = shdrTab[idx].sh_flags;
+ sh_offset = shdrTab[idx].sh_offset;
+ sh_size = shdrTab[idx].sh_size;
+ sh_link = shdrTab[idx].sh_link;
+ sh_info = shdrTab[idx].sh_info;
sh_addralign = shdrTab[idx].sh_addralign;
- }
- else {
- sh_name = mcld::bswap32(shdrTab[idx].sh_name);
- sh_type = mcld::bswap32(shdrTab[idx].sh_type);
- sh_flags = mcld::bswap64(shdrTab[idx].sh_flags);
- sh_offset = mcld::bswap64(shdrTab[idx].sh_offset);
- sh_size = mcld::bswap64(shdrTab[idx].sh_size);
- sh_link = mcld::bswap32(shdrTab[idx].sh_link);
- sh_info = mcld::bswap32(shdrTab[idx].sh_info);
+ } else {
+ sh_name = mcld::bswap32(shdrTab[idx].sh_name);
+ sh_type = mcld::bswap32(shdrTab[idx].sh_type);
+ sh_flags = mcld::bswap64(shdrTab[idx].sh_flags);
+ sh_offset = mcld::bswap64(shdrTab[idx].sh_offset);
+ sh_size = mcld::bswap64(shdrTab[idx].sh_size);
+ sh_link = mcld::bswap32(shdrTab[idx].sh_link);
+ sh_info = mcld::bswap32(shdrTab[idx].sh_info);
sh_addralign = mcld::bswap64(shdrTab[idx].sh_addralign);
}
- LDSection* section = IRBuilder::CreateELFHeader(pInput,
- sect_name+sh_name,
- sh_type,
- sh_flags,
- sh_addralign);
+ LDSection* section = IRBuilder::CreateELFHeader(
+ pInput, sect_name + sh_name, sh_type, sh_flags, sh_addralign);
section->setSize(sh_size);
section->setOffset(sh_offset);
section->setInfo(sh_info);
if (sh_link != 0x0 || sh_info != 0x0) {
- LinkInfo link_info = { section, sh_link, sh_info };
+ LinkInfo link_info = {section, sh_link, sh_info};
link_info_list.push_back(link_info);
}
- } // end of for
+ } // end of for
// set up InfoLink
LinkInfoList::iterator info, infoEnd = link_info_list.end();
@@ -971,31 +924,29 @@ bool ELFReader<64, true>::readSectionHeaders(Input& pInput,
/// This is used to get the signature of a group section.
ResolveInfo* ELFReader<64, true>::readSignature(Input& pInput,
LDSection& pSymTab,
- uint32_t pSymIdx) const
-{
+ uint32_t pSymIdx) const {
LDSection* symtab = &pSymTab;
LDSection* strtab = symtab->getLink();
- assert(NULL != symtab && NULL != strtab);
+ assert(symtab != NULL && strtab != NULL);
uint64_t offset = pInput.fileOffset() + symtab->offset() +
- sizeof(llvm::ELF::Elf64_Sym) * pSymIdx;
+ sizeof(llvm::ELF::Elf64_Sym) * pSymIdx;
llvm::StringRef symbol_region =
pInput.memArea()->request(offset, sizeof(llvm::ELF::Elf64_Sym));
const llvm::ELF::Elf64_Sym* entry =
reinterpret_cast<const llvm::ELF::Elf64_Sym*>(symbol_region.begin());
- uint32_t st_name = 0x0;
- uint8_t st_info = 0x0;
- uint8_t st_other = 0x0;
+ uint32_t st_name = 0x0;
+ uint8_t st_info = 0x0;
+ uint8_t st_other = 0x0;
uint16_t st_shndx = 0x0;
- st_info = entry->st_info;
+ st_info = entry->st_info;
st_other = entry->st_other;
if (llvm::sys::IsLittleEndianHost) {
- st_name = entry->st_name;
+ st_name = entry->st_name;
st_shndx = entry->st_shndx;
- }
- else {
- st_name = mcld::bswap32(entry->st_name);
+ } else {
+ st_name = mcld::bswap32(entry->st_name);
st_shndx = mcld::bswap16(entry->st_shndx);
}
@@ -1016,15 +967,14 @@ ResolveInfo* ELFReader<64, true>::readSignature(Input& pInput,
}
/// readDynamic - read ELF .dynamic in input dynobj
-bool ELFReader<64, true>::readDynamic(Input& pInput) const
-{
+bool ELFReader<64, true>::readDynamic(Input& pInput) const {
assert(pInput.type() == Input::DynObj);
const LDSection* dynamic_sect = pInput.context()->getSection(".dynamic");
- if (NULL == dynamic_sect) {
+ if (dynamic_sect == NULL) {
fatal(diag::err_cannot_read_section) << ".dynamic";
}
const LDSection* dynstr_sect = dynamic_sect->getLink();
- if (NULL == dynstr_sect) {
+ if (dynstr_sect == NULL) {
fatal(diag::err_cannot_read_section) << ".dynstr";
}
@@ -1041,7 +991,6 @@ bool ELFReader<64, true>::readDynamic(Input& pInput) const
size_t numOfEntries = dynamic_sect->size() / sizeof(llvm::ELF::Elf64_Dyn);
for (size_t idx = 0; idx < numOfEntries; ++idx) {
-
llvm::ELF::Elf64_Sxword d_tag = 0x0;
llvm::ELF::Elf64_Xword d_val = 0x0;
@@ -1074,3 +1023,5 @@ bool ELFReader<64, true>::readDynamic(Input& pInput) const
return true;
}
+
+} // namespace mcld
diff --git a/lib/LD/ELFReaderIf.cpp b/lib/LD/ELFReaderIf.cpp
index 7d72596..b9d4d32 100644
--- a/lib/LD/ELFReaderIf.cpp
+++ b/lib/LD/ELFReaderIf.cpp
@@ -6,31 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFReaderIf.h>
+#include "mcld/LD/ELFReaderIf.h"
-#include <mcld/IRBuilder.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Target/GNULDBackend.h>
-
-#include <cstring>
+#include "mcld/IRBuilder.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/Twine.h>
#include <llvm/Support/ELF.h>
#include <llvm/Support/Host.h>
-using namespace mcld;
+#include <cstring>
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFReaderIF
//===----------------------------------------------------------------------===//
/// getSymType
-ResolveInfo::Type ELFReaderIF::getSymType(uint8_t pInfo, uint16_t pShndx) const
-{
+ResolveInfo::Type ELFReaderIF::getSymType(uint8_t pInfo,
+ uint16_t pShndx) const {
ResolveInfo::Type result = static_cast<ResolveInfo::Type>(pInfo & 0xF);
- if (llvm::ELF::SHN_ABS == pShndx && ResolveInfo::Section == result) {
+ if (pShndx == llvm::ELF::SHN_ABS && result == ResolveInfo::Section) {
// In Mips, __gp_disp is a special section symbol. Its name comes from
// .strtab, not .shstrtab. However, it is unique. Only it is also a ABS
// symbol. So here is a tricky to identify __gp_disp and convert it to
@@ -42,16 +43,15 @@ ResolveInfo::Type ELFReaderIF::getSymType(uint8_t pInfo, uint16_t pShndx) const
}
/// getSymDesc
-ResolveInfo::Desc ELFReaderIF::getSymDesc(uint16_t pShndx, const Input& pInput) const
-{
+ResolveInfo::Desc ELFReaderIF::getSymDesc(uint16_t pShndx,
+ const Input& pInput) const {
if (pShndx == llvm::ELF::SHN_UNDEF)
return ResolveInfo::Undefined;
if (pShndx < llvm::ELF::SHN_LORESERVE) {
// an ELF symbol defined in a section which we are not including
// must be treated as an Undefined.
- // @ref Google gold linker: symtab.cc: 1086
- if (NULL == pInput.context()->getSection(pShndx) ||
+ if (pInput.context()->getSection(pShndx) == NULL ||
LDFileFormat::Ignore == pInput.context()->getSection(pShndx)->kind())
return ResolveInfo::Undefined;
return ResolveInfo::Define;
@@ -63,8 +63,7 @@ ResolveInfo::Desc ELFReaderIF::getSymDesc(uint16_t pShndx, const Input& pInput)
if (pShndx == llvm::ELF::SHN_COMMON)
return ResolveInfo::Common;
- if (pShndx >= llvm::ELF::SHN_LOPROC &&
- pShndx <= llvm::ELF::SHN_HIPROC)
+ if (pShndx >= llvm::ELF::SHN_LOPROC && pShndx <= llvm::ELF::SHN_HIPROC)
return target().getSymDesc(pShndx);
// FIXME: ELF weak alias should be ResolveInfo::Indirect
@@ -72,80 +71,75 @@ ResolveInfo::Desc ELFReaderIF::getSymDesc(uint16_t pShndx, const Input& pInput)
}
/// getSymBinding
-ResolveInfo::Binding
-ELFReaderIF::getSymBinding(uint8_t pBinding, uint16_t pShndx, uint8_t pVis) const
-{
-
+ResolveInfo::Binding ELFReaderIF::getSymBinding(uint8_t pBinding,
+ uint16_t pShndx,
+ uint8_t pVis) const {
// TODO:
// if --just-symbols option is enabled, the symbol must covert to Absolute
- switch(pBinding) {
- case llvm::ELF::STB_LOCAL:
- return ResolveInfo::Local;
- case llvm::ELF::STB_GLOBAL:
- if (pShndx == llvm::ELF::SHN_ABS)
- return ResolveInfo::Absolute;
- return ResolveInfo::Global;
- case llvm::ELF::STB_WEAK:
- return ResolveInfo::Weak;
+ switch (pBinding) {
+ case llvm::ELF::STB_LOCAL:
+ return ResolveInfo::Local;
+ case llvm::ELF::STB_GLOBAL:
+ if (pShndx == llvm::ELF::SHN_ABS)
+ return ResolveInfo::Absolute;
+ return ResolveInfo::Global;
+ case llvm::ELF::STB_WEAK:
+ return ResolveInfo::Weak;
}
return ResolveInfo::NoneBinding;
}
/// getSymFragmentRef
-FragmentRef*
-ELFReaderIF::getSymFragmentRef(Input& pInput,
- uint16_t pShndx,
- uint32_t pOffset) const
-{
-
- if (Input::DynObj == pInput.type())
+FragmentRef* ELFReaderIF::getSymFragmentRef(Input& pInput,
+ uint16_t pShndx,
+ uint32_t pOffset) const {
+ if (pInput.type() == Input::DynObj)
return FragmentRef::Null();
if (pShndx == llvm::ELF::SHN_UNDEF)
return FragmentRef::Null();
- if (pShndx >= llvm::ELF::SHN_LORESERVE) // including ABS and COMMON
+ if (pShndx >= llvm::ELF::SHN_LORESERVE) // including ABS and COMMON
return FragmentRef::Null();
LDSection* sect_hdr = pInput.context()->getSection(pShndx);
- if (NULL == sect_hdr)
- unreachable(diag::unreachable_invalid_section_idx) << pShndx
- << pInput.path().native();
+ if (sect_hdr == NULL)
+ unreachable(diag::unreachable_invalid_section_idx)
+ << pShndx << pInput.path().native();
- if (LDFileFormat::Ignore == sect_hdr->kind())
+ if (sect_hdr->kind() == LDFileFormat::Ignore)
return FragmentRef::Null();
- if (LDFileFormat::Group == sect_hdr->kind())
+ if (sect_hdr->kind() == LDFileFormat::Group)
return FragmentRef::Null();
return FragmentRef::Create(*sect_hdr, pOffset);
}
/// getSymVisibility
-ResolveInfo::Visibility
-ELFReaderIF::getSymVisibility(uint8_t pVis) const
-{
+ResolveInfo::Visibility ELFReaderIF::getSymVisibility(uint8_t pVis) const {
return static_cast<ResolveInfo::Visibility>(pVis);
}
/// getSymValue - get the section offset of the symbol.
uint64_t ELFReaderIF::getSymValue(uint64_t pValue,
uint16_t pShndx,
- const Input& pInput) const
-{
- if (Input::Object == pInput.type()) {
+ const Input& pInput) const {
+ if (pInput.type() == Input::Object) {
// In relocatable files, st_value holds alignment constraints for a symbol
// whose section index is SHN_COMMON
if (pShndx == llvm::ELF::SHN_COMMON || pShndx == llvm::ELF::SHN_ABS) {
return pValue;
}
- // In relocatable files, st_value holds a section offset for a defined symbol.
+ // In relocatable files, st_value holds a section offset for a defined
+ // symbol.
// TODO:
- // if --just-symbols option are enabled, convert the value from section offset
+ // if --just-symbols option are enabled, convert the value from section
+ // offset
// to virtual address by adding input section's virtual address.
// The section's virtual address in relocatable files is normally zero, but
// people can use link script to change it.
@@ -157,3 +151,4 @@ uint64_t ELFReaderIF::getSymValue(uint64_t pValue,
return pValue;
}
+} // namespace mcld
diff --git a/lib/LD/ELFSegment.cpp b/lib/LD/ELFSegment.cpp
index 1c09514..da8f5c5 100644
--- a/lib/LD/ELFSegment.cpp
+++ b/lib/LD/ELFSegment.cpp
@@ -6,14 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Support/GCFactory.h>
-#include <mcld/Config/Config.h>
+#include "mcld/LD/ELFSegment.h"
+
+#include "mcld/Config/Config.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Support/GCFactory.h"
+
#include <llvm/Support/ManagedStatic.h>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<ELFSegment, MCLD_SEGMENTS_PER_OUTPUT> ELFSegmentFactory;
static llvm::ManagedStatic<ELFSegmentFactory> g_ELFSegmentFactory;
@@ -22,47 +25,41 @@ static llvm::ManagedStatic<ELFSegmentFactory> g_ELFSegmentFactory;
// ELFSegment
//===----------------------------------------------------------------------===//
ELFSegment::ELFSegment()
- : m_Type(llvm::ELF::PT_NULL),
- m_Flag(llvm::ELF::PF_R),
- m_Offset(0x0),
- m_Vaddr(0x0),
- m_Paddr(0x0),
- m_Filesz(0x0),
- m_Memsz(0x0),
- m_Align(0x0),
- m_MaxSectionAlign(0x0)
-{
+ : m_Type(llvm::ELF::PT_NULL),
+ m_Flag(llvm::ELF::PF_R),
+ m_Offset(0x0),
+ m_Vaddr(0x0),
+ m_Paddr(0x0),
+ m_Filesz(0x0),
+ m_Memsz(0x0),
+ m_Align(0x0),
+ m_MaxSectionAlign(0x0) {
}
ELFSegment::ELFSegment(uint32_t pType, uint32_t pFlag)
- : m_Type(pType),
- m_Flag(pFlag),
- m_Offset(0x0),
- m_Vaddr(0x0),
- m_Paddr(0x0),
- m_Filesz(0x0),
- m_Memsz(0x0),
- m_Align(0x0),
- m_MaxSectionAlign(0x0)
-{
+ : m_Type(pType),
+ m_Flag(pFlag),
+ m_Offset(0x0),
+ m_Vaddr(0x0),
+ m_Paddr(0x0),
+ m_Filesz(0x0),
+ m_Memsz(0x0),
+ m_Align(0x0),
+ m_MaxSectionAlign(0x0) {
}
-ELFSegment::~ELFSegment()
-{
+ELFSegment::~ELFSegment() {
}
-bool ELFSegment::isLoadSegment() const
-{
+bool ELFSegment::isLoadSegment() const {
return type() == llvm::ELF::PT_LOAD;
}
-bool ELFSegment::isDataSegment() const
-{
+bool ELFSegment::isDataSegment() const {
return (type() == llvm::ELF::PT_LOAD) && ((flag() & llvm::ELF::PF_W) != 0x0);
}
-bool ELFSegment::isBssSegment() const
-{
+bool ELFSegment::isBssSegment() const {
if (!isDataSegment())
return false;
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
@@ -73,34 +70,31 @@ bool ELFSegment::isBssSegment() const
}
ELFSegment::iterator ELFSegment::insert(ELFSegment::iterator pPos,
- LDSection* pSection)
-{
+ LDSection* pSection) {
return m_SectionList.insert(pPos, pSection);
}
-void ELFSegment::append(LDSection* pSection)
-{
- assert(NULL != pSection);
+void ELFSegment::append(LDSection* pSection) {
+ assert(pSection != NULL);
if (pSection->align() > m_MaxSectionAlign)
m_MaxSectionAlign = pSection->align();
m_SectionList.push_back(pSection);
}
-ELFSegment* ELFSegment::Create(uint32_t pType, uint32_t pFlag)
-{
+ELFSegment* ELFSegment::Create(uint32_t pType, uint32_t pFlag) {
ELFSegment* seg = g_ELFSegmentFactory->allocate();
new (seg) ELFSegment(pType, pFlag);
return seg;
}
-void ELFSegment::Destroy(ELFSegment*& pSegment)
-{
+void ELFSegment::Destroy(ELFSegment*& pSegment) {
g_ELFSegmentFactory->destroy(pSegment);
g_ELFSegmentFactory->deallocate(pSegment);
pSegment = NULL;
}
-void ELFSegment::Clear()
-{
+void ELFSegment::Clear() {
g_ELFSegmentFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/LD/ELFSegmentFactory.cpp b/lib/LD/ELFSegmentFactory.cpp
index 4d06629..de2d175 100644
--- a/lib/LD/ELFSegmentFactory.cpp
+++ b/lib/LD/ELFSegmentFactory.cpp
@@ -6,18 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/ELFSegment.h>
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/ELFSegment.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFSegmentFactory
//===----------------------------------------------------------------------===//
-ELFSegmentFactory::iterator
-ELFSegmentFactory::find(uint32_t pType, uint32_t pFlagSet, uint32_t pFlagClear)
-{
+ELFSegmentFactory::iterator ELFSegmentFactory::find(uint32_t pType,
+ uint32_t pFlagSet,
+ uint32_t pFlagClear) {
iterator segment, segEnd = end();
for (segment = begin(); segment != segEnd; ++segment) {
if ((*segment)->type() == pType &&
@@ -29,11 +29,10 @@ ELFSegmentFactory::find(uint32_t pType, uint32_t pFlagSet, uint32_t pFlagClear)
return segEnd;
}
-ELFSegmentFactory::const_iterator
-ELFSegmentFactory::find(uint32_t pType,
- uint32_t pFlagSet,
- uint32_t pFlagClear) const
-{
+ELFSegmentFactory::const_iterator ELFSegmentFactory::find(
+ uint32_t pType,
+ uint32_t pFlagSet,
+ uint32_t pFlagClear) const {
const_iterator segment, segEnd = end();
for (segment = begin(); segment != segEnd; ++segment) {
if ((*segment)->type() == pType &&
@@ -45,9 +44,8 @@ ELFSegmentFactory::find(uint32_t pType,
return segEnd;
}
-ELFSegmentFactory::iterator
-ELFSegmentFactory::find(uint32_t pType, const LDSection* pSection)
-{
+ELFSegmentFactory::iterator ELFSegmentFactory::find(uint32_t pType,
+ const LDSection* pSection) {
iterator segment, segEnd = end();
for (segment = begin(); segment != segEnd; ++segment) {
if ((*segment)->type() == pType) {
@@ -55,15 +53,15 @@ ELFSegmentFactory::find(uint32_t pType, const LDSection* pSection)
for (sect = (*segment)->begin(); sect != sectEnd; ++sect) {
if (*sect == pSection)
return segment;
- } // for each section
+ } // for each section
}
- } // for each segment
+ } // for each segment
return segEnd;
}
-ELFSegmentFactory::const_iterator
-ELFSegmentFactory::find(uint32_t pType, const LDSection* pSection) const
-{
+ELFSegmentFactory::const_iterator ELFSegmentFactory::find(
+ uint32_t pType,
+ const LDSection* pSection) const {
const_iterator segment, segEnd = end();
for (segment = begin(); segment != segEnd; ++segment) {
if ((*segment)->type() == pType) {
@@ -71,19 +69,19 @@ ELFSegmentFactory::find(uint32_t pType, const LDSection* pSection) const
for (sect = (*segment)->begin(); sect != sectEnd; ++sect) {
if (*sect == pSection)
return segment;
- } // for each section
+ } // for each section
}
- } // for each segment
+ } // for each segment
return segEnd;
}
-ELFSegment* ELFSegmentFactory::produce(uint32_t pType, uint32_t pFlag)
-{
+ELFSegment* ELFSegmentFactory::produce(uint32_t pType, uint32_t pFlag) {
m_Segments.push_back(ELFSegment::Create(pType, pFlag));
return back();
}
-void ELFSegmentFactory::erase(iterator pSegment)
-{
+void ELFSegmentFactory::erase(iterator pSegment) {
m_Segments.erase(pSegment);
}
+
+} // namespace mcld
diff --git a/lib/LD/EhFrame.cpp b/lib/LD/EhFrame.cpp
index 5ac3e72..84896d3 100644
--- a/lib/LD/EhFrame.cpp
+++ b/lib/LD/EhFrame.cpp
@@ -6,21 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/LD/EhFrame.h"
+
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/GCFactory.h"
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<EhFrame, MCLD_SECTIONS_PER_INPUT> EhFrameFactory;
@@ -29,12 +30,10 @@ static llvm::ManagedStatic<EhFrameFactory> g_EhFrameFactory;
//===----------------------------------------------------------------------===//
// EhFrame::Record
//===----------------------------------------------------------------------===//
-EhFrame::Record::Record(llvm::StringRef pRegion)
- : RegionFragment(pRegion) {
+EhFrame::Record::Record(llvm::StringRef pRegion) : RegionFragment(pRegion) {
}
-EhFrame::Record::~Record()
-{
+EhFrame::Record::~Record() {
// llvm::iplist will manage and delete the fragments
}
@@ -42,27 +41,27 @@ EhFrame::Record::~Record()
// EhFrame::CIE
//===----------------------------------------------------------------------===//
EhFrame::CIE::CIE(llvm::StringRef pRegion)
- : EhFrame::Record(pRegion),
- m_FDEEncode(0u), m_Mergeable(false), m_pReloc(0), m_PersonalityOffset(0) {
+ : EhFrame::Record(pRegion),
+ m_FDEEncode(0u),
+ m_Mergeable(false),
+ m_pReloc(0),
+ m_PersonalityOffset(0) {
}
-EhFrame::CIE::~CIE()
-{
+EhFrame::CIE::~CIE() {
}
//===----------------------------------------------------------------------===//
// EhFrame::FDE
//===----------------------------------------------------------------------===//
EhFrame::FDE::FDE(llvm::StringRef pRegion, EhFrame::CIE& pCIE)
- : EhFrame::Record(pRegion), m_pCIE(&pCIE) {
+ : EhFrame::Record(pRegion), m_pCIE(&pCIE) {
}
-EhFrame::FDE::~FDE()
-{
+EhFrame::FDE::~FDE() {
}
-void EhFrame::FDE::setCIE(EhFrame::CIE& pCIE)
-{
+void EhFrame::FDE::setCIE(EhFrame::CIE& pCIE) {
m_pCIE = &pCIE;
m_pCIE->add(*this);
}
@@ -71,74 +70,63 @@ void EhFrame::FDE::setCIE(EhFrame::CIE& pCIE)
// EhFrame::GeneratedCIE
//===----------------------------------------------------------------------===//
EhFrame::GeneratedCIE::GeneratedCIE(llvm::StringRef pRegion)
- : EhFrame::CIE(pRegion) {
+ : EhFrame::CIE(pRegion) {
}
-EhFrame::GeneratedCIE::~GeneratedCIE()
-{
+EhFrame::GeneratedCIE::~GeneratedCIE() {
}
//===----------------------------------------------------------------------===//
// EhFrame::GeneratedFDE
//===----------------------------------------------------------------------===//
-EhFrame::GeneratedFDE::GeneratedFDE(llvm::StringRef pRegion, CIE &pCIE)
- : EhFrame::FDE(pRegion, pCIE) {
+EhFrame::GeneratedFDE::GeneratedFDE(llvm::StringRef pRegion, CIE& pCIE)
+ : EhFrame::FDE(pRegion, pCIE) {
}
-EhFrame::GeneratedFDE::~GeneratedFDE()
-{
+EhFrame::GeneratedFDE::~GeneratedFDE() {
}
//===----------------------------------------------------------------------===//
// EhFrame
//===----------------------------------------------------------------------===//
-EhFrame::EhFrame()
- : m_pSection(NULL), m_pSectionData(NULL) {
+EhFrame::EhFrame() : m_pSection(NULL), m_pSectionData(NULL) {
}
EhFrame::EhFrame(LDSection& pSection)
- : m_pSection(&pSection),
- m_pSectionData(NULL) {
+ : m_pSection(&pSection), m_pSectionData(NULL) {
m_pSectionData = SectionData::Create(pSection);
}
-EhFrame::~EhFrame()
-{
+EhFrame::~EhFrame() {
}
-EhFrame* EhFrame::Create(LDSection& pSection)
-{
+EhFrame* EhFrame::Create(LDSection& pSection) {
EhFrame* result = g_EhFrameFactory->allocate();
new (result) EhFrame(pSection);
return result;
}
-void EhFrame::Destroy(EhFrame*& pSection)
-{
+void EhFrame::Destroy(EhFrame*& pSection) {
pSection->~EhFrame();
g_EhFrameFactory->deallocate(pSection);
pSection = NULL;
}
-void EhFrame::Clear()
-{
+void EhFrame::Clear() {
g_EhFrameFactory->clear();
}
-const LDSection& EhFrame::getSection() const
-{
- assert(NULL != m_pSection);
+const LDSection& EhFrame::getSection() const {
+ assert(m_pSection != NULL);
return *m_pSection;
}
-LDSection& EhFrame::getSection()
-{
- assert(NULL != m_pSection);
+LDSection& EhFrame::getSection() {
+ assert(m_pSection != NULL);
return *m_pSection;
}
-void EhFrame::addFragment(Fragment& pFrag)
-{
+void EhFrame::addFragment(Fragment& pFrag) {
uint32_t offset = 0;
if (!m_pSectionData->empty())
offset = m_pSectionData->back().getOffset() + m_pSectionData->back().size();
@@ -148,22 +136,19 @@ void EhFrame::addFragment(Fragment& pFrag)
pFrag.setOffset(offset);
}
-void EhFrame::addCIE(EhFrame::CIE& pCIE, bool pAlsoAddFragment)
-{
+void EhFrame::addCIE(EhFrame::CIE& pCIE, bool pAlsoAddFragment) {
m_CIEs.push_back(&pCIE);
if (pAlsoAddFragment)
addFragment(pCIE);
}
-void EhFrame::addFDE(EhFrame::FDE& pFDE, bool pAlsoAddFragment)
-{
+void EhFrame::addFDE(EhFrame::FDE& pFDE, bool pAlsoAddFragment) {
pFDE.getCIE().add(pFDE);
if (pAlsoAddFragment)
addFragment(pFDE);
}
-size_t EhFrame::numOfFDEs() const
-{
+size_t EhFrame::numOfFDEs() const {
// FDE number only used by .eh_frame_hdr computation, and the number of CIE
// is usually not too many. It is worthy to compromise space by time
size_t size = 0u;
@@ -172,9 +157,8 @@ size_t EhFrame::numOfFDEs() const
return size;
}
-EhFrame& EhFrame::merge(const Input& pInput, EhFrame& pFrame)
-{
- assert (this != &pFrame);
+EhFrame& EhFrame::merge(const Input& pInput, EhFrame& pFrame) {
+ assert(this != &pFrame);
if (pFrame.emptyCIEs()) {
// May be a partial linking, or the eh_frame has no data.
// Just append the fragments.
@@ -185,7 +169,9 @@ EhFrame& EhFrame::merge(const Input& pInput, EhFrame& pFrame)
const LDContext& ctx = *pInput.context();
const LDSection* rel_sec = 0;
for (LDContext::const_sect_iterator ri = ctx.relocSectBegin(),
- re = ctx.relocSectEnd(); ri != re; ++ri) {
+ re = ctx.relocSectEnd();
+ ri != re;
+ ++ri) {
if ((*ri)->getLink() == &pFrame.getSection()) {
rel_sec = *ri;
break;
@@ -221,8 +207,7 @@ EhFrame& EhFrame::merge(const Input& pInput, EhFrame& pFrame)
return *this;
}
-void EhFrame::setupAttributes(const LDSection* rel_sec)
-{
+void EhFrame::setupAttributes(const LDSection* rel_sec) {
for (cie_iterator i = cie_begin(), e = cie_end(); i != e; ++i) {
CIE* cie = *i;
removeDiscardedFDE(*cie, rel_sec);
@@ -233,16 +218,18 @@ void EhFrame::setupAttributes(const LDSection* rel_sec)
} else {
if (!rel_sec) {
// No relocation to eh_frame section
- assert (cie->getPersonalityName() != "" &&
- "PR name should be a symbol address or offset");
+ assert(cie->getPersonalityName() != "" &&
+ "PR name should be a symbol address or offset");
continue;
}
const RelocData* reloc_data = rel_sec->getRelocData();
for (RelocData::const_iterator ri = reloc_data->begin(),
- re = reloc_data->end(); ri != re; ++ri) {
+ re = reloc_data->end();
+ ri != re;
+ ++ri) {
const Relocation& rel = *ri;
- if (rel.targetRef().getOutputOffset() == cie->getOffset() +
- cie->getPersonalityOffset()) {
+ if (rel.targetRef().getOutputOffset() ==
+ cie->getOffset() + cie->getPersonalityOffset()) {
cie->setMergeable();
cie->setPersonalityName(rel.symInfo()->outSymbol()->name());
cie->setRelocation(rel);
@@ -250,14 +237,13 @@ void EhFrame::setupAttributes(const LDSection* rel_sec)
}
}
- assert (cie->getPersonalityName() != "" &&
- "PR name should be a symbol address or offset");
+ assert(cie->getPersonalityName() != "" &&
+ "PR name should be a symbol address or offset");
}
}
}
-void EhFrame::removeDiscardedFDE(CIE& pCIE, const LDSection* pRelocSect)
-{
+void EhFrame::removeDiscardedFDE(CIE& pCIE, const LDSection* pRelocSect) {
if (!pRelocSect)
return;
@@ -267,10 +253,12 @@ void EhFrame::removeDiscardedFDE(CIE& pCIE, const LDSection* pRelocSect)
for (fde_iterator i = pCIE.begin(), e = pCIE.end(); i != e; ++i) {
FDE& fde = **i;
for (RelocData::const_iterator ri = reloc_data->begin(),
- re = reloc_data->end(); ri != re; ++ri) {
+ re = reloc_data->end();
+ ri != re;
+ ++ri) {
const Relocation& rel = *ri;
- if (rel.targetRef().getOutputOffset() == fde.getOffset() +
- getDataStartOffset<32>()) {
+ if (rel.targetRef().getOutputOffset() ==
+ fde.getOffset() + getDataStartOffset<32>()) {
bool has_section = rel.symInfo()->outSymbol()->hasFragRef();
if (!has_section)
// The section was discarded, just ignore this FDE.
@@ -282,7 +270,9 @@ void EhFrame::removeDiscardedFDE(CIE& pCIE, const LDSection* pRelocSect)
}
for (FDERemoveList::iterator i = to_be_removed_fdes.begin(),
- e = to_be_removed_fdes.end(); i != e; ++i) {
+ e = to_be_removed_fdes.end();
+ i != e;
+ ++i) {
FDE& fde = **i;
fde.getCIE().remove(fde);
@@ -291,7 +281,8 @@ void EhFrame::removeDiscardedFDE(CIE& pCIE, const LDSection* pRelocSect)
// order, so we can bookkeep the previously found relocation for next use.
// Note: We must ensure FDE order is ordered.
for (RelocData::const_iterator ri = reloc_data->begin(),
- re = reloc_data->end(); ri != re; ) {
+ re = reloc_data->end();
+ ri != re;) {
Relocation& rel = const_cast<Relocation&>(*ri++);
if (rel.targetRef().getOutputOffset() >= fde.getOffset() &&
rel.targetRef().getOutputOffset() < fde.getOffset() + fde.size()) {
@@ -301,9 +292,10 @@ void EhFrame::removeDiscardedFDE(CIE& pCIE, const LDSection* pRelocSect)
}
}
-void EhFrame::removeAndUpdateCIEForFDE(EhFrame& pInFrame, CIE& pInCIE,
- CIE& pOutCIE, const LDSection* rel_sect)
-{
+void EhFrame::removeAndUpdateCIEForFDE(EhFrame& pInFrame,
+ CIE& pInCIE,
+ CIE& pOutCIE,
+ const LDSection* rel_sect) {
// Make this relocation to be ignored.
Relocation* rel = const_cast<Relocation*>(pInCIE.getRelocation());
if (rel && rel_sect)
@@ -318,8 +310,7 @@ void EhFrame::removeAndUpdateCIEForFDE(EhFrame& pInFrame, CIE& pInCIE,
pInCIE.clearFDEs();
}
-void EhFrame::moveInputFragments(EhFrame& pInFrame)
-{
+void EhFrame::moveInputFragments(EhFrame& pInFrame) {
SectionData& in_sd = *pInFrame.getSectionData();
SectionData::FragmentListType& in_frag_list = in_sd.getFragmentList();
SectionData& out_sd = *getSectionData();
@@ -332,9 +323,7 @@ void EhFrame::moveInputFragments(EhFrame& pInFrame)
}
}
-void EhFrame::moveInputFragments(EhFrame& pInFrame,
- CIE& pInCIE, CIE* pOutCIE)
-{
+void EhFrame::moveInputFragments(EhFrame& pInFrame, CIE& pInCIE, CIE* pOutCIE) {
SectionData& in_sd = *pInFrame.getSectionData();
SectionData::FragmentListType& in_frag_list = in_sd.getFragmentList();
SectionData& out_sd = *getSectionData();
@@ -354,7 +343,7 @@ void EhFrame::moveInputFragments(EhFrame& pInFrame,
}
SectionData::iterator cur_iter(*pOutCIE);
- assert (cur_iter != out_frag_list.end());
+ assert(cur_iter != out_frag_list.end());
for (fde_iterator i = pInCIE.begin(), e = pInCIE.end(); i != e; ++i) {
Fragment* frag = in_frag_list.remove(SectionData::iterator(**i));
cur_iter = out_frag_list.insertAfter(cur_iter, frag);
@@ -362,12 +351,12 @@ void EhFrame::moveInputFragments(EhFrame& pInFrame,
}
}
-size_t EhFrame::computeOffsetSize()
-{
+size_t EhFrame::computeOffsetSize() {
size_t offset = 0u;
- SectionData::FragmentListType& frag_list = getSectionData()->getFragmentList();
- for (SectionData::iterator i = frag_list.begin(), e = frag_list.end();
- i != e; ++i) {
+ SectionData::FragmentListType& frag_list =
+ getSectionData()->getFragmentList();
+ for (SectionData::iterator i = frag_list.begin(), e = frag_list.end(); i != e;
+ ++i) {
Fragment& frag = *i;
frag.setOffset(offset);
offset += frag.size();
@@ -376,8 +365,9 @@ size_t EhFrame::computeOffsetSize()
return offset;
}
-bool mcld::operator==(const EhFrame::CIE& p1, const EhFrame::CIE& p2)
-{
+bool operator==(const EhFrame::CIE& p1, const EhFrame::CIE& p2) {
return p1.getPersonalityName() == p2.getPersonalityName() &&
p1.getAugmentationData() == p2.getAugmentationData();
}
+
+} // namespace mcld
diff --git a/lib/LD/EhFrameHdr.cpp b/lib/LD/EhFrameHdr.cpp
index 74516d1..50e8cad 100644
--- a/lib/LD/EhFrameHdr.cpp
+++ b/lib/LD/EhFrameHdr.cpp
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/EhFrameHdr.h>
+#include "mcld/LD/EhFrameHdr.h"
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/LDSection.h>
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDSection.h"
#include <llvm/Support/Dwarf.h>
#include <llvm/Support/DataTypes.h>
@@ -17,8 +17,7 @@
#include <algorithm>
#include <cstring>
-using namespace mcld;
-using namespace llvm::dwarf;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Helper Function
@@ -27,62 +26,64 @@ namespace bit32 {
typedef std::pair<SizeTraits<32>::Address, SizeTraits<32>::Address> Entry;
-bool EntryCompare(const Entry& pX, const Entry& pY)
-{ return (pX.first < pY.first); }
+bool EntryCompare(const Entry& pX, const Entry& pY) {
+ return (pX.first < pY.first);
+}
-} // bit32 namespace
+} // namespace bit32
//===----------------------------------------------------------------------===//
// Template Specification Functions
//===----------------------------------------------------------------------===//
/// emitOutput<32> - write out eh_frame_hdr
-template<>
-void EhFrameHdr::emitOutput<32>(FileOutputBuffer& pOutput)
-{
- MemoryRegion ehframehdr_region = pOutput.request(m_EhFrameHdr.offset(),
- m_EhFrameHdr.size());
+template <>
+void EhFrameHdr::emitOutput<32>(FileOutputBuffer& pOutput) {
+ MemoryRegion ehframehdr_region =
+ pOutput.request(m_EhFrameHdr.offset(), m_EhFrameHdr.size());
- MemoryRegion ehframe_region = pOutput.request(m_EhFrame.offset(),
- m_EhFrame.size());
+ MemoryRegion ehframe_region =
+ pOutput.request(m_EhFrame.offset(), m_EhFrame.size());
uint8_t* data = ehframehdr_region.begin();
// version
data[0] = 1;
// eh_frame_ptr_enc
- data[1] = DW_EH_PE_pcrel | DW_EH_PE_sdata4;
+ data[1] = llvm::dwarf::DW_EH_PE_pcrel | llvm::dwarf::DW_EH_PE_sdata4;
// eh_frame_ptr
- uint32_t* eh_frame_ptr = (uint32_t*)(data + 4);
+ uint32_t* eh_frame_ptr = reinterpret_cast<uint32_t*>(data + 4);
*eh_frame_ptr = m_EhFrame.addr() - (m_EhFrameHdr.addr() + 4);
// fde_count
- uint32_t* fde_count = (uint32_t*)(data + 8);
+ uint32_t* fde_count = reinterpret_cast<uint32_t*>(data + 8);
if (m_EhFrame.hasEhFrame())
*fde_count = m_EhFrame.getEhFrame()->numOfFDEs();
else
*fde_count = 0;
- if (0 == *fde_count) {
+ if (*fde_count == 0) {
// fde_count_enc
- data[2] = DW_EH_PE_omit;
+ data[2] = llvm::dwarf::DW_EH_PE_omit;
// table_enc
- data[3] = DW_EH_PE_omit;
- }
- else {
+ data[3] = llvm::dwarf::DW_EH_PE_omit;
+ } else {
// fde_count_enc
- data[2] = DW_EH_PE_udata4;
+ data[2] = llvm::dwarf::DW_EH_PE_udata4;
// table_enc
- data[3] = DW_EH_PE_datarel | DW_EH_PE_sdata4;
+ data[3] = llvm::dwarf::DW_EH_PE_datarel | llvm::dwarf::DW_EH_PE_sdata4;
// prepare the binary search table
typedef std::vector<bit32::Entry> SearchTableType;
SearchTableType search_table;
for (EhFrame::const_cie_iterator i = m_EhFrame.getEhFrame()->cie_begin(),
- e = m_EhFrame.getEhFrame()->cie_end(); i != e; ++i) {
+ e = m_EhFrame.getEhFrame()->cie_end();
+ i != e;
+ ++i) {
EhFrame::CIE& cie = **i;
for (EhFrame::const_fde_iterator fi = cie.begin(), fe = cie.end();
- fi != fe; ++fi) {
+ fi != fe;
+ ++fi) {
EhFrame::FDE& fde = **fi;
SizeTraits<32>::Offset offset;
SizeTraits<32>::Address fde_pc;
@@ -97,7 +98,7 @@ void EhFrameHdr::emitOutput<32>(FileOutputBuffer& pOutput)
std::sort(search_table.begin(), search_table.end(), bit32::EntryCompare);
// write out the binary search table
- uint32_t* bst = (uint32_t*)(data + 12);
+ uint32_t* bst = reinterpret_cast<uint32_t*>(data + 12);
SearchTableType::const_iterator entry, entry_end = search_table.end();
size_t id = 0;
for (entry = search_table.begin(); entry != entry_end; ++entry) {
@@ -112,11 +113,10 @@ void EhFrameHdr::emitOutput<32>(FileOutputBuffer& pOutput)
//===----------------------------------------------------------------------===//
EhFrameHdr::EhFrameHdr(LDSection& pEhFrameHdr, const LDSection& pEhFrame)
- : m_EhFrameHdr(pEhFrameHdr), m_EhFrame(pEhFrame) {
+ : m_EhFrameHdr(pEhFrameHdr), m_EhFrame(pEhFrame) {
}
-EhFrameHdr::~EhFrameHdr()
-{
+EhFrameHdr::~EhFrameHdr() {
}
/// @ref lsb core generic 4.1
@@ -130,8 +130,7 @@ EhFrameHdr::~EhFrameHdr()
/// __________________________ when fde_count > 0
/// <uint32_t, uint32_t>+ : binary search table
/// sizeOutput - base on the fde count to size output
-void EhFrameHdr::sizeOutput()
-{
+void EhFrameHdr::sizeOutput() {
size_t size = 12;
if (m_EhFrame.hasEhFrame())
size += 8 * m_EhFrame.getEhFrame()->numOfFDEs();
@@ -139,27 +138,25 @@ void EhFrameHdr::sizeOutput()
}
/// computePCBegin - return the address of FDE's pc
-/// @ref binutils gold: ehframe.cc:222
uint32_t EhFrameHdr::computePCBegin(const EhFrame::FDE& pFDE,
- const MemoryRegion& pEhFrameRegion)
-{
+ const MemoryRegion& pEhFrameRegion) {
uint8_t fde_encoding = pFDE.getCIE().getFDEEncode();
unsigned int eh_value = fde_encoding & 0x7;
// check the size to read in
if (eh_value == llvm::dwarf::DW_EH_PE_absptr) {
- eh_value = DW_EH_PE_udata4;
+ eh_value = llvm::dwarf::DW_EH_PE_udata4;
}
size_t pc_size = 0x0;
switch (eh_value) {
- case DW_EH_PE_udata2:
+ case llvm::dwarf::DW_EH_PE_udata2:
pc_size = 2;
break;
- case DW_EH_PE_udata4:
+ case llvm::dwarf::DW_EH_PE_udata4:
pc_size = 4;
break;
- case DW_EH_PE_udata8:
+ case llvm::dwarf::DW_EH_PE_udata8:
pc_size = 8;
break;
default:
@@ -168,26 +165,24 @@ uint32_t EhFrameHdr::computePCBegin(const EhFrame::FDE& pFDE,
}
SizeTraits<32>::Address pc = 0x0;
- const uint8_t* offset = (const uint8_t*) pEhFrameRegion.begin() +
- pFDE.getOffset() +
- EhFrame::getDataStartOffset<32>();
+ const uint8_t* offset = (const uint8_t*)pEhFrameRegion.begin() +
+ pFDE.getOffset() + EhFrame::getDataStartOffset<32>();
std::memcpy(&pc, offset, pc_size);
// adjust the signed value
bool is_signed = (fde_encoding & llvm::dwarf::DW_EH_PE_signed) != 0x0;
- if (DW_EH_PE_udata2 == eh_value && is_signed)
+ if (llvm::dwarf::DW_EH_PE_udata2 == eh_value && is_signed)
pc = (pc ^ 0x8000) - 0x8000;
// handle eh application
- switch (fde_encoding & 0x70)
- {
- case DW_EH_PE_absptr:
+ switch (fde_encoding & 0x70) {
+ case llvm::dwarf::DW_EH_PE_absptr:
break;
- case DW_EH_PE_pcrel:
+ case llvm::dwarf::DW_EH_PE_pcrel:
pc += m_EhFrame.addr() + pFDE.getOffset() +
- EhFrame::getDataStartOffset<32>();
+ EhFrame::getDataStartOffset<32>();
break;
- case DW_EH_PE_datarel:
+ case llvm::dwarf::DW_EH_PE_datarel:
// TODO
break;
default:
@@ -196,3 +191,5 @@ uint32_t EhFrameHdr::computePCBegin(const EhFrame::FDE& pFDE,
}
return pc;
}
+
+} // namespace mcld
diff --git a/lib/LD/EhFrameReader.cpp b/lib/LD/EhFrameReader.cpp
index 49950a0..383c1ee 100644
--- a/lib/LD/EhFrameReader.cpp
+++ b/lib/LD/EhFrameReader.cpp
@@ -6,20 +6,19 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/EhFrameReader.h>
+#include "mcld/LD/EhFrameReader.h"
-#include <mcld/Fragment/NullFragment.h>
-#include <mcld/MC/Input.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/MemoryArea.h>
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/MC/Input.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/MemoryArea.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/Dwarf.h>
#include <llvm/Support/LEB128.h>
-using namespace mcld;
-using namespace llvm::dwarf;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Helper Functions
@@ -27,12 +26,10 @@ using namespace llvm::dwarf;
/// skip_LEB128 - skip the first LEB128 encoded value from *pp, update *pp
/// to the next character.
/// @return - false if we ran off the end of the string.
-/// @ref - GNU gold 1.11, ehframe.h, Eh_frame::skip_leb128.
-static bool
-skip_LEB128(EhFrameReader::ConstAddress* pp, EhFrameReader::ConstAddress pend)
-{
+static bool skip_LEB128(EhFrameReader::ConstAddress* pp,
+ EhFrameReader::ConstAddress pend) {
for (EhFrameReader::ConstAddress p = *pp; p < pend; ++p) {
- if (0x0 == (*p & 0x80)) {
+ if ((*p & 0x80) == 0x0) {
*pp = p + 1;
return true;
}
@@ -43,11 +40,10 @@ skip_LEB128(EhFrameReader::ConstAddress* pp, EhFrameReader::ConstAddress pend)
//===----------------------------------------------------------------------===//
// EhFrameReader
//===----------------------------------------------------------------------===//
-template<> EhFrameReader::Token
-EhFrameReader::scan<true>(ConstAddress pHandler,
- uint64_t pOffset,
- llvm::StringRef pData) const
-{
+template <>
+EhFrameReader::Token EhFrameReader::scan<true>(ConstAddress pHandler,
+ uint64_t pOffset,
+ llvm::StringRef pData) const {
Token result;
result.file_off = pOffset;
@@ -56,7 +52,7 @@ EhFrameReader::scan<true>(ConstAddress pHandler,
// Length Field
uint32_t length = data[cur_idx++];
- if (0x0 == length) {
+ if (length == 0x0) {
// terminator
result.kind = Terminator;
result.data_off = 4;
@@ -66,23 +62,22 @@ EhFrameReader::scan<true>(ConstAddress pHandler,
// Extended Field
uint64_t extended = 0x0;
- if (0xFFFFFFFF == length) {
+ if (length == 0xFFFFFFFF) {
extended = data[cur_idx++];
extended <<= 32;
extended |= data[cur_idx++];
result.size = extended + 12;
result.data_off = 16;
// 64-bit obj file still uses 32-bit eh_frame.
- assert (false && "We don't support 64-bit eh_frame.");
- }
- else {
+ assert(false && "We don't support 64-bit eh_frame.");
+ } else {
result.size = length + 4;
result.data_off = 8;
}
// ID Field
uint32_t ID = data[cur_idx++];
- if (0x0 == ID)
+ if (ID == 0x0)
result.kind = CIE;
else
result.kind = FDE;
@@ -90,9 +85,8 @@ EhFrameReader::scan<true>(ConstAddress pHandler,
return result;
}
-template<>
-bool EhFrameReader::read<32, true>(Input& pInput, EhFrame& pEhFrame)
-{
+template <>
+bool EhFrameReader::read<32, true>(Input& pInput, EhFrame& pEhFrame) {
// Alphabet:
// {CIE, FDE, CIEt}
//
@@ -112,15 +106,15 @@ bool EhFrameReader::read<32, true>(Input& pInput, EhFrame& pEhFrame)
// +-----------------------+
// CIEt
const State autometa[NumOfStates][NumOfTokenKinds] = {
- // CIE FDE Term Unknown
- { Q1, Reject, Accept, Reject }, // Q0
- { Q1, Q1, Accept, Reject }, // Q1
+ // CIE FDE Term Unknown
+ {Q1, Reject, Accept, Reject}, // Q0
+ {Q1, Q1, Accept, Reject}, // Q1
};
const Action transition[NumOfStates][NumOfTokenKinds] = {
- /* CIE FDE Term Unknown */
- { addCIE, reject, addTerm, reject}, // Q0
- { addCIE, addFDE, addTerm, reject}, // Q1
+ /* CIE FDE Term Unknown */
+ {addCIE, reject, addTerm, reject}, // Q0
+ {addCIE, addFDE, addTerm, reject}, // Q1
};
LDSection& section = pEhFrame.getSection();
@@ -138,9 +132,9 @@ bool EhFrameReader::read<32, true>(Input& pInput, EhFrame& pEhFrame)
State cur_state = Q0;
while (Reject != cur_state && Accept != cur_state) {
-
Token token = scan<true>(handler, file_off, sect_reg);
- llvm::StringRef entry = pInput.memArea()->request(token.file_off, token.size);
+ llvm::StringRef entry =
+ pInput.memArea()->request(token.file_off, token.size);
if (!transition[cur_state][token.kind](pEhFrame, entry, token)) {
// fail to scan
@@ -151,14 +145,14 @@ bool EhFrameReader::read<32, true>(Input& pInput, EhFrame& pEhFrame)
file_off += token.size;
handler += token.size;
- if (handler == sect_reg.end())
+ if (handler == sect_reg.end()) {
cur_state = Accept;
- else if (handler > sect_reg.end()) {
+ } else if (handler > sect_reg.end()) {
cur_state = Reject;
- }
- else
+ } else {
cur_state = autometa[cur_state][token.kind];
- } // end of while
+ }
+ } // end of while
if (Reject == cur_state) {
// fail to parse
@@ -170,8 +164,7 @@ bool EhFrameReader::read<32, true>(Input& pInput, EhFrame& pEhFrame)
bool EhFrameReader::addCIE(EhFrame& pEhFrame,
llvm::StringRef pRegion,
- const EhFrameReader::Token& pToken)
-{
+ const EhFrameReader::Token& pToken) {
// skip Length, Extended Length and CIE ID.
ConstAddress handler = pRegion.begin() + pToken.data_off;
ConstAddress cie_end = pRegion.end();
@@ -180,15 +173,15 @@ bool EhFrameReader::addCIE(EhFrame& pEhFrame,
// the version should be 1 or 3
uint8_t version = *handler++;
- if (1 != version && 3 != version) {
+ if (version != 1 && version != 3) {
return false;
}
// Set up the Augumentation String
ConstAddress aug_str_front = handler;
- ConstAddress aug_str_back = static_cast<ConstAddress>(
- memchr(aug_str_front, '\0', cie_end - aug_str_front));
- if (NULL == aug_str_back) {
+ ConstAddress aug_str_back = static_cast<ConstAddress>(
+ memchr(aug_str_front, '\0', cie_end - aug_str_front));
+ if (aug_str_back == NULL) {
return false;
}
@@ -212,7 +205,7 @@ bool EhFrameReader::addCIE(EhFrame& pEhFrame,
llvm::StringRef augment((const char*)aug_str_front);
// we discard this CIE if the augumentation string is '\0'
- if (0 == augment.size()) {
+ if (augment.size() == 0) {
EhFrame::CIE* cie = new EhFrame::CIE(pRegion);
cie->setFDEEncode(llvm::dwarf::DW_EH_PE_absptr);
pEhFrame.addCIE(*cie);
@@ -230,7 +223,7 @@ bool EhFrameReader::addCIE(EhFrame& pEhFrame,
uint8_t fde_encoding = llvm::dwarf::DW_EH_PE_absptr;
std::string augdata;
std::string pr_ptr_data;
- if ('z' == augment[0]) {
+ if (augment[0] == 'z') {
unsigned offset;
size_t augdata_size = llvm::decodeULEB128((const uint8_t*)handler, &offset);
handler += offset;
@@ -259,7 +252,7 @@ bool EhFrameReader::addCIE(EhFrame& pEhFrame,
++handler;
// get the length of the second argument
uint32_t per_length = 0;
- if (0x60 == (per_encode & 0x60)) {
+ if ((per_encode & 0x60) == 0x60) {
return false;
}
switch (per_encode & 7) {
@@ -275,14 +268,14 @@ bool EhFrameReader::addCIE(EhFrame& pEhFrame,
per_length = 8;
break;
case llvm::dwarf::DW_EH_PE_absptr:
- per_length = 4; // pPkg.bitclass / 8;
+ per_length = 4; // pPkg.bitclass / 8;
break;
}
// skip the alignment
if (llvm::dwarf::DW_EH_PE_aligned == (per_encode & 0xf0)) {
uint32_t per_align = handler - cie_end;
per_align += per_length - 1;
- per_align &= ~(per_length -1);
+ per_align &= ~(per_length - 1);
if (static_cast<uint32_t>(cie_end - handler) < per_align) {
return false;
}
@@ -296,7 +289,7 @@ bool EhFrameReader::addCIE(EhFrame& pEhFrame,
pr_ptr_data = std::string((const char*)handler, per_length);
handler += per_length;
break;
- } // end of case 'P'
+ } // end of case 'P'
// FDE encoding (1 byte)
case 'R': {
@@ -318,9 +311,9 @@ bool EhFrameReader::addCIE(EhFrame& pEhFrame,
}
default:
return false;
- } // end switch
- } // the rest chars.
- } // first char is 'z'
+ } // end switch
+ } // the rest chars.
+ } // first char is 'z'
// create and push back the CIE entry
EhFrame::CIE* cie = new EhFrame::CIE(pRegion);
@@ -335,15 +328,14 @@ bool EhFrameReader::addCIE(EhFrame& pEhFrame,
bool EhFrameReader::addFDE(EhFrame& pEhFrame,
llvm::StringRef pRegion,
- const EhFrameReader::Token& pToken)
-{
+ const EhFrameReader::Token& pToken) {
if (pToken.data_off == pRegion.size())
return false;
- const int32_t offset = *(const int32_t*) (pRegion.begin() + pToken.data_off
- - 4);
- size_t cie_offset = (size_t) ((int64_t) (pToken.file_off + 4) -
- (int32_t) offset);
+ const int32_t offset =
+ *(const int32_t*)(pRegion.begin() + pToken.data_off - 4);
+ size_t cie_offset =
+ (size_t)((int64_t)(pToken.file_off + 4) - (int32_t)offset);
EhFrame::CIEMap::iterator iter = pEhFrame.getCIEMap().find(cie_offset);
if (iter == pEhFrame.getCIEMap().end())
@@ -357,14 +349,14 @@ bool EhFrameReader::addFDE(EhFrame& pEhFrame,
bool EhFrameReader::addTerm(EhFrame& pEhFrame,
llvm::StringRef pRegion,
- const EhFrameReader::Token& pToken)
-{
+ const EhFrameReader::Token& pToken) {
return true;
}
bool EhFrameReader::reject(EhFrame& pEhFrame,
llvm::StringRef pRegion,
- const EhFrameReader::Token& pToken)
-{
+ const EhFrameReader::Token& pToken) {
return true;
}
+
+} // namespace mcld
diff --git a/lib/LD/GNUArchiveReader.cpp b/lib/LD/GNUArchiveReader.cpp
index 4553bfb..f9e4d51 100644
--- a/lib/LD/GNUArchiveReader.cpp
+++ b/lib/LD/GNUArchiveReader.cpp
@@ -6,44 +6,40 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/GNUArchiveReader.h>
-
-#include <mcld/Module.h>
-#include <mcld/InputTree.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/Attribute.h>
-#include <mcld/MC/Input.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/ELFObjectReader.h>
-#include <mcld/Support/FileSystem.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/Path.h>
-#include <mcld/ADT/SizeTraits.h>
+#include "mcld/LD/GNUArchiveReader.h"
+
+#include "mcld/InputTree.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Module.h"
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/MC/Input.h"
+#include "mcld/LD/ELFObjectReader.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/FileSystem.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/Path.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/Host.h>
-#include <cstring>
#include <cstdlib>
+#include <cstring>
-using namespace mcld;
+namespace mcld {
GNUArchiveReader::GNUArchiveReader(Module& pModule,
ELFObjectReader& pELFObjectReader)
- : m_Module(pModule),
- m_ELFObjectReader(pELFObjectReader)
-{
+ : m_Module(pModule), m_ELFObjectReader(pELFObjectReader) {
}
-GNUArchiveReader::~GNUArchiveReader()
-{
+GNUArchiveReader::~GNUArchiveReader() {
}
/// isMyFormat
-bool GNUArchiveReader::isMyFormat(Input& pInput, bool &pContinue) const
-{
+bool GNUArchiveReader::isMyFormat(Input& pInput, bool& pContinue) const {
assert(pInput.hasMemArea());
if (pInput.memArea()->size() < Archive::MAGIC_LEN)
return false;
@@ -53,7 +49,7 @@ bool GNUArchiveReader::isMyFormat(Input& pInput, bool &pContinue) const
const char* str = region.begin();
bool result = false;
- assert(NULL != str);
+ assert(str != NULL);
pContinue = true;
if (isArchive(str) || isThinArchive(str))
result = true;
@@ -62,27 +58,24 @@ bool GNUArchiveReader::isMyFormat(Input& pInput, bool &pContinue) const
}
/// isArchive
-bool GNUArchiveReader::isArchive(const char* pStr) const
-{
- return (0 == memcmp(pStr, Archive::MAGIC, Archive::MAGIC_LEN));
+bool GNUArchiveReader::isArchive(const char* pStr) const {
+ return (memcmp(pStr, Archive::MAGIC, Archive::MAGIC_LEN) == 0);
}
/// isThinArchive
-bool GNUArchiveReader::isThinArchive(const char* pStr) const
-{
- return (0 == memcmp(pStr, Archive::THIN_MAGIC, Archive::MAGIC_LEN));
+bool GNUArchiveReader::isThinArchive(const char* pStr) const {
+ return (memcmp(pStr, Archive::THIN_MAGIC, Archive::MAGIC_LEN) == 0);
}
/// isThinArchive
-bool GNUArchiveReader::isThinArchive(Input& pInput) const
-{
+bool GNUArchiveReader::isThinArchive(Input& pInput) const {
assert(pInput.hasMemArea());
llvm::StringRef region =
pInput.memArea()->request(pInput.fileOffset(), Archive::MAGIC_LEN);
const char* str = region.begin();
bool result = false;
- assert(NULL != str);
+ assert(str != NULL);
if (isThinArchive(str))
result = true;
@@ -90,8 +83,7 @@ bool GNUArchiveReader::isThinArchive(Input& pInput) const
}
bool GNUArchiveReader::readArchive(const LinkerConfig& pConfig,
- Archive& pArchive)
-{
+ Archive& pArchive) {
// bypass the empty archive
if (Archive::MAGIC_LEN == pArchive.getARFile().memArea()->size())
return true;
@@ -101,16 +93,16 @@ bool GNUArchiveReader::readArchive(const LinkerConfig& pConfig,
// if this is the first time read this archive, setup symtab and strtab
if (pArchive.getSymbolTable().empty()) {
- // read the symtab of the archive
- readSymbolTable(pArchive);
+ // read the symtab of the archive
+ readSymbolTable(pArchive);
- // read the strtab of the archive
- readStringTable(pArchive);
+ // read the strtab of the archive
+ readStringTable(pArchive);
- // add root archive to ArchiveMemberMap
- pArchive.addArchiveMember(pArchive.getARFile().name(),
- pArchive.inputs().root(),
- &InputTree::Downward);
+ // add root archive to ArchiveMemberMap
+ pArchive.addArchiveMember(pArchive.getARFile().name(),
+ pArchive.inputs().root(),
+ &InputTree::Downward);
}
// include the needed members in the archive and build up the input tree
@@ -130,7 +122,7 @@ bool GNUArchiveReader::readArchive(const LinkerConfig& pConfig,
// check if we should include this defined symbol
Archive::Symbol::Status status =
- shouldIncludeSymbol(pArchive.getSymbolName(idx));
+ shouldIncludeSymbol(pArchive.getSymbolName(idx));
if (Archive::Symbol::Unknown != status)
pArchive.setSymbolStatus(idx, status);
@@ -138,8 +130,8 @@ bool GNUArchiveReader::readArchive(const LinkerConfig& pConfig,
// include the object member from the given offset
includeMember(pConfig, pArchive, pArchive.getObjFileOffset(idx));
willSymResolved = true;
- } // end of if
- } // end of for
+ } // end of if
+ } // end of for
} while (willSymResolved);
return true;
@@ -158,29 +150,27 @@ Input* GNUArchiveReader::readMemberHeader(Archive& pArchiveRoot,
Input& pArchiveFile,
uint32_t pFileOffset,
uint32_t& pNestedOffset,
- size_t& pMemberSize)
-{
+ size_t& pMemberSize) {
assert(pArchiveFile.hasMemArea());
- llvm::StringRef header_region =
- pArchiveFile.memArea()->request((pArchiveFile.fileOffset() + pFileOffset),
- sizeof(Archive::MemberHeader));
+ llvm::StringRef header_region = pArchiveFile.memArea()->request(
+ (pArchiveFile.fileOffset() + pFileOffset), sizeof(Archive::MemberHeader));
const Archive::MemberHeader* header =
- reinterpret_cast<const Archive::MemberHeader*>(header_region.begin());
+ reinterpret_cast<const Archive::MemberHeader*>(header_region.begin());
- assert(0 == memcmp(header->fmag, Archive::MEMBER_MAGIC, sizeof(header->fmag)));
+ assert(memcmp(header->fmag, Archive::MEMBER_MAGIC, sizeof(header->fmag)) ==
+ 0);
pMemberSize = atoi(header->size);
// parse the member name and nested offset if any
std::string member_name;
llvm::StringRef name_field(header->name, sizeof(header->name));
- if ('/' != header->name[0]) {
+ if (header->name[0] != '/') {
// this is an object file in an archive
size_t pos = name_field.find_first_of('/');
member_name.assign(name_field.substr(0, pos).str());
- }
- else {
+ } else {
// this is an object/archive file in a thin archive
size_t begin = 1;
size_t end = name_field.find_first_of(" :");
@@ -188,7 +178,7 @@ Input* GNUArchiveReader::readMemberHeader(Archive& pArchiveRoot,
// parse the name offset
name_field.substr(begin, end - begin).getAsInteger(10, name_offset);
- if (':' == name_field[end]) {
+ if (name_field[end] == ':') {
// there is a nested offset
begin = end + 1;
end = name_field.find_first_of(' ', begin);
@@ -199,26 +189,26 @@ Input* GNUArchiveReader::readMemberHeader(Archive& pArchiveRoot,
assert(pArchiveRoot.hasStrTable());
begin = name_offset;
end = pArchiveRoot.getStrTable().find_first_of('\n', begin);
- member_name.assign(pArchiveRoot.getStrTable().substr(begin, end - begin -1));
+ member_name.assign(
+ pArchiveRoot.getStrTable().substr(begin, end - begin - 1));
}
Input* member = NULL;
bool isThinAR = isThinArchive(pArchiveFile);
if (!isThinAR) {
// this is an object file in an archive
- member = pArchiveRoot.getMemberFile(pArchiveFile,
- isThinAR,
- member_name,
- pArchiveFile.path(),
- (pFileOffset +
- sizeof(Archive::MemberHeader)));
- }
- else {
+ member = pArchiveRoot.getMemberFile(
+ pArchiveFile,
+ isThinAR,
+ member_name,
+ pArchiveFile.path(),
+ (pFileOffset + sizeof(Archive::MemberHeader)));
+ } else {
// this is a member in a thin archive
// try to find if this is a archive already in the map first
Archive::ArchiveMember* ar_member =
- pArchiveRoot.getArchiveMember(member_name);
- if (NULL != ar_member) {
+ pArchiveRoot.getArchiveMember(member_name);
+ if (ar_member != NULL) {
return ar_member->file;
}
@@ -226,22 +216,20 @@ Input* GNUArchiveReader::readMemberHeader(Archive& pArchiveRoot,
// path to the archive containing it.
sys::fs::Path input_path(pArchiveFile.path().parent_path());
if (!input_path.empty())
- input_path.append(member_name);
+ input_path.append(sys::fs::Path(member_name));
else
input_path.assign(member_name);
- member = pArchiveRoot.getMemberFile(pArchiveFile,
- isThinAR,
- member_name,
- input_path);
+ member = pArchiveRoot.getMemberFile(
+ pArchiveFile, isThinAR, member_name, input_path);
}
return member;
}
template <size_t SIZE>
-static void readSymbolTableEntries(Archive& pArchive, llvm::StringRef pMemRegion)
-{
+static void readSymbolTableEntries(Archive& pArchive,
+ llvm::StringRef pMemRegion) {
typedef typename SizeTraits<SIZE>::Offset Offset;
const Offset* data = reinterpret_cast<const Offset*>(pMemRegion.begin());
@@ -269,70 +257,68 @@ static void readSymbolTableEntries(Archive& pArchive, llvm::StringRef pMemRegion
}
/// readSymbolTable - read the archive symbol map (armap)
-bool GNUArchiveReader::readSymbolTable(Archive& pArchive)
-{
+bool GNUArchiveReader::readSymbolTable(Archive& pArchive) {
assert(pArchive.getARFile().hasMemArea());
+ MemoryArea* memory_area = pArchive.getARFile().memArea();
- llvm::StringRef header_region =
- pArchive.getARFile().memArea()->request((pArchive.getARFile().fileOffset() +
- Archive::MAGIC_LEN),
- sizeof(Archive::MemberHeader));
+ llvm::StringRef header_region = memory_area->request(
+ (pArchive.getARFile().fileOffset() + Archive::MAGIC_LEN),
+ sizeof(Archive::MemberHeader));
const Archive::MemberHeader* header =
- reinterpret_cast<const Archive::MemberHeader*>(header_region.begin());
- assert(0 == memcmp(header->fmag, Archive::MEMBER_MAGIC, sizeof(header->fmag)));
+ reinterpret_cast<const Archive::MemberHeader*>(header_region.begin());
+ assert(memcmp(header->fmag, Archive::MEMBER_MAGIC, sizeof(header->fmag)) ==
+ 0);
int symtab_size = atoi(header->size);
pArchive.setSymTabSize(symtab_size);
if (!pArchive.getARFile().attribute()->isWholeArchive()) {
- llvm::StringRef symtab_region = pArchive.getARFile().memArea()->request(
- (pArchive.getARFile().fileOffset() +
- Archive::MAGIC_LEN +
+ llvm::StringRef symtab_region = memory_area->request(
+ (pArchive.getARFile().fileOffset() + Archive::MAGIC_LEN +
sizeof(Archive::MemberHeader)),
symtab_size);
- if (0 == strncmp(header->name, Archive::SVR4_SYMTAB_NAME,
- strlen(Archive::SVR4_SYMTAB_NAME)))
+ if (strncmp(header->name,
+ Archive::SVR4_SYMTAB_NAME,
+ strlen(Archive::SVR4_SYMTAB_NAME)) == 0)
readSymbolTableEntries<32>(pArchive, symtab_region);
- else if (0 == strncmp(header->name, Archive::IRIX6_SYMTAB_NAME,
- strlen(Archive::IRIX6_SYMTAB_NAME)))
+ else if (strncmp(header->name,
+ Archive::IRIX6_SYMTAB_NAME,
+ strlen(Archive::IRIX6_SYMTAB_NAME)) == 0)
readSymbolTableEntries<64>(pArchive, symtab_region);
else
unreachable(diag::err_unsupported_archive);
-
}
return true;
}
/// readStringTable - read the strtab for long file name of the archive
-bool GNUArchiveReader::readStringTable(Archive& pArchive)
-{
- size_t offset = Archive::MAGIC_LEN +
- sizeof(Archive::MemberHeader) +
+bool GNUArchiveReader::readStringTable(Archive& pArchive) {
+ size_t offset = Archive::MAGIC_LEN + sizeof(Archive::MemberHeader) +
pArchive.getSymTabSize();
- if (0x0 != (offset & 1))
+ if ((offset & 1) != 0x0)
++offset;
assert(pArchive.getARFile().hasMemArea());
+ MemoryArea* memory_area = pArchive.getARFile().memArea();
llvm::StringRef header_region =
- pArchive.getARFile().memArea()->request((pArchive.getARFile().fileOffset() +
- offset),
- sizeof(Archive::MemberHeader));
+ memory_area->request((pArchive.getARFile().fileOffset() + offset),
+ sizeof(Archive::MemberHeader));
const Archive::MemberHeader* header =
- reinterpret_cast<const Archive::MemberHeader*>(header_region.begin());
+ reinterpret_cast<const Archive::MemberHeader*>(header_region.begin());
- assert(0 == memcmp(header->fmag, Archive::MEMBER_MAGIC, sizeof(header->fmag)));
+ assert(memcmp(header->fmag, Archive::MEMBER_MAGIC, sizeof(header->fmag)) ==
+ 0);
- if (0 == memcmp(header->name, Archive::STRTAB_NAME, sizeof(header->name))) {
+ if (memcmp(header->name, Archive::STRTAB_NAME, sizeof(header->name)) == 0) {
// read the extended name table
int strtab_size = atoi(header->size);
llvm::StringRef strtab_region =
- pArchive.getARFile().memArea()->request(
- (pArchive.getARFile().fileOffset() +
- offset + sizeof(Archive::MemberHeader)),
- strtab_size);
+ memory_area->request((pArchive.getARFile().fileOffset() + offset +
+ sizeof(Archive::MemberHeader)),
+ strtab_size);
const char* strtab = strtab_region.begin();
pArchive.getStrTable().assign(strtab, strtab_size);
}
@@ -341,12 +327,11 @@ bool GNUArchiveReader::readStringTable(Archive& pArchive)
/// shouldIncludeStatus - given a sym name from armap and check if including
/// the corresponding archive member, and then return the decision
-enum Archive::Symbol::Status
-GNUArchiveReader::shouldIncludeSymbol(const llvm::StringRef& pSymName) const
-{
+enum Archive::Symbol::Status GNUArchiveReader::shouldIncludeSymbol(
+ const llvm::StringRef& pSymName) const {
// TODO: handle symbol version issue and user defined symbols
const ResolveInfo* info = m_Module.getNamePool().findInfo(pSymName);
- if (NULL != info) {
+ if (info != NULL) {
if (!info->isUndef())
return Archive::Symbol::Exclude;
if (info->isWeak())
@@ -363,8 +348,7 @@ GNUArchiveReader::shouldIncludeSymbol(const llvm::StringRef& pSymName) const
/// @param pFileOffset - file offset of the member header in the archive
size_t GNUArchiveReader::includeMember(const LinkerConfig& pConfig,
Archive& pArchive,
- uint32_t pFileOffset)
-{
+ uint32_t pFileOffset) {
Input* cur_archive = &(pArchive.getARFile());
Input* member = NULL;
uint32_t file_offset = pFileOffset;
@@ -373,24 +357,21 @@ size_t GNUArchiveReader::includeMember(const LinkerConfig& pConfig,
uint32_t nested_offset = 0;
// use the file offset in current archive to find out the member we
// want to include
- member = readMemberHeader(pArchive,
- *cur_archive,
- file_offset,
- nested_offset,
- size);
+ member = readMemberHeader(
+ pArchive, *cur_archive, file_offset, nested_offset, size);
assert(member != NULL);
// bypass if we get an archive that is already in the map
if (Input::Archive == member->type()) {
- cur_archive = member;
- file_offset = nested_offset;
- continue;
+ cur_archive = member;
+ file_offset = nested_offset;
+ continue;
}
// insert a node into the subtree of current archive.
Archive::ArchiveMember* parent =
- pArchive.getArchiveMember(cur_archive->name());
+ pArchive.getArchiveMember(cur_archive->name());
- assert(NULL != parent);
+ assert(parent != NULL);
pArchive.inputs().insert(parent->lastPos, *(parent->move), *member);
// move the iterator to new created node, and also adjust the
@@ -410,20 +391,17 @@ size_t GNUArchiveReader::includeMember(const LinkerConfig& pConfig,
m_ELFObjectReader.readSections(*member);
m_ELFObjectReader.readSymbols(*member);
m_Module.getObjectList().push_back(member);
- }
- else if (doContinue && isMyFormat(*member, doContinue)) {
+ } else if (doContinue && isMyFormat(*member, doContinue)) {
member->setType(Input::Archive);
// when adding a new archive node, set the iterator to archive
// itself, and set the direction to Downward
- pArchive.addArchiveMember(member->name(),
- parent->lastPos,
- &InputTree::Downward);
+ pArchive.addArchiveMember(
+ member->name(), parent->lastPos, &InputTree::Downward);
cur_archive = member;
file_offset = nested_offset;
- }
- else {
- warning(diag::warn_unrecognized_input_file) << member->path()
- << pConfig.targets().triple().str();
+ } else {
+ warning(diag::warn_unrecognized_input_file)
+ << member->path() << pConfig.targets().triple().str();
}
} while (Input::Object != member->type());
return size;
@@ -432,8 +410,7 @@ size_t GNUArchiveReader::includeMember(const LinkerConfig& pConfig,
/// includeAllMembers - include all object members. This is called if
/// --whole-archive is the attribute for this archive file.
bool GNUArchiveReader::includeAllMembers(const LinkerConfig& pConfig,
- Archive& pArchive)
-{
+ Archive& pArchive) {
// read the symtab of the archive
readSymbolTable(pArchive);
@@ -447,28 +424,27 @@ bool GNUArchiveReader::includeAllMembers(const LinkerConfig& pConfig,
bool isThinAR = isThinArchive(pArchive.getARFile());
uint32_t begin_offset = pArchive.getARFile().fileOffset() +
- Archive::MAGIC_LEN +
- sizeof(Archive::MemberHeader) +
+ Archive::MAGIC_LEN + sizeof(Archive::MemberHeader) +
pArchive.getSymTabSize();
if (pArchive.hasStrTable()) {
- if (0x0 != (begin_offset & 1))
+ if ((begin_offset & 1) != 0x0)
++begin_offset;
- begin_offset += sizeof(Archive::MemberHeader) +
- pArchive.getStrTable().size();
+ begin_offset +=
+ sizeof(Archive::MemberHeader) + pArchive.getStrTable().size();
}
uint32_t end_offset = pArchive.getARFile().memArea()->size();
- for (uint32_t offset = begin_offset;
- offset < end_offset;
+ for (uint32_t offset = begin_offset; offset < end_offset;
offset += sizeof(Archive::MemberHeader)) {
-
size_t size = includeMember(pConfig, pArchive, offset);
if (!isThinAR) {
offset += size;
}
- if (0x0 != (offset & 1))
+ if ((offset & 1) != 0x0)
++offset;
}
return true;
}
+
+} // namespace mcld
diff --git a/lib/LD/GarbageCollection.cpp b/lib/LD/GarbageCollection.cpp
index 44c9b5a..b36f7ee 100644
--- a/lib/LD/GarbageCollection.cpp
+++ b/lib/LD/GarbageCollection.cpp
@@ -6,34 +6,35 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/Fragment.h>
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/LD/GarbageCollection.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Target/TargetLDBackend.h>
+#include "mcld/LD/GarbageCollection.h"
+
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/TargetLDBackend.h"
#include <llvm/Support/Casting.h>
#include <queue>
#if !defined(MCLD_ON_WIN32)
#include <fnmatch.h>
-#define fnmatch0(pattern,string) (fnmatch(pattern,string,0) == 0)
+#define fnmatch0(pattern, string) (fnmatch(pattern, string, 0) == 0)
#else
#include <windows.h>
#include <shlwapi.h>
-#define fnmatch0(pattern,string) (PathMatchSpec(string, pattern) == true)
+#define fnmatch0(pattern, string) (PathMatchSpec(string, pattern) == true)
#endif
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Non-member functions
@@ -41,20 +42,16 @@ using namespace mcld;
// FIXME: these rules should be added into SectionMap, while currently adding to
// SectionMap will cause the output order change in .text section and leads to
// the .ARM.exidx order incorrect. We should sort the .ARM.exidx.
-static const char* pattern_to_keep[] =
-{
- ".text*personality*",
- ".data*personality*",
- ".gnu.linkonce.d*personality*",
- ".sdata*personality*"
-};
+static const char* pattern_to_keep[] = {".text*personality*",
+ ".data*personality*",
+ ".gnu.linkonce.d*personality*",
+ ".sdata*personality*"};
/// shouldKeep - check the section name for the keep sections
-static bool shouldKeep(const std::string& pName)
-{
+static bool shouldKeep(const std::string& pName) {
static const unsigned int pattern_size =
- sizeof(pattern_to_keep) / sizeof(pattern_to_keep[0]);
- for (unsigned int i=0; i < pattern_size; ++i) {
+ sizeof(pattern_to_keep) / sizeof(pattern_to_keep[0]);
+ for (unsigned int i = 0; i < pattern_size; ++i) {
if (fnmatch0(pattern_to_keep[i], pName.c_str()))
return true;
}
@@ -62,8 +59,7 @@ static bool shouldKeep(const std::string& pName)
}
/// shouldProcessGC - check if the section kind is handled in GC
-static bool mayProcessGC(const LDSection& pSection)
-{
+static bool mayProcessGC(const LDSection& pSection) {
if (pSection.kind() == LDFileFormat::TEXT ||
pSection.kind() == LDFileFormat::DATA ||
pSection.kind() == LDFileFormat::BSS ||
@@ -75,24 +71,21 @@ static bool mayProcessGC(const LDSection& pSection)
//===----------------------------------------------------------------------===//
// GarbageCollection::SectionReachedListMap
//===----------------------------------------------------------------------===//
-void
-GarbageCollection::SectionReachedListMap::addReference(const LDSection& pFrom,
- const LDSection& pTo)
-{
+void GarbageCollection::SectionReachedListMap::addReference(
+ const LDSection& pFrom,
+ const LDSection& pTo) {
m_ReachedSections[&pFrom].insert(&pTo);
}
GarbageCollection::SectionListTy&
GarbageCollection::SectionReachedListMap::getReachedList(
- const LDSection& pSection)
-{
+ const LDSection& pSection) {
return m_ReachedSections[&pSection];
}
GarbageCollection::SectionListTy*
GarbageCollection::SectionReachedListMap::findReachedList(
- const LDSection& pSection)
-{
+ const LDSection& pSection) {
ReachedSectionsTy::iterator it = m_ReachedSections.find(&pSection);
if (it == m_ReachedSections.end())
return NULL;
@@ -105,16 +98,13 @@ GarbageCollection::SectionReachedListMap::findReachedList(
GarbageCollection::GarbageCollection(const LinkerConfig& pConfig,
const TargetLDBackend& pBackend,
Module& pModule)
- : m_Config(pConfig), m_Backend(pBackend), m_Module(pModule)
-{
+ : m_Config(pConfig), m_Backend(pBackend), m_Module(pModule) {
}
-GarbageCollection::~GarbageCollection()
-{
+GarbageCollection::~GarbageCollection() {
}
-bool GarbageCollection::run()
-{
+bool GarbageCollection::run() {
// 1. traverse all the relocations to set up the reached sections of each
// section
setUpReachedSections();
@@ -132,8 +122,7 @@ bool GarbageCollection::run()
return true;
}
-void GarbageCollection::setUpReachedSections()
-{
+void GarbageCollection::setUpReachedSections() {
// traverse all the input relocations to setup the reached sections
Module::obj_iterator input, inEnd = m_Module.obj_end();
for (input = m_Module.obj_begin(); input != inEnd; ++input) {
@@ -158,12 +147,12 @@ void GarbageCollection::setUpReachedSections()
SectionListTy* reached_sects = NULL;
RelocData::iterator reloc_it, rEnd = reloc_sect->getRelocData()->end();
for (reloc_it = reloc_sect->getRelocData()->begin(); reloc_it != rEnd;
- ++reloc_it) {
+ ++reloc_it) {
Relocation* reloc = llvm::cast<Relocation>(reloc_it);
ResolveInfo* sym = reloc->symInfo();
// only the target symbols defined in the input fragments can make the
// reference
- if (NULL == sym)
+ if (sym == NULL)
continue;
if (!sym->isDefine() || !sym->outSymbol()->hasFragRef())
continue;
@@ -171,7 +160,7 @@ void GarbageCollection::setUpReachedSections()
// only the target symbols defined in the concerned sections can make
// the reference
const LDSection* target_sect =
- &sym->outSymbol()->fragRef()->frag()->getParent()->getSection();
+ &sym->outSymbol()->fragRef()->frag()->getParent()->getSection();
if (!mayProcessGC(*target_sect))
continue;
@@ -189,8 +178,7 @@ void GarbageCollection::setUpReachedSections()
}
}
-void GarbageCollection::getEntrySections(SectionVecTy& pEntry)
-{
+void GarbageCollection::getEntrySections(SectionVecTy& pEntry) {
// all the KEEP sections defined in ldscript are entries, traverse all the
// input sections and check the SectionMap to find the KEEP sections
Module::obj_iterator obj, objEnd = m_Module.obj_end();
@@ -204,7 +192,7 @@ void GarbageCollection::getEntrySections(SectionVecTy& pEntry)
continue;
SectionMap::Input* sm_input =
- sect_map.find(input_name, section->name()).second;
+ sect_map.find(input_name, section->name()).second;
if (((sm_input != NULL) && (InputSectDesc::Keep == sm_input->policy())) ||
shouldKeep(section->name()))
pEntry.push_back(section);
@@ -213,19 +201,19 @@ void GarbageCollection::getEntrySections(SectionVecTy& pEntry)
// get the sections those the entry symbols defined in
if (LinkerConfig::Exec == m_Config.codeGenType() ||
- m_Config.options().isPIE()) {
+ m_Config.options().isPIE()) {
// when building executable
// 1. the entry symbol is the entry
LDSymbol* entry_sym =
- m_Module.getNamePool().findSymbol(m_Backend.getEntry(m_Module));
- assert(NULL != entry_sym);
+ m_Module.getNamePool().findSymbol(m_Backend.getEntry(m_Module));
+ assert(entry_sym != NULL);
pEntry.push_back(&entry_sym->fragRef()->frag()->getParent()->getSection());
// 2. the symbols have been seen in dynamice objects are entries
NamePool::syminfo_iterator info_it,
- info_end = m_Module.getNamePool().syminfo_end();
+ info_end = m_Module.getNamePool().syminfo_end();
for (info_it = m_Module.getNamePool().syminfo_begin(); info_it != info_end;
- ++info_it) {
+ ++info_it) {
ResolveInfo* info = info_it.getEntry();
if (!info->isDefine() || info->isLocal())
continue;
@@ -234,39 +222,36 @@ void GarbageCollection::getEntrySections(SectionVecTy& pEntry)
continue;
LDSymbol* sym = info->outSymbol();
- if (NULL == sym || !sym->hasFragRef())
+ if (sym == NULL || !sym->hasFragRef())
continue;
// only the target symbols defined in the concerned sections can be
// entries
const LDSection* sect =
- &sym->fragRef()->frag()->getParent()->getSection();
+ &sym->fragRef()->frag()->getParent()->getSection();
if (!mayProcessGC(*sect))
continue;
pEntry.push_back(sect);
}
- }
-
- else {
+ } else {
// when building shared objects, the global define symbols are entries
NamePool::syminfo_iterator info_it,
- info_end = m_Module.getNamePool().syminfo_end();
+ info_end = m_Module.getNamePool().syminfo_end();
for (info_it = m_Module.getNamePool().syminfo_begin(); info_it != info_end;
- ++info_it) {
+ ++info_it) {
ResolveInfo* info = info_it.getEntry();
- if (!info->isDefine() ||
- info->isLocal() ||
+ if (!info->isDefine() || info->isLocal() ||
info->shouldForceLocal(m_Config))
continue;
LDSymbol* sym = info->outSymbol();
- if (NULL == sym || !sym->hasFragRef())
+ if (sym == NULL || !sym->hasFragRef())
continue;
// only the target symbols defined in the concerned sections can be
// entries
const LDSection* sect =
- &sym->fragRef()->frag()->getParent()->getSection();
+ &sym->fragRef()->frag()->getParent()->getSection();
if (!mayProcessGC(*sect))
continue;
pEntry.push_back(sect);
@@ -276,7 +261,7 @@ void GarbageCollection::getEntrySections(SectionVecTy& pEntry)
// symbols set by -u should not be garbage collected. Set them entries.
GeneralOptions::const_undef_sym_iterator usym;
GeneralOptions::const_undef_sym_iterator usymEnd =
- m_Config.options().undef_sym_end();
+ m_Config.options().undef_sym_end();
for (usym = m_Config.options().undef_sym_begin(); usym != usymEnd; ++usym) {
LDSymbol* sym = m_Module.getNamePool().findSymbol(*usym);
assert(sym);
@@ -292,8 +277,7 @@ void GarbageCollection::getEntrySections(SectionVecTy& pEntry)
}
}
-void GarbageCollection::findReferencedSections(SectionVecTy& pEntry)
-{
+void GarbageCollection::findReferencedSections(SectionVecTy& pEntry) {
// list of sections waiting to be processed
typedef std::queue<const LDSection*> WorkListTy;
WorkListTy work_list;
@@ -316,8 +300,8 @@ void GarbageCollection::findReferencedSections(SectionVecTy& pEntry)
// get the section reached list, if the section do not has one, which
// means no referenced between it and other sections, then skip it
SectionListTy* reach_list =
- m_SectionReachedListMap.findReachedList(*sect);
- if (NULL == reach_list)
+ m_SectionReachedListMap.findReachedList(*sect);
+ if (reach_list == NULL)
continue;
// put the reached sections to work list, skip the one already be in
@@ -331,8 +315,7 @@ void GarbageCollection::findReferencedSections(SectionVecTy& pEntry)
}
}
-void GarbageCollection::stripSections()
-{
+void GarbageCollection::stripSections() {
// Traverse all the input Regular and BSS sections, if a section is not found
// in the ReferencedSections, then it should be garbage collected
Module::obj_iterator obj, objEnd = m_Module.obj_end();
@@ -364,3 +347,4 @@ void GarbageCollection::stripSections()
}
}
+} // namespace mcld
diff --git a/lib/LD/GroupReader.cpp b/lib/LD/GroupReader.cpp
index b3e6f9e..87deb33 100644
--- a/lib/LD/GroupReader.cpp
+++ b/lib/LD/GroupReader.cpp
@@ -6,40 +6,38 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/Archive.h>
-#include <mcld/LD/ArchiveReader.h>
-#include <mcld/LD/DynObjReader.h>
-#include <mcld/LD/GroupReader.h>
-#include <mcld/LD/ObjectReader.h>
-#include <mcld/LD/BinaryReader.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/Attribute.h>
-#include <mcld/Support/MsgHandling.h>
-
-using namespace mcld;
+#include "mcld/LD/GroupReader.h"
+
+#include "mcld/LD/Archive.h"
+#include "mcld/LD/ArchiveReader.h"
+#include "mcld/LD/BinaryReader.h"
+#include "mcld/LD/DynObjReader.h"
+#include "mcld/LD/ObjectReader.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/Support/MsgHandling.h"
+
+namespace mcld {
GroupReader::GroupReader(Module& pModule,
ObjectReader& pObjectReader,
DynObjReader& pDynObjReader,
ArchiveReader& pArchiveReader,
BinaryReader& pBinaryReader)
- : m_Module(pModule),
- m_ObjectReader(pObjectReader),
- m_DynObjReader(pDynObjReader),
- m_ArchiveReader(pArchiveReader),
- m_BinaryReader(pBinaryReader)
-{
+ : m_Module(pModule),
+ m_ObjectReader(pObjectReader),
+ m_DynObjReader(pDynObjReader),
+ m_ArchiveReader(pArchiveReader),
+ m_BinaryReader(pBinaryReader) {
}
-GroupReader::~GroupReader()
-{
+GroupReader::~GroupReader() {
}
bool GroupReader::readGroup(Module::input_iterator pRoot,
Module::input_iterator pEnd,
InputBuilder& pBuilder,
- const LinkerConfig& pConfig)
-{
+ const LinkerConfig& pConfig) {
// record the number of total objects included in this sub-tree
size_t cur_obj_cnt = 0;
size_t last_obj_cnt = 0;
@@ -83,15 +81,13 @@ bool GroupReader::readGroup(Module::input_iterator pRoot,
// read archive
m_ArchiveReader.readArchive(pConfig, *ar);
cur_obj_cnt += ar->numOfObjectMember();
- }
- // read input as a binary file
- else if (doContinue && m_BinaryReader.isMyFormat(**input, doContinue)) {
+ } else if (doContinue && m_BinaryReader.isMyFormat(**input, doContinue)) {
+ // read input as a binary file
(*input)->setType(Input::Object);
m_BinaryReader.readBinary(**input);
m_Module.getObjectList().push_back(*input);
- }
- // is a relocatable object file
- else if (doContinue && m_ObjectReader.isMyFormat(**input, doContinue)) {
+ } else if (doContinue && m_ObjectReader.isMyFormat(**input, doContinue)) {
+ // is a relocatable object file
(*input)->setType(Input::Object);
m_ObjectReader.readHeader(**input);
m_ObjectReader.readSections(**input);
@@ -99,17 +95,15 @@ bool GroupReader::readGroup(Module::input_iterator pRoot,
m_Module.getObjectList().push_back(*input);
++cur_obj_cnt;
++non_ar_obj_cnt;
- }
- // is a shared object file
- else if (doContinue && m_DynObjReader.isMyFormat(**input, doContinue)) {
+ } else if (doContinue && m_DynObjReader.isMyFormat(**input, doContinue)) {
+ // is a shared object file
(*input)->setType(Input::DynObj);
m_DynObjReader.readHeader(**input);
m_DynObjReader.readSymbols(**input);
m_Module.getLibraryList().push_back(*input);
- }
- else {
- warning(diag::warn_unrecognized_input_file) << (*input)->path()
- << pConfig.targets().triple().str();
+ } else {
+ warning(diag::warn_unrecognized_input_file)
+ << (*input)->path() << pConfig.targets().triple().str();
}
++input;
}
@@ -124,7 +118,7 @@ bool GroupReader::readGroup(Module::input_iterator pRoot,
for (it = ar_list.begin(); it != end; ++it) {
Archive& ar = (*it)->archive;
// if --whole-archive is given to this archive, no need to read it again
- if ( ar.getARFile().attribute()->isWholeArchive())
+ if (ar.getARFile().attribute()->isWholeArchive())
continue;
m_ArchiveReader.readArchive(pConfig, ar);
cur_obj_cnt += ar.numOfObjectMember();
@@ -151,3 +145,4 @@ bool GroupReader::readGroup(Module::input_iterator pRoot,
return true;
}
+} // namespace mcld
diff --git a/lib/LD/IdenticalCodeFolding.cpp b/lib/LD/IdenticalCodeFolding.cpp
index b3ba59d..11e3701 100644
--- a/lib/LD/IdenticalCodeFolding.cpp
+++ b/lib/LD/IdenticalCodeFolding.cpp
@@ -6,22 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "mcld/LD/IdenticalCodeFolding.h"
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/LD/IdenticalCodeFolding.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/Relocator.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/Input.h>
-#include <mcld/GeneralOptions.h>
-#include <mcld/Module.h>
-#include <mcld/Support/Demangle.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Target/GNULDBackend.h>
+#include "mcld/GeneralOptions.h"
+#include "mcld/Module.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/Relocator.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Support/Demangle.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/Casting.h>
@@ -32,10 +32,10 @@
#include <set>
#include <zlib.h>
-using namespace mcld;
-static bool isSymCtorOrDtor(const ResolveInfo& pSym)
-{
+namespace mcld {
+
+static bool isSymCtorOrDtor(const ResolveInfo& pSym) {
// We can always fold ctors and dtors since accessing function pointer in C++
// is forbidden.
llvm::StringRef name(pSym.name(), pSym.nameSize());
@@ -48,12 +48,10 @@ static bool isSymCtorOrDtor(const ResolveInfo& pSym)
IdenticalCodeFolding::IdenticalCodeFolding(const LinkerConfig& pConfig,
const TargetLDBackend& pBackend,
Module& pModule)
- : m_Config(pConfig), m_Backend(pBackend), m_Module(pModule)
-{
+ : m_Config(pConfig), m_Backend(pBackend), m_Module(pModule) {
}
-void IdenticalCodeFolding::foldIdenticalCode()
-{
+void IdenticalCodeFolding::foldIdenticalCode() {
// 1. Find folding candidates.
FoldingCandidates candidate_list;
findCandidates(candidate_list);
@@ -91,8 +89,7 @@ void IdenticalCodeFolding::foldIdenticalCode()
KeptSections::iterator it = m_KeptSections.begin() + kept_index;
LDSection* kept_sect = (*it).first;
Input* kept_obj = (*it).second.first;
- debug(diag::debug_icf_folded_section) << sect->name()
- << obj->name()
+ debug(diag::debug_icf_folded_section) << sect->name() << obj->name()
<< kept_sect->name()
<< kept_obj->name();
}
@@ -110,18 +107,16 @@ void IdenticalCodeFolding::foldIdenticalCode()
LDSection* sect = &(frag_ref->frag()->getParent()->getSection());
if (sect->kind() == LDFileFormat::Folded) {
size_t kept_index = m_KeptSections[sect].second;
- LDSection* kept_sect =
- (*(m_KeptSections.begin() + kept_index)).first;
+ LDSection* kept_sect = (*(m_KeptSections.begin() + kept_index)).first;
frag_ref->assign(kept_sect->getSectionData()->front(),
frag_ref->offset());
}
}
- } // for each symbol
- } // for each folded object
+ } // for each symbol
+ } // for each folded object
}
-void IdenticalCodeFolding::findCandidates(FoldingCandidates& pCandidateList)
-{
+void IdenticalCodeFolding::findCandidates(FoldingCandidates& pCandidateList) {
Module::obj_iterator obj, objEnd = m_Module.obj_end();
for (obj = m_Module.obj_begin(); obj != objEnd; ++obj) {
std::set<const LDSection*> funcptr_access_set;
@@ -131,7 +126,8 @@ void IdenticalCodeFolding::findCandidates(FoldingCandidates& pCandidateList)
for (sect = (*obj)->context()->sectBegin(); sect != sectEnd; ++sect) {
switch ((*sect)->kind()) {
case LDFileFormat::TEXT: {
- candidate_map.insert(std::make_pair(*sect, (LDSection*)NULL));
+ candidate_map.insert(
+ std::make_pair(*sect, reinterpret_cast<LDSection*>(NULL)));
break;
}
case LDFileFormat::Relocation: {
@@ -150,22 +146,22 @@ void IdenticalCodeFolding::findCandidates(FoldingCandidates& pCandidateList)
&sym->fragRef()->frag()->getParent()->getSection();
if (!isSymCtorOrDtor(*rel->symInfo()) &&
m_Backend.mayHaveUnsafeFunctionPointerAccess(*target) &&
- m_Backend.
- getRelocator()->mayHaveFunctionPointerAccess(*rel)) {
+ m_Backend.getRelocator()
+ ->mayHaveFunctionPointerAccess(*rel)) {
funcptr_access_set.insert(def);
}
}
- } // for each reloc
+ } // for each reloc
}
break;
}
default: {
// skip
- break;;
+ break;
}
- } // end of switch
- } // for each section
+ } // end of switch
+ } // for each section
CandidateMap::iterator candidate, candidateEnd = candidate_map.end();
for (candidate = candidate_map.begin(); candidate != candidateEnd;
@@ -174,25 +170,22 @@ void IdenticalCodeFolding::findCandidates(FoldingCandidates& pCandidateList)
(funcptr_access_set.count(candidate->first) == 0)) {
size_t index = m_KeptSections.size();
m_KeptSections[candidate->first] = ObjectAndId(*obj, index);
- pCandidateList.push_back(FoldingCandidate(candidate->first,
- candidate->second,
- *obj));
+ pCandidateList.push_back(
+ FoldingCandidate(candidate->first, candidate->second, *obj));
}
- } // for each possible candidate
-
- } // for each obj
+ } // for each possible candidate
+ } // for each obj
}
-bool IdenticalCodeFolding::matchCandidates(FoldingCandidates& pCandidateList)
-{
+bool IdenticalCodeFolding::matchCandidates(FoldingCandidates& pCandidateList) {
typedef std::multimap<uint32_t, size_t> ChecksumMap;
ChecksumMap checksum_map;
std::vector<std::string> contents(pCandidateList.size());
bool converged = true;
for (size_t index = 0; index < pCandidateList.size(); ++index) {
- contents[index] = pCandidateList[index].
- getContentWithVariables(m_Backend, m_KeptSections);
+ contents[index] = pCandidateList[index].getContentWithVariables(
+ m_Backend, m_KeptSections);
uint32_t checksum = ::crc32(0xFFFFFFFF,
(const uint8_t*)contents[index].c_str(),
contents[index].length());
@@ -219,8 +212,7 @@ bool IdenticalCodeFolding::matchCandidates(FoldingCandidates& pCandidateList)
void IdenticalCodeFolding::FoldingCandidate::initConstantContent(
const TargetLDBackend& pBackend,
- const IdenticalCodeFolding::KeptSections& pKeptSections)
-{
+ const IdenticalCodeFolding::KeptSections& pKeptSections) {
// Get the static content from text.
assert(sect != NULL && sect->hasSectionData());
SectionData::const_iterator frag, fragEnd = sect->getSectionData()->end();
@@ -242,10 +234,14 @@ void IdenticalCodeFolding::FoldingCandidate::initConstantContent(
if (reloc_sect != NULL && reloc_sect->hasRelocData()) {
RelocData::iterator rel, relEnd = reloc_sect->getRelocData()->end();
for (rel = reloc_sect->getRelocData()->begin(); rel != relEnd; ++rel) {
- llvm::format_object4<Relocation::Type, Relocation::Address,
- Relocation::Address, Relocation::Address>
- rel_info("%x%llx%llx%llx", rel->type(), rel->symValue(),
- rel->addend(), rel->place());
+ llvm::format_object4<Relocation::Type,
+ Relocation::Address,
+ Relocation::Address,
+ Relocation::Address> rel_info("%x%llx%llx%llx",
+ rel->type(),
+ rel->symValue(),
+ rel->addend(),
+ rel->place());
char rel_str[48];
rel_info.print(rel_str, sizeof(rel_str));
content.append(rel_str);
@@ -259,11 +255,10 @@ void IdenticalCodeFolding::FoldingCandidate::initConstantContent(
}
}
- if (!pBackend.isSymbolPreemptible(*rel->symInfo()) &&
- sym->hasFragRef() &&
+ if (!pBackend.isSymbolPreemptible(*rel->symInfo()) && sym->hasFragRef() &&
(pKeptSections.find(
- &sym->fragRef()->frag()->getParent()->getSection()) !=
- pKeptSections.end())) {
+ &sym->fragRef()->frag()->getParent()->getSection()) !=
+ pKeptSections.end())) {
// Mark this reloc as a variable.
variable_relocs.push_back(rel);
} else {
@@ -271,9 +266,8 @@ void IdenticalCodeFolding::FoldingCandidate::initConstantContent(
if ((sym->binding() == ResolveInfo::Local) ||
(sym->binding() == ResolveInfo::Absolute)) {
// ABS or Local symbols.
- content.append(sym->name())
- .append(obj->name())
- .append(obj->path().native());
+ content.append(sym->name()).append(obj->name()).append(
+ obj->path().native());
} else {
content.append(sym->name());
}
@@ -284,8 +278,7 @@ void IdenticalCodeFolding::FoldingCandidate::initConstantContent(
std::string IdenticalCodeFolding::FoldingCandidate::getContentWithVariables(
const TargetLDBackend& pBackend,
- const IdenticalCodeFolding::KeptSections& pKeptSections)
-{
+ const IdenticalCodeFolding::KeptSections& pKeptSections) {
std::string result(content);
// Compute the variable content from relocs.
std::vector<Relocation*>::const_iterator rel, relEnd = variable_relocs.end();
@@ -302,3 +295,5 @@ std::string IdenticalCodeFolding::FoldingCandidate::getContentWithVariables(
return result;
}
+
+} // namespace mcld
diff --git a/lib/LD/LDContext.cpp b/lib/LD/LDContext.cpp
index 8607dfd..ecb8e37 100644
--- a/lib/LD/LDContext.cpp
+++ b/lib/LD/LDContext.cpp
@@ -6,18 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDSymbol.h>
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+
#include <llvm/ADT/StringRef.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// LDContext
//===----------------------------------------------------------------------===//
-LDContext& LDContext::appendSection(LDSection& pSection)
-{
+LDContext& LDContext::appendSection(LDSection& pSection) {
if (LDFileFormat::Relocation == pSection.kind())
m_RelocSections.push_back(&pSection);
pSection.setIndex(m_SectionTable.size());
@@ -25,42 +25,37 @@ LDContext& LDContext::appendSection(LDSection& pSection)
return *this;
}
-LDSection* LDContext::getSection(unsigned int pIdx)
-{
+LDSection* LDContext::getSection(unsigned int pIdx) {
if (pIdx >= m_SectionTable.size())
return NULL;
return m_SectionTable[pIdx];
}
-const LDSection* LDContext::getSection(unsigned int pIdx) const
-{
+const LDSection* LDContext::getSection(unsigned int pIdx) const {
if (pIdx >= m_SectionTable.size())
return NULL;
return m_SectionTable[pIdx];
}
-LDSection* LDContext::getSection(const std::string& pName)
-{
+LDSection* LDContext::getSection(const std::string& pName) {
sect_iterator sect_iter, sect_end = sectEnd();
for (sect_iter = sectBegin(); sect_iter != sect_end; ++sect_iter) {
- if(NULL != *sect_iter && (*sect_iter)->name() == pName)
+ if (*sect_iter != NULL && (*sect_iter)->name() == pName)
return *sect_iter;
}
return NULL;
}
-const LDSection* LDContext::getSection(const std::string& pName) const
-{
+const LDSection* LDContext::getSection(const std::string& pName) const {
const_sect_iterator sect_iter, sect_end = sectEnd();
for (sect_iter = sectBegin(); sect_iter != sect_end; ++sect_iter) {
- if(NULL != *sect_iter && (*sect_iter)->name() == pName)
+ if (*sect_iter != NULL && (*sect_iter)->name() == pName)
return *sect_iter;
}
return NULL;
}
-size_t LDContext::getSectionIdx(const std::string& pName) const
-{
+size_t LDContext::getSectionIdx(const std::string& pName) const {
size_t result = 1;
size_t size = m_SectionTable.size();
for (; result != size; ++result)
@@ -69,23 +64,19 @@ size_t LDContext::getSectionIdx(const std::string& pName) const
return 0;
}
-LDSymbol* LDContext::getSymbol(unsigned int pIdx)
-{
+LDSymbol* LDContext::getSymbol(unsigned int pIdx) {
if (pIdx >= m_SymTab.size())
return NULL;
return m_SymTab[pIdx];
}
-const LDSymbol* LDContext::getSymbol(unsigned int pIdx) const
-{
+const LDSymbol* LDContext::getSymbol(unsigned int pIdx) const {
if (pIdx >= m_SymTab.size())
return NULL;
return m_SymTab[pIdx];
}
-
-LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName)
-{
+LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName) {
size_t sym = 1;
size_t size = m_SymTab.size();
for (; sym < size; ++sym)
@@ -94,8 +85,7 @@ LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName)
return NULL;
}
-const LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName) const
-{
+const LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName) const {
size_t sym = 1;
size_t size = m_SymTab.size();
for (; sym < size; ++sym)
@@ -103,3 +93,5 @@ const LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName) const
return m_SymTab[sym];
return NULL;
}
+
+} // namespace mcld
diff --git a/lib/LD/LDFileFormat.cpp b/lib/LD/LDFileFormat.cpp
index d1f0b80..0393c97 100644
--- a/lib/LD/LDFileFormat.cpp
+++ b/lib/LD/LDFileFormat.cpp
@@ -6,21 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDFileFormat.h>
+#include "mcld/LD/LDFileFormat.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// LDFileInfo
//===----------------------------------------------------------------------===//
LDFileFormat::LDFileFormat()
- : f_pTextSection(NULL),
- f_pDataSection(NULL),
- f_pBSSSection(NULL),
- f_pReadOnlySection(NULL) {
+ : f_pTextSection(NULL),
+ f_pDataSection(NULL),
+ f_pBSSSection(NULL),
+ f_pReadOnlySection(NULL) {
}
-LDFileFormat::~LDFileFormat()
-{
+LDFileFormat::~LDFileFormat() {
}
+} // namespace mcld
diff --git a/lib/LD/LDReader.cpp b/lib/LD/LDReader.cpp
index b74fc68..384e24c 100644
--- a/lib/LD/LDReader.cpp
+++ b/lib/LD/LDReader.cpp
@@ -6,9 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDReader.h>
+#include "mcld/LD/LDReader.h"
-using namespace mcld;
+namespace mcld {
//==========================
// LDReader
+
+} // namespace mcld
diff --git a/lib/LD/LDSection.cpp b/lib/LD/LDSection.cpp
index 30daee3..6faedc1 100644
--- a/lib/LD/LDSection.cpp
+++ b/lib/LD/LDSection.cpp
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDSection.h>
+#include "mcld/LD/LDSection.h"
-#include <mcld/Support/GCFactory.h>
+#include "mcld/Support/GCFactory.h"
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<LDSection, MCLD_SECTIONS_PER_INPUT> SectionFactory;
@@ -22,17 +22,17 @@ static llvm::ManagedStatic<SectionFactory> g_SectFactory;
// LDSection
//===----------------------------------------------------------------------===//
LDSection::LDSection()
- : m_Name(),
- m_Kind(LDFileFormat::Ignore),
- m_Type(0x0),
- m_Flag(0x0),
- m_Size(0),
- m_Offset(~uint64_t(0)),
- m_Addr(0x0),
- m_Align(0),
- m_Info(0),
- m_pLink(NULL),
- m_Index(0) {
+ : m_Name(),
+ m_Kind(LDFileFormat::Ignore),
+ m_Type(0x0),
+ m_Flag(0x0),
+ m_Size(0),
+ m_Offset(~uint64_t(0)),
+ m_Addr(0x0),
+ m_Align(0),
+ m_Info(0),
+ m_pLink(NULL),
+ m_Index(0) {
m_Data.sect_data = NULL;
}
@@ -42,26 +42,24 @@ LDSection::LDSection(const std::string& pName,
uint32_t pFlag,
uint64_t pSize,
uint64_t pAddr)
- : m_Name(pName),
- m_Kind(pKind),
- m_Type(pType),
- m_Flag(pFlag),
- m_Size(pSize),
- m_Offset(~uint64_t(0)),
- m_Addr(pAddr),
- m_Align(0),
- m_Info(0),
- m_pLink(NULL),
- m_Index(0) {
+ : m_Name(pName),
+ m_Kind(pKind),
+ m_Type(pType),
+ m_Flag(pFlag),
+ m_Size(pSize),
+ m_Offset(~uint64_t(0)),
+ m_Addr(pAddr),
+ m_Align(0),
+ m_Info(0),
+ m_pLink(NULL),
+ m_Index(0) {
m_Data.sect_data = NULL;
}
-LDSection::~LDSection()
-{
+LDSection::~LDSection() {
}
-bool LDSection::hasOffset() const
-{
+bool LDSection::hasOffset() const {
return (m_Offset != ~uint64_t(0));
}
@@ -70,40 +68,40 @@ LDSection* LDSection::Create(const std::string& pName,
uint32_t pType,
uint32_t pFlag,
uint64_t pSize,
- uint64_t pAddr)
-{
+ uint64_t pAddr) {
LDSection* result = g_SectFactory->allocate();
new (result) LDSection(pName, pKind, pType, pFlag, pSize, pAddr);
return result;
}
-void LDSection::Destroy(LDSection*& pSection)
-{
+void LDSection::Destroy(LDSection*& pSection) {
g_SectFactory->destroy(pSection);
g_SectFactory->deallocate(pSection);
pSection = NULL;
}
-void LDSection::Clear()
-{
+void LDSection::Clear() {
g_SectFactory->clear();
}
-bool LDSection::hasSectionData() const
-{
+bool LDSection::hasSectionData() const {
assert(LDFileFormat::Relocation != kind() && LDFileFormat::EhFrame != kind());
- return (NULL != m_Data.sect_data);
+ return (m_Data.sect_data != NULL);
}
-bool LDSection::hasRelocData() const
-{
+bool LDSection::hasRelocData() const {
assert(LDFileFormat::Relocation == kind());
- return (NULL != m_Data.reloc_data);
+ return (m_Data.reloc_data != NULL);
}
-bool LDSection::hasEhFrame() const
-{
+bool LDSection::hasEhFrame() const {
assert(LDFileFormat::EhFrame == kind());
- return (NULL != m_Data.eh_frame);
+ return (m_Data.eh_frame != NULL);
}
+bool LDSection::hasDebugString() const {
+ assert(LDFileFormat::DebugString == kind());
+ return (NULL != m_Data.debug_string);
+}
+
+} // namespace mcld
diff --git a/lib/LD/LDSymbol.cpp b/lib/LD/LDSymbol.cpp
index 9002235..5b389ea 100644
--- a/lib/LD/LDSymbol.cpp
+++ b/lib/LD/LDSymbol.cpp
@@ -6,18 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDSymbol.h>
+#include "mcld/LD/LDSymbol.h"
-#include <mcld/Config/Config.h>
-#include <mcld/Fragment/FragmentRef.h>
-#include <mcld/Fragment/NullFragment.h>
-#include <mcld/Support/GCFactory.h>
-
-#include <cstring>
+#include "mcld/Config/Config.h"
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/Support/GCFactory.h"
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+#include <cstring>
+
+namespace mcld {
typedef GCFactory<LDSymbol, MCLD_SYMBOLS_PER_INPUT> LDSymbolFactory;
@@ -28,52 +28,45 @@ static llvm::ManagedStatic<LDSymbolFactory> g_LDSymbolFactory;
//===----------------------------------------------------------------------===//
// LDSymbol
//===----------------------------------------------------------------------===//
-LDSymbol::LDSymbol()
- : m_pResolveInfo(NULL), m_pFragRef(NULL), m_Value(0) {
+LDSymbol::LDSymbol() : m_pResolveInfo(NULL), m_pFragRef(NULL), m_Value(0) {
}
-LDSymbol::~LDSymbol()
-{
+LDSymbol::~LDSymbol() {
}
LDSymbol::LDSymbol(const LDSymbol& pCopy)
- : m_pResolveInfo(pCopy.m_pResolveInfo),
- m_pFragRef(pCopy.m_pFragRef),
- m_Value(pCopy.m_Value) {
+ : m_pResolveInfo(pCopy.m_pResolveInfo),
+ m_pFragRef(pCopy.m_pFragRef),
+ m_Value(pCopy.m_Value) {
}
-LDSymbol& LDSymbol::operator=(const LDSymbol& pCopy)
-{
+LDSymbol& LDSymbol::operator=(const LDSymbol& pCopy) {
m_pResolveInfo = pCopy.m_pResolveInfo;
m_pFragRef = pCopy.m_pFragRef;
m_Value = pCopy.m_Value;
return (*this);
}
-LDSymbol* LDSymbol::Create(ResolveInfo& pResolveInfo)
-{
+LDSymbol* LDSymbol::Create(ResolveInfo& pResolveInfo) {
LDSymbol* result = g_LDSymbolFactory->allocate();
new (result) LDSymbol();
result->setResolveInfo(pResolveInfo);
return result;
}
-void LDSymbol::Destroy(LDSymbol*& pSymbol)
-{
+void LDSymbol::Destroy(LDSymbol*& pSymbol) {
pSymbol->~LDSymbol();
g_LDSymbolFactory->deallocate(pSymbol);
pSymbol = NULL;
}
-void LDSymbol::Clear()
-{
+void LDSymbol::Clear() {
g_LDSymbolFactory->clear();
}
-LDSymbol* LDSymbol::Null()
-{
+LDSymbol* LDSymbol::Null() {
// lazy initialization
- if (NULL == g_NullSymbol->resolveInfo()) {
+ if (g_NullSymbol->resolveInfo() == NULL) {
g_NullSymbol->setResolveInfo(*ResolveInfo::Null());
g_NullSymbol->setFragmentRef(FragmentRef::Create(*g_NullSymbolFragment, 0));
ResolveInfo::Null()->setSymPtr(&*g_NullSymbol);
@@ -81,23 +74,20 @@ LDSymbol* LDSymbol::Null()
return &*g_NullSymbol;
}
-void LDSymbol::setFragmentRef(FragmentRef* pFragmentRef)
-{
+void LDSymbol::setFragmentRef(FragmentRef* pFragmentRef) {
m_pFragRef = pFragmentRef;
}
-void LDSymbol::setResolveInfo(const ResolveInfo& pInfo)
-{
+void LDSymbol::setResolveInfo(const ResolveInfo& pInfo) {
m_pResolveInfo = const_cast<ResolveInfo*>(&pInfo);
}
-bool LDSymbol::isNull() const
-{
+bool LDSymbol::isNull() const {
return (this == Null());
}
-bool LDSymbol::hasFragRef() const
-{
+bool LDSymbol::hasFragRef() const {
return !m_pFragRef->isNull();
}
+} // namespace mcld
diff --git a/lib/LD/MergedStringTable.cpp b/lib/LD/MergedStringTable.cpp
new file mode 100644
index 0000000..70735cb
--- /dev/null
+++ b/lib/LD/MergedStringTable.cpp
@@ -0,0 +1,42 @@
+//===- MergedStringTable.cpp ----------------------------------------------===//
+//
+// The MCLinker Project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "mcld/LD/MergedStringTable.h"
+
+namespace mcld {
+
+bool MergedStringTable::insertString(llvm::StringRef pString) {
+ return m_StringMap.insert(std::make_pair(pString, 0)).second;
+}
+
+uint64_t MergedStringTable::finalizeOffset() {
+ // trverse the string table and set the offset
+ string_map_iterator it, end = m_StringMap.end();
+ size_t offset = 0;
+ for (it = m_StringMap.begin(); it != end; ++it) {
+ it->setValue(offset);
+ offset += it->getKey().size() + 1;
+ }
+ return offset;
+}
+
+void MergedStringTable::emit(MemoryRegion& pRegion) {
+ char* ptr = reinterpret_cast<char*>(pRegion.begin());
+ string_map_iterator it, end = m_StringMap.end();
+ for (it = m_StringMap.begin(); it != end; ++it) {
+ ::memcpy(ptr, it->getKey().data(), it->getKey().size());
+ ptr += it->getKey().size() + 1;
+ }
+}
+
+size_t MergedStringTable::getOutputOffset(llvm::StringRef pStr) {
+ assert(m_StringMap.find(pStr) != m_StringMap.end());
+ return m_StringMap[pStr];
+}
+
+} // namespace mcld
diff --git a/lib/LD/MsgHandler.cpp b/lib/LD/MsgHandler.cpp
index 96310a2..0c88565 100644
--- a/lib/LD/MsgHandler.cpp
+++ b/lib/LD/MsgHandler.cpp
@@ -6,47 +6,45 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/MsgHandler.h>
-#include <mcld/LD/DiagnosticEngine.h>
+#include "mcld/LD/MsgHandler.h"
-using namespace mcld;
+#include "mcld/LD/DiagnosticEngine.h"
+
+namespace mcld {
MsgHandler::MsgHandler(DiagnosticEngine& pEngine)
- : m_Engine(pEngine), m_NumArgs(0) {
+ : m_Engine(pEngine), m_NumArgs(0) {
}
-MsgHandler::~MsgHandler()
-{
+MsgHandler::~MsgHandler() {
emit();
}
-bool MsgHandler::emit()
-{
+bool MsgHandler::emit() {
flushCounts();
return m_Engine.emit();
}
-void MsgHandler::addString(llvm::StringRef pStr) const
-{
+void MsgHandler::addString(llvm::StringRef pStr) const {
assert(m_NumArgs < DiagnosticEngine::MaxArguments &&
"Too many arguments to diagnostic!");
m_Engine.state().ArgumentKinds[m_NumArgs] = DiagnosticEngine::ak_std_string;
m_Engine.state().ArgumentStrs[m_NumArgs++] = pStr.data();
}
-void MsgHandler::addString(const std::string& pStr) const
-{
+void MsgHandler::addString(const std::string& pStr) const {
assert(m_NumArgs < DiagnosticEngine::MaxArguments &&
"Too many arguments to diagnostic!");
m_Engine.state().ArgumentKinds[m_NumArgs] = DiagnosticEngine::ak_std_string;
m_Engine.state().ArgumentStrs[m_NumArgs++] = pStr;
}
-void MsgHandler::addTaggedVal(intptr_t pValue, DiagnosticEngine::ArgumentKind pKind) const
-{
+void MsgHandler::addTaggedVal(intptr_t pValue,
+ DiagnosticEngine::ArgumentKind pKind) const {
assert(m_NumArgs < DiagnosticEngine::MaxArguments &&
"Too many arguments to diagnostic!");
m_Engine.state().ArgumentKinds[m_NumArgs] = pKind;
m_Engine.state().ArgumentVals[m_NumArgs++] = pValue;
}
+} // namespace mcld
diff --git a/lib/LD/NamePool.cpp b/lib/LD/NamePool.cpp
index 151b1dd..3eecda4 100644
--- a/lib/LD/NamePool.cpp
+++ b/lib/LD/NamePool.cpp
@@ -6,21 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "mcld/LD/NamePool.h"
+
+#include "mcld/LD/StaticResolver.h"
+
#include <llvm/Support/raw_ostream.h>
-#include <mcld/LD/NamePool.h>
-#include <mcld/LD/StaticResolver.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// NamePool
//===----------------------------------------------------------------------===//
NamePool::NamePool(NamePool::size_type pSize)
- : m_pResolver(new StaticResolver()), m_Table(pSize) {
+ : m_pResolver(new StaticResolver()), m_Table(pSize) {
}
-NamePool::~NamePool()
-{
+NamePool::~NamePool() {
delete m_pResolver;
FreeInfoSet::iterator info, iEnd = m_FreeInfoSet.end();
@@ -36,8 +37,7 @@ ResolveInfo* NamePool::createSymbol(const llvm::StringRef& pName,
ResolveInfo::Desc pDesc,
ResolveInfo::Binding pBinding,
ResolveInfo::SizeType pSize,
- ResolveInfo::Visibility pVisibility)
-{
+ ResolveInfo::Visibility pVisibility) {
ResolveInfo** result = m_FreeInfoSet.allocate();
(*result) = ResolveInfo::Create(pName);
(*result)->setIsSymbol(true);
@@ -54,16 +54,15 @@ ResolveInfo* NamePool::createSymbol(const llvm::StringRef& pName,
/// @return the pointer of resolved ResolveInfo
/// @return is the symbol existent?
void NamePool::insertSymbol(const llvm::StringRef& pName,
- bool pIsDyn,
- ResolveInfo::Type pType,
- ResolveInfo::Desc pDesc,
- ResolveInfo::Binding pBinding,
- ResolveInfo::SizeType pSize,
- LDSymbol::ValueType pValue,
- ResolveInfo::Visibility pVisibility,
- ResolveInfo* pOldInfo,
- Resolver::Result& pResult)
-{
+ bool pIsDyn,
+ ResolveInfo::Type pType,
+ ResolveInfo::Desc pDesc,
+ ResolveInfo::Binding pBinding,
+ ResolveInfo::SizeType pSize,
+ LDSymbol::ValueType pValue,
+ ResolveInfo::Visibility pVisibility,
+ ResolveInfo* pOldInfo,
+ Resolver::Result& pResult) {
// We should check if there is any symbol with the same name existed.
// If it already exists, we should use resolver to decide which symbol
// should be reserved. Otherwise, we insert the symbol and set up its
@@ -73,8 +72,7 @@ void NamePool::insertSymbol(const llvm::StringRef& pName,
ResolveInfo* new_symbol = NULL;
if (exist && old_symbol->isSymbol()) {
new_symbol = m_Table.getEntryFactory().produce(pName);
- }
- else {
+ } else {
exist = false;
new_symbol = old_symbol;
}
@@ -89,12 +87,11 @@ void NamePool::insertSymbol(const llvm::StringRef& pName,
if (!exist) {
// old_symbol is neither existed nor a symbol.
- pResult.info = new_symbol;
- pResult.existent = false;
+ pResult.info = new_symbol;
+ pResult.existent = false;
pResult.overriden = true;
return;
- }
- else if (NULL != pOldInfo) {
+ } else if (pOldInfo != NULL) {
// existent, remember its attribute
pOldInfo->override(*old_symbol);
}
@@ -104,64 +101,57 @@ void NamePool::insertSymbol(const llvm::StringRef& pName,
bool override = false;
unsigned int action = Resolver::LastAction;
if (m_pResolver->resolve(*old_symbol, *new_symbol, override, pValue)) {
- pResult.info = old_symbol;
- pResult.existent = true;
+ pResult.info = old_symbol;
+ pResult.existent = true;
pResult.overriden = override;
- }
- else {
- m_pResolver->resolveAgain(*this, action, *old_symbol, *new_symbol, pResult);
+ } else {
+ m_pResolver->resolveAgain(*this, action, *old_symbol, *new_symbol, pResult);
}
m_Table.getEntryFactory().destroy(new_symbol);
return;
}
-llvm::StringRef NamePool::insertString(const llvm::StringRef& pString)
-{
+llvm::StringRef NamePool::insertString(const llvm::StringRef& pString) {
bool exist = false;
ResolveInfo* resolve_info = m_Table.insert(pString, exist);
return llvm::StringRef(resolve_info->name(), resolve_info->nameSize());
}
-void NamePool::reserve(NamePool::size_type pSize)
-{
+void NamePool::reserve(NamePool::size_type pSize) {
m_Table.rehash(pSize);
}
-NamePool::size_type NamePool::capacity() const
-{
+NamePool::size_type NamePool::capacity() const {
return (m_Table.numOfBuckets() - m_Table.numOfEntries());
}
/// findInfo - find the resolved ResolveInfo
-ResolveInfo* NamePool::findInfo(const llvm::StringRef& pName)
-{
+ResolveInfo* NamePool::findInfo(const llvm::StringRef& pName) {
Table::iterator iter = m_Table.find(pName);
return iter.getEntry();
}
/// findInfo - find the resolved ResolveInfo
-const ResolveInfo* NamePool::findInfo(const llvm::StringRef& pName) const
-{
+const ResolveInfo* NamePool::findInfo(const llvm::StringRef& pName) const {
Table::const_iterator iter = m_Table.find(pName);
return iter.getEntry();
}
/// findSymbol - find the resolved output LDSymbol
-LDSymbol* NamePool::findSymbol(const llvm::StringRef& pName)
-{
+LDSymbol* NamePool::findSymbol(const llvm::StringRef& pName) {
ResolveInfo* info = findInfo(pName);
- if (NULL == info)
+ if (info == NULL)
return NULL;
return info->outSymbol();
}
/// findSymbol - find the resolved output LDSymbol
-const LDSymbol* NamePool::findSymbol(const llvm::StringRef& pName) const
-{
+const LDSymbol* NamePool::findSymbol(const llvm::StringRef& pName) const {
const ResolveInfo* info = findInfo(pName);
- if (NULL == info)
+ if (info == NULL)
return NULL;
return info->outSymbol();
}
+} // namespace mcld
diff --git a/lib/LD/ObjectWriter.cpp b/lib/LD/ObjectWriter.cpp
index 17d04eb..c06a546 100644
--- a/lib/LD/ObjectWriter.cpp
+++ b/lib/LD/ObjectWriter.cpp
@@ -6,17 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ObjectWriter.h>
+#include "mcld/LD/ObjectWriter.h"
-using namespace mcld;
+namespace mcld {
//==========================
// ObjectWriter
-ObjectWriter::ObjectWriter()
-{
+ObjectWriter::ObjectWriter() {
}
-ObjectWriter::~ObjectWriter()
-{
+ObjectWriter::~ObjectWriter() {
}
+} // namespace mcld
diff --git a/lib/LD/RelocData.cpp b/lib/LD/RelocData.cpp
index 8379872..8732bdb 100644
--- a/lib/LD/RelocData.cpp
+++ b/lib/LD/RelocData.cpp
@@ -6,12 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/RelocData.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/LD/RelocData.h"
+
+#include "mcld/Support/GCFactory.h"
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<RelocData, MCLD_SECTIONS_PER_INPUT> RelocDataFactory;
@@ -20,42 +21,37 @@ static llvm::ManagedStatic<RelocDataFactory> g_RelocDataFactory;
//===----------------------------------------------------------------------===//
// RelocData
//===----------------------------------------------------------------------===//
-RelocData::RelocData()
- : m_pSection(NULL) {
+RelocData::RelocData() : m_pSection(NULL) {
}
-RelocData::RelocData(LDSection &pSection)
- : m_pSection(&pSection) {
+RelocData::RelocData(LDSection& pSection) : m_pSection(&pSection) {
}
-RelocData* RelocData::Create(LDSection& pSection)
-{
+RelocData* RelocData::Create(LDSection& pSection) {
RelocData* result = g_RelocDataFactory->allocate();
new (result) RelocData(pSection);
return result;
}
-void RelocData::Destroy(RelocData*& pSection)
-{
+void RelocData::Destroy(RelocData*& pSection) {
pSection->~RelocData();
g_RelocDataFactory->deallocate(pSection);
pSection = NULL;
}
-void RelocData::Clear()
-{
+void RelocData::Clear() {
g_RelocDataFactory->clear();
}
-RelocData& RelocData::append(Relocation& pRelocation)
-{
+RelocData& RelocData::append(Relocation& pRelocation) {
m_Relocations.push_back(&pRelocation);
return *this;
}
-Relocation& RelocData::remove(Relocation& pRelocation)
-{
+Relocation& RelocData::remove(Relocation& pRelocation) {
iterator iter(pRelocation);
Relocation* rel = m_Relocations.remove(iter);
return *rel;
}
+
+} // namespace mcld
diff --git a/lib/LD/RelocationFactory.cpp b/lib/LD/RelocationFactory.cpp
index 08eb347..402c3d6 100644
--- a/lib/LD/RelocationFactory.cpp
+++ b/lib/LD/RelocationFactory.cpp
@@ -6,35 +6,34 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/RelocationFactory.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Target/TargetLDBackend.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/LD/RelocationFactory.h"
+
+#include "mcld/LinkerConfig.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/TargetLDBackend.h"
#include <llvm/Support/Host.h>
-#include <cstring>
#include <cassert>
+#include <cstring>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// RelocationFactory
//===----------------------------------------------------------------------===//
RelocationFactory::RelocationFactory()
- : GCFactory<Relocation, MCLD_RELOCATIONS_PER_INPUT>(), m_pConfig(NULL) {
+ : GCFactory<Relocation, MCLD_RELOCATIONS_PER_INPUT>(), m_pConfig(NULL) {
}
-void RelocationFactory::setConfig(const LinkerConfig& pConfig)
-{
+void RelocationFactory::setConfig(const LinkerConfig& pConfig) {
m_pConfig = &pConfig;
}
Relocation* RelocationFactory::produce(RelocationFactory::Type pType,
FragmentRef& pFragRef,
- Address pAddend)
-{
- if (NULL == m_pConfig) {
+ Address pAddend) {
+ if (m_pConfig == NULL) {
fatal(diag::reloc_factory_has_not_config);
return NULL;
}
@@ -65,10 +64,9 @@ Relocation* RelocationFactory::produce(RelocationFactory::Type pType,
<< m_pConfig->targets().bitclass();
return NULL;
}
- } // end of switch
- }
- else {
- pFragRef.memcpy(&target_data, (m_pConfig->targets().bitclass()/8));
+ } // end of switch
+ } else {
+ pFragRef.memcpy(&target_data, (m_pConfig->targets().bitclass() / 8));
}
Relocation* result = allocate();
@@ -76,15 +74,14 @@ Relocation* RelocationFactory::produce(RelocationFactory::Type pType,
return result;
}
-Relocation* RelocationFactory::produceEmptyEntry()
-{
+Relocation* RelocationFactory::produceEmptyEntry() {
Relocation* result = allocate();
new (result) Relocation(0, 0, 0, 0);
return result;
}
-void RelocationFactory::destroy(Relocation* pRelocation)
-{
- /** GCFactory will recycle the relocation **/
+void RelocationFactory::destroy(Relocation* pRelocation) {
+ /** GCFactory will recycle the relocation **/
}
+} // namespace mcld
diff --git a/lib/LD/Relocator.cpp b/lib/LD/Relocator.cpp
index fa3a94f..46fc4c4 100644
--- a/lib/LD/Relocator.cpp
+++ b/lib/LD/Relocator.cpp
@@ -6,31 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Fragment/Fragment.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/Relocator.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Support/Demangle.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Module.h>
+#include "mcld/LD/Relocator.h"
+
+#include "mcld/Module.h"
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Support/Demangle.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <sstream>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Relocator
//===----------------------------------------------------------------------===//
-Relocator::~Relocator()
-{
+Relocator::~Relocator() {
}
void Relocator::partialScanRelocation(Relocation& pReloc,
- Module& pModule,
- const LDSection& pSection)
-{
+ Module& pModule) {
// if we meet a section symbol
if (pReloc.symInfo()->type() == ResolveInfo::Section) {
LDSymbol* input_sym = pReloc.symInfo()->outSymbol();
@@ -43,9 +42,9 @@ void Relocator::partialScanRelocation(Relocation& pReloc,
// 2. get output section symbol
// get the output LDSection which the symbol defined in
const LDSection& out_sect =
- input_sym->fragRef()->frag()->getParent()->getSection();
+ input_sym->fragRef()->frag()->getParent()->getSection();
ResolveInfo* sym_info =
- pModule.getSectionSymbolSet().get(out_sect)->resolveInfo();
+ pModule.getSectionSymbolSet().get(out_sect)->resolveInfo();
// set relocation target symbol to the output section symbol's resolveInfo
pReloc.setSymInfo(sym_info);
}
@@ -53,11 +52,11 @@ void Relocator::partialScanRelocation(Relocation& pReloc,
void Relocator::issueUndefRef(Relocation& pReloc,
LDSection& pSection,
- Input& pInput)
-{
+ Input& pInput) {
FragmentRef::Offset undef_sym_pos = pReloc.targetRef().offset();
std::string sect_name(pSection.name());
- sect_name = sect_name.substr(sect_name.find('.', /*pos=*/1)); // Drop .rel(a) prefix
+ // Drop .rel(a) prefix
+ sect_name = sect_name.substr(sect_name.find('.', /*pos=*/1));
std::string reloc_sym(pReloc.symInfo()->name());
reloc_sym = demangleName(reloc_sym);
@@ -68,9 +67,7 @@ void Relocator::issueUndefRef(Relocation& pReloc,
if (sect_name.substr(0, 5) != ".text") {
// Function name is only valid for text section
- fatal(diag::undefined_reference) << reloc_sym
- << pInput.path()
- << sect_name
+ fatal(diag::undefined_reference) << reloc_sym << pInput.path() << sect_name
<< undef_sym_pos_hex;
return;
}
@@ -78,7 +75,9 @@ void Relocator::issueUndefRef(Relocation& pReloc,
std::string caller_file_name;
std::string caller_func_name;
for (LDContext::sym_iterator i = pInput.context()->symTabBegin(),
- e = pInput.context()->symTabEnd(); i != e; ++i) {
+ e = pInput.context()->symTabEnd();
+ i != e;
+ ++i) {
LDSymbol& sym = **i;
if (sym.resolveInfo()->type() == ResolveInfo::File)
caller_file_name = sym.resolveInfo()->name();
@@ -93,8 +92,8 @@ void Relocator::issueUndefRef(Relocation& pReloc,
caller_func_name = demangleName(caller_func_name);
- fatal(diag::undefined_reference_text) << reloc_sym
- << pInput.path()
- << caller_file_name
- << caller_func_name;
+ fatal(diag::undefined_reference_text) << reloc_sym << pInput.path()
+ << caller_file_name << caller_func_name;
}
+
+} // namespace mcld
diff --git a/lib/LD/ResolveInfo.cpp b/lib/LD/ResolveInfo.cpp
index ca26d63..b152044 100644
--- a/lib/LD/ResolveInfo.cpp
+++ b/lib/LD/ResolveInfo.cpp
@@ -6,15 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/LD/ResolveInfo.h"
+
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Support/GCFactory.h"
+
#include <llvm/Support/ManagedStatic.h>
+
#include <cstdlib>
#include <cstring>
-using namespace mcld;
+namespace mcld {
/// g_NullResolveInfo - a pointer to Null ResolveInfo.
static ResolveInfo* g_NullResolveInfo = NULL;
@@ -22,34 +25,27 @@ static ResolveInfo* g_NullResolveInfo = NULL;
//===----------------------------------------------------------------------===//
// ResolveInfo
//===----------------------------------------------------------------------===//
-ResolveInfo::ResolveInfo()
- : m_Size(0), m_BitField(0) {
+ResolveInfo::ResolveInfo() : m_Size(0), m_BitField(0) {
m_Ptr.sym_ptr = 0;
}
-ResolveInfo::~ResolveInfo()
-{
+ResolveInfo::~ResolveInfo() {
}
-void ResolveInfo::override(const ResolveInfo& pFrom)
-{
+void ResolveInfo::override(const ResolveInfo& pFrom) {
m_Size = pFrom.m_Size;
overrideAttributes(pFrom);
overrideVisibility(pFrom);
}
-void ResolveInfo::overrideAttributes(const ResolveInfo& pFrom)
-{
- m_BitField &= ~RESOLVE_MASK;
- m_BitField |= (pFrom.m_BitField & RESOLVE_MASK);
+void ResolveInfo::overrideAttributes(const ResolveInfo& pFrom) {
+ m_BitField &= ~RESOLVE_MASK | VISIBILITY_MASK;
+ m_BitField |= (pFrom.m_BitField & (RESOLVE_MASK & ~VISIBILITY_MASK));
}
/// overrideVisibility - override the visibility
/// always use the most strict visibility
-void ResolveInfo::overrideVisibility(const ResolveInfo& pFrom)
-{
- // Reference: Google gold linker: resolve.cc
- //
+void ResolveInfo::overrideVisibility(const ResolveInfo& pFrom) {
// The rule for combining visibility is that we always choose the
// most constrained visibility. In order of increasing constraint,
// visibility goes PROTECTED, HIDDEN, INTERNAL. This is the reverse
@@ -65,51 +61,44 @@ void ResolveInfo::overrideVisibility(const ResolveInfo& pFrom)
Visibility from_vis = pFrom.visibility();
Visibility cur_vis = visibility();
- if (0 != from_vis ) {
- if (0 == cur_vis)
+ if (from_vis != 0) {
+ if (cur_vis == 0)
setVisibility(from_vis);
else if (cur_vis > from_vis)
setVisibility(from_vis);
}
}
-void ResolveInfo::setRegular()
-{
+void ResolveInfo::setRegular() {
m_BitField &= (~dynamic_flag);
}
-void ResolveInfo::setDynamic()
-{
+void ResolveInfo::setDynamic() {
m_BitField |= dynamic_flag;
}
-void ResolveInfo::setSource(bool pIsDyn)
-{
+void ResolveInfo::setSource(bool pIsDyn) {
if (pIsDyn)
m_BitField |= dynamic_flag;
else
m_BitField &= (~dynamic_flag);
}
-void ResolveInfo::setInDyn()
-{
+void ResolveInfo::setInDyn() {
m_BitField |= indyn_flag;
}
-void ResolveInfo::setType(uint32_t pType)
-{
+void ResolveInfo::setType(uint32_t pType) {
m_BitField &= ~TYPE_MASK;
m_BitField |= ((pType << TYPE_OFFSET) & TYPE_MASK);
}
-void ResolveInfo::setDesc(uint32_t pDesc)
-{
+void ResolveInfo::setDesc(uint32_t pDesc) {
m_BitField &= ~DESC_MASK;
m_BitField |= ((pDesc << DESC_OFFSET) & DESC_MASK);
}
-void ResolveInfo::setBinding(uint32_t pBinding)
-{
+void ResolveInfo::setBinding(uint32_t pBinding) {
m_BitField &= ~BINDING_MASK;
if (pBinding == Local || pBinding == Absolute)
m_BitField |= local_flag;
@@ -117,112 +106,92 @@ void ResolveInfo::setBinding(uint32_t pBinding)
m_BitField |= weak_flag;
}
-void ResolveInfo::setReserved(uint32_t pReserved)
-{
+void ResolveInfo::setReserved(uint32_t pReserved) {
m_BitField &= ~RESERVED_MASK;
m_BitField |= ((pReserved << RESERVED_OFFSET) & RESERVED_MASK);
}
-void ResolveInfo::setOther(uint32_t pOther)
-{
+void ResolveInfo::setOther(uint32_t pOther) {
setVisibility(static_cast<ResolveInfo::Visibility>(pOther & 0x3));
}
-void ResolveInfo::setVisibility(ResolveInfo::Visibility pVisibility)
-{
+void ResolveInfo::setVisibility(ResolveInfo::Visibility pVisibility) {
m_BitField &= ~VISIBILITY_MASK;
m_BitField |= pVisibility << VISIBILITY_OFFSET;
}
-void ResolveInfo::setIsSymbol(bool pIsSymbol)
-{
+void ResolveInfo::setIsSymbol(bool pIsSymbol) {
if (pIsSymbol)
m_BitField |= symbol_flag;
else
m_BitField &= ~symbol_flag;
}
-bool ResolveInfo::isNull() const
-{
+bool ResolveInfo::isNull() const {
return (this == Null());
}
-bool ResolveInfo::isDyn() const
-{
+bool ResolveInfo::isDyn() const {
return (dynamic_flag == (m_BitField & DYN_MASK));
}
-bool ResolveInfo::isUndef() const
-{
+bool ResolveInfo::isUndef() const {
return (undefine_flag == (m_BitField & DESC_MASK));
}
-bool ResolveInfo::isDefine() const
-{
+bool ResolveInfo::isDefine() const {
return (define_flag == (m_BitField & DESC_MASK));
}
-bool ResolveInfo::isCommon() const
-{
+bool ResolveInfo::isCommon() const {
return (common_flag == (m_BitField & DESC_MASK));
}
-bool ResolveInfo::isIndirect() const
-{
+bool ResolveInfo::isIndirect() const {
return (indirect_flag == (m_BitField & DESC_MASK));
}
// isGlobal - [L,W] == [0, 0]
-bool ResolveInfo::isGlobal() const
-{
+bool ResolveInfo::isGlobal() const {
return (global_flag == (m_BitField & BINDING_MASK));
}
// isWeak - [L,W] == [0, 1]
-bool ResolveInfo::isWeak() const
-{
+bool ResolveInfo::isWeak() const {
return (weak_flag == (m_BitField & BINDING_MASK));
}
// isLocal - [L,W] == [1, 0]
-bool ResolveInfo::isLocal() const
-{
+bool ResolveInfo::isLocal() const {
return (local_flag == (m_BitField & BINDING_MASK));
}
// isAbsolute - [L,W] == [1, 1]
-bool ResolveInfo::isAbsolute() const
-{
+bool ResolveInfo::isAbsolute() const {
return (absolute_flag == (m_BitField & BINDING_MASK));
}
-bool ResolveInfo::isSymbol() const
-{
+bool ResolveInfo::isSymbol() const {
return (symbol_flag == (m_BitField & SYMBOL_MASK));
}
-bool ResolveInfo::isString() const
-{
+bool ResolveInfo::isString() const {
return (string_flag == (m_BitField & SYMBOL_MASK));
}
-bool ResolveInfo::isInDyn() const
-{
+bool ResolveInfo::isInDyn() const {
return (indyn_flag == (m_BitField & IN_DYN_MASK));
}
-uint32_t ResolveInfo::type() const
-{
+uint32_t ResolveInfo::type() const {
return (m_BitField & TYPE_MASK) >> TYPE_OFFSET;
}
-uint32_t ResolveInfo::desc() const
-{
+uint32_t ResolveInfo::desc() const {
return (m_BitField & DESC_MASK) >> DESC_OFFSET;
}
-uint32_t ResolveInfo::binding() const
-{
+uint32_t ResolveInfo::binding() const {
if (m_BitField & LOCAL_MASK) {
if (m_BitField & GLOBAL_MASK) {
return ResolveInfo::Absolute;
@@ -232,26 +201,23 @@ uint32_t ResolveInfo::binding() const
return m_BitField & GLOBAL_MASK;
}
-uint32_t ResolveInfo::reserved() const
-{
+uint32_t ResolveInfo::reserved() const {
return (m_BitField & RESERVED_MASK) >> RESERVED_OFFSET;
}
-ResolveInfo::Visibility ResolveInfo::visibility() const
-{
- return static_cast<ResolveInfo::Visibility>((m_BitField & VISIBILITY_MASK) >> VISIBILITY_OFFSET);
+ResolveInfo::Visibility ResolveInfo::visibility() const {
+ return static_cast<ResolveInfo::Visibility>((m_BitField & VISIBILITY_MASK) >>
+ VISIBILITY_OFFSET);
}
-bool ResolveInfo::compare(const ResolveInfo::key_type& pKey)
-{
+bool ResolveInfo::compare(const ResolveInfo::key_type& pKey) {
size_t length = nameSize();
if (length != pKey.size())
return false;
- return (0 == std::memcmp(m_Name, pKey.data(), length));
+ return (std::memcmp(m_Name, pKey.data(), length) == 0);
}
-bool ResolveInfo::shouldForceLocal(const LinkerConfig& pConfig)
-{
+bool ResolveInfo::shouldForceLocal(const LinkerConfig& pConfig) {
// forced local symbol matches all rules:
// 1. We are not doing incremental linking.
// 2. The symbol is with Hidden or Internal visibility.
@@ -260,22 +226,20 @@ bool ResolveInfo::shouldForceLocal(const LinkerConfig& pConfig)
if (LinkerConfig::Object != pConfig.codeGenType() &&
(visibility() == ResolveInfo::Hidden ||
visibility() == ResolveInfo::Internal) &&
- (isGlobal() || isWeak()) &&
- (isDefine() || isCommon()))
+ (isGlobal() || isWeak()) && (isDefine() || isCommon()))
return true;
return false;
}
//===----------------------------------------------------------------------===//
// ResolveInfo Factory Methods
//===----------------------------------------------------------------------===//
-ResolveInfo* ResolveInfo::Create(const ResolveInfo::key_type& pKey)
-{
- ResolveInfo* info = static_cast<ResolveInfo*>(
- malloc(sizeof(ResolveInfo)+pKey.size()+1));
- if (NULL == info)
+ResolveInfo* ResolveInfo::Create(const ResolveInfo::key_type& pKey) {
+ ResolveInfo* info =
+ static_cast<ResolveInfo*>(malloc(sizeof(ResolveInfo) + pKey.size() + 1));
+ if (info == NULL)
return NULL;
- new (info) ResolveInfo(); // call constructor at the `result` address.
+ new (info) ResolveInfo(); // call constructor at the `result` address.
std::memcpy(info->m_Name, pKey.data(), pKey.size());
info->m_Name[pKey.size()] = '\0';
info->m_BitField &= ~ResolveInfo::RESOLVE_MASK;
@@ -283,12 +247,11 @@ ResolveInfo* ResolveInfo::Create(const ResolveInfo::key_type& pKey)
return info;
}
-void ResolveInfo::Destroy(ResolveInfo*& pInfo)
-{
+void ResolveInfo::Destroy(ResolveInfo*& pInfo) {
if (pInfo->isNull())
return;
- if (NULL != pInfo) {
+ if (pInfo != NULL) {
pInfo->~ResolveInfo();
free(pInfo);
}
@@ -296,11 +259,10 @@ void ResolveInfo::Destroy(ResolveInfo*& pInfo)
pInfo = NULL;
}
-ResolveInfo* ResolveInfo::Null()
-{
- if (NULL == g_NullResolveInfo) {
- g_NullResolveInfo = static_cast<ResolveInfo*>(
- malloc(sizeof(ResolveInfo) + 1));
+ResolveInfo* ResolveInfo::Null() {
+ if (g_NullResolveInfo == NULL) {
+ g_NullResolveInfo =
+ static_cast<ResolveInfo*>(malloc(sizeof(ResolveInfo) + 1));
new (g_NullResolveInfo) ResolveInfo();
g_NullResolveInfo->m_Name[0] = '\0';
g_NullResolveInfo->m_BitField = 0x0;
@@ -309,4 +271,4 @@ ResolveInfo* ResolveInfo::Null()
return g_NullResolveInfo;
}
-
+} // namespace mcld
diff --git a/lib/LD/Resolver.cpp b/lib/LD/Resolver.cpp
index aa39b13..1824d92 100644
--- a/lib/LD/Resolver.cpp
+++ b/lib/LD/Resolver.cpp
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/Resolver.h>
+#include "mcld/LD/Resolver.h"
-using namespace mcld;
+namespace mcld {
//==========================
// Resolver
-Resolver::~Resolver()
-{
+Resolver::~Resolver() {
}
+} // namespace mcld
diff --git a/lib/LD/SectionData.cpp b/lib/LD/SectionData.cpp
index bb73724..6f669b7 100644
--- a/lib/LD/SectionData.cpp
+++ b/lib/LD/SectionData.cpp
@@ -6,14 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/SectionData.h>
+#include "mcld/LD/SectionData.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/Support/GCFactory.h"
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<SectionData, MCLD_SECTIONS_PER_INPUT> SectDataFactory;
@@ -22,30 +22,26 @@ static llvm::ManagedStatic<SectDataFactory> g_SectDataFactory;
//===----------------------------------------------------------------------===//
// SectionData
//===----------------------------------------------------------------------===//
-SectionData::SectionData()
- : m_pSection(NULL) {
+SectionData::SectionData() : m_pSection(NULL) {
}
-SectionData::SectionData(LDSection &pSection)
- : m_pSection(&pSection) {
+SectionData::SectionData(LDSection& pSection) : m_pSection(&pSection) {
}
-SectionData* SectionData::Create(LDSection& pSection)
-{
+SectionData* SectionData::Create(LDSection& pSection) {
SectionData* result = g_SectDataFactory->allocate();
new (result) SectionData(pSection);
return result;
}
-void SectionData::Destroy(SectionData*& pSection)
-{
+void SectionData::Destroy(SectionData*& pSection) {
pSection->~SectionData();
g_SectDataFactory->deallocate(pSection);
pSection = NULL;
}
-void SectionData::Clear()
-{
+void SectionData::Clear() {
g_SectDataFactory->clear();
}
+} // namespace mcld
diff --git a/lib/LD/SectionSymbolSet.cpp b/lib/LD/SectionSymbolSet.cpp
index 07157cb..0d2555c 100644
--- a/lib/LD/SectionSymbolSet.cpp
+++ b/lib/LD/SectionSymbolSet.cpp
@@ -6,36 +6,33 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/SectionSymbolSet.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/NamePool.h>
-#include <mcld/Fragment/FragmentRef.h>
-#include <mcld/LD/LDFileFormat.h>
+#include "mcld/LD/SectionSymbolSet.h"
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/NamePool.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// SectionSymbolSet
//===----------------------------------------------------------------------===//
-SectionSymbolSet::SectionSymbolSet()
-{
+SectionSymbolSet::SectionSymbolSet() {
m_pSectionSymbolMap = new SectHashTableType(16);
}
-SectionSymbolSet::~SectionSymbolSet()
-{
+SectionSymbolSet::~SectionSymbolSet() {
delete m_pSectionSymbolMap;
}
-bool SectionSymbolSet::add(LDSection& pOutSect, NamePool& pNamePool)
-{
+bool SectionSymbolSet::add(LDSection& pOutSect, NamePool& pNamePool) {
// create the resolveInfo for this section symbol
llvm::StringRef sym_name = llvm::StringRef(pOutSect.name());
ResolveInfo* sym_info = pNamePool.createSymbol(sym_name,
@@ -43,7 +40,7 @@ bool SectionSymbolSet::add(LDSection& pOutSect, NamePool& pNamePool)
ResolveInfo::Section,
ResolveInfo::Define,
ResolveInfo::Local,
- 0x0, // size
+ 0x0, // size
ResolveInfo::Default);
// create the output section symbol and set its fragRef to the first fragment
@@ -54,7 +51,7 @@ bool SectionSymbolSet::add(LDSection& pOutSect, NamePool& pNamePool)
// insert the symbol to the Section to Symbol hash map
bool exist = false;
SectHashTableType::entry_type* entry =
- m_pSectionSymbolMap->insert(&pOutSect, exist);
+ m_pSectionSymbolMap->insert(&pOutSect, exist);
assert(!exist);
entry->setValue(sym);
@@ -62,13 +59,13 @@ bool SectionSymbolSet::add(LDSection& pOutSect, NamePool& pNamePool)
}
bool SectionSymbolSet::finalize(LDSection& pOutSect,
- SymbolTable& pSymTab, bool relocatable)
-{
+ SymbolTable& pSymTab,
+ bool relocatable) {
if (!relocatable && pOutSect.size() == 0)
- return true;
+ return true;
LDSymbol* sym = get(pOutSect);
- assert(NULL != sym);
+ assert(sym != NULL);
SectionData* data = NULL;
switch (pOutSect.kind()) {
case LDFileFormat::Relocation:
@@ -76,8 +73,8 @@ bool SectionSymbolSet::finalize(LDSection& pOutSect,
return true;
case LDFileFormat::EhFrame:
- if (EhFrame *ehframe = pOutSect.getEhFrame())
- data = ehframe->getSectionData();
+ if (EhFrame* ehframe = pOutSect.getEhFrame())
+ data = ehframe->getSectionData();
break;
default:
@@ -96,15 +93,14 @@ bool SectionSymbolSet::finalize(LDSection& pOutSect,
return true;
}
-LDSymbol* SectionSymbolSet::get(const LDSection& pOutSect)
-{
+LDSymbol* SectionSymbolSet::get(const LDSection& pOutSect) {
SectHashTableType::iterator entry = m_pSectionSymbolMap->find(&pOutSect);
return entry.getEntry()->value();
}
-const LDSymbol* SectionSymbolSet::get(const LDSection& pOutSect) const
-{
+const LDSymbol* SectionSymbolSet::get(const LDSection& pOutSect) const {
SectHashTableType::iterator entry = m_pSectionSymbolMap->find(&pOutSect);
return entry.getEntry()->value();
}
+} // namespace mcld
diff --git a/lib/LD/StaticResolver.cpp b/lib/LD/StaticResolver.cpp
index 3dad005..1dd9747 100644
--- a/lib/LD/StaticResolver.cpp
+++ b/lib/LD/StaticResolver.cpp
@@ -6,45 +6,43 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/StaticResolver.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Support/Demangle.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/LD/StaticResolver.h"
-using namespace mcld;
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/Support/Demangle.h"
+#include "mcld/Support/MsgHandling.h"
+
+namespace mcld {
//==========================
// StaticResolver
-StaticResolver::~StaticResolver()
-{
+StaticResolver::~StaticResolver() {
}
bool StaticResolver::resolve(ResolveInfo& __restrict__ pOld,
const ResolveInfo& __restrict__ pNew,
- bool &pOverride, LDSymbol::ValueType pValue) const
-{
-
+ bool& pOverride,
+ LDSymbol::ValueType pValue) const {
/* The state table itself.
* The first index is a link_row and the second index is a bfd_link_hash_type.
*
* Cs -> all rest kind of common (d_C, wd_C)
* Is -> all kind of indirect
*/
- static const enum LinkAction link_action[LAST_ORD][LAST_ORD] =
- {
- /* new\old U w_U d_U wd_U D w_D d_D wd_D C w_C, Cs, Is */
- /* U */ {NOACT, UND, UND, UND, NOACT, NOACT, DUND, DUND, NOACT, NOACT, NOACT, REFC },
- /* w_U */ {NOACT, NOACT, NOACT, WEAK, NOACT, NOACT, DUNDW, DUNDW, NOACT, NOACT, NOACT, REFC },
- /* d_U */ {NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, REFC },
- /* wd_U */ {NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, REFC },
- /* D */ {DEF, DEF, DEF, DEF, MDEF, DEF, DEF, DEF, CDEF, CDEF, CDEF, MDEF },
- /* w_D */ {DEFW, DEFW, DEFW, DEFW, NOACT, NOACT, DEFW, DEFW, NOACT, NOACT, NOACT, NOACT},
- /* d_D */ {MDEFD, MDEFD, DEFD, DEFD, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, MDEF },
- /* wd_D */ {MDEFWD, MDEFWD, DEFWD, DEFWD, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT},
- /* C */ {COM, COM, COM, COM, CREF, COM, COM, COM, MBIG, COM, BIG, REFC },
- /* w_C */ {COM, COM, COM, COM, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, REFC },
- /* Cs */ {COM, COM, COM, COM, NOACT, NOACT, NOACT, NOACT, MBIG, MBIG, MBIG, REFC },
- /* Is */ {IND, IND, IND, IND, MDEF, IND, IND, IND, CIND, CIND, CIND, MIND }
+ static const enum LinkAction link_action[LAST_ORD][LAST_ORD] = {
+ /* new\old U w_U d_U wd_U D w_D d_D wd_D C w_C, Cs, Is */ // NOLINT
+ /* U */ {NOACT, UND, UND, UND, NOACT, NOACT, DUND, DUND, NOACT, NOACT, NOACT, REFC }, // NOLINT
+ /* w_U */ {NOACT, NOACT, NOACT, WEAK, NOACT, NOACT, DUNDW, DUNDW, NOACT, NOACT, NOACT, REFC }, // NOLINT
+ /* d_U */ {NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, REFC }, // NOLINT
+ /* wd_U */ {NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, REFC }, // NOLINT
+ /* D */ {DEF, DEF, DEF, DEF, MDEF, DEF, DEF, DEF, CDEF, CDEF, CDEF, MDEF }, // NOLINT
+ /* w_D */ {DEFW, DEFW, DEFW, DEFW, NOACT, NOACT, DEFW, DEFW, NOACT, NOACT, NOACT, NOACT}, // NOLINT
+ /* d_D */ {MDEFD, MDEFD, DEFD, DEFD, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, MDEF }, // NOLINT
+ /* wd_D */ {MDEFWD, MDEFWD, DEFWD, DEFWD, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT}, // NOLINT
+ /* C */ {COM, COM, COM, COM, CREF, COM, COM, COM, MBIG, COM, BIG, REFC }, // NOLINT
+ /* w_C */ {COM, COM, COM, COM, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, NOACT, REFC }, // NOLINT
+ /* Cs */ {COM, COM, COM, COM, NOACT, NOACT, NOACT, NOACT, MBIG, MBIG, MBIG, REFC }, // NOLINT
+ /* Is */ {IND, IND, IND, IND, MDEF, IND, IND, IND, CIND, CIND, CIND, MIND } // NOLINT
};
// Special cases:
@@ -57,7 +55,7 @@ bool StaticResolver::resolve(ResolveInfo& __restrict__ pOld,
// * When a undefined symbol meets a dynamic defined symbol or a weak
// undefined symbol meets a dynamic defined symbol, should override.
// * When a common symbol meets a weak common symbol, adjust the size of
- // common symbol (ref: Google gold linker: resolve.cc)
+ // common symbol.
unsigned int row = getOrdinate(pNew);
unsigned int col = getOrdinate(pOld);
@@ -70,31 +68,30 @@ bool StaticResolver::resolve(ResolveInfo& __restrict__ pOld,
cycle = false;
action = link_action[row][col];
- switch(action) {
- case FAIL: { /* abort. */
- fatal(diag::fail_sym_resolution)
- << __FILE__ << __LINE__
- << "mclinker@googlegroups.com";
+ switch (action) {
+ case FAIL: { /* abort. */
+ fatal(diag::fail_sym_resolution) << __FILE__ << __LINE__
+ << "mclinker@googlegroups.com";
return false;
}
- case NOACT: { /* no action. */
+ case NOACT: { /* no action. */
pOverride = false;
old->overrideVisibility(pNew);
break;
}
- case UND: /* override by symbol undefined symbol. */
- case WEAK: /* override by symbol weak undefined. */
- case DEF: /* override by symbol defined. */
- case DEFW: /* override by symbol weak defined. */
- case DEFD: /* override by symbol dynamic defined. */
- case DEFWD: /* override by symbol dynamic weak defined. */
- case COM: { /* override by symbol common defined. */
+ case UND: /* override by symbol undefined symbol. */
+ case WEAK: /* override by symbol weak undefined. */
+ case DEF: /* override by symbol defined. */
+ case DEFW: /* override by symbol weak defined. */
+ case DEFD: /* override by symbol dynamic defined. */
+ case DEFWD: /* override by symbol dynamic weak defined. */
+ case COM: { /* override by symbol common defined. */
pOverride = true;
old->override(pNew);
break;
}
- case MDEFD: /* mark symbol dynamic defined. */
- case MDEFWD: { /* mark symbol dynamic weak defined. */
+ case MDEFD: /* mark symbol dynamic defined. */
+ case MDEFWD: { /* mark symbol dynamic weak defined. */
uint32_t binding = old->binding();
old->override(pNew);
old->setBinding(binding);
@@ -109,23 +106,24 @@ bool StaticResolver::resolve(ResolveInfo& __restrict__ pOld,
pOverride = false;
break;
}
- case CREF: { /* Possibly warn about common reference to defined symbol. */
+ case CREF: { /* Possibly warn about common reference to defined symbol. */
// A common symbol does not override a definition.
ignore(diag::comm_refer_to_define) << old->name();
pOverride = false;
break;
}
- case CDEF: { /* redefine existing common symbol. */
+ case CDEF: { /* redefine existing common symbol. */
// We've seen a common symbol and now we see a definition. The
// definition overrides.
//
- // NOTE: m_Mesg uses 'name' instead of `name' for being compatible to GNU ld.
+ // NOTE: m_Mesg uses 'name' instead of `name' for being compatible to
+ // GNU ld.
ignore(diag::redefine_common) << old->name();
old->override(pNew);
pOverride = true;
break;
}
- case BIG: { /* override by symbol common using largest size. */
+ case BIG: { /* override by symbol common using largest size. */
if (old->size() < pNew.size())
old->setSize(pNew.size());
old->overrideAttributes(pNew);
@@ -133,26 +131,27 @@ bool StaticResolver::resolve(ResolveInfo& __restrict__ pOld,
pOverride = true;
break;
}
- case MBIG: { /* mark common symbol by larger size. */
+ case MBIG: { /* mark common symbol by larger size. */
if (old->size() < pNew.size())
old->setSize(pNew.size());
old->overrideVisibility(pNew);
pOverride = false;
break;
}
- case CIND: { /* mark indirect symbol from existing common symbol. */
- ignore(diag::indirect_refer_to_common) << old->name();
+ case CIND: { /* mark indirect symbol from existing common symbol. */
+ ignore(diag::indirect_refer_to_common) << old->name();
}
/* Fall through */
- case IND: { /* override by indirect symbol. */
- if (NULL == pNew.link()) {
+ case IND: { /* override by indirect symbol. */
+ if (pNew.link() == NULL) {
fatal(diag::indirect_refer_to_inexist) << pNew.name();
break;
}
/** Should detect the loop of indirect symbol during file reading **/
// if (pNew.link()->isIndirect() && pNew.link()->link() == &pNew) {
- // m_Mesg = "indirect symbol `"+pNew.name()+"' to `"+pNew.link()->name()+"' is a loop.";
+ // m_Mesg = "indirect symbol `"+pNew.name()+"' to
+ // `"+pNew.link()->name()+"' is a loop.";
// return Resolver::Abort;
//}
@@ -161,7 +160,7 @@ bool StaticResolver::resolve(ResolveInfo& __restrict__ pOld,
pOverride = true;
break;
}
- case MIND: { /* multiple indirect symbols. */
+ case MIND: { /* multiple indirect symbols. */
// it is OK if they both point to the same symbol
if (old->link() == pNew.link()) {
pOverride = false;
@@ -169,9 +168,9 @@ bool StaticResolver::resolve(ResolveInfo& __restrict__ pOld,
}
}
/* Fall through */
- case MDEF: { /* multiple definition error. */
- if (pOld.isDefine() && pNew.isDefine() &&
- pOld.isAbsolute() && pNew.isAbsolute() &&
+ case MDEF: { /* multiple definition error. */
+ if (pOld.isDefine() && pNew.isDefine() && pOld.isAbsolute() &&
+ pNew.isAbsolute() &&
(pOld.desc() == pNew.desc() || pOld.desc() == ResolveInfo::NoType ||
pNew.desc() == ResolveInfo::NoType)) {
if (pOld.outSymbol()->value() == pValue) {
@@ -180,8 +179,7 @@ bool StaticResolver::resolve(ResolveInfo& __restrict__ pOld,
break;
} else {
error(diag::multiple_absolute_definitions)
- << demangleName(pNew.name())
- << pOld.outSymbol()->value()
+ << demangleName(pNew.name()) << pOld.outSymbol()->value()
<< pValue;
break;
}
@@ -190,8 +188,8 @@ bool StaticResolver::resolve(ResolveInfo& __restrict__ pOld,
error(diag::multiple_definitions) << demangleName(pNew.name());
break;
}
- case REFC: { /* Mark indirect symbol referenced and then CYCLE. */
- if (NULL == old->link()) {
+ case REFC: { /* Mark indirect symbol referenced and then CYCLE. */
+ if (old->link() == NULL) {
fatal(diag::indirect_refer_to_inexist) << old->name();
break;
}
@@ -202,11 +200,13 @@ bool StaticResolver::resolve(ResolveInfo& __restrict__ pOld,
break;
}
default: {
- error(diag::undefined_situation) << action << old->name() << pNew.name();
+ error(diag::undefined_situation) << action << old->name()
+ << pNew.name();
return false;
}
- } // end of the big switch (action)
- } while(cycle);
+ } // end of the big switch (action)
+ } while (cycle);
return true;
}
+} // namespace mcld
diff --git a/lib/LD/StubFactory.cpp b/lib/LD/StubFactory.cpp
index 52c372c..75de0cf 100644
--- a/lib/LD/StubFactory.cpp
+++ b/lib/LD/StubFactory.cpp
@@ -6,32 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/StubFactory.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/LD/BranchIsland.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/Fragment/Stub.h>
-#include <mcld/Fragment/Relocation.h>
+#include "mcld/LD/StubFactory.h"
+
+#include "mcld/IRBuilder.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/BranchIsland.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
#include <string>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// StubFactory
//===----------------------------------------------------------------------===//
-StubFactory::~StubFactory()
-{
+StubFactory::~StubFactory() {
for (StubPoolType::iterator it = m_StubPool.begin(), ie = m_StubPool.end();
- it != ie; ++it)
- delete(*it);
+ it != ie;
+ ++it)
+ delete (*it);
}
/// addPrototype - register a stub prototype
-void StubFactory::addPrototype(Stub* pPrototype)
-{
+void StubFactory::addPrototype(Stub* pPrototype) {
m_StubPool.push_back(pPrototype);
}
@@ -39,8 +39,7 @@ void StubFactory::addPrototype(Stub* pPrototype)
Stub* StubFactory::create(Relocation& pReloc,
uint64_t pTargetSymValue,
IRBuilder& pBuilder,
- BranchIslandFactory& pBRIslandFactory)
-{
+ BranchIslandFactory& pBRIslandFactory) {
// find if there is a prototype stub for the input relocation
Stub* stub = NULL;
Stub* prototype = findPrototype(pReloc, pReloc.place(), pTargetSymValue);
@@ -87,16 +86,18 @@ Stub* StubFactory::create(Relocation& pReloc,
ResolveInfo::Function,
ResolveInfo::Define,
ResolveInfo::Local,
- stub->size(), // size
- stub->initSymValue(), // value
+ stub->size(), // size
+ stub->initSymValue(), // value
FragmentRef::Create(*stub, stub->initSymValue()),
ResolveInfo::Default);
stub->setSymInfo(symbol->resolveInfo());
- // add relocations of this stub (i.e., set the branch target of the stub)
+ // add relocations of this stub (i.e., set the branch target of the
+ // stub)
for (Stub::fixup_iterator it = stub->fixup_begin(),
- ie = stub->fixup_end(); it != ie; ++it) {
-
+ ie = stub->fixup_end();
+ it != ie;
+ ++it) {
Relocation* reloc =
Relocation::Create((*it)->type(),
*(FragmentRef::Create(*stub, (*it)->offset())),
@@ -120,12 +121,14 @@ Stub* StubFactory::create(Relocation& pReloc,
/// relocation
Stub* StubFactory::findPrototype(const Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue)
-{
+ uint64_t pTargetSymValue) {
for (StubPoolType::iterator it = m_StubPool.begin(), ie = m_StubPool.end();
- it != ie; ++it) {
+ it != ie;
+ ++it) {
if ((*it)->isMyDuty(pReloc, pSource, pTargetSymValue))
return (*it);
}
return NULL;
}
+
+} // namespace mcld
diff --git a/lib/LD/TextDiagnosticPrinter.cpp b/lib/LD/TextDiagnosticPrinter.cpp
index 9fcabea..5b1d488 100644
--- a/lib/LD/TextDiagnosticPrinter.cpp
+++ b/lib/LD/TextDiagnosticPrinter.cpp
@@ -6,38 +6,45 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/TextDiagnosticPrinter.h>
-#include <mcld/LinkerConfig.h>
+#include "mcld/LD/TextDiagnosticPrinter.h"
+
+#include "mcld/LinkerConfig.h"
+
#include <llvm/Support/Signals.h>
+
#include <string>
-using namespace mcld;
+namespace mcld {
-static const enum llvm::raw_ostream::Colors UnreachableColor = llvm::raw_ostream::RED;
-static const enum llvm::raw_ostream::Colors FatalColor = llvm::raw_ostream::YELLOW;
-static const enum llvm::raw_ostream::Colors ErrorColor = llvm::raw_ostream::RED;
-static const enum llvm::raw_ostream::Colors WarningColor = llvm::raw_ostream::MAGENTA;
-static const enum llvm::raw_ostream::Colors DebugColor = llvm::raw_ostream::CYAN;
-static const enum llvm::raw_ostream::Colors NoteColor = llvm::raw_ostream::GREEN;
-static const enum llvm::raw_ostream::Colors IgnoreColor = llvm::raw_ostream::BLUE;
+static const enum llvm::raw_ostream::Colors UnreachableColor =
+ llvm::raw_ostream::RED;
+static const enum llvm::raw_ostream::Colors FatalColor =
+ llvm::raw_ostream::YELLOW;
+static const enum llvm::raw_ostream::Colors ErrorColor = llvm::raw_ostream::RED;
+static const enum llvm::raw_ostream::Colors WarningColor =
+ llvm::raw_ostream::MAGENTA;
+static const enum llvm::raw_ostream::Colors DebugColor =
+ llvm::raw_ostream::CYAN;
+static const enum llvm::raw_ostream::Colors NoteColor =
+ llvm::raw_ostream::GREEN;
+static const enum llvm::raw_ostream::Colors IgnoreColor =
+ llvm::raw_ostream::BLUE;
//===----------------------------------------------------------------------===//
// TextDiagnosticPrinter
TextDiagnosticPrinter::TextDiagnosticPrinter(llvm::raw_ostream& pOStream,
const LinkerConfig& pConfig)
- : m_OStream(pOStream), m_Config(pConfig), m_pInput(NULL) {
+ : m_OStream(pOStream), m_Config(pConfig), m_pInput(NULL) {
}
-TextDiagnosticPrinter::~TextDiagnosticPrinter()
-{
+TextDiagnosticPrinter::~TextDiagnosticPrinter() {
}
/// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
/// capturing it to a log as needed.
-void
-TextDiagnosticPrinter::handleDiagnostic(DiagnosticEngine::Severity pSeverity,
- const Diagnostic& pInfo)
-{
+void TextDiagnosticPrinter::handleDiagnostic(
+ DiagnosticEngine::Severity pSeverity,
+ const Diagnostic& pInfo) {
DiagnosticPrinter::handleDiagnostic(pSeverity, pInfo);
std::string out_string;
@@ -74,7 +81,7 @@ TextDiagnosticPrinter::handleDiagnostic(DiagnosticEngine::Severity pSeverity,
}
case DiagnosticEngine::Debug: {
// show debug message only if verbose >= 0
- if (0 <= m_Config.options().verbose()) {
+ if (m_Config.options().verbose() >= 0) {
m_OStream.changeColor(DebugColor, true);
m_OStream << "Debug: ";
m_OStream.resetColor();
@@ -84,7 +91,7 @@ TextDiagnosticPrinter::handleDiagnostic(DiagnosticEngine::Severity pSeverity,
}
case DiagnosticEngine::Note: {
// show ignored message only if verbose >= 1
- if (1 <= m_Config.options().verbose()) {
+ if (m_Config.options().verbose() >= 1) {
m_OStream.changeColor(NoteColor, true);
m_OStream << "Note: ";
m_OStream.resetColor();
@@ -94,7 +101,7 @@ TextDiagnosticPrinter::handleDiagnostic(DiagnosticEngine::Severity pSeverity,
}
case DiagnosticEngine::Ignore: {
// show ignored message only if verbose >= 2
- if (2 <= m_Config.options().verbose()) {
+ if (m_Config.options().verbose() >= 2) {
m_OStream.changeColor(IgnoreColor, true);
m_OStream << "Ignore: ";
m_OStream.resetColor();
@@ -116,8 +123,10 @@ TextDiagnosticPrinter::handleDiagnostic(DiagnosticEngine::Severity pSeverity,
}
/** fall through **/
case DiagnosticEngine::Fatal: {
- // If we reached here, we are failing ungracefully. Run the interrupt handlers
- // to make sure any special cleanups get done, in particular that we remove
+ // If we reached here, we are failing ungracefully. Run the interrupt
+ // handlers
+ // to make sure any special cleanups get done, in particular that we
+ // remove
// files registered with RemoveFileOnSignal.
llvm::sys::RunInterruptHandlers();
exit(1);
@@ -142,7 +151,8 @@ TextDiagnosticPrinter::handleDiagnostic(DiagnosticEngine::Severity pSeverity,
(getNumWarnings() > static_cast<unsigned>(warning_limit))) {
m_OStream << "\n\n";
m_OStream.changeColor(llvm::raw_ostream::YELLOW);
- m_OStream << "too many warning messages (>" << warning_limit << ")...\n";
+ m_OStream << "too many warning messages (>" << warning_limit
+ << ")...\n";
m_OStream.resetColor();
llvm::sys::RunInterruptHandlers();
exit(1);
@@ -153,12 +163,13 @@ TextDiagnosticPrinter::handleDiagnostic(DiagnosticEngine::Severity pSeverity,
}
}
-void TextDiagnosticPrinter::beginInput(const Input& pInput, const LinkerConfig& pConfig)
-{
+void TextDiagnosticPrinter::beginInput(const Input& pInput,
+ const LinkerConfig& pConfig) {
m_pInput = &pInput;
}
-void TextDiagnosticPrinter::endInput()
-{
+void TextDiagnosticPrinter::endInput() {
m_pInput = NULL;
}
+
+} // namespace mcld
diff --git a/lib/MC/Attribute.cpp b/lib/MC/Attribute.cpp
index 64782db..859689d 100644
--- a/lib/MC/Attribute.cpp
+++ b/lib/MC/Attribute.cpp
@@ -6,17 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/Attribute.h>
-#include <mcld/MC/AttributeSet.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/MC/Attribute.h"
-using namespace mcld;
+#include "mcld/MC/AttributeSet.h"
+#include "mcld/Support/MsgHandling.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// AttrConstraint
//===----------------------------------------------------------------------===//
-bool AttrConstraint::isLegal(const Attribute& pAttr) const
-{
+bool AttrConstraint::isLegal(const Attribute& pAttr) const {
if (!isWholeArchive() && pAttr.isWholeArchive()) {
error(diag::err_unsupported_whole_archive);
return false;
@@ -51,47 +51,41 @@ bool AttrConstraint::isLegal(const Attribute& pAttr) const
AttributeProxy::AttributeProxy(AttributeSet& pParent,
const Attribute& pBase,
const AttrConstraint& pConstraint)
- : m_AttrPool(pParent), m_pBase(&pBase), m_Constraint(pConstraint) {
+ : m_AttrPool(pParent), m_pBase(&pBase), m_Constraint(pConstraint) {
}
-AttributeProxy::~AttributeProxy()
-{
+AttributeProxy::~AttributeProxy() {
}
-bool AttributeProxy::isWholeArchive() const
-{
+bool AttributeProxy::isWholeArchive() const {
if (m_Constraint.isWholeArchive())
return m_pBase->isWholeArchive();
else
return false;
}
-bool AttributeProxy::isAsNeeded() const
-{
+bool AttributeProxy::isAsNeeded() const {
if (m_Constraint.isAsNeeded())
return m_pBase->isAsNeeded();
else
return false;
}
-bool AttributeProxy::isAddNeeded() const
-{
+bool AttributeProxy::isAddNeeded() const {
if (m_Constraint.isAddNeeded())
return m_pBase->isAddNeeded();
else
return false;
}
-bool AttributeProxy::isStatic() const
-{
+bool AttributeProxy::isStatic() const {
if (m_Constraint.isSharedSystem())
return m_pBase->isStatic();
else
return true;
}
-bool AttributeProxy::isDynamic() const
-{
+bool AttributeProxy::isDynamic() const {
if (m_Constraint.isSharedSystem())
return m_pBase->isDynamic();
else
@@ -99,79 +93,69 @@ bool AttributeProxy::isDynamic() const
}
static inline void ReplaceOrRecord(AttributeSet& pParent,
- const Attribute *&pBase,
- Attribute *&pCopy)
-{
- Attribute *result = pParent.exists(*pCopy);
- if (NULL == result) { // can not find
+ const Attribute*& pBase,
+ Attribute*& pCopy) {
+ Attribute* result = pParent.exists(*pCopy);
+ if (result == NULL) { // can not find
pParent.record(*pCopy);
pBase = pCopy;
- }
- else { // find
+ } else { // find
delete pCopy;
pBase = result;
}
}
-void AttributeProxy::setWholeArchive()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::setWholeArchive() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->setWholeArchive();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::unsetWholeArchive()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::unsetWholeArchive() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->unsetWholeArchive();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::setAsNeeded()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::setAsNeeded() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->setAsNeeded();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::unsetAsNeeded()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::unsetAsNeeded() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->unsetAsNeeded();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::setAddNeeded()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::setAddNeeded() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->setAddNeeded();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::unsetAddNeeded()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::unsetAddNeeded() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->unsetAddNeeded();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::setStatic()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::setStatic() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->setStatic();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-void AttributeProxy::setDynamic()
-{
- Attribute *copy = new Attribute(*m_pBase);
+void AttributeProxy::setDynamic() {
+ Attribute* copy = new Attribute(*m_pBase);
copy->setDynamic();
ReplaceOrRecord(m_AttrPool, m_pBase, copy);
}
-AttributeProxy& AttributeProxy::assign(Attribute* pBase)
-{
+AttributeProxy& AttributeProxy::assign(Attribute* pBase) {
m_pBase = pBase;
return *this;
}
+} // namespace mcld
diff --git a/lib/MC/AttributeSet.cpp b/lib/MC/AttributeSet.cpp
index e657207..96dc77f 100644
--- a/lib/MC/AttributeSet.cpp
+++ b/lib/MC/AttributeSet.cpp
@@ -6,39 +6,39 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/Attribute.h>
-#include <mcld/MC/AttributeSet.h>
+#include "mcld/MC/AttributeSet.h"
+
+#include "mcld/MC/Attribute.h"
+
#include <cstddef>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// AttributeSet
//===----------------------------------------------------------------------===//
AttributeSet::AttributeSet(unsigned int pNum, const Attribute& pPredefined)
- : m_AttrSet(), m_Predefined(pPredefined) {
+ : m_AttrSet(), m_Predefined(pPredefined) {
m_AttrSet.reserve(pNum);
}
-AttributeSet::~AttributeSet()
-{
+AttributeSet::~AttributeSet() {
iterator cur = m_AttrSet.begin();
iterator aEnd = m_AttrSet.end();
- while(cur != aEnd) {
+ while (cur != aEnd) {
delete (*cur);
++cur;
}
}
-Attribute* AttributeSet::exists(const Attribute& pAttr) const
-{
+Attribute* AttributeSet::exists(const Attribute& pAttr) const {
if (m_Predefined == pAttr)
return const_cast<Attribute*>(&m_Predefined);
const_iterator cur = m_AttrSet.begin();
const_iterator aEnd = m_AttrSet.end();
- while(cur != aEnd) {
+ while (cur != aEnd) {
if (*(*cur) == pAttr) {
return *cur;
}
@@ -47,8 +47,8 @@ Attribute* AttributeSet::exists(const Attribute& pAttr) const
return NULL;
}
-void AttributeSet::record(mcld::Attribute &pAttr)
-{
+void AttributeSet::record(mcld::Attribute& pAttr) {
m_AttrSet.push_back(&pAttr);
}
+} // namespace mcld
diff --git a/lib/MC/CommandAction.cpp b/lib/MC/CommandAction.cpp
index bae5fbf..4439d7e 100644
--- a/lib/MC/CommandAction.cpp
+++ b/lib/MC/CommandAction.cpp
@@ -6,15 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/CommandAction.h>
-#include <mcld/MC/InputBuilder.h>
-#include <mcld/MC/SearchDirs.h>
-#include <mcld/MC/Attribute.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/FileSystem.h>
-#include <mcld/LinkerConfig.h>
+#include "mcld/MC/CommandAction.h"
-using namespace mcld;
+#include "mcld/LinkerConfig.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/MC/SearchDirs.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/FileSystem.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// Derived Positional Option
@@ -22,12 +23,16 @@ using namespace mcld;
// InputFileAction
//===----------------------------------------------------------------------===//
InputFileAction::InputFileAction(unsigned int pPosition,
- const sys::fs::Path &pPath)
- : InputAction(pPosition), m_Path(pPath) {
+ const sys::fs::Path& pPath)
+ : InputAction(pPosition), m_Path(pPath) {
+}
+
+InputFileAction::InputFileAction(unsigned int pPosition,
+ const char* pPath)
+ : InputAction(pPosition), m_Path(pPath) {
}
-bool InputFileAction::activate(InputBuilder& pBuilder) const
-{
+bool InputFileAction::activate(InputBuilder& pBuilder) const {
pBuilder.createNode<InputTree::Positional>(path().stem().native(), path());
return true;
}
@@ -36,13 +41,12 @@ bool InputFileAction::activate(InputBuilder& pBuilder) const
// NamespecAction
//===----------------------------------------------------------------------===//
NamespecAction::NamespecAction(unsigned int pPosition,
- const std::string &pNamespec,
+ const std::string& pNamespec,
const SearchDirs& pSearchDirs)
- : InputAction(pPosition), m_Namespec(pNamespec), m_SearchDirs(pSearchDirs) {
+ : InputAction(pPosition), m_Namespec(pNamespec), m_SearchDirs(pSearchDirs) {
}
-bool NamespecAction::activate(InputBuilder& pBuilder) const
-{
+bool NamespecAction::activate(InputBuilder& pBuilder) const {
const sys::fs::Path* path = NULL;
// find out the real path of the namespec.
if (pBuilder.getConstraint().isSharedSystem()) {
@@ -52,19 +56,17 @@ bool NamespecAction::activate(InputBuilder& pBuilder) const
if (pBuilder.getAttributes().isStatic()) {
// with --static, we must search an archive.
path = m_SearchDirs.find(namespec(), Input::Archive);
- }
- else {
+ } else {
// otherwise, with --Bdynamic, we can find either an archive or a
// shared object.
path = m_SearchDirs.find(namespec(), Input::DynObj);
}
- }
- else {
+ } else {
// In the system without shared object support, we only look for an archive
path = m_SearchDirs.find(namespec(), Input::Archive);
}
- if (NULL == path) {
+ if (path == NULL) {
fatal(diag::err_cannot_find_namespec) << namespec();
return false;
}
@@ -76,13 +78,13 @@ bool NamespecAction::activate(InputBuilder& pBuilder) const
//===----------------------------------------------------------------------===//
// BitcodeAction
//===----------------------------------------------------------------------===//
-BitcodeAction::BitcodeAction(unsigned int pPosition, const sys::fs::Path &pPath)
- : InputAction(pPosition), m_Path(pPath) {
+BitcodeAction::BitcodeAction(unsigned int pPosition, const sys::fs::Path& pPath)
+ : InputAction(pPosition), m_Path(pPath) {
}
-bool BitcodeAction::activate(InputBuilder& pBuilder) const
-{
- pBuilder.createNode<InputTree::Positional>("bitcode", path(), Input::External);
+bool BitcodeAction::activate(InputBuilder& pBuilder) const {
+ pBuilder.createNode<InputTree::Positional>(
+ "bitcode", path(), Input::External);
return true;
}
@@ -90,11 +92,10 @@ bool BitcodeAction::activate(InputBuilder& pBuilder) const
// StartGroupAction
//===----------------------------------------------------------------------===//
StartGroupAction::StartGroupAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool StartGroupAction::activate(InputBuilder& pBuilder) const
-{
+bool StartGroupAction::activate(InputBuilder& pBuilder) const {
if (pBuilder.isInGroup()) {
fatal(diag::fatal_forbid_nest_group);
return false;
@@ -107,11 +108,10 @@ bool StartGroupAction::activate(InputBuilder& pBuilder) const
// EndGroupAction
//===----------------------------------------------------------------------===//
EndGroupAction::EndGroupAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool EndGroupAction::activate(InputBuilder& pBuilder) const
-{
+bool EndGroupAction::activate(InputBuilder& pBuilder) const {
pBuilder.exitGroup();
return true;
}
@@ -120,11 +120,10 @@ bool EndGroupAction::activate(InputBuilder& pBuilder) const
// WholeArchiveAction
//===----------------------------------------------------------------------===//
WholeArchiveAction::WholeArchiveAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool WholeArchiveAction::activate(InputBuilder& pBuilder) const
-{
+bool WholeArchiveAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().setWholeArchive();
return true;
}
@@ -133,11 +132,10 @@ bool WholeArchiveAction::activate(InputBuilder& pBuilder) const
// NoWholeArchiveAction
//===----------------------------------------------------------------------===//
NoWholeArchiveAction::NoWholeArchiveAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool NoWholeArchiveAction::activate(InputBuilder& pBuilder) const
-{
+bool NoWholeArchiveAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().unsetWholeArchive();
return true;
}
@@ -146,11 +144,10 @@ bool NoWholeArchiveAction::activate(InputBuilder& pBuilder) const
// AsNeededAction
//===----------------------------------------------------------------------===//
AsNeededAction::AsNeededAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool AsNeededAction::activate(InputBuilder& pBuilder) const
-{
+bool AsNeededAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().setAsNeeded();
return true;
}
@@ -159,11 +156,10 @@ bool AsNeededAction::activate(InputBuilder& pBuilder) const
// NoAsNeededAction
//===----------------------------------------------------------------------===//
NoAsNeededAction::NoAsNeededAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool NoAsNeededAction::activate(InputBuilder& pBuilder) const
-{
+bool NoAsNeededAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().unsetAsNeeded();
return true;
}
@@ -172,11 +168,10 @@ bool NoAsNeededAction::activate(InputBuilder& pBuilder) const
// AddNeededAction
//===----------------------------------------------------------------------===//
AddNeededAction::AddNeededAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool AddNeededAction::activate(InputBuilder& pBuilder) const
-{
+bool AddNeededAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().setAddNeeded();
return true;
}
@@ -185,11 +180,10 @@ bool AddNeededAction::activate(InputBuilder& pBuilder) const
// NoAddNeededAction
//===----------------------------------------------------------------------===//
NoAddNeededAction::NoAddNeededAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool NoAddNeededAction::activate(InputBuilder& pBuilder) const
-{
+bool NoAddNeededAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().unsetAddNeeded();
return true;
}
@@ -198,11 +192,10 @@ bool NoAddNeededAction::activate(InputBuilder& pBuilder) const
// BDynamicAction
//===----------------------------------------------------------------------===//
BDynamicAction::BDynamicAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ : InputAction(pPosition) {
}
-bool BDynamicAction::activate(InputBuilder& pBuilder) const
-{
+bool BDynamicAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().setDynamic();
return true;
}
@@ -210,12 +203,10 @@ bool BDynamicAction::activate(InputBuilder& pBuilder) const
//===----------------------------------------------------------------------===//
// BStaticAction
//===----------------------------------------------------------------------===//
-BStaticAction::BStaticAction(unsigned int pPosition)
- : InputAction(pPosition) {
+BStaticAction::BStaticAction(unsigned int pPosition) : InputAction(pPosition) {
}
-bool BStaticAction::activate(InputBuilder& pBuilder) const
-{
+bool BStaticAction::activate(InputBuilder& pBuilder) const {
pBuilder.getAttributes().setStatic();
return true;
}
@@ -224,12 +215,11 @@ bool BStaticAction::activate(InputBuilder& pBuilder) const
// DefSymAction
//===----------------------------------------------------------------------===//
DefSymAction::DefSymAction(unsigned int pPosition, std::string& pAssignment)
- : InputAction(pPosition), m_Assignment(pAssignment) {
+ : InputAction(pPosition), m_Assignment(pAssignment) {
}
-bool DefSymAction::activate(InputBuilder& pBuilder) const
-{
- pBuilder.createNode<InputTree::Positional>("defsym", "NAN");
+bool DefSymAction::activate(InputBuilder& pBuilder) const {
+ pBuilder.createNode<InputTree::Positional>("defsym", sys::fs::Path("NAN"));
Input* input = *pBuilder.getCurrentNode();
pBuilder.setContext(*input, false);
@@ -245,31 +235,33 @@ ScriptAction::ScriptAction(unsigned int pPosition,
const std::string& pFileName,
ScriptFile::Kind pKind,
const SearchDirs& pSearchDirs)
- : InputAction(pPosition),
- m_FileName(pFileName),
- m_Kind(pKind),
- m_SearchDirs(pSearchDirs) {
+ : InputAction(pPosition),
+ m_FileName(pFileName),
+ m_Kind(pKind),
+ m_SearchDirs(pSearchDirs) {
}
-bool ScriptAction::activate(InputBuilder& pBuilder) const
-{
+bool ScriptAction::activate(InputBuilder& pBuilder) const {
sys::fs::Path path(m_FileName);
if (!exists(path)) {
const sys::fs::Path* res = m_SearchDirs.find(m_FileName, Input::Script);
if (res == NULL) {
switch (m_Kind) {
- case ScriptFile::LDScript:
- fatal(diag::err_cannot_find_scriptfile) << "linker script" << m_FileName;
- break;
- case ScriptFile::VersionScript:
- fatal(diag::err_cannot_find_scriptfile) << "version script" << m_FileName;
- break;
- case ScriptFile::DynamicList:
- fatal(diag::err_cannot_find_scriptfile) << "dynamic list" << m_FileName;
- break;
- default:
- break;
+ case ScriptFile::LDScript:
+ fatal(diag::err_cannot_find_scriptfile) << "linker script"
+ << m_FileName;
+ break;
+ case ScriptFile::VersionScript:
+ fatal(diag::err_cannot_find_scriptfile) << "version script"
+ << m_FileName;
+ break;
+ case ScriptFile::DynamicList:
+ fatal(diag::err_cannot_find_scriptfile) << "dynamic list"
+ << m_FileName;
+ break;
+ default:
+ break;
}
return false;
}
@@ -280,3 +272,5 @@ bool ScriptAction::activate(InputBuilder& pBuilder) const
return true;
}
+
+} // namespace mcld
diff --git a/lib/MC/ContextFactory.cpp b/lib/MC/ContextFactory.cpp
index 5b698c7..fe0489c 100644
--- a/lib/MC/ContextFactory.cpp
+++ b/lib/MC/ContextFactory.cpp
@@ -6,26 +6,24 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDContext.h>
-#include <mcld/MC/ContextFactory.h>
+#include "mcld/MC/ContextFactory.h"
-using namespace mcld;
+#include "mcld/LD/LDContext.h"
+
+namespace mcld {
//===---------------------------------------------------------------------===//
// LDContextFactory
ContextFactory::ContextFactory(size_t pNum)
- : UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>(pNum)
-{
+ : UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>(pNum) {
}
-ContextFactory::~ContextFactory()
-{
+ContextFactory::~ContextFactory() {
}
-LDContext* ContextFactory::produce(const sys::fs::Path& pPath)
-{
+LDContext* ContextFactory::produce(const sys::fs::Path& pPath) {
LDContext* result = find(pPath);
- if (0 == result) {
+ if (result == NULL) {
result = UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>::allocate();
new (result) LDContext();
f_KeyMap.insert(std::make_pair(pPath, result));
@@ -33,10 +31,14 @@ LDContext* ContextFactory::produce(const sys::fs::Path& pPath)
return result;
}
-LDContext* ContextFactory::produce()
-{
+LDContext* ContextFactory::produce(const char* pPath) {
+ return produce(sys::fs::Path(pPath));
+}
+
+LDContext* ContextFactory::produce() {
LDContext* result = allocate();
new (result) LDContext();
return result;
}
+} // namespace mcld
diff --git a/lib/MC/FileAction.cpp b/lib/MC/FileAction.cpp
index 0de60ee..f4e68df 100644
--- a/lib/MC/FileAction.cpp
+++ b/lib/MC/FileAction.cpp
@@ -6,31 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/FileAction.h>
-#include <mcld/MC/Input.h>
-#include <mcld/MC/InputBuilder.h>
+#include "mcld/MC/FileAction.h"
-using namespace mcld;
+#include "mcld/MC/Input.h"
+#include "mcld/MC/InputBuilder.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// ContextAction
//===----------------------------------------------------------------------===//
-ContextAction::ContextAction(unsigned int pPosition)
- : InputAction(pPosition) {
+ContextAction::ContextAction(unsigned int pPosition) : InputAction(pPosition) {
}
-bool ContextAction::activate(InputBuilder& pBuilder) const
-{
+bool ContextAction::activate(InputBuilder& pBuilder) const {
Input* input = *pBuilder.getCurrentNode();
if (input->hasContext())
return false;
// already got type - for example, bitcode
- if (input->type() == Input::Script ||
- input->type() == Input::Object ||
- input->type() == Input::DynObj ||
- input->type() == Input::Archive)
+ if (input->type() == Input::Script || input->type() == Input::Object ||
+ input->type() == Input::DynObj || input->type() == Input::Archive)
return false;
return pBuilder.setContext(*input);
@@ -40,25 +37,23 @@ bool ContextAction::activate(InputBuilder& pBuilder) const
// MemoryAreaAction
//===----------------------------------------------------------------------===//
MemoryAreaAction::MemoryAreaAction(unsigned int pPosition,
- FileHandle::OpenMode pMode,
- FileHandle::Permission pPerm)
- : InputAction(pPosition), m_Mode(pMode), m_Permission(pPerm) {
+ FileHandle::OpenModeEnum pMode,
+ FileHandle::PermissionEnum pPerm)
+ : InputAction(pPosition), m_Mode(pMode), m_Permission(pPerm) {
}
-bool MemoryAreaAction::activate(InputBuilder& pBuilder) const
-{
+bool MemoryAreaAction::activate(InputBuilder& pBuilder) const {
Input* input = *pBuilder.getCurrentNode();
if (input->hasMemArea())
return false;
// already got type - for example, bitcode
- if (input->type() == Input::Script ||
- input->type() == Input::Object ||
- input->type() == Input::DynObj ||
- input->type() == Input::Archive)
+ if (input->type() == Input::Script || input->type() == Input::Object ||
+ input->type() == Input::DynObj || input->type() == Input::Archive)
return false;
return pBuilder.setMemory(*input, m_Mode, m_Permission);
}
+} // namespace mcld
diff --git a/lib/MC/Input.cpp b/lib/MC/Input.cpp
index 26234fc..e19f667 100644
--- a/lib/MC/Input.cpp
+++ b/lib/MC/Input.cpp
@@ -6,73 +6,74 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/Input.h>
-#include <mcld/MC/Attribute.h>
-#include <mcld/LD/LDContext.h>
+#include "mcld/MC/Input.h"
-using namespace mcld;
+#include "mcld/MC/Attribute.h"
+#include "mcld/LD/LDContext.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// mcld::Input
//===----------------------------------------------------------------------===//
Input::Input(llvm::StringRef pName)
- : m_Type(Unknown),
- m_Name(pName.data()),
- m_Path(),
- m_pAttr(NULL),
- m_bNeeded(false),
- m_bNoExport(false),
- m_fileOffset(0),
- m_pMemArea(NULL),
- m_pContext(NULL) {
+ : m_Type(Unknown),
+ m_Name(pName.data()),
+ m_Path(),
+ m_pAttr(NULL),
+ m_bNeeded(false),
+ m_bNoExport(false),
+ m_fileOffset(0),
+ m_pMemArea(NULL),
+ m_pContext(NULL) {
}
Input::Input(llvm::StringRef pName, const AttributeProxy& pProxy)
- : m_Type(Unknown),
- m_Name(pName.data()),
- m_Path(),
- m_pAttr(const_cast<Attribute*>(pProxy.attr())),
- m_bNeeded(false),
- m_bNoExport(false),
- m_fileOffset(0),
- m_pMemArea(NULL),
- m_pContext(NULL) {
+ : m_Type(Unknown),
+ m_Name(pName.data()),
+ m_Path(),
+ m_pAttr(const_cast<Attribute*>(pProxy.attr())),
+ m_bNeeded(false),
+ m_bNoExport(false),
+ m_fileOffset(0),
+ m_pMemArea(NULL),
+ m_pContext(NULL) {
}
Input::Input(llvm::StringRef pName,
- const sys::fs::Path& pPath,
- unsigned int pType,
- off_t pFileOffset)
- : m_Type(pType),
- m_Name(pName.data()),
- m_Path(pPath),
- m_pAttr(NULL),
- m_bNeeded(false),
- m_bNoExport(false),
- m_fileOffset(pFileOffset),
- m_pMemArea(NULL),
- m_pContext(NULL) {
+ const sys::fs::Path& pPath,
+ unsigned int pType,
+ off_t pFileOffset)
+ : m_Type(pType),
+ m_Name(pName.data()),
+ m_Path(pPath),
+ m_pAttr(NULL),
+ m_bNeeded(false),
+ m_bNoExport(false),
+ m_fileOffset(pFileOffset),
+ m_pMemArea(NULL),
+ m_pContext(NULL) {
}
Input::Input(llvm::StringRef pName,
- const sys::fs::Path& pPath,
- const AttributeProxy& pProxy,
- unsigned int pType,
- off_t pFileOffset)
- : m_Type(pType),
- m_Name(pName.data()),
- m_Path(pPath),
- m_pAttr(const_cast<Attribute*>(pProxy.attr())),
- m_bNeeded(false),
- m_bNoExport(false),
- m_fileOffset(pFileOffset),
- m_pMemArea(NULL),
- m_pContext(NULL) {
+ const sys::fs::Path& pPath,
+ const AttributeProxy& pProxy,
+ unsigned int pType,
+ off_t pFileOffset)
+ : m_Type(pType),
+ m_Name(pName.data()),
+ m_Path(pPath),
+ m_pAttr(const_cast<Attribute*>(pProxy.attr())),
+ m_bNeeded(false),
+ m_bNoExport(false),
+ m_fileOffset(pFileOffset),
+ m_pMemArea(NULL),
+ m_pContext(NULL) {
}
-Input::~Input()
-{
+Input::~Input() {
// Attribute is deleted by AttributeFactory
// MemoryArea is deleted by MemoryAreaFactory
}
+} // namespace mcld
diff --git a/lib/MC/InputAction.cpp b/lib/MC/InputAction.cpp
index f9078c6..7fdb93a 100644
--- a/lib/MC/InputAction.cpp
+++ b/lib/MC/InputAction.cpp
@@ -6,18 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/InputAction.h>
+#include "mcld/MC/InputAction.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Base Positional Option
//===----------------------------------------------------------------------===//
-InputAction::InputAction(unsigned int pPosition)
- : m_Position(pPosition) {
+InputAction::InputAction(unsigned int pPosition) : m_Position(pPosition) {
}
-InputAction::~InputAction()
-{
+InputAction::~InputAction() {
}
+} // namespace mcld
diff --git a/lib/MC/InputBuilder.cpp b/lib/MC/InputBuilder.cpp
index 842c476..e20403f 100644
--- a/lib/MC/InputBuilder.cpp
+++ b/lib/MC/InputBuilder.cpp
@@ -6,25 +6,26 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/InputBuilder.h>
+#include "mcld/MC/InputBuilder.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/Config/Config.h>
-#include <mcld/Support/Path.h>
-#include <mcld/MC/InputFactory.h>
-#include <mcld/MC/ContextFactory.h>
-#include <mcld/Support/MemoryAreaFactory.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/Config/Config.h"
+#include "mcld/MC/ContextFactory.h"
+#include "mcld/MC/InputFactory.h"
+#include "mcld/Support/MemoryAreaFactory.h"
+#include "mcld/Support/Path.h"
-using namespace mcld;
+namespace mcld {
InputBuilder::InputBuilder(const LinkerConfig& pConfig)
- : m_Config(pConfig),
- m_pCurrentTree(NULL), m_pMove(NULL), m_Root(),
- m_bOwnFactory(true) {
-
- m_pInputFactory = new InputFactory(MCLD_NUM_OF_INPUTS, pConfig);
- m_pContextFactory = new ContextFactory(MCLD_NUM_OF_INPUTS);
- m_pMemFactory = new MemoryAreaFactory(MCLD_NUM_OF_INPUTS);
+ : m_Config(pConfig),
+ m_pCurrentTree(NULL),
+ m_pMove(NULL),
+ m_Root(),
+ m_bOwnFactory(true) {
+ m_pInputFactory = new InputFactory(MCLD_NUM_OF_INPUTS, pConfig);
+ m_pContextFactory = new ContextFactory(MCLD_NUM_OF_INPUTS);
+ m_pMemFactory = new MemoryAreaFactory(MCLD_NUM_OF_INPUTS);
}
InputBuilder::InputBuilder(const LinkerConfig& pConfig,
@@ -32,17 +33,17 @@ InputBuilder::InputBuilder(const LinkerConfig& pConfig,
ContextFactory& pContextFactory,
MemoryAreaFactory& pMemoryFactory,
bool pDelegate)
- : m_Config(pConfig),
- m_pInputFactory(&pInputFactory),
- m_pMemFactory(&pMemoryFactory),
- m_pContextFactory(&pContextFactory),
- m_pCurrentTree(NULL), m_pMove(NULL), m_Root(),
- m_bOwnFactory(pDelegate) {
-
+ : m_Config(pConfig),
+ m_pInputFactory(&pInputFactory),
+ m_pMemFactory(&pMemoryFactory),
+ m_pContextFactory(&pContextFactory),
+ m_pCurrentTree(NULL),
+ m_pMove(NULL),
+ m_Root(),
+ m_bOwnFactory(pDelegate) {
}
-InputBuilder::~InputBuilder()
-{
+InputBuilder::~InputBuilder() {
if (m_bOwnFactory) {
delete m_pInputFactory;
delete m_pContextFactory;
@@ -53,14 +54,12 @@ InputBuilder::~InputBuilder()
Input* InputBuilder::createInput(const std::string& pName,
const sys::fs::Path& pPath,
unsigned int pType,
- off_t pFileOffset)
-{
+ off_t pFileOffset) {
return m_pInputFactory->produce(pName, pPath, pType, pFileOffset);
}
-InputTree& InputBuilder::enterGroup()
-{
- assert(NULL != m_pCurrentTree && NULL != m_pMove);
+InputTree& InputBuilder::enterGroup() {
+ assert(m_pCurrentTree != NULL && m_pMove != NULL);
m_pCurrentTree->enterGroup(m_Root, *m_pMove);
m_pMove->move(m_Root);
@@ -70,9 +69,8 @@ InputTree& InputBuilder::enterGroup()
return *m_pCurrentTree;
}
-InputTree& InputBuilder::exitGroup()
-{
- assert(NULL != m_pCurrentTree && NULL != m_pMove);
+InputTree& InputBuilder::exitGroup() {
+ assert(m_pCurrentTree != NULL && m_pMove != NULL);
m_Root = m_ReturnStack.top();
m_ReturnStack.pop();
@@ -81,42 +79,36 @@ InputTree& InputBuilder::exitGroup()
return *m_pCurrentTree;
}
-bool InputBuilder::isInGroup() const
-{
+bool InputBuilder::isInGroup() const {
return !m_ReturnStack.empty();
}
-const InputTree& InputBuilder::getCurrentTree() const
-{
- assert(NULL != m_pCurrentTree && NULL != m_pMove);
+const InputTree& InputBuilder::getCurrentTree() const {
+ assert(m_pCurrentTree != NULL && m_pMove != NULL);
return *m_pCurrentTree;
}
-InputTree& InputBuilder::getCurrentTree()
-{
- assert(NULL != m_pCurrentTree && NULL != m_pMove);
+InputTree& InputBuilder::getCurrentTree() {
+ assert(m_pCurrentTree != NULL && m_pMove != NULL);
return *m_pCurrentTree;
}
-void InputBuilder::setCurrentTree(InputTree& pInputTree)
-{
+void InputBuilder::setCurrentTree(InputTree& pInputTree) {
m_pCurrentTree = &pInputTree;
m_Root = m_pCurrentTree->root();
m_pMove = &InputTree::Downward;
}
-bool InputBuilder::setContext(Input& pInput, bool pCheck)
-{
+bool InputBuilder::setContext(Input& pInput, bool pCheck) {
// The object files in an archive have common path. Every object files in an
// archive needs a individual context. We identify the object files in an
// archive by its file offset. Their file offsets are not zero.
LDContext* context = NULL;
- if (0 != pInput.fileOffset() || !pCheck) {
+ if (pInput.fileOffset() != 0 || !pCheck) {
// pInput is an object in an archive file. Produce a new context in this
// case.
context = m_pContextFactory->produce();
- }
- else {
+ } else {
// Using pInput.path() to avoid from creating context for identical file
// twice.
context = m_pContextFactory->produce(pInput.path());
@@ -128,32 +120,28 @@ bool InputBuilder::setContext(Input& pInput, bool pCheck)
bool InputBuilder::setMemory(Input& pInput,
FileHandle::OpenMode pMode,
- FileHandle::Permission pPerm)
-{
- MemoryArea *memory = m_pMemFactory->produce(pInput.path(), pMode, pPerm);
+ FileHandle::Permission pPerm) {
+ MemoryArea* memory = m_pMemFactory->produce(pInput.path(), pMode, pPerm);
pInput.setMemArea(memory);
return true;
}
-bool InputBuilder::setMemory(Input& pInput, void* pMemBuffer, size_t pSize)
-{
- MemoryArea *memory = m_pMemFactory->produce(pMemBuffer, pSize);
+bool InputBuilder::setMemory(Input& pInput, void* pMemBuffer, size_t pSize) {
+ MemoryArea* memory = m_pMemFactory->produce(pMemBuffer, pSize);
pInput.setMemArea(memory);
return true;
}
-const AttrConstraint& InputBuilder::getConstraint() const
-{
+const AttrConstraint& InputBuilder::getConstraint() const {
return m_Config.attribute().constraint();
}
-const AttributeProxy& InputBuilder::getAttributes() const
-{
+const AttributeProxy& InputBuilder::getAttributes() const {
return m_pInputFactory->attr();
}
-AttributeProxy& InputBuilder::getAttributes()
-{
+AttributeProxy& InputBuilder::getAttributes() {
return m_pInputFactory->attr();
}
+} // namespace mcld
diff --git a/lib/MC/InputFactory.cpp b/lib/MC/InputFactory.cpp
index b0b7aaa..32d1913 100644
--- a/lib/MC/InputFactory.cpp
+++ b/lib/MC/InputFactory.cpp
@@ -6,27 +6,26 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/InputFactory.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/AttributeSet.h>
-#include <mcld/AttributeOption.h>
+#include "mcld/MC/InputFactory.h"
-using namespace mcld;
+#include "mcld/LinkerConfig.h"
+#include "mcld/AttributeOption.h"
+#include "mcld/MC/AttributeSet.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// InputFactory
//===----------------------------------------------------------------------===//
InputFactory::InputFactory(size_t pNum, const LinkerConfig& pConfig)
- : GCFactory<Input,0>(pNum) {
-
+ : GCFactory<Input, 0>(pNum) {
m_pAttrSet = new AttributeSet(16, pConfig.attribute().predefined());
m_pLast = new AttributeProxy(*m_pAttrSet,
pConfig.attribute().predefined(),
pConfig.attribute().constraint());
}
-InputFactory::~InputFactory()
-{
+InputFactory::~InputFactory() {
delete m_pAttrSet;
delete m_pLast;
}
@@ -34,10 +33,19 @@ InputFactory::~InputFactory()
Input* InputFactory::produce(llvm::StringRef pName,
const sys::fs::Path& pPath,
unsigned int pType,
- off_t pFileOffset)
-{
+ off_t pFileOffset) {
Input* result = Alloc::allocate();
new (result) Input(pName, pPath, *m_pLast, pType, pFileOffset);
return result;
}
+Input* InputFactory::produce(llvm::StringRef pName,
+ const char* pPath,
+ unsigned int pType,
+ off_t pFileOffset) {
+ Input* result = Alloc::allocate();
+ new (result) Input(pName, sys::fs::Path(pPath), *m_pLast, pType, pFileOffset);
+ return result;
+}
+
+} // namespace mcld
diff --git a/lib/MC/MCLDDirectory.cpp b/lib/MC/MCLDDirectory.cpp
index a15e744..5d281d5 100644
--- a/lib/MC/MCLDDirectory.cpp
+++ b/lib/MC/MCLDDirectory.cpp
@@ -6,99 +6,93 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/MCLDDirectory.h>
-#include <mcld/Support/FileSystem.h>
+#include "mcld/MC/MCLDDirectory.h"
+#include "mcld/Support/FileSystem.h"
-using namespace mcld;
-using namespace mcld::sys::fs;
+namespace mcld {
//===----------------------------------------------------------------------===//
// MCLDDirectory
//===----------------------------------------------------------------------===//
-MCLDDirectory::MCLDDirectory()
- : Directory(), m_Name(), m_bInSysroot(false) {
+MCLDDirectory::MCLDDirectory() : Directory(), m_Name(), m_bInSysroot(false) {
}
-MCLDDirectory::MCLDDirectory(const char* pName)
- : Directory(), m_Name(pName) {
+MCLDDirectory::MCLDDirectory(const char* pName) : Directory(), m_Name(pName) {
Directory::m_Path.assign(pName);
if (!Directory::m_Path.empty())
- m_bInSysroot = ('=' == Directory::m_Path.native()[0]);
+ m_bInSysroot = (Directory::m_Path.native()[0] == '=');
Directory::m_Path.m_append_separator_if_needed();
if (m_bInSysroot)
Directory::m_Path.native().erase(Directory::m_Path.native().begin());
else
- detail::open_dir(*this);
+ sys::fs::detail::open_dir(*this);
}
-MCLDDirectory::MCLDDirectory(const std::string &pName)
- : Directory(), m_Name(pName) {
+MCLDDirectory::MCLDDirectory(const std::string& pName)
+ : Directory(), m_Name(pName) {
Directory::m_Path.assign(pName);
if (!Directory::m_Path.empty())
- m_bInSysroot = ('=' == Directory::m_Path.native()[0]);
+ m_bInSysroot = (Directory::m_Path.native()[0] == '=');
Directory::m_Path.m_append_separator_if_needed();
if (m_bInSysroot)
Directory::m_Path.native().erase(Directory::m_Path.native().begin());
else
- detail::open_dir(*this);
+ sys::fs::detail::open_dir(*this);
}
MCLDDirectory::MCLDDirectory(llvm::StringRef pName)
- : Directory(), m_Name(pName.data(), pName.size()) {
+ : Directory(), m_Name(pName.data(), pName.size()) {
Directory::m_Path.assign(pName.str());
if (!Directory::m_Path.empty())
- m_bInSysroot = ('=' == Directory::m_Path.native()[0]);
+ m_bInSysroot = (Directory::m_Path.native()[0] == '=');
Directory::m_Path.m_append_separator_if_needed();
if (m_bInSysroot)
Directory::m_Path.native().erase(Directory::m_Path.native().begin());
else
- detail::open_dir(*this);
+ sys::fs::detail::open_dir(*this);
}
-MCLDDirectory &MCLDDirectory::assign(llvm::StringRef pName)
-{
+MCLDDirectory& MCLDDirectory::assign(llvm::StringRef pName) {
m_Name.assign(pName.data(), pName.size());
Directory::m_Path.assign(pName.str());
if (!Directory::m_Path.empty())
- m_bInSysroot = ('=' == Directory::m_Path.native()[0]);
+ m_bInSysroot = (Directory::m_Path.native()[0] == '=');
Directory::m_Path.m_append_separator_if_needed();
if (m_bInSysroot)
Directory::m_Path.native().erase(Directory::m_Path.native().begin());
else
- detail::open_dir(*this);
- Directory::m_FileStatus = FileStatus();
- Directory::m_SymLinkStatus = FileStatus();
+ sys::fs::detail::open_dir(*this);
+ Directory::m_FileStatus = sys::fs::FileStatus();
+ Directory::m_SymLinkStatus = sys::fs::FileStatus();
Directory::m_Cache.clear();
Directory::m_Handler = 0;
return (*this);
}
-MCLDDirectory::~MCLDDirectory()
-{
+MCLDDirectory::~MCLDDirectory() {
}
-bool MCLDDirectory::isInSysroot() const
-{
+bool MCLDDirectory::isInSysroot() const {
return m_bInSysroot;
}
-void MCLDDirectory::setSysroot(const sys::fs::Path& pSysroot)
-{
+void MCLDDirectory::setSysroot(const sys::fs::Path& pSysroot) {
if (m_bInSysroot) {
std::string old_path = Directory::m_Path.native();
Directory::m_Path.native() = pSysroot.native();
Directory::m_Path.m_append_separator_if_needed();
Directory::m_Path.native() += old_path;
- detail::canonicalize(Directory::m_Path.native());
- detail::open_dir(*this);
+ sys::fs::detail::canonicalize(Directory::m_Path.native());
+ sys::fs::detail::open_dir(*this);
}
}
+} // namespace mcld
diff --git a/lib/MC/SearchDirs.cpp b/lib/MC/SearchDirs.cpp
index 1950f96..07c02b6 100644
--- a/lib/MC/SearchDirs.cpp
+++ b/lib/MC/SearchDirs.cpp
@@ -6,17 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/SearchDirs.h>
-#include <mcld/MC/MCLDDirectory.h>
-#include <mcld/Support/FileSystem.h>
+#include "mcld/MC/SearchDirs.h"
-using namespace mcld;
+#include "mcld/MC/MCLDDirectory.h"
+#include "mcld/Support/FileSystem.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// Non-member functions
//===----------------------------------------------------------------------===//
-static inline void SpecToFilename(const std::string& pSpec, std::string& pFile)
-{
+static inline void SpecToFilename(const std::string& pSpec,
+ std::string& pFile) {
pFile = "lib";
pFile += pSpec;
}
@@ -24,30 +25,26 @@ static inline void SpecToFilename(const std::string& pSpec, std::string& pFile)
//===----------------------------------------------------------------------===//
// SearchDirs
//===----------------------------------------------------------------------===//
-SearchDirs::SearchDirs()
-{
+SearchDirs::SearchDirs() {
// a magic number 8, no why.
// please prove it or change it
m_DirList.reserve(8);
}
-SearchDirs::SearchDirs(const sys::fs::Path& pSysRoot)
- : m_SysRoot(pSysRoot) {
+SearchDirs::SearchDirs(const sys::fs::Path& pSysRoot) : m_SysRoot(pSysRoot) {
// a magic number 8, no why.
// please prove it or change it
m_DirList.reserve(8);
}
-SearchDirs::~SearchDirs()
-{
+SearchDirs::~SearchDirs() {
iterator dir, dirEnd = end();
- for (dir = begin(); dir!=dirEnd; ++dir) {
+ for (dir = begin(); dir != dirEnd; ++dir) {
delete (*dir);
}
}
-bool SearchDirs::insert(const std::string& pPath)
-{
+bool SearchDirs::insert(const std::string& pPath) {
MCLDDirectory* dir = new MCLDDirectory(pPath);
if (dir->isInSysroot())
dir->setSysroot(m_SysRoot);
@@ -55,43 +52,38 @@ bool SearchDirs::insert(const std::string& pPath)
if (exists(dir->path()) && is_directory(dir->path())) {
m_DirList.push_back(dir);
return true;
- }
- else {
+ } else {
delete dir;
return false;
}
return true;
}
-bool SearchDirs::insert(const char* pPath)
-{
+bool SearchDirs::insert(const char* pPath) {
return insert(std::string(pPath));
}
-bool SearchDirs::insert(const sys::fs::Path& pPath)
-{
+bool SearchDirs::insert(const sys::fs::Path& pPath) {
return insert(pPath.native());
}
-mcld::sys::fs::Path*
-SearchDirs::find(const std::string& pNamespec, mcld::Input::Type pType)
-{
- assert(Input::DynObj == pType ||
- Input::Archive == pType ||
- Input::Script == pType);
+mcld::sys::fs::Path* SearchDirs::find(const std::string& pNamespec,
+ mcld::Input::Type pType) {
+ assert(Input::DynObj == pType || Input::Archive == pType ||
+ Input::Script == pType);
std::string file;
- switch(pType) {
- case Input::Script:
- file.assign(pNamespec);
- break;
- case Input::DynObj:
- case Input::Archive :
- SpecToFilename(pNamespec, file);
- break;
- default:
- break;
- } // end of switch
+ switch (pType) {
+ case Input::Script:
+ file.assign(pNamespec);
+ break;
+ case Input::DynObj:
+ case Input::Archive:
+ SpecToFilename(pNamespec, file);
+ break;
+ default:
+ break;
+ } // end of switch
// for all MCLDDirectorys
DirList::iterator mcld_dir, mcld_dir_end = m_DirList.end();
@@ -100,65 +92,63 @@ SearchDirs::find(const std::string& pNamespec, mcld::Input::Type pType)
MCLDDirectory::iterator entry = (*mcld_dir)->begin();
MCLDDirectory::iterator enEnd = (*mcld_dir)->end();
- switch(pType) {
- case Input::Script: {
- while (entry != enEnd) {
- if (file == entry.path()->filename())
- return entry.path();
- ++entry;
+ switch (pType) {
+ case Input::Script: {
+ while (entry != enEnd) {
+ if (file == entry.path()->filename().native())
+ return entry.path();
+ ++entry;
+ }
+ break;
}
- break;
- }
- case Input::DynObj: {
- while (entry != enEnd) {
- if (file == entry.path()->stem().native() ) {
- if (mcld::sys::fs::detail::shared_library_extension ==
+ case Input::DynObj: {
+ while (entry != enEnd) {
+ if (file == entry.path()->stem().native()) {
+ if (mcld::sys::fs::detail::shared_library_extension ==
entry.path()->extension().native()) {
- return entry.path();
+ return entry.path();
+ }
}
+ ++entry;
}
- ++entry;
}
- }
- /** Fall through **/
- case Input::Archive : {
- entry = (*mcld_dir)->begin();
- enEnd = (*mcld_dir)->end();
- while (entry != enEnd) {
- if (file == entry.path()->stem().native() &&
- mcld::sys::fs::detail::static_library_extension ==
- entry.path()->extension().native()) {
- return entry.path();
+ /** Fall through **/
+ case Input::Archive: {
+ entry = (*mcld_dir)->begin();
+ enEnd = (*mcld_dir)->end();
+ while (entry != enEnd) {
+ if (file == entry.path()->stem().native() &&
+ mcld::sys::fs::detail::static_library_extension ==
+ entry.path()->extension().native()) {
+ return entry.path();
+ }
+ ++entry;
}
- ++entry;
}
- }
- default:
- break;
- } // end of switch
- } // end of for
+ default:
+ break;
+ } // end of switch
+ } // end of for
return NULL;
}
-const mcld::sys::fs::Path*
-SearchDirs::find(const std::string& pNamespec, mcld::Input::Type pType) const
-{
- assert(Input::DynObj == pType ||
- Input::Archive == pType ||
- Input::Script == pType);
+const mcld::sys::fs::Path* SearchDirs::find(const std::string& pNamespec,
+ mcld::Input::Type pType) const {
+ assert(Input::DynObj == pType || Input::Archive == pType ||
+ Input::Script == pType);
std::string file;
- switch(pType) {
- case Input::Script:
- file.assign(pNamespec);
- break;
- case Input::DynObj:
- case Input::Archive :
- SpecToFilename(pNamespec, file);
- break;
- default:
- break;
- } // end of switch
+ switch (pType) {
+ case Input::Script:
+ file.assign(pNamespec);
+ break;
+ case Input::DynObj:
+ case Input::Archive:
+ SpecToFilename(pNamespec, file);
+ break;
+ default:
+ break;
+ } // end of switch
// for all MCLDDirectorys
DirList::const_iterator mcld_dir, mcld_dir_end = m_DirList.end();
@@ -167,42 +157,44 @@ SearchDirs::find(const std::string& pNamespec, mcld::Input::Type pType) const
MCLDDirectory::iterator entry = (*mcld_dir)->begin();
MCLDDirectory::iterator enEnd = (*mcld_dir)->end();
- switch(pType) {
- case Input::Script: {
- while (entry != enEnd) {
- if (file == entry.path()->filename())
- return entry.path();
- ++entry;
+ switch (pType) {
+ case Input::Script: {
+ while (entry != enEnd) {
+ if (file == entry.path()->filename().native())
+ return entry.path();
+ ++entry;
+ }
+ break;
}
- break;
- }
- case Input::DynObj: {
- while (entry != enEnd) {
- if (file == entry.path()->stem().native() ) {
- if (mcld::sys::fs::detail::shared_library_extension ==
+ case Input::DynObj: {
+ while (entry != enEnd) {
+ if (file == entry.path()->stem().native()) {
+ if (mcld::sys::fs::detail::shared_library_extension ==
entry.path()->extension().native()) {
- return entry.path();
+ return entry.path();
+ }
}
+ ++entry;
}
- ++entry;
}
- }
- /** Fall through **/
- case Input::Archive : {
- entry = (*mcld_dir)->begin();
- enEnd = (*mcld_dir)->end();
- while ( entry!=enEnd ) {
- if (file == entry.path()->stem().native() &&
- mcld::sys::fs::detail::static_library_extension ==
- entry.path()->extension().native()) {
- return entry.path();
+ /** Fall through **/
+ case Input::Archive: {
+ entry = (*mcld_dir)->begin();
+ enEnd = (*mcld_dir)->end();
+ while (entry != enEnd) {
+ if (file == entry.path()->stem().native() &&
+ mcld::sys::fs::detail::static_library_extension ==
+ entry.path()->extension().native()) {
+ return entry.path();
+ }
+ ++entry;
}
- ++entry;
}
- }
- default:
- break;
- } // end of switch
- } // end of for
+ default:
+ break;
+ } // end of switch
+ } // end of for
return NULL;
}
+
+} // namespace mcld
diff --git a/lib/MC/SymbolCategory.cpp b/lib/MC/SymbolCategory.cpp
index 3bd3df6..71a5bfd 100644
--- a/lib/MC/SymbolCategory.cpp
+++ b/lib/MC/SymbolCategory.cpp
@@ -6,26 +6,27 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/SymbolCategory.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/ResolveInfo.h>
+#include "mcld/MC/SymbolCategory.h"
+
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
+
#include <algorithm>
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Category
-SymbolCategory::Category::Type
-SymbolCategory::Category::categorize(const ResolveInfo& pInfo)
-{
+SymbolCategory::Category::Type SymbolCategory::Category::categorize(
+ const ResolveInfo& pInfo) {
if (ResolveInfo::File == pInfo.type())
return Category::File;
if (ResolveInfo::Local == pInfo.binding())
return Category::Local;
if (ResolveInfo::Common == pInfo.desc())
return Category::Common;
- if (ResolveInfo::Default == pInfo.visibility() ||
+ if (ResolveInfo::Default == pInfo.visibility() ||
ResolveInfo::Protected == pInfo.visibility())
return Category::Dynamic;
return Category::Regular;
@@ -33,50 +34,46 @@ SymbolCategory::Category::categorize(const ResolveInfo& pInfo)
//===----------------------------------------------------------------------===//
// SymbolCategory
-SymbolCategory::SymbolCategory()
-{
- m_pFile = new Category(Category::File);
- m_pLocal = new Category(Category::Local);
+SymbolCategory::SymbolCategory() {
+ m_pFile = new Category(Category::File);
+ m_pLocal = new Category(Category::Local);
m_pLocalDyn = new Category(Category::LocalDyn);
- m_pCommon = new Category(Category::Common);
- m_pDynamic = new Category(Category::Dynamic);
- m_pRegular = new Category(Category::Regular);
+ m_pCommon = new Category(Category::Common);
+ m_pDynamic = new Category(Category::Dynamic);
+ m_pRegular = new Category(Category::Regular);
- m_pFile->next = m_pLocal;
- m_pLocal->next = m_pLocalDyn;
+ m_pFile->next = m_pLocal;
+ m_pLocal->next = m_pLocalDyn;
m_pLocalDyn->next = m_pCommon;
- m_pCommon->next = m_pDynamic;
- m_pDynamic->next = m_pRegular;
+ m_pCommon->next = m_pDynamic;
+ m_pDynamic->next = m_pRegular;
- m_pRegular->prev = m_pDynamic;
- m_pDynamic->prev = m_pCommon;
- m_pCommon->prev = m_pLocalDyn;
+ m_pRegular->prev = m_pDynamic;
+ m_pDynamic->prev = m_pCommon;
+ m_pCommon->prev = m_pLocalDyn;
m_pLocalDyn->prev = m_pLocal;
- m_pLocal->prev = m_pFile;
+ m_pLocal->prev = m_pFile;
}
-SymbolCategory::~SymbolCategory()
-{
+SymbolCategory::~SymbolCategory() {
Category* current = m_pFile;
- while (NULL != current) {
+ while (current != NULL) {
Category* tmp = current;
current = current->next;
delete tmp;
}
}
-SymbolCategory& SymbolCategory::add(LDSymbol& pSymbol, Category::Type pTarget)
-{
+SymbolCategory& SymbolCategory::add(LDSymbol& pSymbol, Category::Type pTarget) {
Category* current = m_pRegular;
m_OutputSymbols.push_back(&pSymbol);
// use non-stable bubble sort to arrange the order of symbols.
- while (NULL != current) {
+ while (current != NULL) {
if (current->type == pTarget) {
current->end++;
break;
- }
- else {
+ } else {
if (!current->empty()) {
std::swap(m_OutputSymbols[current->begin],
m_OutputSymbols[current->end]);
@@ -89,23 +86,20 @@ SymbolCategory& SymbolCategory::add(LDSymbol& pSymbol, Category::Type pTarget)
return *this;
}
-SymbolCategory& SymbolCategory::add(LDSymbol& pSymbol)
-{
- assert(NULL != pSymbol.resolveInfo());
+SymbolCategory& SymbolCategory::add(LDSymbol& pSymbol) {
+ assert(pSymbol.resolveInfo() != NULL);
return add(pSymbol, Category::categorize(*pSymbol.resolveInfo()));
}
-SymbolCategory& SymbolCategory::forceLocal(LDSymbol& pSymbol)
-{
+SymbolCategory& SymbolCategory::forceLocal(LDSymbol& pSymbol) {
return add(pSymbol, Category::Local);
}
SymbolCategory& SymbolCategory::arrange(LDSymbol& pSymbol,
Category::Type pSource,
- Category::Type pTarget)
-{
+ Category::Type pTarget) {
int distance = pTarget - pSource;
- if (0 == distance) {
+ if (distance == 0) {
// in the same category, do not need to re-arrange
return *this;
}
@@ -113,13 +107,13 @@ SymbolCategory& SymbolCategory::arrange(LDSymbol& pSymbol,
// source and target are not in the same category
// find the category of source
Category* current = m_pFile;
- while(NULL != current) {
+ while (current != NULL) {
if (pSource == current->type)
break;
current = current->next;
}
- assert(NULL != current);
+ assert(current != NULL);
size_t pos = 0;
if (!current->empty()) {
// find the position of source
@@ -158,8 +152,7 @@ SymbolCategory& SymbolCategory::arrange(LDSymbol& pSymbol,
do {
if (current->type == pTarget) {
break;
- }
- else {
+ } else {
assert(!current->isLast() && "target category is wrong.");
rear = current->end - 1;
std::swap(m_OutputSymbols[pos], m_OutputSymbols[rear]);
@@ -168,20 +161,18 @@ SymbolCategory& SymbolCategory::arrange(LDSymbol& pSymbol,
current->end--;
}
current = current->next;
- } while(NULL != current);
+ } while (current != NULL);
return *this;
- } // downward
+ } // downward
// The distance is negative. It means we should bubble sort upward.
if (distance < 0) {
-
// upward
do {
if (current->type == pTarget) {
break;
- }
- else {
+ } else {
assert(!current->isFirst() && "target category is wrong.");
std::swap(m_OutputSymbols[current->begin], m_OutputSymbols[pos]);
pos = current->begin;
@@ -189,282 +180,238 @@ SymbolCategory& SymbolCategory::arrange(LDSymbol& pSymbol,
current->prev->end++;
}
current = current->prev;
- } while(NULL != current);
+ } while (current != NULL);
return *this;
- } // upward
+ } // upward
return *this;
}
SymbolCategory& SymbolCategory::arrange(LDSymbol& pSymbol,
- const ResolveInfo& pSourceInfo)
-{
- assert(NULL != pSymbol.resolveInfo());
+ const ResolveInfo& pSourceInfo) {
+ assert(pSymbol.resolveInfo() != NULL);
return arrange(pSymbol,
Category::categorize(pSourceInfo),
Category::categorize(*pSymbol.resolveInfo()));
}
-SymbolCategory& SymbolCategory::changeCommonsToGlobal()
-{
+SymbolCategory& SymbolCategory::changeCommonsToGlobal() {
// Change Common to Dynamic/Regular
while (!emptyCommons()) {
size_t pos = m_pCommon->end - 1;
switch (Category::categorize(*(m_OutputSymbols[pos]->resolveInfo()))) {
- case Category::Dynamic:
- m_pCommon->end--;
- m_pDynamic->begin--;
- break;
- case Category::Regular:
- std::swap(m_OutputSymbols[pos], m_OutputSymbols[m_pDynamic->end - 1]);
- m_pCommon->end--;
- m_pDynamic->begin--;
- m_pDynamic->end--;
- m_pRegular->begin--;
- break;
- default:
- assert(0);
- break;
+ case Category::Dynamic:
+ m_pCommon->end--;
+ m_pDynamic->begin--;
+ break;
+ case Category::Regular:
+ std::swap(m_OutputSymbols[pos], m_OutputSymbols[m_pDynamic->end - 1]);
+ m_pCommon->end--;
+ m_pDynamic->begin--;
+ m_pDynamic->end--;
+ m_pRegular->begin--;
+ break;
+ default:
+ assert(0);
+ break;
}
}
return *this;
}
-SymbolCategory& SymbolCategory::changeToDynamic(LDSymbol& pSymbol)
-{
- assert(NULL != pSymbol.resolveInfo());
+SymbolCategory& SymbolCategory::changeToDynamic(LDSymbol& pSymbol) {
+ assert(pSymbol.resolveInfo() != NULL);
return arrange(pSymbol,
Category::categorize(*pSymbol.resolveInfo()),
Category::LocalDyn);
}
-size_t SymbolCategory::numOfSymbols() const
-{
+size_t SymbolCategory::numOfSymbols() const {
return m_OutputSymbols.size();
}
-size_t SymbolCategory::numOfFiles() const
-{
+size_t SymbolCategory::numOfFiles() const {
return m_pFile->size();
}
-size_t SymbolCategory::numOfLocals() const
-{
+size_t SymbolCategory::numOfLocals() const {
return m_pLocal->size();
}
-size_t SymbolCategory::numOfLocalDyns() const
-{
+size_t SymbolCategory::numOfLocalDyns() const {
return m_pLocalDyn->size();
}
-size_t SymbolCategory::numOfCommons() const
-{
+size_t SymbolCategory::numOfCommons() const {
return m_pCommon->size();
}
-size_t SymbolCategory::numOfDynamics() const
-{
+size_t SymbolCategory::numOfDynamics() const {
return m_pDynamic->size();
}
-size_t SymbolCategory::numOfRegulars() const
-{
+size_t SymbolCategory::numOfRegulars() const {
return m_pRegular->size();
}
-bool SymbolCategory::empty() const
-{
+bool SymbolCategory::empty() const {
return m_OutputSymbols.empty();
}
-bool SymbolCategory::emptyFiles() const
-{
+bool SymbolCategory::emptyFiles() const {
return m_pFile->empty();
}
-bool SymbolCategory::emptyLocals() const
-{
+bool SymbolCategory::emptyLocals() const {
return m_pLocal->empty();
}
-bool SymbolCategory::emptyLocalDyns() const
-{
+bool SymbolCategory::emptyLocalDyns() const {
return m_pLocalDyn->empty();
}
-bool SymbolCategory::emptyCommons() const
-{
+bool SymbolCategory::emptyCommons() const {
return m_pCommon->empty();
}
-bool SymbolCategory::emptyDynamics() const
-{
+bool SymbolCategory::emptyDynamics() const {
return m_pDynamic->empty();
}
-bool SymbolCategory::emptyRegulars() const
-{
+bool SymbolCategory::emptyRegulars() const {
return m_pRegular->empty();
}
-SymbolCategory::iterator SymbolCategory::begin()
-{
+SymbolCategory::iterator SymbolCategory::begin() {
return m_OutputSymbols.begin();
}
-SymbolCategory::iterator SymbolCategory::end()
-{
+SymbolCategory::iterator SymbolCategory::end() {
return m_OutputSymbols.end();
}
-SymbolCategory::const_iterator SymbolCategory::begin() const
-{
+SymbolCategory::const_iterator SymbolCategory::begin() const {
return m_OutputSymbols.begin();
}
-SymbolCategory::const_iterator SymbolCategory::end() const
-{
+SymbolCategory::const_iterator SymbolCategory::end() const {
return m_OutputSymbols.end();
}
-SymbolCategory::iterator SymbolCategory::fileBegin()
-{
+SymbolCategory::iterator SymbolCategory::fileBegin() {
return m_OutputSymbols.begin();
}
-SymbolCategory::iterator SymbolCategory::fileEnd()
-{
+SymbolCategory::iterator SymbolCategory::fileEnd() {
iterator iter = fileBegin();
iter += m_pFile->size();
return iter;
}
-SymbolCategory::const_iterator SymbolCategory::fileBegin() const
-{
+SymbolCategory::const_iterator SymbolCategory::fileBegin() const {
return m_OutputSymbols.begin();
}
-SymbolCategory::const_iterator SymbolCategory::fileEnd() const
-{
+SymbolCategory::const_iterator SymbolCategory::fileEnd() const {
const_iterator iter = fileBegin();
iter += m_pFile->size();
return iter;
}
-SymbolCategory::iterator SymbolCategory::localBegin()
-{
+SymbolCategory::iterator SymbolCategory::localBegin() {
return fileEnd();
}
-SymbolCategory::iterator SymbolCategory::localEnd()
-{
+SymbolCategory::iterator SymbolCategory::localEnd() {
iterator iter = localBegin();
iter += m_pLocal->size();
return iter;
}
-SymbolCategory::const_iterator SymbolCategory::localBegin() const
-{
+SymbolCategory::const_iterator SymbolCategory::localBegin() const {
return fileEnd();
}
-SymbolCategory::const_iterator SymbolCategory::localEnd() const
-{
+SymbolCategory::const_iterator SymbolCategory::localEnd() const {
const_iterator iter = localBegin();
iter += m_pLocal->size();
return iter;
}
-SymbolCategory::iterator SymbolCategory::localDynBegin()
-{
+SymbolCategory::iterator SymbolCategory::localDynBegin() {
return localEnd();
}
-SymbolCategory::iterator SymbolCategory::localDynEnd()
-{
+SymbolCategory::iterator SymbolCategory::localDynEnd() {
iterator iter = localDynBegin();
iter += m_pLocalDyn->size();
return iter;
}
-SymbolCategory::const_iterator SymbolCategory::localDynBegin() const
-{
+SymbolCategory::const_iterator SymbolCategory::localDynBegin() const {
return localEnd();
}
-SymbolCategory::const_iterator SymbolCategory::localDynEnd() const
-{
+SymbolCategory::const_iterator SymbolCategory::localDynEnd() const {
const_iterator iter = localDynBegin();
iter += m_pLocalDyn->size();
return iter;
}
-SymbolCategory::iterator SymbolCategory::commonBegin()
-{
+SymbolCategory::iterator SymbolCategory::commonBegin() {
return localDynEnd();
}
-SymbolCategory::iterator SymbolCategory::commonEnd()
-{
+SymbolCategory::iterator SymbolCategory::commonEnd() {
iterator iter = commonBegin();
iter += m_pCommon->size();
return iter;
}
-SymbolCategory::const_iterator SymbolCategory::commonBegin() const
-{
+SymbolCategory::const_iterator SymbolCategory::commonBegin() const {
return localDynEnd();
}
-SymbolCategory::const_iterator SymbolCategory::commonEnd() const
-{
+SymbolCategory::const_iterator SymbolCategory::commonEnd() const {
const_iterator iter = commonBegin();
iter += m_pCommon->size();
return iter;
}
-SymbolCategory::iterator SymbolCategory::dynamicBegin()
-{
+SymbolCategory::iterator SymbolCategory::dynamicBegin() {
return commonEnd();
}
-SymbolCategory::iterator SymbolCategory::dynamicEnd()
-{
+SymbolCategory::iterator SymbolCategory::dynamicEnd() {
iterator iter = dynamicBegin();
iter += m_pDynamic->size();
return iter;
}
-SymbolCategory::const_iterator SymbolCategory::dynamicBegin() const
-{
+SymbolCategory::const_iterator SymbolCategory::dynamicBegin() const {
return commonEnd();
}
-SymbolCategory::const_iterator SymbolCategory::dynamicEnd() const
-{
+SymbolCategory::const_iterator SymbolCategory::dynamicEnd() const {
const_iterator iter = dynamicBegin();
iter += m_pDynamic->size();
return iter;
}
-SymbolCategory::iterator SymbolCategory::regularBegin()
-{
- return commonEnd();
+SymbolCategory::iterator SymbolCategory::regularBegin() {
+ return dynamicEnd();
}
-SymbolCategory::iterator SymbolCategory::regularEnd()
-{
+SymbolCategory::iterator SymbolCategory::regularEnd() {
return m_OutputSymbols.end();
}
-SymbolCategory::const_iterator SymbolCategory::regularBegin() const
-{
- return commonEnd();
+SymbolCategory::const_iterator SymbolCategory::regularBegin() const {
+ return dynamicEnd();
}
-SymbolCategory::const_iterator SymbolCategory::regularEnd() const
-{
+SymbolCategory::const_iterator SymbolCategory::regularEnd() const {
return m_OutputSymbols.end();
}
+} // namespace mcld
diff --git a/lib/MC/ZOption.cpp b/lib/MC/ZOption.cpp
index 8b11765..c955967 100644
--- a/lib/MC/ZOption.cpp
+++ b/lib/MC/ZOption.cpp
@@ -6,14 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/ZOption.h>
+#include "mcld/MC/ZOption.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ZOption
//===----------------------------------------------------------------------===//
-ZOption::ZOption()
- : m_Kind(Unknown), m_PageSize(0x0) {
+ZOption::ZOption() : ZOption(Unknown) {
}
+ZOption::ZOption(Kind pKind) : ZOption(pKind, 0x0) {
+}
+
+ZOption::ZOption(Kind pKind, uint64_t pPageSize)
+ : m_Kind(pKind), m_PageSize(pPageSize) {
+}
+
+} // namespace mcld
diff --git a/lib/Object/ObjectBuilder.cpp b/lib/Object/ObjectBuilder.cpp
index 5543f46..8bbbda1 100644
--- a/lib/Object/ObjectBuilder.cpp
+++ b/lib/Object/ObjectBuilder.cpp
@@ -6,28 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Object/ObjectBuilder.h>
-
-#include <mcld/Module.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/Object/SectionMap.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/Fragment/AlignFragment.h>
-#include <mcld/Fragment/NullFragment.h>
-#include <mcld/Fragment/FillFragment.h>
+#include "mcld/Object/ObjectBuilder.h"
+
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/LD/DebugString.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Object/SectionMap.h"
#include <llvm/Support/Casting.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ObjectBuilder
//===----------------------------------------------------------------------===//
-ObjectBuilder::ObjectBuilder(Module& pTheModule)
- : m_Module(pTheModule) {
+ObjectBuilder::ObjectBuilder(Module& pTheModule) : m_Module(pTheModule) {
}
/// CreateSection - create an output section.
@@ -35,16 +35,15 @@ LDSection* ObjectBuilder::CreateSection(const std::string& pName,
LDFileFormat::Kind pKind,
uint32_t pType,
uint32_t pFlag,
- uint32_t pAlign)
-{
+ uint32_t pAlign) {
// try to get one from output LDSection
SectionMap::const_mapping pair =
- m_Module.getScript().sectionMap().find("*", pName);
+ m_Module.getScript().sectionMap().find("*", pName);
std::string output_name = (pair.first == NULL) ? pName : pair.first->name();
LDSection* output_sect = m_Module.getSection(output_name);
- if (NULL == output_sect) {
+ if (output_sect == NULL) {
output_sect = LDSection::Create(pName, pKind, pType, pFlag);
output_sect->setAlign(pAlign);
m_Module.getSectionTable().push_back(output_sect);
@@ -54,22 +53,20 @@ LDSection* ObjectBuilder::CreateSection(const std::string& pName,
/// MergeSection - merge the pInput section to the pOutput section
LDSection* ObjectBuilder::MergeSection(const Input& pInputFile,
- LDSection& pInputSection)
-{
- SectionMap::mapping pair =
- m_Module.getScript().sectionMap().find(pInputFile.path().native(),
- pInputSection.name());
+ LDSection& pInputSection) {
+ SectionMap::mapping pair = m_Module.getScript().sectionMap().find(
+ pInputFile.path().native(), pInputSection.name());
if (pair.first != NULL && pair.first->isDiscard()) {
pInputSection.setKind(LDFileFormat::Ignore);
return NULL;
}
- std::string output_name = (pair.first == NULL) ?
- pInputSection.name() : pair.first->name();
+ std::string output_name =
+ (pair.first == NULL) ? pInputSection.name() : pair.first->name();
LDSection* target = m_Module.getSection(output_name);
- if (NULL == target) {
+ if (target == NULL) {
target = LDSection::Create(output_name,
pInputSection.kind(),
pInputSection.type(),
@@ -90,6 +87,17 @@ LDSection* ObjectBuilder::MergeSection(const Input& pInputFile,
UpdateSectionAlign(*target, pInputSection);
return target;
}
+ case LDFileFormat::DebugString: {
+ DebugString* debug_str = NULL;
+ if (target->hasDebugString())
+ debug_str = target->getDebugString();
+ else
+ debug_str = IRBuilder::CreateDebugString(*target);
+
+ debug_str->merge(pInputSection);
+ UpdateSectionAlign(*target, pInputSection);
+ return target;
+ }
default: {
if (!target->hasSectionData())
IRBuilder::CreateSectionData(*target);
@@ -98,6 +106,11 @@ LDSection* ObjectBuilder::MergeSection(const Input& pInputFile,
if (pair.first != NULL) {
assert(pair.second != NULL);
data = pair.second->getSection()->getSectionData();
+
+ // force input alignment from ldscript if any
+ if (pair.first->prolog().hasSubAlign()) {
+ pInputSection.setAlign(pair.second->getSection()->align());
+ }
} else {
// orphan section
data = target->getSectionData();
@@ -114,19 +127,18 @@ LDSection* ObjectBuilder::MergeSection(const Input& pInputFile,
}
/// MoveSectionData - move the fragments of pTO section data to pTo
-bool ObjectBuilder::MoveSectionData(SectionData& pFrom, SectionData& pTo)
-{
+bool ObjectBuilder::MoveSectionData(SectionData& pFrom, SectionData& pTo) {
assert(&pFrom != &pTo && "Cannot move section data to itself!");
uint64_t offset = pTo.getSection().size();
AlignFragment* align = NULL;
if (pFrom.getSection().align() > 1) {
// if the align constraint is larger than 1, append an alignment
- align = new AlignFragment(pFrom.getSection().align(), // alignment
- 0x0, // the filled value
- 1u, // the size of filled value
- pFrom.getSection().align() - 1 // max bytes to emit
- );
+ unsigned int alignment = pFrom.getSection().align();
+ align = new AlignFragment(/*alignment*/alignment,
+ /*the filled value*/0x0,
+ /*the size of filled value*/1u,
+ /*max bytes to emit*/alignment - 1);
align->setOffset(offset);
align->setParent(&pTo);
pTo.getFragmentList().push_back(align);
@@ -151,16 +163,14 @@ bool ObjectBuilder::MoveSectionData(SectionData& pFrom, SectionData& pTo)
}
/// UpdateSectionAlign - update alignment for input section
-void ObjectBuilder::UpdateSectionAlign(LDSection& pTo, const LDSection& pFrom)
-{
+void ObjectBuilder::UpdateSectionAlign(LDSection& pTo, const LDSection& pFrom) {
if (pFrom.align() > pTo.align())
pTo.setAlign(pFrom.align());
}
/// UpdateSectionAlign - update alignment for input section
void ObjectBuilder::UpdateSectionAlign(LDSection& pSection,
- uint32_t pAlignConstraint)
-{
+ uint32_t pAlignConstraint) {
if (pSection.align() < pAlignConstraint)
pSection.setAlign(pAlignConstraint);
}
@@ -168,8 +178,7 @@ void ObjectBuilder::UpdateSectionAlign(LDSection& pSection,
/// AppendFragment - To append pFrag to the given SectionData pSD.
uint64_t ObjectBuilder::AppendFragment(Fragment& pFrag,
SectionData& pSD,
- uint32_t pAlignConstraint)
-{
+ uint32_t pAlignConstraint) {
// get initial offset.
uint64_t offset = 0;
if (!pSD.empty())
@@ -178,11 +187,10 @@ uint64_t ObjectBuilder::AppendFragment(Fragment& pFrag,
AlignFragment* align = NULL;
if (pAlignConstraint > 1) {
// if the align constraint is larger than 1, append an alignment
- align = new AlignFragment(pAlignConstraint, // alignment
- 0x0, // the filled value
- 1u, // the size of filled value
- pAlignConstraint - 1 // max bytes to emit
- );
+ align = new AlignFragment(/*alignment*/pAlignConstraint,
+ /*the filled value*/0x0,
+ /*the size of filled value*/1u,
+ /*max bytes to emit*/pAlignConstraint - 1);
align->setOffset(offset);
align->setParent(&pSD);
pSD.getFragmentList().push_back(align);
@@ -199,9 +207,10 @@ uint64_t ObjectBuilder::AppendFragment(Fragment& pFrag,
NullFragment* null = new NullFragment(&pSD);
null->setOffset(offset);
- if (NULL != align)
+ if (align != NULL)
return align->size() + pFrag.size();
else
return pFrag.size();
}
+} // namespace mcld
diff --git a/lib/Object/ObjectLinker.cpp b/lib/Object/ObjectLinker.cpp
index dfc7f37..f32ebfc 100644
--- a/lib/Object/ObjectLinker.cpp
+++ b/lib/Object/ObjectLinker.cpp
@@ -6,68 +6,68 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Object/ObjectLinker.h>
-
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
-#include <mcld/InputTree.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/Archive.h>
-#include <mcld/LD/ArchiveReader.h>
-#include <mcld/LD/ObjectReader.h>
-#include <mcld/LD/DynObjReader.h>
-#include <mcld/LD/GroupReader.h>
-#include <mcld/LD/BinaryReader.h>
-#include <mcld/LD/GarbageCollection.h>
-#include <mcld/LD/IdenticalCodeFolding.h>
-#include <mcld/LD/ObjectWriter.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/Relocator.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/Script/ScriptFile.h>
-#include <mcld/Script/ScriptReader.h>
-#include <mcld/Script/Assignment.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/RpnEvaluator.h>
-#include <mcld/Support/RealPath.h>
-#include <mcld/Support/FileOutputBuffer.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Target/TargetLDBackend.h>
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/Object/ObjectLinker.h"
+
+#include "mcld/InputTree.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/Archive.h"
+#include "mcld/LD/ArchiveReader.h"
+#include "mcld/LD/BinaryReader.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/DebugString.h"
+#include "mcld/LD/DynObjReader.h"
+#include "mcld/LD/GarbageCollection.h"
+#include "mcld/LD/GroupReader.h"
+#include "mcld/LD/IdenticalCodeFolding.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/ObjectReader.h"
+#include "mcld/LD/ObjectWriter.h"
+#include "mcld/LD/Relocator.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Script/Assignment.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/RpnEvaluator.h"
+#include "mcld/Script/ScriptFile.h"
+#include "mcld/Script/ScriptReader.h"
+#include "mcld/Support/FileOutputBuffer.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/RealPath.h"
+#include "mcld/Target/TargetLDBackend.h"
#include <llvm/Support/Casting.h>
#include <llvm/Support/Host.h>
+
#include <system_error>
-using namespace llvm;
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ObjectLinker
//===----------------------------------------------------------------------===//
ObjectLinker::ObjectLinker(const LinkerConfig& pConfig,
TargetLDBackend& pLDBackend)
- : m_Config(pConfig),
- m_pModule(NULL),
- m_pBuilder(NULL),
- m_LDBackend(pLDBackend),
- m_pObjectReader(NULL),
- m_pDynObjReader(NULL),
- m_pArchiveReader(NULL),
- m_pGroupReader(NULL),
- m_pBinaryReader(NULL),
- m_pScriptReader(NULL),
- m_pWriter(NULL) {
+ : m_Config(pConfig),
+ m_pModule(NULL),
+ m_pBuilder(NULL),
+ m_LDBackend(pLDBackend),
+ m_pObjectReader(NULL),
+ m_pDynObjReader(NULL),
+ m_pArchiveReader(NULL),
+ m_pGroupReader(NULL),
+ m_pBinaryReader(NULL),
+ m_pScriptReader(NULL),
+ m_pWriter(NULL) {
}
-ObjectLinker::~ObjectLinker()
-{
+ObjectLinker::~ObjectLinker() {
delete m_pObjectReader;
delete m_pDynObjReader;
delete m_pArchiveReader;
@@ -77,20 +77,23 @@ ObjectLinker::~ObjectLinker()
delete m_pWriter;
}
-bool ObjectLinker::initialize(Module& pModule, IRBuilder& pBuilder)
-{
+bool ObjectLinker::initialize(Module& pModule, IRBuilder& pBuilder) {
m_pModule = &pModule;
m_pBuilder = &pBuilder;
// initialize the readers and writers
- m_pObjectReader = m_LDBackend.createObjectReader(*m_pBuilder);
+ m_pObjectReader = m_LDBackend.createObjectReader(*m_pBuilder);
m_pArchiveReader = m_LDBackend.createArchiveReader(*m_pModule);
- m_pDynObjReader = m_LDBackend.createDynObjReader(*m_pBuilder);
- m_pBinaryReader = m_LDBackend.createBinaryReader(*m_pBuilder);
- m_pGroupReader = new GroupReader(*m_pModule, *m_pObjectReader,
- *m_pDynObjReader, *m_pArchiveReader, *m_pBinaryReader);
- m_pScriptReader = new ScriptReader(*m_pGroupReader);
- m_pWriter = m_LDBackend.createWriter();
+ m_pDynObjReader = m_LDBackend.createDynObjReader(*m_pBuilder);
+ m_pBinaryReader = m_LDBackend.createBinaryReader(*m_pBuilder);
+ m_pGroupReader = new GroupReader(*m_pModule,
+ *m_pObjectReader,
+ *m_pDynObjReader,
+ *m_pArchiveReader,
+ *m_pBinaryReader);
+ m_pScriptReader = new ScriptReader(
+ *m_pObjectReader, *m_pArchiveReader, *m_pDynObjReader, *m_pGroupReader);
+ m_pWriter = m_LDBackend.createWriter();
// initialize Relocator
m_LDBackend.initRelocator();
@@ -99,8 +102,7 @@ bool ObjectLinker::initialize(Module& pModule, IRBuilder& pBuilder)
}
/// initStdSections - initialize standard sections
-bool ObjectLinker::initStdSections()
-{
+bool ObjectLinker::initStdSections() {
ObjectBuilder builder(*m_pModule);
// initialize standard sections
@@ -113,30 +115,27 @@ bool ObjectLinker::initStdSections()
return true;
}
-void ObjectLinker::addUndefinedSymbols()
-{
+void ObjectLinker::addUndefinedSymbols() {
// Add the symbol set by -u as an undefind global symbol into symbol pool
GeneralOptions::const_undef_sym_iterator usym;
GeneralOptions::const_undef_sym_iterator usymEnd =
- m_Config.options().undef_sym_end();
+ m_Config.options().undef_sym_end();
for (usym = m_Config.options().undef_sym_begin(); usym != usymEnd; ++usym) {
Resolver::Result result;
- m_pModule->getNamePool().insertSymbol(*usym, // name
- false, // isDyn
+ m_pModule->getNamePool().insertSymbol(*usym, // name
+ false, // isDyn
ResolveInfo::NoType,
ResolveInfo::Undefined,
ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
+ 0x0, // size
+ 0x0, // value
ResolveInfo::Default,
NULL,
result);
LDSymbol* output_sym = result.info->outSymbol();
- bool has_output_sym = (NULL != output_sym);
-
// create the output symbol if it dose not have one
- if (!result.existent || !has_output_sym) {
+ if (!result.existent || (output_sym != NULL)) {
output_sym = LDSymbol::Create(*result.info);
result.info->setSymPtr(output_sym);
output_sym->setFragmentRef(FragmentRef::Null());
@@ -144,15 +143,14 @@ void ObjectLinker::addUndefinedSymbols()
}
}
-void ObjectLinker::normalize()
-{
+void ObjectLinker::normalize() {
// ----- set up inputs ----- //
Module::input_iterator input, inEnd = m_pModule->input_end();
- for (input = m_pModule->input_begin(); input!=inEnd; ++input) {
+ for (input = m_pModule->input_begin(); input != inEnd; ++input) {
// is a group node
if (isGroup(input)) {
- getGroupReader()->readGroup(input, inEnd, m_pBuilder->getInputBuilder(),
- m_Config);
+ getGroupReader()->readGroup(
+ input, inEnd, m_pBuilder->getInputBuilder(), m_Config);
continue;
}
@@ -179,58 +177,56 @@ void ObjectLinker::normalize()
(*input)->setType(Input::Object);
getBinaryReader()->readBinary(**input);
m_pModule->getObjectList().push_back(*input);
- }
- // is a relocatable object file
- else if (doContinue && getObjectReader()->isMyFormat(**input, doContinue)) {
+ } else if (doContinue &&
+ getObjectReader()->isMyFormat(**input, doContinue)) {
+ // is a relocatable object file
(*input)->setType(Input::Object);
getObjectReader()->readHeader(**input);
getObjectReader()->readSections(**input);
getObjectReader()->readSymbols(**input);
m_pModule->getObjectList().push_back(*input);
- }
- // is a shared object file
- else if (doContinue && getDynObjReader()->isMyFormat(**input, doContinue)) {
+ } else if (doContinue &&
+ getDynObjReader()->isMyFormat(**input, doContinue)) {
+ // is a shared object file
(*input)->setType(Input::DynObj);
getDynObjReader()->readHeader(**input);
getDynObjReader()->readSymbols(**input);
m_pModule->getLibraryList().push_back(*input);
- }
- // is an archive
- else if (doContinue && getArchiveReader()->isMyFormat(**input, doContinue)) {
+ } else if (doContinue &&
+ getArchiveReader()->isMyFormat(**input, doContinue)) {
+ // is an archive
(*input)->setType(Input::Archive);
if (m_Config.options().isInExcludeLIBS(**input)) {
(*input)->setNoExport();
}
Archive archive(**input, m_pBuilder->getInputBuilder());
getArchiveReader()->readArchive(m_Config, archive);
- if(archive.numOfObjectMember() > 0) {
+ if (archive.numOfObjectMember() > 0) {
m_pModule->getInputTree().merge<InputTree::Inclusive>(input,
archive.inputs());
}
- }
- // try to parse input as a linker script
- else if (doContinue && getScriptReader()->isMyFormat(**input, doContinue)) {
- ScriptFile script(ScriptFile::LDScript, **input,
- m_pBuilder->getInputBuilder());
+ } else if (doContinue &&
+ getScriptReader()->isMyFormat(**input, doContinue)) {
+ // try to parse input as a linker script
+ ScriptFile script(
+ ScriptFile::LDScript, **input, m_pBuilder->getInputBuilder());
if (getScriptReader()->readScript(m_Config, script)) {
(*input)->setType(Input::Script);
script.activate(*m_pModule);
if (script.inputs().size() > 0) {
- m_pModule->getInputTree().merge<InputTree::Inclusive>(input,
- script.inputs());
+ m_pModule->getInputTree().merge<InputTree::Inclusive>(
+ input, script.inputs());
}
}
- }
- else {
+ } else {
if (m_Config.options().warnMismatch())
- warning(diag::warn_unrecognized_input_file) << (*input)->path()
- << m_Config.targets().triple().str();
+ warning(diag::warn_unrecognized_input_file)
+ << (*input)->path() << m_Config.targets().triple().str();
}
- } // end of for
+ } // end of for
}
-bool ObjectLinker::linkable() const
-{
+bool ObjectLinker::linkable() const {
// check we have input and output files
if (m_pModule->getInputTree().empty()) {
error(diag::err_no_inputs);
@@ -240,9 +236,9 @@ bool ObjectLinker::linkable() const
// can not mix -static with shared objects
Module::const_lib_iterator lib, libEnd = m_pModule->lib_end();
for (lib = m_pModule->lib_begin(); lib != libEnd; ++lib) {
- if((*lib)->attribute()->isStatic()) {
- error(diag::err_mixed_shared_static_objects)
- << (*lib)->name() << (*lib)->path();
+ if ((*lib)->attribute()->isStatic()) {
+ error(diag::err_mixed_shared_static_objects) << (*lib)->name()
+ << (*lib)->path();
return false;
}
}
@@ -265,8 +261,11 @@ bool ObjectLinker::linkable() const
return true;
}
-void ObjectLinker::dataStrippingOpt()
-{
+void ObjectLinker::dataStrippingOpt() {
+ if (m_Config.codeGenType() == LinkerConfig::Object) {
+ return;
+ }
+
// Garbege collection
if (m_Config.options().GCSections()) {
GarbageCollection GC(m_Config, m_LDBackend, *m_pModule);
@@ -284,12 +283,12 @@ void ObjectLinker::dataStrippingOpt()
/// readRelocations - read all relocation entries
///
/// All symbols should be read and resolved before this function.
-bool ObjectLinker::readRelocations()
-{
+bool ObjectLinker::readRelocations() {
// Bitcode is read by the other path. This function reads relocation sections
// in object files.
- mcld::InputTree::bfs_iterator input, inEnd = m_pModule->getInputTree().bfs_end();
- for (input=m_pModule->getInputTree().bfs_begin(); input!=inEnd; ++input) {
+ mcld::InputTree::bfs_iterator input,
+ inEnd = m_pModule->getInputTree().bfs_end();
+ for (input = m_pModule->getInputTree().bfs_begin(); input != inEnd; ++input) {
if ((*input)->type() == Input::Object && (*input)->hasMemArea()) {
if (!getObjectReader()->readRelocations(**input))
return false;
@@ -300,8 +299,39 @@ bool ObjectLinker::readRelocations()
}
/// mergeSections - put allinput sections into output sections
-bool ObjectLinker::mergeSections()
-{
+bool ObjectLinker::mergeSections() {
+ // Set up input/output from ldscript requirement if any
+ {
+ RpnEvaluator evaluator(*m_pModule, m_LDBackend);
+ SectionMap::iterator out, outBegin, outEnd;
+ outBegin = m_pModule->getScript().sectionMap().begin();
+ outEnd = m_pModule->getScript().sectionMap().end();
+ for (out = outBegin; out != outEnd; ++out) {
+ uint64_t out_align = 0x0, in_align = 0x0;
+ LDSection* out_sect = (*out)->getSection();
+ SectionMap::Output::iterator in, inBegin, inEnd;
+ inBegin = (*out)->begin();
+ inEnd = (*out)->end();
+
+ // force input alignment from ldscript if any
+ if ((*out)->prolog().hasSubAlign()) {
+ evaluator.eval((*out)->prolog().subAlign(), in_align);
+ }
+
+ for (in = inBegin; in != inEnd; ++in) {
+ LDSection* in_sect = (*in)->getSection();
+ if ((*out)->prolog().hasSubAlign())
+ in_sect->setAlign(in_align);
+ } // for each input section description
+
+ // force output alignment from ldscript if any
+ if ((*out)->prolog().hasAlign()) {
+ evaluator.eval((*out)->prolog().align(), out_align);
+ out_sect->setAlign(out_align);
+ }
+ } // for each output section description
+ }
+
ObjectBuilder builder(*m_pModule);
Module::obj_iterator obj, objEnd = m_pModule->obj_end();
for (obj = m_pModule->obj_begin(); obj != objEnd; ++obj) {
@@ -317,15 +347,14 @@ bool ObjectLinker::mergeSections()
case LDFileFormat::StackNote:
// skip
continue;
- case LDFileFormat::Relocation: {
+ case LDFileFormat::Relocation:
if (!(*sect)->hasRelocData())
- continue; // skip
+ continue; // skip
if ((*sect)->getLink()->kind() == LDFileFormat::Ignore ||
(*sect)->getLink()->kind() == LDFileFormat::Folded)
(*sect)->setKind(LDFileFormat::Ignore);
break;
- }
case LDFileFormat::Target:
if (!m_LDBackend.mergeSection(*m_pModule, **obj, **sect)) {
error(diag::err_cannot_merge_section) << (*sect)->name()
@@ -335,10 +364,10 @@ bool ObjectLinker::mergeSections()
break;
case LDFileFormat::EhFrame: {
if (!(*sect)->hasEhFrame())
- continue; // skip
+ continue; // skip
LDSection* out_sect = NULL;
- if (NULL != (out_sect = builder.MergeSection(**obj, **sect))) {
+ if ((out_sect = builder.MergeSection(**obj, **sect)) != NULL) {
if (!m_LDBackend.updateSectionFlags(*out_sect, **sect)) {
error(diag::err_cannot_merge_section) << (*sect)->name()
<< (*obj)->name();
@@ -347,12 +376,17 @@ bool ObjectLinker::mergeSections()
}
break;
}
+ case LDFileFormat::DebugString: {
+ // FIXME: disable debug string merge when doing partial link.
+ if (LinkerConfig::Object == m_Config.codeGenType())
+ (*sect)->setKind(LDFileFormat::Debug);
+ } // Fall through
default: {
if (!(*sect)->hasSectionData())
- continue; // skip
+ continue; // skip
LDSection* out_sect = NULL;
- if (NULL != (out_sect = builder.MergeSection(**obj, **sect))) {
+ if ((out_sect = builder.MergeSection(**obj, **sect)) != NULL) {
if (!m_LDBackend.updateSectionFlags(*out_sect, **sect)) {
error(diag::err_cannot_merge_section) << (*sect)->name()
<< (*obj)->name();
@@ -361,69 +395,72 @@ bool ObjectLinker::mergeSections()
}
break;
}
- } // end of switch
- } // for each section
- } // for each obj
-
- RpnEvaluator evaluator(*m_pModule, m_LDBackend);
- SectionMap::iterator out, outBegin, outEnd;
- outBegin = m_pModule->getScript().sectionMap().begin();
- outEnd = m_pModule->getScript().sectionMap().end();
- for (out = outBegin; out != outEnd; ++out) {
- uint64_t out_align = 0x0, in_align = 0x0;
- LDSection* out_sect = (*out)->getSection();
- SectionMap::Output::iterator in, inBegin, inEnd;
- inBegin = (*out)->begin();
- inEnd = (*out)->end();
-
- // force input alignment from ldscript if any
- if ((*out)->prolog().hasSubAlign()) {
- evaluator.eval((*out)->prolog().subAlign(), in_align);
- }
-
- for (in = inBegin; in != inEnd; ++in) {
- LDSection* in_sect = (*in)->getSection();
- if ((*out)->prolog().hasSubAlign())
- in_sect->setAlign(in_align);
-
- if (builder.MoveSectionData(*in_sect->getSectionData(),
- *out_sect->getSectionData())) {
- builder.UpdateSectionAlign(*out_sect, *in_sect);
- m_LDBackend.updateSectionFlags(*out_sect, *in_sect);
- }
- } // for each input section description
-
- // force output alignment from ldscript if any
- if ((*out)->prolog().hasAlign()) {
- evaluator.eval((*out)->prolog().align(), out_align);
- out_sect->setAlign(out_align);
- }
-
- if ((*out)->hasContent()) {
- LDSection* target = m_pModule->getSection((*out)->name());
- assert(target != NULL && target->hasSectionData());
- if (builder.MoveSectionData(*out_sect->getSectionData(),
- *target->getSectionData())) {
- builder.UpdateSectionAlign(*target, *out_sect);
- m_LDBackend.updateSectionFlags(*target, *out_sect);
+ } // end of switch
+ } // for each section
+ } // for each obj
+
+ {
+ SectionMap::iterator out, outBegin, outEnd;
+ outBegin = m_pModule->getScript().sectionMap().begin();
+ outEnd = m_pModule->getScript().sectionMap().end();
+ for (out = outBegin; out != outEnd; ++out) {
+ LDSection* out_sect = (*out)->getSection();
+ SectionMap::Output::iterator in, inBegin, inEnd;
+ inBegin = (*out)->begin();
+ inEnd = (*out)->end();
+
+ for (in = inBegin; in != inEnd; ++in) {
+ LDSection* in_sect = (*in)->getSection();
+ if (builder.MoveSectionData(*in_sect->getSectionData(),
+ *out_sect->getSectionData())) {
+ builder.UpdateSectionAlign(*out_sect, *in_sect);
+ m_LDBackend.updateSectionFlags(*out_sect, *in_sect);
+ }
+ } // for each input section description
+
+ if ((*out)->hasContent()) {
+ LDSection* target = m_pModule->getSection((*out)->name());
+ assert(target != NULL && target->hasSectionData());
+ if (builder.MoveSectionData(*out_sect->getSectionData(),
+ *target->getSectionData())) {
+ builder.UpdateSectionAlign(*target, *out_sect);
+ m_LDBackend.updateSectionFlags(*target, *out_sect);
+ }
}
- }
- } // for each output section description
+ } // for each output section description
+ }
return true;
}
-void ObjectLinker::addSymbolToOutput(ResolveInfo& pInfo, Module& pModule)
-{
+void ObjectLinker::addSymbolToOutput(ResolveInfo& pInfo, Module& pModule) {
// section symbols will be defined by linker later, we should not add section
// symbols to output here
- if (ResolveInfo::Section == pInfo.type() || NULL == pInfo.outSymbol())
+ if (ResolveInfo::Section == pInfo.type() || pInfo.outSymbol() == NULL)
return;
// if the symbols defined in the Ignore sections (e.g. discared by GC), then
// not to put them to output
- if (pInfo.outSymbol()->hasFragRef() && LDFileFormat::Ignore ==
- pInfo.outSymbol()->fragRef()->frag()->getParent()->getSection().kind())
+ // make sure that symbols defined in .debug_str won't add into output
+ // symbol table. Since these symbols has fragRef to input fragments, which
+ // will refer to input LDSection and has bad result when emitting their
+ // section index. However, .debug_str actually does not need symobl in
+ // shrad/executable objects, so it's fine to do so.
+ if (pInfo.outSymbol()->hasFragRef() &&
+ (LDFileFormat::Ignore ==
+ pInfo.outSymbol()
+ ->fragRef()
+ ->frag()
+ ->getParent()
+ ->getSection()
+ .kind() ||
+ LDFileFormat::DebugString ==
+ pInfo.outSymbol()
+ ->fragRef()
+ ->frag()
+ ->getParent()
+ ->getSection()
+ .kind()))
return;
if (pInfo.shouldForceLocal(m_Config))
@@ -432,31 +469,27 @@ void ObjectLinker::addSymbolToOutput(ResolveInfo& pInfo, Module& pModule)
pModule.getSymbolTable().add(*pInfo.outSymbol());
}
-void ObjectLinker::addSymbolsToOutput(Module& pModule)
-{
+void ObjectLinker::addSymbolsToOutput(Module& pModule) {
// Traverse all the free ResolveInfo and add the output symobols to output
NamePool::freeinfo_iterator free_it,
- free_end = pModule.getNamePool().freeinfo_end();
+ free_end = pModule.getNamePool().freeinfo_end();
for (free_it = pModule.getNamePool().freeinfo_begin(); free_it != free_end;
- ++free_it)
+ ++free_it)
addSymbolToOutput(**free_it, pModule);
-
// Traverse all the resolveInfo and add the output symbol to output
NamePool::syminfo_iterator info_it,
- info_end = pModule.getNamePool().syminfo_end();
+ info_end = pModule.getNamePool().syminfo_end();
for (info_it = pModule.getNamePool().syminfo_begin(); info_it != info_end;
- ++info_it)
+ ++info_it)
addSymbolToOutput(*info_it.getEntry(), pModule);
}
-
/// addStandardSymbols - shared object and executable files need some
/// standard symbols
/// @return if there are some input symbols with the same name to the
/// standard symbols, return false
-bool ObjectLinker::addStandardSymbols()
-{
+bool ObjectLinker::addStandardSymbols() {
// create and add section symbols for each output section
Module::iterator iter, iterEnd = m_pModule->end();
for (iter = m_pModule->begin(); iter != iterEnd; ++iter) {
@@ -470,25 +503,23 @@ bool ObjectLinker::addStandardSymbols()
/// target-dependent symbols
/// @return if there are some input symbols with the same name to the
/// target symbols, return false
-bool ObjectLinker::addTargetSymbols()
-{
+bool ObjectLinker::addTargetSymbols() {
m_LDBackend.initTargetSymbols(*m_pBuilder, *m_pModule);
return true;
}
/// addScriptSymbols - define symbols from the command line option or linker
/// scripts.
-bool ObjectLinker::addScriptSymbols()
-{
+bool ObjectLinker::addScriptSymbols() {
LinkerScript& script = m_pModule->getScript();
LinkerScript::Assignments::iterator it, ie = script.assignments().end();
// go through the entire symbol assignments
for (it = script.assignments().begin(); it != ie; ++it) {
LDSymbol* symbol = NULL;
assert((*it).second.symbol().type() == Operand::SYMBOL);
- const llvm::StringRef symName = (*it).second.symbol().name();
- ResolveInfo::Type type = ResolveInfo::NoType;
- ResolveInfo::Visibility vis = ResolveInfo::Default;
+ const llvm::StringRef symName = (*it).second.symbol().name();
+ ResolveInfo::Type type = ResolveInfo::NoType;
+ ResolveInfo::Visibility vis = ResolveInfo::Default;
size_t size = 0;
ResolveInfo* old_info = m_pModule->getNamePool().findInfo(symName);
// if the symbol does not exist, we can set type to NOTYPE
@@ -504,36 +535,35 @@ bool ObjectLinker::addScriptSymbols()
// FIXME: bfd linker would change the binding instead, but currently
// ABS is also a kind of Binding in ResolveInfo.
switch ((*it).second.type()) {
- case Assignment::HIDDEN:
- vis = ResolveInfo::Hidden;
+ case Assignment::HIDDEN:
+ vis = ResolveInfo::Hidden;
// Fall through
- case Assignment::DEFAULT:
- symbol =
- m_pBuilder->AddSymbol<IRBuilder::Force,
- IRBuilder::Unresolve>(symName,
- type,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- size,
- 0x0,
- FragmentRef::Null(),
- vis);
- break;
- case Assignment::PROVIDE_HIDDEN:
- vis = ResolveInfo::Hidden;
+ case Assignment::DEFAULT:
+ symbol = m_pBuilder->AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
+ symName,
+ type,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ size,
+ 0x0,
+ FragmentRef::Null(),
+ vis);
+ break;
+ case Assignment::PROVIDE_HIDDEN:
+ vis = ResolveInfo::Hidden;
// Fall through
- case Assignment::PROVIDE:
- symbol =
- m_pBuilder->AddSymbol<IRBuilder::AsReferred,
- IRBuilder::Unresolve>(symName,
- type,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- size,
- 0x0,
- FragmentRef::Null(),
- vis);
- break;
+ case Assignment::PROVIDE:
+ symbol =
+ m_pBuilder->AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>(
+ symName,
+ type,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ size,
+ 0x0,
+ FragmentRef::Null(),
+ vis);
+ break;
}
// Set symbol of this assignment.
(*it).first = symbol;
@@ -541,8 +571,7 @@ bool ObjectLinker::addScriptSymbols()
return true;
}
-bool ObjectLinker::scanRelocations()
-{
+bool ObjectLinker::scanRelocations() {
// apply all relocations of all inputs
Module::obj_iterator input, inEnd = m_pModule->obj_end();
for (input = m_pModule->obj_begin(); input != inEnd; ++input) {
@@ -565,25 +594,25 @@ bool ObjectLinker::scanRelocations()
if (!info->outSymbol()->hasFragRef() &&
ResolveInfo::Section == info->type() &&
ResolveInfo::Undefined == info->desc())
- continue;
+ continue;
// scan relocation
- if (LinkerConfig::Object != m_Config.codeGenType())
+ if (LinkerConfig::Object != m_Config.codeGenType()) {
m_LDBackend.getRelocator()->scanRelocation(
- *relocation, *m_pBuilder, *m_pModule, **rs, **input);
- else
+ *relocation, *m_pBuilder, *m_pModule, **rs, **input);
+ } else {
m_LDBackend.getRelocator()->partialScanRelocation(
- *relocation, *m_pModule, **rs);
- } // for all relocations
- } // for all relocation section
+ *relocation, *m_pModule);
+ }
+ } // for all relocations
+ } // for all relocation section
m_LDBackend.getRelocator()->finalizeScan(**input);
- } // for all inputs
+ } // for all inputs
return true;
}
/// initStubs - initialize stub-related stuff.
-bool ObjectLinker::initStubs()
-{
+bool ObjectLinker::initStubs() {
// initialize BranchIslandFactory
m_LDBackend.initBRIslandFactory();
@@ -597,8 +626,7 @@ bool ObjectLinker::initStubs()
/// allocateCommonSymobols - allocate fragments for common symbols to the
/// corresponding sections
-bool ObjectLinker::allocateCommonSymbols()
-{
+bool ObjectLinker::allocateCommonSymbols() {
if (LinkerConfig::Object != m_Config.codeGenType() ||
m_Config.options().isDefineCommon())
return m_LDBackend.allocateCommonSymbols(*m_pModule);
@@ -606,13 +634,13 @@ bool ObjectLinker::allocateCommonSymbols()
}
/// prelayout - help backend to do some modification before layout
-bool ObjectLinker::prelayout()
-{
+bool ObjectLinker::prelayout() {
// finalize the section symbols, set their fragment reference and push them
// into output symbol table
Module::iterator sect, sEnd = m_pModule->end();
for (sect = m_pModule->begin(); sect != sEnd; ++sect) {
- m_pModule->getSectionSymbolSet().finalize(**sect,
+ m_pModule->getSectionSymbolSet().finalize(
+ **sect,
m_pModule->getSymbolTable(),
m_Config.codeGenType() == LinkerConfig::Object);
}
@@ -622,15 +650,15 @@ bool ObjectLinker::prelayout()
/// check program interpreter - computer the name size of the runtime dyld
if (!m_Config.isCodeStatic() &&
(LinkerConfig::Exec == m_Config.codeGenType() ||
- m_Config.options().isPIE() ||
- m_Config.options().hasDyld()))
+ m_Config.options().isPIE() || m_Config.options().hasDyld()))
m_LDBackend.sizeInterp();
/// measure NamePools - compute the size of name pool sections
/// In ELF, will compute the size of.symtab, .strtab, .dynsym, .dynstr,
/// .hash and .shstrtab sections.
///
- /// dump all symbols and strings from ObjectLinker and build the format-dependent
+ /// dump all symbols and strings from ObjectLinker and build the
+ /// format-dependent
/// hash table.
/// @note sizeNamePools replies on LinkerConfig::CodePosition. Must determine
/// code position model before calling GNULDBackend::sizeNamePools()
@@ -642,6 +670,16 @@ bool ObjectLinker::prelayout()
eh_frame_sect->getEhFrame()->computeOffsetSize();
m_LDBackend.createAndSizeEhFrameHdr(*m_pModule);
+ // size debug string table and set up the debug string offset
+ // we set the .debug_str size here so that there won't be a section symbol for
+ // .debug_str. While actually it doesn't matter that .debug_str has section
+ // symbol or not.
+ // FIXME: disable debug string merge when doing partial link.
+ if (LinkerConfig::Object != m_Config.codeGenType()) {
+ LDSection* debug_str_sect = m_pModule->getSection(".debug_str");
+ if (debug_str_sect && debug_str_sect->hasDebugString())
+ debug_str_sect->getDebugString()->computeOffsetSize();
+ }
return true;
}
@@ -650,27 +688,24 @@ bool ObjectLinker::prelayout()
/// Because we do not support instruction relaxing in this early version,
/// if there is a branch can not jump to its target, we return false
/// directly
-bool ObjectLinker::layout()
-{
+bool ObjectLinker::layout() {
m_LDBackend.layout(*m_pModule);
return true;
}
/// prelayout - help backend to do some modification after layout
-bool ObjectLinker::postlayout()
-{
+bool ObjectLinker::postlayout() {
m_LDBackend.postLayout(*m_pModule, *m_pBuilder);
return true;
}
/// finalizeSymbolValue - finalize the resolved symbol value.
-/// Before relocate(), after layout(), ObjectLinker should correct value of all
+/// Before relocate(), after layout(), ObjectLinker should correct value of
+/// all
/// symbol.
-bool ObjectLinker::finalizeSymbolValue()
-{
+bool ObjectLinker::finalizeSymbolValue() {
Module::sym_iterator symbol, symEnd = m_pModule->sym_end();
for (symbol = m_pModule->sym_begin(); symbol != symEnd; ++symbol) {
-
if ((*symbol)->resolveInfo()->isAbsolute() ||
(*symbol)->resolveInfo()->type() == ResolveInfo::File) {
// absolute symbols should just use its value directly (i.e., the result
@@ -688,9 +723,9 @@ bool ObjectLinker::finalizeSymbolValue()
// relocatable object file, the section's virtual address becomes zero.
// And the symbol's value become section relative offset.
uint64_t value = (*symbol)->fragRef()->getOutputOffset();
- assert(NULL != (*symbol)->fragRef()->frag());
+ assert((*symbol)->fragRef()->frag() != NULL);
uint64_t addr =
- (*symbol)->fragRef()->frag()->getParent()->getSection().addr();
+ (*symbol)->fragRef()->frag()->getParent()->getSection().addr();
(*symbol)->setValue(value + addr);
continue;
}
@@ -714,7 +749,7 @@ bool ObjectLinker::finalizeSymbolValue()
break;
symbol->setValue(assignment.symbol().value());
- } // for each script symbol assignment
+ } // for each script symbol assignment
bool assertionsPassed = true;
LinkerScript::Assertions::iterator assert, assertEnd;
@@ -724,7 +759,7 @@ bool ObjectLinker::finalizeSymbolValue()
evaluator.eval((*assert).getRpnExpr(), res);
if (res == 0x0)
fatal(diag::err_assert_failed) << (*assert).message();
- } // for each assertion in ldscript
+ } // for each assertion in ldscript
return finalized && scriptSymsFinalized && assertionsPassed;
}
@@ -734,12 +769,13 @@ bool ObjectLinker::finalizeSymbolValue()
/// Create relocation section, asking TargetLDBackend to
/// read the relocation information into RelocationEntry
/// and push_back into the relocation section
-bool ObjectLinker::relocation()
-{
+bool ObjectLinker::relocation() {
// when producing relocatables, no need to apply relocation
if (LinkerConfig::Object == m_Config.codeGenType())
return true;
+ LDSection* debug_str_sect = m_pModule->getSection(".debug_str");
+
// apply all relocations of all inputs
Module::obj_iterator input, inEnd = m_pModule->obj_end();
for (input = m_pModule->obj_begin(); input != inEnd; ++input) {
@@ -764,11 +800,24 @@ bool ObjectLinker::relocation()
ResolveInfo::Undefined == info->desc())
continue;
+ // apply the relocation aginst symbol on DebugString
+ if (info->outSymbol()->hasFragRef() &&
+ info->outSymbol()->fragRef()->frag()->getKind()
+ == Fragment::Region &&
+ info->outSymbol()->fragRef()->frag()->getParent()->getSection()
+ .kind() == LDFileFormat::DebugString) {
+ assert(debug_str_sect != NULL);
+ assert(debug_str_sect->hasDebugString());
+ debug_str_sect->getDebugString()->applyOffset(*relocation,
+ m_LDBackend);
+ continue;
+ }
+
relocation->apply(*m_LDBackend.getRelocator());
- } // for all relocations
- } // for all relocation section
+ } // for all relocations
+ } // for all relocation section
m_LDBackend.getRelocator()->finalizeApply(**input);
- } // for all inputs
+ } // for all inputs
// apply relocations created by relaxation
BranchIslandFactory* br_factory = m_LDBackend.getBRIslandFactory();
@@ -779,19 +828,17 @@ bool ObjectLinker::relocation()
for (iter = island.reloc_begin(); iter != iterEnd; ++iter)
(*iter)->apply(*m_LDBackend.getRelocator());
}
+
return true;
}
/// emitOutput - emit the output file.
-bool ObjectLinker::emitOutput(FileOutputBuffer& pOutput)
-{
+bool ObjectLinker::emitOutput(FileOutputBuffer& pOutput) {
return std::error_code() == getWriter()->writeObject(*m_pModule, pOutput);
}
-
/// postProcessing - do modification after all processes
-bool ObjectLinker::postProcessing(FileOutputBuffer& pOutput)
-{
+bool ObjectLinker::postProcessing(FileOutputBuffer& pOutput) {
if (LinkerConfig::Object != m_Config.codeGenType())
normalSyncRelocationResult(pOutput);
else
@@ -804,8 +851,7 @@ bool ObjectLinker::postProcessing(FileOutputBuffer& pOutput)
return true;
}
-void ObjectLinker::normalSyncRelocationResult(FileOutputBuffer& pOutput)
-{
+void ObjectLinker::normalSyncRelocationResult(FileOutputBuffer& pOutput) {
uint8_t* data = pOutput.getBufferStart();
// sync all relocations of all inputs
@@ -837,12 +883,12 @@ void ObjectLinker::normalSyncRelocationResult(FileOutputBuffer& pOutput)
// we want is the value of the other relocation result. For example,
// in .exidx, there are usually an R_ARM_NONE and R_ARM_PREL31 apply to
// the same place
- if (0x0 == relocation->type())
+ if (relocation->type() == 0x0)
continue;
writeRelocationResult(*relocation, data);
- } // for all relocations
- } // for all relocation section
- } // for all inputs
+ } // for all relocations
+ } // for all relocation section
+ } // for all inputs
// sync relocations created by relaxation
BranchIslandFactory* br_factory = m_LDBackend.getBRIslandFactory();
@@ -857,8 +903,7 @@ void ObjectLinker::normalSyncRelocationResult(FileOutputBuffer& pOutput)
}
}
-void ObjectLinker::partialSyncRelocationResult(FileOutputBuffer& pOutput)
-{
+void ObjectLinker::partialSyncRelocationResult(FileOutputBuffer& pOutput) {
uint8_t* data = pOutput.getBufferStart();
// traverse outputs' LDSection to get RelocData
@@ -878,51 +923,52 @@ void ObjectLinker::partialSyncRelocationResult(FileOutputBuffer& pOutput)
// we want is the value of the other relocation result. For example,
// in .exidx, there are usually an R_ARM_NONE and R_ARM_PREL31 apply to
// the same place
- if (0x0 == reloc->type())
+ if (reloc->type() == 0x0)
continue;
writeRelocationResult(*reloc, data);
}
}
}
-void ObjectLinker::writeRelocationResult(Relocation& pReloc, uint8_t* pOutput)
-{
+void ObjectLinker::writeRelocationResult(Relocation& pReloc, uint8_t* pOutput) {
// get output file offset
size_t out_offset =
- pReloc.targetRef().frag()->getParent()->getSection().offset() +
- pReloc.targetRef().getOutputOffset();
+ pReloc.targetRef().frag()->getParent()->getSection().offset() +
+ pReloc.targetRef().getOutputOffset();
uint8_t* target_addr = pOutput + out_offset;
// byte swapping if target and host has different endian, and then write back
- if(llvm::sys::IsLittleEndianHost != m_Config.targets().isLittleEndian()) {
- uint64_t tmp_data = 0;
-
- switch(pReloc.size(*m_LDBackend.getRelocator())) {
- case 8u:
- std::memcpy(target_addr, &pReloc.target(), 1);
- break;
-
- case 16u:
- tmp_data = mcld::bswap16(pReloc.target());
- std::memcpy(target_addr, &tmp_data, 2);
- break;
-
- case 32u:
- tmp_data = mcld::bswap32(pReloc.target());
- std::memcpy(target_addr, &tmp_data, 4);
- break;
-
- case 64u:
- tmp_data = mcld::bswap64(pReloc.target());
- std::memcpy(target_addr, &tmp_data, 8);
- break;
-
- default:
- break;
+ if (llvm::sys::IsLittleEndianHost != m_Config.targets().isLittleEndian()) {
+ uint64_t tmp_data = 0;
+
+ switch (pReloc.size(*m_LDBackend.getRelocator())) {
+ case 8u:
+ std::memcpy(target_addr, &pReloc.target(), 1);
+ break;
+
+ case 16u:
+ tmp_data = mcld::bswap16(pReloc.target());
+ std::memcpy(target_addr, &tmp_data, 2);
+ break;
+
+ case 32u:
+ tmp_data = mcld::bswap32(pReloc.target());
+ std::memcpy(target_addr, &tmp_data, 4);
+ break;
+
+ case 64u:
+ tmp_data = mcld::bswap64(pReloc.target());
+ std::memcpy(target_addr, &tmp_data, 8);
+ break;
+
+ default:
+ break;
}
+ } else {
+ std::memcpy(target_addr,
+ &pReloc.target(),
+ pReloc.size(*m_LDBackend.getRelocator()) / 8);
}
- else
- std::memcpy(target_addr, &pReloc.target(),
- pReloc.size(*m_LDBackend.getRelocator())/8);
}
+} // namespace mcld
diff --git a/lib/Object/SectionMap.cpp b/lib/Object/SectionMap.cpp
index 4453d42..615c493 100644
--- a/lib/Object/SectionMap.cpp
+++ b/lib/Object/SectionMap.cpp
@@ -6,44 +6,47 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Object/SectionMap.h>
-#include <mcld/Script/Assignment.h>
-#include <mcld/Script/WildcardPattern.h>
-#include <mcld/Script/StringList.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/Operator.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Fragment/NullFragment.h>
+#include "mcld/Object/SectionMap.h"
+
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Script/Assignment.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/Operator.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Script/StringList.h"
+#include "mcld/Script/WildcardPattern.h"
+
#include <llvm/Support/Casting.h>
+
#include <cassert>
#include <cstring>
#include <climits>
#if !defined(MCLD_ON_WIN32)
#include <fnmatch.h>
-#define fnmatch0(pattern,string) (fnmatch(pattern,string,0) == 0)
+#define fnmatch0(pattern, string) (fnmatch(pattern, string, 0) == 0)
#else
#include <windows.h>
#include <shlwapi.h>
-#define fnmatch0(pattern,string) (PathMatchSpec(string, pattern) == true)
+#define fnmatch0(pattern, string) (PathMatchSpec(string, pattern) == true)
#endif
-using namespace mcld;
+namespace mcld {
+
//===----------------------------------------------------------------------===//
// SectionMap::Input
//===----------------------------------------------------------------------===//
SectionMap::Input::Input(const std::string& pName,
InputSectDesc::KeepPolicy pPolicy)
- : m_Policy(pPolicy)
-{
+ : m_Policy(pPolicy) {
m_Spec.m_pWildcardFile =
- WildcardPattern::create("*", WildcardPattern::SORT_NONE);
+ WildcardPattern::create("*", WildcardPattern::SORT_NONE);
m_Spec.m_pExcludeFiles = NULL;
StringList* sections = StringList::create();
sections->push_back(
- WildcardPattern::create(pName, WildcardPattern::SORT_NONE));
+ WildcardPattern::create(pName, WildcardPattern::SORT_NONE));
m_Spec.m_pWildcardSections = sections;
m_pSection = LDSection::Create(pName, LDFileFormat::TEXT, 0, 0);
@@ -54,8 +57,7 @@ SectionMap::Input::Input(const std::string& pName,
}
SectionMap::Input::Input(const InputSectDesc& pInputDesc)
- : m_Policy(pInputDesc.policy())
-{
+ : m_Policy(pInputDesc.policy()) {
m_Spec.m_pWildcardFile = pInputDesc.spec().m_pWildcardFile;
m_Spec.m_pExcludeFiles = pInputDesc.spec().m_pExcludeFiles;
m_Spec.m_pWildcardSections = pInputDesc.spec().m_pWildcardSections;
@@ -70,9 +72,7 @@ SectionMap::Input::Input(const InputSectDesc& pInputDesc)
// SectionMap::Output
//===----------------------------------------------------------------------===//
SectionMap::Output::Output(const std::string& pName)
- : m_Name(pName),
- m_Order(UINT_MAX)
-{
+ : m_Name(pName), m_Order(UINT_MAX) {
m_Prolog.m_pVMA = NULL;
m_Prolog.m_Type = OutputSectDesc::LOAD;
m_Prolog.m_pLMA = NULL;
@@ -93,11 +93,10 @@ SectionMap::Output::Output(const std::string& pName)
}
SectionMap::Output::Output(const OutputSectDesc& pOutputDesc)
- : m_Name(pOutputDesc.name()),
- m_Prolog(pOutputDesc.prolog()),
- m_Epilog(pOutputDesc.epilog()),
- m_Order(UINT_MAX)
-{
+ : m_Name(pOutputDesc.name()),
+ m_Prolog(pOutputDesc.prolog()),
+ m_Epilog(pOutputDesc.epilog()),
+ m_Order(UINT_MAX) {
m_pSection = LDSection::Create(m_Name, LDFileFormat::TEXT, 0, 0);
SectionData* sd = SectionData::Create(*m_pSection);
m_pSection->setSectionData(sd);
@@ -105,14 +104,12 @@ SectionMap::Output::Output(const OutputSectDesc& pOutputDesc)
m_bIsDiscard = m_Name.compare("/DISCARD/") == 0;
}
-bool SectionMap::Output::hasContent() const
-{
+bool SectionMap::Output::hasContent() const {
return m_pSection != NULL && m_pSection->size() != 0;
}
SectionMap::Output::const_dot_iterator
-SectionMap::Output::find_first_explicit_dot() const
-{
+SectionMap::Output::find_first_explicit_dot() const {
for (const_dot_iterator it = dot_begin(), ie = dot_end(); it != ie; ++it) {
if ((*it).type() == Assignment::DEFAULT)
return it;
@@ -120,8 +117,7 @@ SectionMap::Output::find_first_explicit_dot() const
return dot_end();
}
-SectionMap::Output::dot_iterator SectionMap::Output::find_first_explicit_dot()
-{
+SectionMap::Output::dot_iterator SectionMap::Output::find_first_explicit_dot() {
for (dot_iterator it = dot_begin(), ie = dot_end(); it != ie; ++it) {
if ((*it).type() == Assignment::DEFAULT)
return it;
@@ -130,11 +126,11 @@ SectionMap::Output::dot_iterator SectionMap::Output::find_first_explicit_dot()
}
SectionMap::Output::const_dot_iterator
-SectionMap::Output::find_last_explicit_dot() const
-{
+SectionMap::Output::find_last_explicit_dot() const {
typedef DotAssignments::const_reverse_iterator CONST_RIT;
for (CONST_RIT rit = dotAssignments().rbegin(), rie = dotAssignments().rend();
- rit != rie; ++rit) {
+ rit != rie;
+ ++rit) {
if ((*rit).type() == Assignment::DEFAULT) {
return dot_begin() +
(dotAssignments().size() - (rit - dotAssignments().rbegin()) - 1);
@@ -143,11 +139,11 @@ SectionMap::Output::find_last_explicit_dot() const
return dot_end();
}
-SectionMap::Output::dot_iterator SectionMap::Output::find_last_explicit_dot()
-{
+SectionMap::Output::dot_iterator SectionMap::Output::find_last_explicit_dot() {
typedef DotAssignments::reverse_iterator RIT;
for (RIT rit = dotAssignments().rbegin(), rie = dotAssignments().rend();
- rit != rie; ++rit) {
+ rit != rie;
+ ++rit) {
if ((*rit).type() == Assignment::DEFAULT) {
return dot_begin() +
(dotAssignments().size() - (rit - dotAssignments().rbegin()) - 1);
@@ -159,8 +155,7 @@ SectionMap::Output::dot_iterator SectionMap::Output::find_last_explicit_dot()
//===----------------------------------------------------------------------===//
// SectionMap
//===----------------------------------------------------------------------===//
-SectionMap::~SectionMap()
-{
+SectionMap::~SectionMap() {
iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
if (*out != NULL) {
@@ -174,10 +169,9 @@ SectionMap::~SectionMap()
}
}
-SectionMap::const_mapping
-SectionMap::find(const std::string& pInputFile,
- const std::string& pInputSection) const
-{
+SectionMap::const_mapping SectionMap::find(
+ const std::string& pInputFile,
+ const std::string& pInputSection) const {
const_iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
Output::const_iterator in, inBegin = (*out)->begin(), inEnd = (*out)->end();
@@ -190,8 +184,7 @@ SectionMap::find(const std::string& pInputFile,
}
SectionMap::mapping SectionMap::find(const std::string& pInputFile,
- const std::string& pInputSection)
-{
+ const std::string& pInputSection) {
iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
Output::iterator in, inBegin = (*out)->begin(), inEnd = (*out)->end();
@@ -200,12 +193,12 @@ SectionMap::mapping SectionMap::find(const std::string& pInputFile,
return std::make_pair(*out, *in);
}
}
- return std::make_pair((Output*)NULL, (Input*)NULL);
+ return std::make_pair(reinterpret_cast<Output*>(NULL),
+ reinterpret_cast<Input*>(NULL));
}
-SectionMap::const_iterator
-SectionMap::find(const std::string& pOutputSection) const
-{
+SectionMap::const_iterator SectionMap::find(
+ const std::string& pOutputSection) const {
const_iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
if ((*out)->name().compare(pOutputSection) == 0)
@@ -214,9 +207,7 @@ SectionMap::find(const std::string& pOutputSection) const
return outEnd;
}
-SectionMap::iterator
-SectionMap::find(const std::string& pOutputSection)
-{
+SectionMap::iterator SectionMap::find(const std::string& pOutputSection) {
iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
if ((*out)->name().compare(pOutputSection) == 0)
@@ -225,11 +216,10 @@ SectionMap::find(const std::string& pOutputSection)
return outEnd;
}
-std::pair<SectionMap::mapping, bool>
-SectionMap::insert(const std::string& pInputSection,
- const std::string& pOutputSection,
- InputSectDesc::KeepPolicy pPolicy)
-{
+std::pair<SectionMap::mapping, bool> SectionMap::insert(
+ const std::string& pInputSection,
+ const std::string& pOutputSection,
+ InputSectDesc::KeepPolicy pPolicy) {
iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
if ((*out)->name().compare(pOutputSection) == 0)
@@ -259,10 +249,9 @@ SectionMap::insert(const std::string& pInputSection,
return std::make_pair(std::make_pair(output, input), true);
}
-std::pair<SectionMap::mapping, bool>
-SectionMap::insert(const InputSectDesc& pInputDesc,
- const OutputSectDesc& pOutputDesc)
-{
+std::pair<SectionMap::mapping, bool> SectionMap::insert(
+ const InputSectDesc& pInputDesc,
+ const OutputSectDesc& pOutputDesc) {
iterator out, outBegin = begin(), outEnd = end();
for (out = outBegin; out != outEnd; ++out) {
if ((*out)->name().compare(pOutputDesc.name()) == 0 &&
@@ -296,9 +285,8 @@ SectionMap::insert(const InputSectDesc& pInputDesc,
return std::make_pair(std::make_pair(output, input), true);
}
-SectionMap::iterator
-SectionMap::insert(iterator pPosition, LDSection* pSection)
-{
+SectionMap::iterator SectionMap::insert(iterator pPosition,
+ LDSection* pSection) {
Output* output = new Output(pSection->name());
output->append(new Input(pSection->name(), InputSectDesc::NoKeep));
output->setSection(pSection);
@@ -307,10 +295,9 @@ SectionMap::insert(iterator pPosition, LDSection* pSection)
bool SectionMap::matched(const SectionMap::Input& pInput,
const std::string& pInputFile,
- const std::string& pInputSection) const
-{
+ const std::string& pInputSection) const {
if (pInput.spec().hasFile() && !matched(pInput.spec().file(), pInputFile))
- return false;
+ return false;
if (pInput.spec().hasExcludeFiles()) {
StringList::const_iterator file, fileEnd;
@@ -335,8 +322,7 @@ bool SectionMap::matched(const SectionMap::Input& pInput,
}
bool SectionMap::matched(const WildcardPattern& pPattern,
- const std::string& pName) const
-{
+ const std::string& pName) const {
if (pPattern.isPrefix()) {
llvm::StringRef name(pName);
return name.startswith(pPattern.prefix());
@@ -346,14 +332,12 @@ bool SectionMap::matched(const WildcardPattern& pPattern,
}
// fixupDotSymbols - ensure the dot symbols are valid
-void SectionMap::fixupDotSymbols()
-{
+void SectionMap::fixupDotSymbols() {
for (iterator it = begin() + 1, ie = end(); it != ie; ++it) {
// fixup the 1st explicit dot assignment if needed
if (!(*it)->dotAssignments().empty()) {
Output::dot_iterator dot = (*it)->find_first_explicit_dot();
- if (dot != (*it)->dot_end() &&
- (*dot).symbol().isDot() &&
+ if (dot != (*it)->dot_end() && (*dot).symbol().isDot() &&
(*dot).getRpnExpr().hasDot()) {
Assignment assign(Assignment::OUTPUT_SECTION,
Assignment::DEFAULT,
@@ -361,11 +345,13 @@ void SectionMap::fixupDotSymbols()
*RpnExpr::buildHelperExpr(it - 1));
Output::dot_iterator ref = (*it)->dotAssignments().insert(dot, assign);
for (RpnExpr::iterator tok = (*dot).getRpnExpr().begin(),
- tokEnd = (*dot).getRpnExpr().end(); tok != tokEnd; ++tok) {
+ tokEnd = (*dot).getRpnExpr().end();
+ tok != tokEnd;
+ ++tok) {
if ((*tok)->kind() == ExprToken::OPERAND &&
llvm::cast<Operand>(*tok)->isDot())
*tok = &((*ref).symbol());
- } // for each token in the RHS expr of the dot assignment
+ } // for each token in the RHS expr of the dot assignment
}
}
@@ -380,12 +366,15 @@ void SectionMap::fixupDotSymbols()
dot = (*it)->dotAssignments().insert(dot, assign);
}
for (RpnExpr::iterator tok = (*it)->prolog().vma().begin(),
- tokEnd = (*it)->prolog().vma().end(); tok != tokEnd; ++tok) {
+ tokEnd = (*it)->prolog().vma().end();
+ tok != tokEnd;
+ ++tok) {
if ((*tok)->kind() == ExprToken::OPERAND &&
llvm::cast<Operand>(*tok)->isDot())
*tok = &((*dot).symbol());
- } // for each token in the RHS expr of the dot assignment
+ } // for each token in the RHS expr of the dot assignment
}
-
- } // for each output section
+ } // for each output section
}
+
+} // namespace mcld
diff --git a/lib/Script/AssertCmd.cpp b/lib/Script/AssertCmd.cpp
index 618731d..8430534 100644
--- a/lib/Script/AssertCmd.cpp
+++ b/lib/Script/AssertCmd.cpp
@@ -6,35 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/AssertCmd.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/Module.h>
-#include <mcld/LinkerScript.h>
+#include "mcld/Script/AssertCmd.h"
-using namespace mcld;
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Support/raw_ostream.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// AssertCmd
//===----------------------------------------------------------------------===//
AssertCmd::AssertCmd(RpnExpr& pRpnExpr, const std::string& pMessage)
- : ScriptCommand(ScriptCommand::ASSERT),
- m_RpnExpr(pRpnExpr),
- m_Message(pMessage)
-{
+ : ScriptCommand(ScriptCommand::ASSERT),
+ m_RpnExpr(pRpnExpr),
+ m_Message(pMessage) {
}
-AssertCmd::~AssertCmd()
-{
+AssertCmd::~AssertCmd() {
}
-AssertCmd& AssertCmd::operator=(const AssertCmd& pAssertCmd)
-{
+AssertCmd& AssertCmd::operator=(const AssertCmd& pAssertCmd) {
return *this;
}
-void AssertCmd::dump() const
-{
+void AssertCmd::dump() const {
mcld::outs() << "Assert ( ";
m_RpnExpr.dump();
@@ -42,7 +39,8 @@ void AssertCmd::dump() const
mcld::outs() << " , " << m_Message << " )\n";
}
-void AssertCmd::activate(Module& pModule)
-{
+void AssertCmd::activate(Module& pModule) {
pModule.getScript().assertions().push_back(*this);
}
+
+} // namespace mcld
diff --git a/lib/Script/Assignment.cpp b/lib/Script/Assignment.cpp
index a7e0f46..333b366 100644
--- a/lib/Script/Assignment.cpp
+++ b/lib/Script/Assignment.cpp
@@ -6,20 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/Assignment.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/Operator.h>
-#include <mcld/Script/RpnEvaluator.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Module.h>
+#include "mcld/Script/Assignment.h"
+
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/Operator.h"
+#include "mcld/Script/RpnEvaluator.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Support/raw_ostream.h"
+
#include <llvm/Support/Casting.h>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Assignment
@@ -28,39 +31,35 @@ Assignment::Assignment(Level pLevel,
Type pType,
SymOperand& pSymbol,
RpnExpr& pRpnExpr)
- : ScriptCommand(ScriptCommand::ASSIGNMENT),
- m_Level(pLevel),
- m_Type(pType),
- m_Symbol(pSymbol),
- m_RpnExpr(pRpnExpr)
-{
+ : ScriptCommand(ScriptCommand::ASSIGNMENT),
+ m_Level(pLevel),
+ m_Type(pType),
+ m_Symbol(pSymbol),
+ m_RpnExpr(pRpnExpr) {
}
-Assignment::~Assignment()
-{
+Assignment::~Assignment() {
}
-Assignment& Assignment::operator=(const Assignment& pAssignment)
-{
+Assignment& Assignment::operator=(const Assignment& pAssignment) {
return *this;
}
-void Assignment::dump() const
-{
+void Assignment::dump() const {
switch (type()) {
- case DEFAULT:
- break;
- case HIDDEN:
- mcld::outs() << "HIDDEN ( ";
- break;
- case PROVIDE:
- mcld::outs() << "PROVIDE ( ";
- break;
- case PROVIDE_HIDDEN:
- mcld::outs() << "PROVIDE_HIDDEN ( ";
- break;
- default:
- break;
+ case DEFAULT:
+ break;
+ case HIDDEN:
+ mcld::outs() << "HIDDEN ( ";
+ break;
+ case PROVIDE:
+ mcld::outs() << "PROVIDE ( ";
+ break;
+ case PROVIDE_HIDDEN:
+ mcld::outs() << "PROVIDE_HIDDEN ( ";
+ break;
+ default:
+ break;
}
m_Symbol.dump();
@@ -75,101 +74,104 @@ void Assignment::dump() const
mcld::outs() << ";\n";
}
-void Assignment::activate(Module& pModule)
-{
+void Assignment::activate(Module& pModule) {
bool isLhsDot = m_Symbol.isDot();
LinkerScript& script = pModule.getScript();
switch (m_Level) {
- case OUTSIDE_SECTIONS:
- assert(!isLhsDot);
- script.assignments().push_back(std::make_pair((LDSymbol*)NULL, *this));
- break;
-
- case OUTPUT_SECTION: {
- bool hasDotInRhs = m_RpnExpr.hasDot();
- SectionMap::reference out = script.sectionMap().back();
- if (hasDotInRhs) {
- if (!isLhsDot && out->dotAssignments().empty()) {
- // . = ADDR ( `prev_output_sect' ) + SIZEOF ( `prev_output_sect' )
- SectionMap::iterator prev = script.sectionMap().begin() +
- script.sectionMap().size() - 2;
- Assignment assign(OUTPUT_SECTION,
- HIDDEN,
- *SymOperand::create("."),
- *RpnExpr::buildHelperExpr(prev));
- out->dotAssignments().push_back(assign);
- }
+ case OUTSIDE_SECTIONS:
+ assert(!isLhsDot);
+ script.assignments().push_back(
+ std::make_pair(reinterpret_cast<LDSymbol*>(NULL), *this));
+ break;
+
+ case OUTPUT_SECTION: {
+ bool hasDotInRhs = m_RpnExpr.hasDot();
+ SectionMap::reference out = script.sectionMap().back();
+ if (hasDotInRhs) {
+ if (!isLhsDot && out->dotAssignments().empty()) {
+ // . = ADDR ( `prev_output_sect' ) + SIZEOF ( `prev_output_sect' )
+ SectionMap::iterator prev =
+ script.sectionMap().begin() + script.sectionMap().size() - 2;
+ Assignment assign(OUTPUT_SECTION,
+ HIDDEN,
+ *SymOperand::create("."),
+ *RpnExpr::buildHelperExpr(prev));
+ out->dotAssignments().push_back(assign);
+ }
- if (!out->dotAssignments().empty()) {
- Assignment& prevDotAssign = out->dotAssignments().back();
- // If this is the 1st explicit assignment that includes both lhs dot and
- // rhs dot, then because of possible orphan sections, we are unable to
- // substitute the rhs dot now.
- if (!isLhsDot || prevDotAssign.type() == DEFAULT) {
- for (RpnExpr::iterator it = m_RpnExpr.begin(), ie = m_RpnExpr.end();
- it != ie; ++it) {
- // substitute the rhs dot with the appropriate helper expr
- if ((*it)->kind() == ExprToken::OPERAND &&
- llvm::cast<Operand>(*it)->isDot())
- *it = &(prevDotAssign.symbol());
- } // for each expression token
+ if (!out->dotAssignments().empty()) {
+ Assignment& prevDotAssign = out->dotAssignments().back();
+ // If this is the 1st explicit assignment that includes both lhs dot
+ // and
+ // rhs dot, then because of possible orphan sections, we are unable to
+ // substitute the rhs dot now.
+ if (!isLhsDot || prevDotAssign.type() == DEFAULT) {
+ for (RpnExpr::iterator it = m_RpnExpr.begin(), ie = m_RpnExpr.end();
+ it != ie;
+ ++it) {
+ // substitute the rhs dot with the appropriate helper expr
+ if ((*it)->kind() == ExprToken::OPERAND &&
+ llvm::cast<Operand>(*it)->isDot()) {
+ *it = &(prevDotAssign.symbol());
+ }
+ } // for each expression token
+ }
}
}
- }
- if (isLhsDot) {
- out->dotAssignments().push_back(*this);
- } else {
- script.assignments().push_back(std::make_pair((LDSymbol*)NULL, *this));
+ if (isLhsDot) {
+ out->dotAssignments().push_back(*this);
+ } else {
+ script.assignments().push_back(
+ std::make_pair(reinterpret_cast<LDSymbol*>(NULL), *this));
+ }
+ break;
}
- break;
- }
+ case INPUT_SECTION: {
+ bool hasDotInRhs = m_RpnExpr.hasDot();
+ SectionMap::Output::reference in = script.sectionMap().back()->back();
+ if (hasDotInRhs) {
+ if (in->dotAssignments().empty()) {
+ // . = `frag'
+ RpnExpr* expr = RpnExpr::buildHelperExpr(
+ in->getSection()->getSectionData()->front());
+ Assignment assign(
+ INPUT_SECTION, HIDDEN, *SymOperand::create("."), *expr);
+ in->dotAssignments().push_back(
+ std::make_pair(reinterpret_cast<Fragment*>(NULL), assign));
+ }
- case INPUT_SECTION: {
- bool hasDotInRhs = m_RpnExpr.hasDot();
- SectionMap::Output::reference in = script.sectionMap().back()->back();
- if (hasDotInRhs) {
- if (in->dotAssignments().empty()) {
- // . = `frag'
- RpnExpr* expr =
- RpnExpr::buildHelperExpr(in->getSection()->getSectionData()->front());
- Assignment assign(INPUT_SECTION,
- HIDDEN,
- *SymOperand::create("."),
- *expr);
- in->dotAssignments().push_back(std::make_pair((Fragment*)NULL, assign));
+ Assignment& prevDotAssign = in->dotAssignments().back().second;
+ for (RpnExpr::iterator it = m_RpnExpr.begin(), ie = m_RpnExpr.end();
+ it != ie;
+ ++it) {
+ // substitute the rhs dot with the appropriate helper expr
+ if ((*it)->kind() == ExprToken::OPERAND &&
+ llvm::cast<Operand>(*it)->isDot()) {
+ *it = &(prevDotAssign.symbol());
+ }
+ } // end of for
}
- Assignment& prevDotAssign = in->dotAssignments().back().second;
- for (RpnExpr::iterator it = m_RpnExpr.begin(), ie = m_RpnExpr.end();
- it != ie; ++it) {
- // substitute the rhs dot with the appropriate helper expr
- if ((*it)->kind() == ExprToken::OPERAND &&
- llvm::cast<Operand>(*it)->isDot())
- *it = &(prevDotAssign.symbol());
- } // end of for
- }
-
- if (isLhsDot) {
- in->dotAssignments().push_back(
- std::make_pair(in->getSection()->getSectionData()->front().getNextNode(),
- *this));
- } else {
- script.assignments().push_back(std::make_pair((LDSymbol*)NULL, *this));
+ if (isLhsDot) {
+ in->dotAssignments().push_back(std::make_pair(
+ in->getSection()->getSectionData()->front().getNextNode(), *this));
+ } else {
+ script.assignments().push_back(
+ std::make_pair(reinterpret_cast<LDSymbol*>(NULL), *this));
+ }
+ break;
}
-
- break;
- }
-
- } // end of switch
+ } // end of switch
}
-bool Assignment::assign(RpnEvaluator& pEvaluator)
-{
+bool Assignment::assign(RpnEvaluator& pEvaluator) {
uint64_t result = 0;
bool success = pEvaluator.eval(m_RpnExpr, result);
if (success)
m_Symbol.setValue(result);
return success;
}
+
+} // namespace mcld
diff --git a/lib/Script/BinaryOp.cpp b/lib/Script/BinaryOp.cpp
index 863eb34..e87c837 100644
--- a/lib/Script/BinaryOp.cpp
+++ b/lib/Script/BinaryOp.cpp
@@ -6,190 +6,175 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/BinaryOp.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/ADT/SizeTraits.h>
-#include <mcld/Module.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Target/TargetLDBackend.h>
+#include "mcld/Script/BinaryOp.h"
+
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Target/TargetLDBackend.h"
+
#include <llvm/Support/Casting.h>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
+
//===----------------------------------------------------------------------===//
// BinaryOp
//===----------------------------------------------------------------------===//
-template<>
+template <>
IntOperand* BinaryOp<Operator::MUL>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() * m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::DIV>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() / m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::MOD>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() % m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::ADD>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() + m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::SUB>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() - m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::LSHIFT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() << m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::RSHIFT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() >> m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::LT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() < m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::LE>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() <= m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::GT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() > m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::GE>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() >= m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::EQ>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() == m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::NE>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() != m_pOperand[1]->value());
return res;
}
-template<>
-IntOperand*
-BinaryOp<Operator::BITWISE_AND>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::BITWISE_AND>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() & m_pOperand[1]->value());
return res;
}
-template<>
-IntOperand*
-BinaryOp<Operator::BITWISE_XOR>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::BITWISE_XOR>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() ^ m_pOperand[1]->value());
return res;
}
-template<>
-IntOperand*
-BinaryOp<Operator::BITWISE_OR>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::BITWISE_OR>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() | m_pOperand[1]->value());
return res;
}
-template<>
-IntOperand*
-BinaryOp<Operator::LOGICAL_AND>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::LOGICAL_AND>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() && m_pOperand[1]->value());
return res;
}
-template<>
-IntOperand*
-BinaryOp<Operator::LOGICAL_OR>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::LOGICAL_OR>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand[0]->value() || m_pOperand[1]->value());
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::ALIGN>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
uint64_t value = m_pOperand[0]->value();
uint64_t align = m_pOperand[1]->value();
@@ -198,11 +183,10 @@ IntOperand* BinaryOp<Operator::ALIGN>::eval(const Module& pModule,
return res;
}
-template<>
-IntOperand*
-BinaryOp<Operator::DATA_SEGMENT_RELRO_END>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::DATA_SEGMENT_RELRO_END>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
/* FIXME: Currently we handle relro in a different way, and now the result
of this expression won't affect DATA_SEGMENT_ALIGN. */
IntOperand* res = result();
@@ -212,10 +196,9 @@ BinaryOp<Operator::DATA_SEGMENT_RELRO_END>::eval(const Module& pModule,
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::MAX>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
if (m_pOperand[0]->value() >= m_pOperand[1]->value())
res->setValue(m_pOperand[0]->value());
@@ -224,10 +207,9 @@ IntOperand* BinaryOp<Operator::MAX>::eval(const Module& pModule,
return res;
}
-template<>
+template <>
IntOperand* BinaryOp<Operator::MIN>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
if (m_pOperand[0]->value() <= m_pOperand[1]->value())
res->setValue(m_pOperand[0]->value());
@@ -236,18 +218,15 @@ IntOperand* BinaryOp<Operator::MIN>::eval(const Module& pModule,
return res;
}
-
/* SEGMENT_START(segment, default) */
-template<>
-IntOperand*
-BinaryOp<Operator::SEGMENT_START>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* BinaryOp<Operator::SEGMENT_START>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
/* Currently we look up segment address from -T command line options. */
SectOperand* sect = llvm::cast<SectOperand>(m_pOperand[0]);
- const LinkerScript::AddressMap& addressMap =
- pModule.getScript().addressMap();
+ const LinkerScript::AddressMap& addressMap = pModule.getScript().addressMap();
LinkerScript::AddressMap::const_iterator addr;
if (sect->name().compare("text-segment") == 0)
addr = addressMap.find(".text");
@@ -266,3 +245,5 @@ BinaryOp<Operator::SEGMENT_START>::eval(const Module& pModule,
}
return res;
}
+
+} // namespace mcld
diff --git a/lib/Script/CMakeLists.txt b/lib/Script/CMakeLists.txt
index 6fed079..1426a23 100644
--- a/lib/Script/CMakeLists.txt
+++ b/lib/Script/CMakeLists.txt
@@ -13,6 +13,7 @@ add_mcld_library(MCLDScript
EntryCmd.cpp
FileToken.cpp
GroupCmd.cpp
+ InputCmd.cpp
InputSectDesc.cpp
InputToken.cpp
NameSpec.cpp
diff --git a/lib/Script/EntryCmd.cpp b/lib/Script/EntryCmd.cpp
index 9e33c53..345b153 100644
--- a/lib/Script/EntryCmd.cpp
+++ b/lib/Script/EntryCmd.cpp
@@ -6,35 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/EntryCmd.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
+#include "mcld/Script/EntryCmd.h"
-using namespace mcld;
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// EntryCmd
//===----------------------------------------------------------------------===//
EntryCmd::EntryCmd(const std::string& pEntry)
- : ScriptCommand(ScriptCommand::ENTRY),
- m_Entry(pEntry)
-{
+ : ScriptCommand(ScriptCommand::ENTRY), m_Entry(pEntry) {
}
-EntryCmd::~EntryCmd()
-{
+EntryCmd::~EntryCmd() {
}
-void EntryCmd::dump() const
-{
+void EntryCmd::dump() const {
mcld::outs() << "ENTRY ( " << m_Entry << " )\n";
}
-void EntryCmd::activate(Module& pModule)
-{
+void EntryCmd::activate(Module& pModule) {
LinkerScript& script = pModule.getScript();
if (!script.hasEntry())
script.setEntry(m_Entry);
}
+} // namespace mcld
diff --git a/lib/Script/FileToken.cpp b/lib/Script/FileToken.cpp
index 2247d6e..29e1544 100644
--- a/lib/Script/FileToken.cpp
+++ b/lib/Script/FileToken.cpp
@@ -6,11 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/FileToken.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/Script/FileToken.h"
+
+#include "mcld/Support/GCFactory.h"
+
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<FileToken, MCLD_SYMBOLS_PER_INPUT> FileTokenFactory;
static llvm::ManagedStatic<FileTokenFactory> g_FileTokenFactory;
@@ -18,34 +20,30 @@ static llvm::ManagedStatic<FileTokenFactory> g_FileTokenFactory;
//===----------------------------------------------------------------------===//
// FileToken
//===----------------------------------------------------------------------===//
-FileToken::FileToken()
-{
+FileToken::FileToken() {
}
FileToken::FileToken(const std::string& pName, bool pAsNeeded)
- : InputToken(InputToken::File, pName, pAsNeeded)
-{
+ : InputToken(InputToken::File, pName, pAsNeeded) {
}
-FileToken::~FileToken()
-{
+FileToken::~FileToken() {
}
-FileToken* FileToken::create(const std::string& pName, bool pAsNeeded)
-{
+FileToken* FileToken::create(const std::string& pName, bool pAsNeeded) {
FileToken* result = g_FileTokenFactory->allocate();
new (result) FileToken(pName, pAsNeeded);
return result;
}
-void FileToken::destroy(FileToken*& pFileToken)
-{
+void FileToken::destroy(FileToken*& pFileToken) {
g_FileTokenFactory->destroy(pFileToken);
g_FileTokenFactory->deallocate(pFileToken);
pFileToken = NULL;
}
-void FileToken::clear()
-{
+void FileToken::clear() {
g_FileTokenFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/Script/GroupCmd.cpp b/lib/Script/GroupCmd.cpp
index 4673242..1cdf84c 100644
--- a/lib/Script/GroupCmd.cpp
+++ b/lib/Script/GroupCmd.cpp
@@ -6,21 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/GroupCmd.h>
-#include <mcld/Script/StringList.h>
-#include <mcld/Script/InputToken.h>
-#include <mcld/MC/InputBuilder.h>
-#include <mcld/MC/Attribute.h>
-#include <mcld/Support/Path.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/InputTree.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/LD/GroupReader.h>
+#include "mcld/Script/GroupCmd.h"
+
+#include "mcld/LD/GroupReader.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/Script/InputToken.h"
+#include "mcld/Script/StringList.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/Path.h"
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/InputTree.h"
+#include "mcld/LinkerScript.h"
+
#include <llvm/Support/Casting.h>
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// GroupCmd
@@ -30,25 +32,24 @@ GroupCmd::GroupCmd(StringList& pStringList,
InputBuilder& pBuilder,
GroupReader& pGroupReader,
const LinkerConfig& pConfig)
- : ScriptCommand(ScriptCommand::GROUP),
- m_StringList(pStringList),
- m_InputTree(pInputTree),
- m_Builder(pBuilder),
- m_GroupReader(pGroupReader),
- m_Config(pConfig)
-{
+ : ScriptCommand(ScriptCommand::GROUP),
+ m_StringList(pStringList),
+ m_InputTree(pInputTree),
+ m_Builder(pBuilder),
+ m_GroupReader(pGroupReader),
+ m_Config(pConfig) {
}
-GroupCmd::~GroupCmd()
-{
+GroupCmd::~GroupCmd() {
}
-void GroupCmd::dump() const
-{
+void GroupCmd::dump() const {
mcld::outs() << "GROUP ( ";
bool prev = false, cur = false;
for (StringList::const_iterator it = m_StringList.begin(),
- ie = m_StringList.end(); it != ie; ++it) {
+ ie = m_StringList.end();
+ it != ie;
+ ++it) {
assert((*it)->kind() == StrToken::Input);
InputToken* input = llvm::cast<InputToken>(*it);
cur = input->asNeeded();
@@ -70,8 +71,7 @@ void GroupCmd::dump() const
mcld::outs() << " )\n";
}
-void GroupCmd::activate(Module& pModule)
-{
+void GroupCmd::activate(Module& pModule) {
LinkerScript& script = pModule.getScript();
// construct the Group tree
m_Builder.setCurrentTree(m_InputTree);
@@ -80,8 +80,9 @@ void GroupCmd::activate(Module& pModule)
InputTree::iterator group = m_Builder.getCurrentNode();
for (StringList::const_iterator it = m_StringList.begin(),
- ie = m_StringList.end(); it != ie; ++it) {
-
+ ie = m_StringList.end();
+ it != ie;
+ ++it) {
assert((*it)->kind() == StrToken::Input);
InputToken* token = llvm::cast<InputToken>(*it);
if (token->asNeeded())
@@ -90,69 +91,72 @@ void GroupCmd::activate(Module& pModule)
m_Builder.getAttributes().unsetAsNeeded();
switch (token->type()) {
- case InputToken::File: {
- sys::fs::Path path;
+ case InputToken::File: {
+ sys::fs::Path path;
- // 1. Looking for file in the sysroot prefix, if a sysroot prefix is
- // configured and the filename starts with '/'
- if (script.hasSysroot() &&
- (token->name().size() > 0 && token->name()[0] == '/')) {
+ // 1. Looking for file in the sysroot prefix, if a sysroot prefix is
+ // configured and the filename starts with '/'
+ if (script.hasSysroot() &&
+ (token->name().size() > 0 && token->name()[0] == '/')) {
path = script.sysroot();
path.append(token->name());
- } else {
- // 2. Try to open the file in CWD
- path.assign(token->name());
- if (!sys::fs::exists(path)) {
- // 3. Search through the library search path
- sys::fs::Path* p =
- script.directories().find(token->name(), Input::Script);
- if (p != NULL)
- path = *p;
+ } else {
+ // 2. Try to open the file in CWD
+ path.assign(token->name());
+ if (!sys::fs::exists(path)) {
+ // 3. Search through the library search path
+ sys::fs::Path* p =
+ script.directories().find(token->name(), Input::Script);
+ if (p != NULL)
+ path = *p;
+ }
}
- }
- if (!sys::fs::exists(path))
- fatal(diag::err_cannot_open_input) << path.filename() << path;
+ if (!sys::fs::exists(path))
+ fatal(diag::err_cannot_open_input) << path.filename() << path;
- m_Builder.createNode<InputTree::Positional>(
- path.filename().native(), path, Input::Unknown);
- break;
- }
- case InputToken::NameSpec: {
- const sys::fs::Path* path = NULL;
- // find out the real path of the namespec.
- if (m_Builder.getConstraint().isSharedSystem()) {
- // In the system with shared object support, we can find both archive
- // and shared object.
- if (m_Builder.getAttributes().isStatic()) {
- // with --static, we must search an archive.
- path = script.directories().find(token->name(), Input::Archive);
+ m_Builder.createNode<InputTree::Positional>(
+ path.filename().native(), path, Input::Unknown);
+ break;
+ }
+ case InputToken::NameSpec: {
+ const sys::fs::Path* path = NULL;
+ // find out the real path of the namespec.
+ if (m_Builder.getConstraint().isSharedSystem()) {
+ // In the system with shared object support, we can find both archive
+ // and shared object.
+ if (m_Builder.getAttributes().isStatic()) {
+ // with --static, we must search an archive.
+ path = script.directories().find(token->name(), Input::Archive);
+ } else {
+ // otherwise, with --Bdynamic, we can find either an archive or a
+ // shared object.
+ path = script.directories().find(token->name(), Input::DynObj);
+ }
} else {
- // otherwise, with --Bdynamic, we can find either an archive or a
- // shared object.
- path = script.directories().find(token->name(), Input::DynObj);
+ // In the system without shared object support, only look for an
+ // archive
+ path = script.directories().find(token->name(), Input::Archive);
}
- } else {
- // In the system without shared object support, only look for an archive
- path = script.directories().find(token->name(), Input::Archive);
- }
- if (NULL == path)
- fatal(diag::err_cannot_find_namespec) << token->name();
+ if (path == NULL)
+ fatal(diag::err_cannot_find_namespec) << token->name();
- m_Builder.createNode<InputTree::Positional>(
- token->name(), *path, Input::Unknown);
- break;
- }
- default:
- assert(0 && "Invalid script token in GROUP!");
- break;
- } // end of switch
+ m_Builder.createNode<InputTree::Positional>(
+ token->name(), *path, Input::Unknown);
+ break;
+ }
+ default:
+ assert(0 && "Invalid script token in GROUP!");
+ break;
+ } // end of switch
Input* input = *m_Builder.getCurrentNode();
assert(input != NULL);
- if (!m_Builder.setMemory(*input, FileHandle::ReadOnly))
+ if (!m_Builder.setMemory(*input, FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System))) {
error(diag::err_cannot_open_input) << input->name() << input->path();
+ }
m_Builder.setContext(*input);
}
@@ -163,3 +167,4 @@ void GroupCmd::activate(Module& pModule)
m_GroupReader.readGroup(group, m_InputTree.end(), m_Builder, m_Config);
}
+} // namespace mcld
diff --git a/lib/Script/InputCmd.cpp b/lib/Script/InputCmd.cpp
new file mode 100644
index 0000000..a497fd9
--- /dev/null
+++ b/lib/Script/InputCmd.cpp
@@ -0,0 +1,213 @@
+//===- InputCmd.cpp -------------------------------------------------------===//
+//
+// The MCLinker Project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "mcld/Script/InputCmd.h"
+
+#include "mcld/LD/Archive.h"
+#include "mcld/LD/ArchiveReader.h"
+#include "mcld/LD/DynObjReader.h"
+#include "mcld/LD/ObjectReader.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/Script/InputToken.h"
+#include "mcld/Script/StringList.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/Path.h"
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/InputTree.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Module.h"
+
+#include <llvm/Support/Casting.h>
+
+#include <cassert>
+#include <iostream>
+
+namespace mcld {
+
+//===----------------------------------------------------------------------===//
+// InputCmd
+//===----------------------------------------------------------------------===//
+InputCmd::InputCmd(StringList& pStringList,
+ InputTree& pInputTree,
+ InputBuilder& pBuilder,
+ ObjectReader& pObjectReader,
+ ArchiveReader& pArchiveReader,
+ DynObjReader& pDynObjReader,
+ const LinkerConfig& pConfig)
+ : ScriptCommand(ScriptCommand::INPUT),
+ m_StringList(pStringList),
+ m_InputTree(pInputTree),
+ m_Builder(pBuilder),
+ m_ObjectReader(pObjectReader),
+ m_ArchiveReader(pArchiveReader),
+ m_DynObjReader(pDynObjReader),
+ m_Config(pConfig) {
+}
+
+InputCmd::~InputCmd() {
+}
+
+void InputCmd::dump() const {
+ mcld::outs() << "INPUT ( ";
+ bool prev = false, cur = false;
+ for (StringList::const_iterator it = m_StringList.begin(),
+ ie = m_StringList.end();
+ it != ie;
+ ++it) {
+ assert((*it)->kind() == StrToken::Input);
+ InputToken* input = llvm::cast<InputToken>(*it);
+ cur = input->asNeeded();
+ if (!prev && cur)
+ mcld::outs() << "AS_NEEDED ( ";
+ else if (prev && !cur)
+ mcld::outs() << " )";
+
+ if (input->type() == InputToken::NameSpec)
+ mcld::outs() << "-l";
+ mcld::outs() << input->name() << " ";
+
+ prev = cur;
+ }
+
+ if (!m_StringList.empty() && prev)
+ mcld::outs() << " )";
+
+ mcld::outs() << " )\n";
+}
+
+void InputCmd::activate(Module& pModule) {
+ LinkerScript& script = pModule.getScript();
+ // construct the INPUT tree
+ m_Builder.setCurrentTree(m_InputTree);
+
+ bool is_begin_marked = false;
+ InputTree::iterator input_begin;
+
+ for (StringList::const_iterator it = m_StringList.begin(),
+ ie = m_StringList.end();
+ it != ie;
+ ++it) {
+ assert((*it)->kind() == StrToken::Input);
+ InputToken* token = llvm::cast<InputToken>(*it);
+ if (token->asNeeded())
+ m_Builder.getAttributes().setAsNeeded();
+ else
+ m_Builder.getAttributes().unsetAsNeeded();
+
+ switch (token->type()) {
+ case InputToken::File: {
+ sys::fs::Path path;
+
+ // 1. Looking for file in the sysroot prefix, if a sysroot prefix is
+ // configured and the filename starts with '/'
+ if (script.hasSysroot() &&
+ (token->name().size() > 0 && token->name()[0] == '/')) {
+ path = script.sysroot();
+ path.append(token->name());
+ } else {
+ // 2. Try to open the file in CWD
+ path.assign(token->name());
+ if (!sys::fs::exists(path)) {
+ // 3. Search through the library search path
+ sys::fs::Path* p =
+ script.directories().find(token->name(), Input::Script);
+ if (p != NULL)
+ path = *p;
+ }
+ }
+
+ if (!sys::fs::exists(path))
+ fatal(diag::err_cannot_open_input) << path.filename() << path;
+
+ m_Builder.createNode<InputTree::Positional>(
+ path.filename().native(), path, Input::Unknown);
+ break;
+ }
+ case InputToken::NameSpec: {
+ const sys::fs::Path* path = NULL;
+ // find out the real path of the namespec.
+ if (m_Builder.getConstraint().isSharedSystem()) {
+ // In the system with shared object support, we can find both archive
+ // and shared object.
+ if (m_Builder.getAttributes().isStatic()) {
+ // with --static, we must search an archive.
+ path = script.directories().find(token->name(), Input::Archive);
+ } else {
+ // otherwise, with --Bdynamic, we can find either an archive or a
+ // shared object.
+ path = script.directories().find(token->name(), Input::DynObj);
+ }
+ } else {
+ // In the system without shared object support, only look for an
+ // archive
+ path = script.directories().find(token->name(), Input::Archive);
+ }
+
+ if (path == NULL)
+ fatal(diag::err_cannot_find_namespec) << token->name();
+
+ m_Builder.createNode<InputTree::Positional>(
+ token->name(), *path, Input::Unknown);
+ break;
+ }
+ default:
+ assert(0 && "Invalid script token in INPUT!");
+ break;
+ } // end of switch
+
+ InputTree::iterator input = m_Builder.getCurrentNode();
+ if (!is_begin_marked) {
+ input_begin = input;
+ is_begin_marked = true;
+ }
+ assert(*input != NULL);
+ if (!m_Builder.setMemory(**input,
+ FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System))) {
+ error(diag::err_cannot_open_input) << (*input)->name()
+ << (*input)->path();
+ }
+ m_Builder.setContext(**input);
+ }
+
+ for (InputTree::iterator input = input_begin, ie = m_InputTree.end();
+ input != ie;
+ ++input) {
+ bool doContinue = false;
+ if (m_ObjectReader.isMyFormat(**input, doContinue)) {
+ (*input)->setType(Input::Object);
+ m_ObjectReader.readHeader(**input);
+ m_ObjectReader.readSections(**input);
+ m_ObjectReader.readSymbols(**input);
+ pModule.getObjectList().push_back(*input);
+ } else if (doContinue && m_DynObjReader.isMyFormat(**input, doContinue)) {
+ (*input)->setType(Input::DynObj);
+ m_DynObjReader.readHeader(**input);
+ m_DynObjReader.readSymbols(**input);
+ pModule.getLibraryList().push_back(*input);
+ } else if (doContinue && m_ArchiveReader.isMyFormat(**input, doContinue)) {
+ (*input)->setType(Input::Archive);
+ if (m_Config.options().isInExcludeLIBS(**input)) {
+ (*input)->setNoExport();
+ }
+ Archive archive(**input, m_Builder);
+ m_ArchiveReader.readArchive(m_Config, archive);
+ if (archive.numOfObjectMember() > 0) {
+ m_InputTree.merge<InputTree::Inclusive>(input, archive.inputs());
+ }
+ } else {
+ if (m_Config.options().warnMismatch())
+ warning(diag::warn_unrecognized_input_file)
+ << (*input)->path() << m_Config.targets().triple().str();
+ }
+ }
+}
+
+} // namespace mcld
diff --git a/lib/Script/InputSectDesc.cpp b/lib/Script/InputSectDesc.cpp
index 842b720..e9ead82 100644
--- a/lib/Script/InputSectDesc.cpp
+++ b/lib/Script/InputSectDesc.cpp
@@ -6,14 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/InputSectDesc.h>
-#include <mcld/Script/WildcardPattern.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
+#include "mcld/Script/InputSectDesc.h"
+
+#include "mcld/Script/WildcardPattern.h"
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+
#include <llvm/Support/Casting.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// InputSectDesc
@@ -21,23 +23,20 @@ using namespace mcld;
InputSectDesc::InputSectDesc(KeepPolicy pPolicy,
const Spec& pSpec,
const OutputSectDesc& pOutputDesc)
- : ScriptCommand(ScriptCommand::INPUT_SECT_DESC),
- m_KeepPolicy(pPolicy),
- m_Spec(pSpec),
- m_OutputSectDesc(pOutputDesc)
-{
+ : ScriptCommand(ScriptCommand::INPUT_SECT_DESC),
+ m_KeepPolicy(pPolicy),
+ m_Spec(pSpec),
+ m_OutputSectDesc(pOutputDesc) {
}
-InputSectDesc::~InputSectDesc()
-{
+InputSectDesc::~InputSectDesc() {
}
-void InputSectDesc::dump() const
-{
+void InputSectDesc::dump() const {
if (m_KeepPolicy == Keep)
mcld::outs() << "KEEP (";
- assert (m_Spec.hasFile());
+ assert(m_Spec.hasFile());
if (m_Spec.file().sortPolicy() == WildcardPattern::SORT_BY_NAME)
mcld::outs() << "SORT (";
@@ -49,7 +48,9 @@ void InputSectDesc::dump() const
if (m_Spec.hasExcludeFiles()) {
mcld::outs() << "EXCLUDE_FILE (";
for (StringList::const_iterator it = m_Spec.excludeFiles().begin(),
- ie = m_Spec.excludeFiles().end(); it != ie; ++it) {
+ ie = m_Spec.excludeFiles().end();
+ it != ie;
+ ++it) {
mcld::outs() << (*it)->name() << " ";
}
mcld::outs() << ")";
@@ -57,25 +58,27 @@ void InputSectDesc::dump() const
if (m_Spec.hasSections()) {
for (StringList::const_iterator it = m_Spec.sections().begin(),
- ie = m_Spec.sections().end(); it != ie; ++it) {
+ ie = m_Spec.sections().end();
+ it != ie;
+ ++it) {
assert((*it)->kind() == StrToken::Wildcard);
WildcardPattern* wildcard = llvm::cast<WildcardPattern>(*it);
switch (wildcard->sortPolicy()) {
- case WildcardPattern::SORT_BY_NAME:
- mcld::outs() << "SORT (";
- break;
- case WildcardPattern::SORT_BY_ALIGNMENT:
- mcld::outs() << "SORT_BY_ALIGNMENT (";
- break;
- case WildcardPattern::SORT_BY_NAME_ALIGNMENT:
- mcld::outs() << "SORT_BY_NAME_ALIGNMENT (";
- break;
- case WildcardPattern::SORT_BY_ALIGNMENT_NAME:
- mcld::outs() << "SORT_BY_ALIGNMENT_NAME (";
- break;
- default:
- break;
+ case WildcardPattern::SORT_BY_NAME:
+ mcld::outs() << "SORT (";
+ break;
+ case WildcardPattern::SORT_BY_ALIGNMENT:
+ mcld::outs() << "SORT_BY_ALIGNMENT (";
+ break;
+ case WildcardPattern::SORT_BY_NAME_ALIGNMENT:
+ mcld::outs() << "SORT_BY_NAME_ALIGNMENT (";
+ break;
+ case WildcardPattern::SORT_BY_ALIGNMENT_NAME:
+ mcld::outs() << "SORT_BY_ALIGNMENT_NAME (";
+ break;
+ default:
+ break;
}
mcld::outs() << wildcard->name() << " ";
@@ -96,7 +99,8 @@ void InputSectDesc::dump() const
mcld::outs() << "\n";
}
-void InputSectDesc::activate(Module& pModule)
-{
+void InputSectDesc::activate(Module& pModule) {
pModule.getScript().sectionMap().insert(*this, m_OutputSectDesc);
}
+
+} // namespace mcld
diff --git a/lib/Script/InputToken.cpp b/lib/Script/InputToken.cpp
index 45b006a..35c38e2 100644
--- a/lib/Script/InputToken.cpp
+++ b/lib/Script/InputToken.cpp
@@ -6,23 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/InputToken.h>
+#include "mcld/Script/InputToken.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// InputToken
//===----------------------------------------------------------------------===//
-InputToken::InputToken()
- : m_Type(Unknown), m_bAsNeeded(false)
-{
+InputToken::InputToken() : m_Type(Unknown), m_bAsNeeded(false) {
}
InputToken::InputToken(Type pType, const std::string& pName, bool pAsNeeded)
- : StrToken(StrToken::Input, pName), m_Type(pType), m_bAsNeeded(pAsNeeded)
-{
+ : StrToken(StrToken::Input, pName), m_Type(pType), m_bAsNeeded(pAsNeeded) {
}
-InputToken::~InputToken()
-{
+InputToken::~InputToken() {
}
+
+} // namespace mcld
diff --git a/lib/Script/NameSpec.cpp b/lib/Script/NameSpec.cpp
index da7a62c..0d0a178 100644
--- a/lib/Script/NameSpec.cpp
+++ b/lib/Script/NameSpec.cpp
@@ -6,11 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/NameSpec.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/Script/NameSpec.h"
+
+#include "mcld/Support/GCFactory.h"
+
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<NameSpec, MCLD_SYMBOLS_PER_INPUT> NameSpecFactory;
static llvm::ManagedStatic<NameSpecFactory> g_NameSpecFactory;
@@ -18,34 +20,30 @@ static llvm::ManagedStatic<NameSpecFactory> g_NameSpecFactory;
//===----------------------------------------------------------------------===//
// NameSpec
//===----------------------------------------------------------------------===//
-NameSpec::NameSpec()
-{
+NameSpec::NameSpec() {
}
NameSpec::NameSpec(const std::string& pName, bool pAsNeeded)
- : InputToken(InputToken::NameSpec, pName, pAsNeeded)
-{
+ : InputToken(InputToken::NameSpec, pName, pAsNeeded) {
}
-NameSpec::~NameSpec()
-{
+NameSpec::~NameSpec() {
}
-NameSpec* NameSpec::create(const std::string& pName, bool pAsNeeded)
-{
+NameSpec* NameSpec::create(const std::string& pName, bool pAsNeeded) {
NameSpec* result = g_NameSpecFactory->allocate();
new (result) NameSpec(pName, pAsNeeded);
return result;
}
-void NameSpec::destroy(NameSpec*& pNameSpec)
-{
+void NameSpec::destroy(NameSpec*& pNameSpec) {
g_NameSpecFactory->destroy(pNameSpec);
g_NameSpecFactory->deallocate(pNameSpec);
pNameSpec = NULL;
}
-void NameSpec::clear()
-{
+void NameSpec::clear() {
g_NameSpecFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/Script/NullaryOp.cpp b/lib/Script/NullaryOp.cpp
index 69382ec..7272e22 100644
--- a/lib/Script/NullaryOp.cpp
+++ b/lib/Script/NullaryOp.cpp
@@ -6,40 +6,40 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/NullaryOp.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Target/TargetLDBackend.h>
+#include "mcld/Script/NullaryOp.h"
-using namespace mcld;
+#include "mcld/Script/Operand.h"
+#include "mcld/Target/TargetLDBackend.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// NullaryOp
//===----------------------------------------------------------------------===//
-template<>
-IntOperand*
-NullaryOp<Operator::SIZEOF_HEADERS>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* NullaryOp<Operator::SIZEOF_HEADERS>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(pBackend.sectionStartOffset());
return res;
}
-template<>
-IntOperand*
-NullaryOp<Operator::MAXPAGESIZE>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* NullaryOp<Operator::MAXPAGESIZE>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(pBackend.abiPageSize());
return res;
}
-template<>
-IntOperand*
-NullaryOp<Operator::COMMONPAGESIZE>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* NullaryOp<Operator::COMMONPAGESIZE>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(pBackend.commonPageSize());
return res;
}
+
+} // namespace mcld
diff --git a/lib/Script/Operand.cpp b/lib/Script/Operand.cpp
index 690ba9b..95781dc 100644
--- a/lib/Script/Operand.cpp
+++ b/lib/Script/Operand.cpp
@@ -6,26 +6,25 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/Operand.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/Support/GCFactory.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/Fragment/Fragment.h>
+#include "mcld/Script/Operand.h"
+
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/Support/GCFactory.h"
+#include "mcld/Support/raw_ostream.h"
+
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Operand
//===----------------------------------------------------------------------===//
-Operand::Operand(Type pType)
- : ExprToken(ExprToken::OPERAND), m_Type(pType)
-{
+Operand::Operand(Type pType) : ExprToken(ExprToken::OPERAND), m_Type(pType) {
}
-Operand::~Operand()
-{
+Operand::~Operand() {
}
//===----------------------------------------------------------------------===//
@@ -34,43 +33,35 @@ Operand::~Operand()
typedef GCFactory<SymOperand, MCLD_SYMBOLS_PER_INPUT> SymOperandFactory;
static llvm::ManagedStatic<SymOperandFactory> g_SymOperandFactory;
-SymOperand::SymOperand()
- : Operand(Operand::SYMBOL), m_Value(0)
-{
+SymOperand::SymOperand() : Operand(Operand::SYMBOL), m_Value(0) {
}
SymOperand::SymOperand(const std::string& pName)
- : Operand(Operand::SYMBOL), m_Name(pName), m_Value(0)
-{
+ : Operand(Operand::SYMBOL), m_Name(pName), m_Value(0) {
}
-void SymOperand::dump() const
-{
+void SymOperand::dump() const {
mcld::outs() << m_Name;
}
-bool SymOperand::isDot() const
-{
+bool SymOperand::isDot() const {
assert(!m_Name.empty());
return m_Name.size() == 1 && m_Name[0] == '.';
}
-SymOperand* SymOperand::create(const std::string& pName)
-{
+SymOperand* SymOperand::create(const std::string& pName) {
SymOperand* result = g_SymOperandFactory->allocate();
new (result) SymOperand(pName);
return result;
}
-void SymOperand::destroy(SymOperand*& pOperand)
-{
+void SymOperand::destroy(SymOperand*& pOperand) {
g_SymOperandFactory->destroy(pOperand);
g_SymOperandFactory->deallocate(pOperand);
pOperand = NULL;
}
-void SymOperand::clear()
-{
+void SymOperand::clear() {
g_SymOperandFactory->clear();
}
@@ -80,37 +71,30 @@ void SymOperand::clear()
typedef GCFactory<IntOperand, MCLD_SYMBOLS_PER_INPUT> IntOperandFactory;
static llvm::ManagedStatic<IntOperandFactory> g_IntOperandFactory;
-IntOperand::IntOperand()
- : Operand(Operand::INTEGER), m_Value(0)
-{
+IntOperand::IntOperand() : Operand(Operand::INTEGER), m_Value(0) {
}
IntOperand::IntOperand(uint64_t pValue)
- : Operand(Operand::INTEGER), m_Value(pValue)
-{
+ : Operand(Operand::INTEGER), m_Value(pValue) {
}
-void IntOperand::dump() const
-{
+void IntOperand::dump() const {
mcld::outs() << m_Value;
}
-IntOperand* IntOperand::create(uint64_t pValue)
-{
+IntOperand* IntOperand::create(uint64_t pValue) {
IntOperand* result = g_IntOperandFactory->allocate();
new (result) IntOperand(pValue);
return result;
}
-void IntOperand::destroy(IntOperand*& pOperand)
-{
+void IntOperand::destroy(IntOperand*& pOperand) {
g_IntOperandFactory->destroy(pOperand);
g_IntOperandFactory->deallocate(pOperand);
pOperand = NULL;
}
-void IntOperand::clear()
-{
+void IntOperand::clear() {
g_IntOperandFactory->clear();
}
@@ -119,78 +103,66 @@ void IntOperand::clear()
//===----------------------------------------------------------------------===//
typedef GCFactory<SectOperand, MCLD_SECTIONS_PER_INPUT> SectOperandFactory;
static llvm::ManagedStatic<SectOperandFactory> g_SectOperandFactory;
-SectOperand::SectOperand()
- : Operand(Operand::SECTION)
-{
+SectOperand::SectOperand() : Operand(Operand::SECTION) {
}
SectOperand::SectOperand(const std::string& pName)
- : Operand(Operand::SECTION), m_Name(pName)
-{
+ : Operand(Operand::SECTION), m_Name(pName) {
}
-void SectOperand::dump() const
-{
+void SectOperand::dump() const {
mcld::outs() << m_Name;
}
-SectOperand* SectOperand::create(const std::string& pName)
-{
+SectOperand* SectOperand::create(const std::string& pName) {
SectOperand* result = g_SectOperandFactory->allocate();
new (result) SectOperand(pName);
return result;
}
-void SectOperand::destroy(SectOperand*& pOperand)
-{
+void SectOperand::destroy(SectOperand*& pOperand) {
g_SectOperandFactory->destroy(pOperand);
g_SectOperandFactory->deallocate(pOperand);
pOperand = NULL;
}
-void SectOperand::clear()
-{
+void SectOperand::clear() {
g_SectOperandFactory->clear();
}
//===----------------------------------------------------------------------===//
// SectDescOperand
//===----------------------------------------------------------------------===//
-typedef GCFactory<SectDescOperand,
- MCLD_SECTIONS_PER_INPUT> SectDescOperandFactory;
+typedef GCFactory<SectDescOperand, MCLD_SECTIONS_PER_INPUT>
+ SectDescOperandFactory;
static llvm::ManagedStatic<SectDescOperandFactory> g_SectDescOperandFactory;
SectDescOperand::SectDescOperand()
- : Operand(Operand::SECTION_DESC), m_pOutputDesc(NULL)
-{
+ : Operand(Operand::SECTION_DESC), m_pOutputDesc(NULL) {
}
SectDescOperand::SectDescOperand(const SectionMap::Output* pOutputDesc)
- : Operand(Operand::SECTION_DESC), m_pOutputDesc(pOutputDesc)
-{
+ : Operand(Operand::SECTION_DESC), m_pOutputDesc(pOutputDesc) {
}
-void SectDescOperand::dump() const
-{
+void SectDescOperand::dump() const {
assert(m_pOutputDesc != NULL);
mcld::outs() << m_pOutputDesc->getSection()->name();
}
-SectDescOperand* SectDescOperand::create(const SectionMap::Output* pOutputDesc)
-{
+SectDescOperand* SectDescOperand::create(
+ const SectionMap::Output* pOutputDesc) {
SectDescOperand* result = g_SectDescOperandFactory->allocate();
new (result) SectDescOperand(pOutputDesc);
return result;
}
-void SectDescOperand::destroy(SectDescOperand*& pOperand)
-{
+void SectDescOperand::destroy(SectDescOperand*& pOperand) {
g_SectDescOperandFactory->destroy(pOperand);
g_SectDescOperandFactory->deallocate(pOperand);
pOperand = NULL;
}
-void SectDescOperand::clear()
-{
+void SectDescOperand::clear() {
g_SectDescOperandFactory->clear();
}
@@ -200,42 +172,36 @@ void SectDescOperand::clear()
typedef GCFactory<FragOperand, MCLD_SYMBOLS_PER_INPUT> FragOperandFactory;
static llvm::ManagedStatic<FragOperandFactory> g_FragOperandFactory;
-FragOperand::FragOperand()
- : Operand(Operand::FRAGMENT), m_pFragment(NULL)
-{
+FragOperand::FragOperand() : Operand(Operand::FRAGMENT), m_pFragment(NULL) {
}
FragOperand::FragOperand(Fragment& pFragment)
- : Operand(Operand::FRAGMENT), m_pFragment(&pFragment)
-{
+ : Operand(Operand::FRAGMENT), m_pFragment(&pFragment) {
}
-void FragOperand::dump() const
-{
+void FragOperand::dump() const {
mcld::outs() << "fragment";
}
-uint64_t FragOperand::value() const
-{
+uint64_t FragOperand::value() const {
return m_pFragment->getOffset() +
m_pFragment->getParent()->getSection().addr();
}
-FragOperand* FragOperand::create(Fragment& pFragment)
-{
+FragOperand* FragOperand::create(Fragment& pFragment) {
FragOperand* result = g_FragOperandFactory->allocate();
new (result) FragOperand(pFragment);
return result;
}
-void FragOperand::destroy(FragOperand*& pOperand)
-{
+void FragOperand::destroy(FragOperand*& pOperand) {
g_FragOperandFactory->destroy(pOperand);
g_FragOperandFactory->deallocate(pOperand);
pOperand = NULL;
}
-void FragOperand::clear()
-{
+void FragOperand::clear() {
g_FragOperandFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/Script/Operator.cpp b/lib/Script/Operator.cpp
index e50a255..21b4ff1 100644
--- a/lib/Script/Operator.cpp
+++ b/lib/Script/Operator.cpp
@@ -6,385 +6,306 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/Operator.h>
-#include <mcld/Script/NullaryOp.h>
-#include <mcld/Script/UnaryOp.h>
-#include <mcld/Script/BinaryOp.h>
-#include <mcld/Script/TernaryOp.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Support/raw_ostream.h>
-
-using namespace mcld;
+#include "mcld/Script/Operator.h"
+
+#include "mcld/Script/BinaryOp.h"
+#include "mcld/Script/NullaryOp.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/UnaryOp.h"
+#include "mcld/Script/TernaryOp.h"
+#include "mcld/Support/raw_ostream.h"
+
+namespace mcld {
+
//===----------------------------------------------------------------------===//
// Operator
//===----------------------------------------------------------------------===//
const char* Operator::OpNames[] = {
- "+",
- "-",
- "!",
- "~",
- "*",
- "/",
- "%",
- "+",
- "-",
- "<<",
- ">>",
- "<",
- "<=",
- ">",
- ">=",
- "==",
- "!=",
- "&",
- "^",
- "|",
- "&&",
- "||",
- "?:",
- "=",
- "+=",
- "-=",
- "*=",
- "/=",
- "&=",
- "|=",
- "<<=",
- ">>=",
- "ABSOLUTE",
- "ADDR",
- "ALIGN",
- "ALIGNOF",
- "BLOCK",
- "DATA_SEGMENT_ALIGN",
- "DATA_SEGMENT_END",
- "DATA_SEGMENT_RELRO_END",
- "DEFINED",
- "LENGTH",
- "LOADADDR",
- "MAX",
- "MIN",
- "NEXT",
- "ORIGIN",
- "SEGMENT_START",
- "SIZEOF",
- "SIZEOF_HEADERS",
- "MAXPAGESIZE",
- "COMMONPAGESIZE"
-};
-
-Operator::Operator(Arity pArity,
- Type pType)
- : ExprToken(ExprToken::OPERATOR),
- m_Arity(pArity),
- m_Type(pType)
-{
+ "+", "-", "!",
+ "~", "*", "/",
+ "%", "+", "-",
+ "<<", ">>", "<",
+ "<=", ">", ">=",
+ "==", "!=", "&",
+ "^", "|", "&&",
+ "||", "?:", "=",
+ "+=", "-=", "*=",
+ "/=", "&=", "|=",
+ "<<=", ">>=", "ABSOLUTE",
+ "ADDR", "ALIGN", "ALIGNOF",
+ "BLOCK", "DATA_SEGMENT_ALIGN", "DATA_SEGMENT_END",
+ "DATA_SEGMENT_RELRO_END", "DEFINED", "LENGTH",
+ "LOADADDR", "MAX", "MIN",
+ "NEXT", "ORIGIN", "SEGMENT_START",
+ "SIZEOF", "SIZEOF_HEADERS", "MAXPAGESIZE",
+ "COMMONPAGESIZE"};
+
+Operator::Operator(Arity pArity, Type pType)
+ : ExprToken(ExprToken::OPERATOR), m_Arity(pArity), m_Type(pType) {
m_pIntOperand = IntOperand::create(0);
}
-Operator::~Operator()
-{
+Operator::~Operator() {
}
-void Operator::dump() const
-{
+void Operator::dump() const {
mcld::outs() << OpNames[type()];
}
/* Nullary operator */
-template<>
-Operator& Operator::create<Operator::SIZEOF_HEADERS>()
-{
+template <>
+Operator& Operator::create<Operator::SIZEOF_HEADERS>() {
static NullaryOp<Operator::SIZEOF_HEADERS> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::MAXPAGESIZE>()
-{
+template <>
+Operator& Operator::create<Operator::MAXPAGESIZE>() {
static NullaryOp<Operator::MAXPAGESIZE> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::COMMONPAGESIZE>()
-{
+template <>
+Operator& Operator::create<Operator::COMMONPAGESIZE>() {
static NullaryOp<Operator::COMMONPAGESIZE> op;
return op;
}
/* Unary operator */
-template<>
-Operator& Operator::create<Operator::UNARY_PLUS>()
-{
+template <>
+Operator& Operator::create<Operator::UNARY_PLUS>() {
static UnaryOp<Operator::UNARY_PLUS> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::UNARY_MINUS>()
-{
+template <>
+Operator& Operator::create<Operator::UNARY_MINUS>() {
static UnaryOp<Operator::UNARY_MINUS> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LOGICAL_NOT>()
-{
+template <>
+Operator& Operator::create<Operator::LOGICAL_NOT>() {
static UnaryOp<Operator::LOGICAL_NOT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::BITWISE_NOT>()
-{
+template <>
+Operator& Operator::create<Operator::BITWISE_NOT>() {
static UnaryOp<Operator::BITWISE_NOT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::ABSOLUTE>()
-{
+template <>
+Operator& Operator::create<Operator::ABSOLUTE>() {
static UnaryOp<Operator::ABSOLUTE> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::ADDR>()
-{
+template <>
+Operator& Operator::create<Operator::ADDR>() {
static UnaryOp<Operator::ADDR> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::ALIGNOF>()
-{
+template <>
+Operator& Operator::create<Operator::ALIGNOF>() {
static UnaryOp<Operator::ALIGNOF> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::DATA_SEGMENT_END>()
-{
+template <>
+Operator& Operator::create<Operator::DATA_SEGMENT_END>() {
static UnaryOp<Operator::DATA_SEGMENT_END> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::DEFINED>()
-{
+template <>
+Operator& Operator::create<Operator::DEFINED>() {
static UnaryOp<Operator::DEFINED> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LENGTH>()
-{
+template <>
+Operator& Operator::create<Operator::LENGTH>() {
static UnaryOp<Operator::LENGTH> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LOADADDR>()
-{
+template <>
+Operator& Operator::create<Operator::LOADADDR>() {
static UnaryOp<Operator::LOADADDR> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::NEXT>()
-{
+template <>
+Operator& Operator::create<Operator::NEXT>() {
static UnaryOp<Operator::NEXT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::ORIGIN>()
-{
+template <>
+Operator& Operator::create<Operator::ORIGIN>() {
static UnaryOp<Operator::ORIGIN> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::SIZEOF>()
-{
+template <>
+Operator& Operator::create<Operator::SIZEOF>() {
static UnaryOp<Operator::SIZEOF> op;
return op;
}
/* Binary operator */
-template<>
-Operator& Operator::create<Operator::MUL>()
-{
+template <>
+Operator& Operator::create<Operator::MUL>() {
static BinaryOp<Operator::MUL> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::DIV>()
-{
+template <>
+Operator& Operator::create<Operator::DIV>() {
static BinaryOp<Operator::DIV> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::MOD>()
-{
+template <>
+Operator& Operator::create<Operator::MOD>() {
static BinaryOp<Operator::MOD> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::ADD>()
-{
+template <>
+Operator& Operator::create<Operator::ADD>() {
static BinaryOp<Operator::ADD> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::SUB>()
-{
+template <>
+Operator& Operator::create<Operator::SUB>() {
static BinaryOp<Operator::SUB> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LSHIFT>()
-{
+template <>
+Operator& Operator::create<Operator::LSHIFT>() {
static BinaryOp<Operator::LSHIFT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::RSHIFT>()
-{
+template <>
+Operator& Operator::create<Operator::RSHIFT>() {
static BinaryOp<Operator::RSHIFT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LT>()
-{
+template <>
+Operator& Operator::create<Operator::LT>() {
static BinaryOp<Operator::LT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LE>()
-{
+template <>
+Operator& Operator::create<Operator::LE>() {
static BinaryOp<Operator::LE> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::GT>()
-{
+template <>
+Operator& Operator::create<Operator::GT>() {
static BinaryOp<Operator::GT> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::GE>()
-{
+template <>
+Operator& Operator::create<Operator::GE>() {
static BinaryOp<Operator::GE> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::EQ>()
-{
+template <>
+Operator& Operator::create<Operator::EQ>() {
static BinaryOp<Operator::EQ> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::NE>()
-{
+template <>
+Operator& Operator::create<Operator::NE>() {
static BinaryOp<Operator::NE> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::BITWISE_AND>()
-{
+template <>
+Operator& Operator::create<Operator::BITWISE_AND>() {
static BinaryOp<Operator::BITWISE_AND> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::BITWISE_XOR>()
-{
+template <>
+Operator& Operator::create<Operator::BITWISE_XOR>() {
static BinaryOp<Operator::BITWISE_XOR> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::BITWISE_OR>()
-{
+template <>
+Operator& Operator::create<Operator::BITWISE_OR>() {
static BinaryOp<Operator::BITWISE_OR> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LOGICAL_AND>()
-{
+template <>
+Operator& Operator::create<Operator::LOGICAL_AND>() {
static BinaryOp<Operator::LOGICAL_AND> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::LOGICAL_OR>()
-{
+template <>
+Operator& Operator::create<Operator::LOGICAL_OR>() {
static BinaryOp<Operator::LOGICAL_OR> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::ALIGN>()
-{
+template <>
+Operator& Operator::create<Operator::ALIGN>() {
static BinaryOp<Operator::ALIGN> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::DATA_SEGMENT_RELRO_END>()
-{
+template <>
+Operator& Operator::create<Operator::DATA_SEGMENT_RELRO_END>() {
static BinaryOp<Operator::DATA_SEGMENT_RELRO_END> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::MAX>()
-{
+template <>
+Operator& Operator::create<Operator::MAX>() {
static BinaryOp<Operator::MAX> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::MIN>()
-{
+template <>
+Operator& Operator::create<Operator::MIN>() {
static BinaryOp<Operator::MIN> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::SEGMENT_START>()
-{
+template <>
+Operator& Operator::create<Operator::SEGMENT_START>() {
static BinaryOp<Operator::SEGMENT_START> op;
return op;
}
/* Ternary operator */
-template<>
-Operator& Operator::create<Operator::TERNARY_IF>()
-{
+template <>
+Operator& Operator::create<Operator::TERNARY_IF>() {
static TernaryOp<Operator::TERNARY_IF> op;
return op;
}
-template<>
-Operator& Operator::create<Operator::DATA_SEGMENT_ALIGN>()
-{
+template <>
+Operator& Operator::create<Operator::DATA_SEGMENT_ALIGN>() {
static TernaryOp<Operator::DATA_SEGMENT_ALIGN> op;
return op;
}
+
+} // namespace mcld
diff --git a/lib/Script/OutputArchCmd.cpp b/lib/Script/OutputArchCmd.cpp
index 4393b84..3bba021 100644
--- a/lib/Script/OutputArchCmd.cpp
+++ b/lib/Script/OutputArchCmd.cpp
@@ -6,31 +6,27 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/OutputArchCmd.h>
-#include <mcld/Support/raw_ostream.h>
+#include "mcld/Script/OutputArchCmd.h"
+#include "mcld/Support/raw_ostream.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// OutputArchCmd
//===----------------------------------------------------------------------===//
OutputArchCmd::OutputArchCmd(const std::string& pArch)
- : ScriptCommand(ScriptCommand::OUTPUT_ARCH),
- m_Arch(pArch)
-{
+ : ScriptCommand(ScriptCommand::OUTPUT_ARCH), m_Arch(pArch) {
}
-OutputArchCmd::~OutputArchCmd()
-{
+OutputArchCmd::~OutputArchCmd() {
}
-void OutputArchCmd::dump() const
-{
+void OutputArchCmd::dump() const {
mcld::outs() << "OUTPUT_ARCH ( " << m_Arch << " )\n";
}
-void OutputArchCmd::activate(Module& pModule)
-{
+void OutputArchCmd::activate(Module& pModule) {
// TODO
}
+} // namespace mcld
diff --git a/lib/Script/OutputCmd.cpp b/lib/Script/OutputCmd.cpp
index c37adcc..c4e5aeb 100644
--- a/lib/Script/OutputCmd.cpp
+++ b/lib/Script/OutputCmd.cpp
@@ -6,36 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/OutputCmd.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
+#include "mcld/Script/OutputCmd.h"
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// OutputCmd
//===----------------------------------------------------------------------===//
OutputCmd::OutputCmd(const std::string& pOutputFile)
- : ScriptCommand(ScriptCommand::OUTPUT),
- m_OutputFile(pOutputFile)
-{
+ : ScriptCommand(ScriptCommand::OUTPUT), m_OutputFile(pOutputFile) {
}
-OutputCmd::~OutputCmd()
-{
+OutputCmd::~OutputCmd() {
}
-void OutputCmd::dump() const
-{
+void OutputCmd::dump() const {
mcld::outs() << "OUTPUT ( " << m_OutputFile << " )\n";
}
-void OutputCmd::activate(Module& pModule)
-{
+void OutputCmd::activate(Module& pModule) {
pModule.getScript().setOutputFile(m_OutputFile);
// TODO: set the output name if there is no `-o filename' on the cmdline.
// This option is to define a default name for the output file other than the
// usual default of a.out.
}
+} // namespace mcld
diff --git a/lib/Script/OutputFormatCmd.cpp b/lib/Script/OutputFormatCmd.cpp
index eca9df5..b0c4fa5 100644
--- a/lib/Script/OutputFormatCmd.cpp
+++ b/lib/Script/OutputFormatCmd.cpp
@@ -6,36 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/OutputFormatCmd.h>
-#include <mcld/Support/raw_ostream.h>
+#include "mcld/Script/OutputFormatCmd.h"
+#include "mcld/Support/raw_ostream.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// OutputFormatCmd
//===----------------------------------------------------------------------===//
OutputFormatCmd::OutputFormatCmd(const std::string& pFormat)
- : ScriptCommand(ScriptCommand::OUTPUT_FORMAT)
-{
+ : ScriptCommand(ScriptCommand::OUTPUT_FORMAT) {
m_FormatList.push_back(pFormat);
}
OutputFormatCmd::OutputFormatCmd(const std::string& pDefault,
const std::string& pBig,
const std::string& pLittle)
- : ScriptCommand(ScriptCommand::OUTPUT_FORMAT)
-{
+ : ScriptCommand(ScriptCommand::OUTPUT_FORMAT) {
m_FormatList.push_back(pDefault);
m_FormatList.push_back(pBig);
m_FormatList.push_back(pLittle);
}
-OutputFormatCmd::~OutputFormatCmd()
-{
+OutputFormatCmd::~OutputFormatCmd() {
}
-void OutputFormatCmd::dump() const
-{
+void OutputFormatCmd::dump() const {
mcld::outs() << "OUTPUT_FORMAT ( ";
assert(m_FormatList.size() == 1 || m_FormatList.size() == 3);
for (size_t i = 0; i < m_FormatList.size(); ++i) {
@@ -46,8 +42,8 @@ void OutputFormatCmd::dump() const
mcld::outs() << " )\n";
}
-void OutputFormatCmd::activate(Module& pModule)
-{
+void OutputFormatCmd::activate(Module& pModule) {
// TODO
}
+} // namespace mcld
diff --git a/lib/Script/OutputSectDesc.cpp b/lib/Script/OutputSectDesc.cpp
index 3442c4e..df994ca 100644
--- a/lib/Script/OutputSectDesc.cpp
+++ b/lib/Script/OutputSectDesc.cpp
@@ -6,40 +6,39 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/OutputSectDesc.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Script/StringList.h>
-#include <mcld/Script/StrToken.h>
-#include <mcld/Script/InputSectDesc.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
+#include "mcld/Script/OutputSectDesc.h"
+
+#include "mcld/Script/InputSectDesc.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Script/StringList.h"
+#include "mcld/Script/StrToken.h"
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+
#include <llvm/Support/Casting.h>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// OutputSectDesc
//===----------------------------------------------------------------------===//
-OutputSectDesc::OutputSectDesc(const std::string& pName,
- const Prolog& pProlog)
- : ScriptCommand(ScriptCommand::OUTPUT_SECT_DESC),
- m_Name(pName),
- m_Prolog(pProlog)
-{
+OutputSectDesc::OutputSectDesc(const std::string& pName, const Prolog& pProlog)
+ : ScriptCommand(ScriptCommand::OUTPUT_SECT_DESC),
+ m_Name(pName),
+ m_Prolog(pProlog) {
}
-OutputSectDesc::~OutputSectDesc()
-{
+OutputSectDesc::~OutputSectDesc() {
for (iterator it = begin(), ie = end(); it != ie; ++it) {
if (*it != NULL)
delete *it;
}
}
-void OutputSectDesc::dump() const
-{
+void OutputSectDesc::dump() const {
mcld::outs() << m_Name << "\t";
if (m_Prolog.hasVMA()) {
@@ -48,23 +47,23 @@ void OutputSectDesc::dump() const
}
switch (m_Prolog.type()) {
- case NOLOAD:
- mcld::outs() << "(NOLOAD)";
- break;
- case DSECT:
- mcld::outs() << "(DSECT)";
- break;
- case COPY:
- mcld::outs() << "(COPY)";
- break;
- case INFO:
- mcld::outs() << "(INFO)";
- break;
- case OVERLAY:
- mcld::outs() << "(OVERLAY)";
- break;
- default:
- break;
+ case NOLOAD:
+ mcld::outs() << "(NOLOAD)";
+ break;
+ case DSECT:
+ mcld::outs() << "(DSECT)";
+ break;
+ case COPY:
+ mcld::outs() << "(COPY)";
+ break;
+ case INFO:
+ mcld::outs() << "(INFO)";
+ break;
+ case OVERLAY:
+ mcld::outs() << "(OVERLAY)";
+ break;
+ default:
+ break;
}
mcld::outs() << ":\n";
@@ -87,27 +86,27 @@ void OutputSectDesc::dump() const
}
switch (m_Prolog.constraint()) {
- case ONLY_IF_RO:
- mcld::outs() << "\tONLY_IF_RO\n";
- break;
- case ONLY_IF_RW:
- mcld::outs() << "\tONLY_IF_RW\n";
- break;
- default:
- break;
+ case ONLY_IF_RO:
+ mcld::outs() << "\tONLY_IF_RO\n";
+ break;
+ case ONLY_IF_RW:
+ mcld::outs() << "\tONLY_IF_RW\n";
+ break;
+ default:
+ break;
}
mcld::outs() << "\t{\n";
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
switch ((*it)->getKind()) {
- case ScriptCommand::ASSIGNMENT:
- case ScriptCommand::INPUT_SECT_DESC:
- mcld::outs() << "\t\t";
- (*it)->dump();
- break;
- default:
- assert(0);
- break;
+ case ScriptCommand::ASSIGNMENT:
+ case ScriptCommand::INPUT_SECT_DESC:
+ mcld::outs() << "\t\t";
+ (*it)->dump();
+ break;
+ default:
+ assert(0);
+ break;
}
}
mcld::outs() << "\t}";
@@ -119,7 +118,9 @@ void OutputSectDesc::dump() const
if (m_Epilog.hasPhdrs()) {
for (StringList::const_iterator it = m_Epilog.phdrs().begin(),
- ie = m_Epilog.phdrs().end(); it != ie; ++it) {
+ ie = m_Epilog.phdrs().end();
+ it != ie;
+ ++it) {
assert((*it)->kind() == StrToken::String);
mcld::outs() << ":" << (*it)->name() << " ";
}
@@ -132,55 +133,54 @@ void OutputSectDesc::dump() const
mcld::outs() << "\n";
}
-void OutputSectDesc::push_back(ScriptCommand* pCommand)
-{
+void OutputSectDesc::push_back(ScriptCommand* pCommand) {
switch (pCommand->getKind()) {
- case ScriptCommand::ASSIGNMENT:
- case ScriptCommand::INPUT_SECT_DESC:
- m_OutputSectCmds.push_back(pCommand);
- break;
- default:
- assert(0);
- break;
+ case ScriptCommand::ASSIGNMENT:
+ case ScriptCommand::INPUT_SECT_DESC:
+ m_OutputSectCmds.push_back(pCommand);
+ break;
+ default:
+ assert(0);
+ break;
}
}
-void OutputSectDesc::setEpilog(const Epilog& pEpilog)
-{
- m_Epilog.m_pRegion = pEpilog.m_pRegion;
+void OutputSectDesc::setEpilog(const Epilog& pEpilog) {
+ m_Epilog.m_pRegion = pEpilog.m_pRegion;
m_Epilog.m_pLMARegion = pEpilog.m_pLMARegion;
- m_Epilog.m_pPhdrs = pEpilog.m_pPhdrs;
- m_Epilog.m_pFillExp = pEpilog.m_pFillExp;
+ m_Epilog.m_pPhdrs = pEpilog.m_pPhdrs;
+ m_Epilog.m_pFillExp = pEpilog.m_pFillExp;
}
-void OutputSectDesc::activate(Module& pModule)
-{
+void OutputSectDesc::activate(Module& pModule) {
// Assignment in an output section
OutputSectCmds assignments;
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
switch ((*it)->getKind()) {
- case ScriptCommand::ASSIGNMENT:
- assignments.push_back(*it);
- break;
- case ScriptCommand::INPUT_SECT_DESC: {
- (*it)->activate(pModule);
-
- for (iterator assign = assignments.begin(), assignEnd = assignments.end();
- assign != assignEnd; ++assign) {
- (*assign)->activate(pModule);
+ case ScriptCommand::ASSIGNMENT:
+ assignments.push_back(*it);
+ break;
+ case ScriptCommand::INPUT_SECT_DESC: {
+ (*it)->activate(pModule);
+
+ for (iterator assign = assignments.begin(),
+ assignEnd = assignments.end();
+ assign != assignEnd;
+ ++assign) {
+ (*assign)->activate(pModule);
+ }
+ assignments.clear();
+ break;
}
- assignments.clear();
- break;
- }
- default:
- assert(0);
- break;
+ default:
+ assert(0);
+ break;
}
}
if (!assignments.empty()) {
- InputSectDesc::Spec spec;;
+ InputSectDesc::Spec spec;
spec.m_pWildcardFile = NULL;
spec.m_pExcludeFiles = NULL;
spec.m_pWildcardSections = NULL;
@@ -188,9 +188,12 @@ void OutputSectDesc::activate(Module& pModule)
pModule.getScript().sectionMap().insert(inputDesc, *this);
for (iterator assign = assignments.begin(), assignEnd = assignments.end();
- assign != assignEnd; ++assign) {
+ assign != assignEnd;
+ ++assign) {
(*assign)->activate(pModule);
}
assignments.clear();
}
}
+
+} // namespace mcld
diff --git a/lib/Script/RpnEvaluator.cpp b/lib/Script/RpnEvaluator.cpp
index 52cb79f..636a89a 100644
--- a/lib/Script/RpnEvaluator.cpp
+++ b/lib/Script/RpnEvaluator.cpp
@@ -6,103 +6,103 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Script/RpnEvaluator.h>
-#include <mcld/Script/ExprToken.h>
-#include <mcld/Script/Operator.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Module.h>
+#include "mcld/Script/RpnEvaluator.h"
+
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/Script/ExprToken.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/Operator.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Module.h"
+
#include <llvm/Support/Casting.h>
#include <llvm/Support/DataTypes.h>
+
#include <stack>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
RpnEvaluator::RpnEvaluator(const Module& pModule,
const TargetLDBackend& pBackend)
- : m_Module(pModule),
- m_Backend(pBackend)
-{
+ : m_Module(pModule), m_Backend(pBackend) {
}
-bool RpnEvaluator::eval(const RpnExpr& pExpr, uint64_t& pResult)
-{
+bool RpnEvaluator::eval(const RpnExpr& pExpr, uint64_t& pResult) {
std::stack<Operand*> operandStack;
for (RpnExpr::const_iterator it = pExpr.begin(), ie = pExpr.end(); it != ie;
- ++it) {
- switch((*it)->kind()) {
- case ExprToken::OPERATOR: {
- Operator* op = llvm::cast<Operator>(*it);
- switch (op->arity()) {
- case Operator::NULLARY: {
- operandStack.push(op->eval(m_Module, m_Backend));
- break;
- }
- case Operator::UNARY: {
- Operand* opd = operandStack.top();
- operandStack.pop();
- op->appendOperand(opd);
- operandStack.push(op->eval(m_Module, m_Backend));
- break;
- }
- case Operator::BINARY: {
- Operand* opd2 = operandStack.top();
- operandStack.pop();
- Operand* opd1 = operandStack.top();
- operandStack.pop();
- op->appendOperand(opd1);
- op->appendOperand(opd2);
- operandStack.push(op->eval(m_Module, m_Backend));
- break;
- }
- case Operator::TERNARY: {
- Operand* opd3 = operandStack.top();
- operandStack.pop();
- Operand* opd2 = operandStack.top();
- operandStack.pop();
- Operand* opd1 = operandStack.top();
- operandStack.pop();
- op->appendOperand(opd1);
- op->appendOperand(opd2);
- op->appendOperand(opd3);
- operandStack.push(op->eval(m_Module, m_Backend));
+ ++it) {
+ switch ((*it)->kind()) {
+ case ExprToken::OPERATOR: {
+ Operator* op = llvm::cast<Operator>(*it);
+ switch (op->arity()) {
+ case Operator::NULLARY: {
+ operandStack.push(op->eval(m_Module, m_Backend));
+ break;
+ }
+ case Operator::UNARY: {
+ Operand* opd = operandStack.top();
+ operandStack.pop();
+ op->appendOperand(opd);
+ operandStack.push(op->eval(m_Module, m_Backend));
+ break;
+ }
+ case Operator::BINARY: {
+ Operand* opd2 = operandStack.top();
+ operandStack.pop();
+ Operand* opd1 = operandStack.top();
+ operandStack.pop();
+ op->appendOperand(opd1);
+ op->appendOperand(opd2);
+ operandStack.push(op->eval(m_Module, m_Backend));
+ break;
+ }
+ case Operator::TERNARY: {
+ Operand* opd3 = operandStack.top();
+ operandStack.pop();
+ Operand* opd2 = operandStack.top();
+ operandStack.pop();
+ Operand* opd1 = operandStack.top();
+ operandStack.pop();
+ op->appendOperand(opd1);
+ op->appendOperand(opd2);
+ op->appendOperand(opd3);
+ operandStack.push(op->eval(m_Module, m_Backend));
+ break;
+ }
+ } // end of switch operator arity
break;
}
- } // end of switch operator arity
- break;
- }
- case ExprToken::OPERAND: {
- Operand* opd = llvm::cast<Operand>(*it);
- switch (opd->type()) {
- case Operand::SYMBOL: {
- // It's possible that there are no operators in an expression, so
- // we set up symbol operand here.
- if (!opd->isDot()) {
- SymOperand* sym_opd = llvm::cast<SymOperand>(opd);
- const LDSymbol* symbol =
- m_Module.getNamePool().findSymbol(sym_opd->name());
- if (symbol == NULL) {
- fatal(diag::fail_sym_resolution) << __FILE__ << __LINE__
- << "mclinker@googlegroups.com";
+ case ExprToken::OPERAND: {
+ Operand* opd = llvm::cast<Operand>(*it);
+ switch (opd->type()) {
+ case Operand::SYMBOL: {
+ // It's possible that there are no operators in an expression, so
+ // we set up symbol operand here.
+ if (!opd->isDot()) {
+ SymOperand* sym_opd = llvm::cast<SymOperand>(opd);
+ const LDSymbol* symbol =
+ m_Module.getNamePool().findSymbol(sym_opd->name());
+ if (symbol == NULL) {
+ fatal(diag::fail_sym_resolution) << __FILE__ << __LINE__
+ << "mclinker@googlegroups.com";
+ }
+ sym_opd->setValue(symbol->value());
+ }
+ operandStack.push(opd);
+ break;
}
- sym_opd->setValue(symbol->value());
- }
- operandStack.push(opd);
+ default:
+ operandStack.push(opd);
+ break;
+ } // end of switch operand type
break;
}
- default:
- operandStack.push(opd);
- break;
- } // end of switch operand type
- break;
- }
-
- } // end of switch
- } // end of for
+ } // end of switch
+ } // end of for
// stack top is result
assert(operandStack.top()->type() == Operand::SYMBOL ||
@@ -112,3 +112,4 @@ bool RpnEvaluator::eval(const RpnExpr& pExpr, uint64_t& pResult)
return true;
}
+} // namespace mcld
diff --git a/lib/Script/RpnExpr.cpp b/lib/Script/RpnExpr.cpp
index a9a4cae..51699e5 100644
--- a/lib/Script/RpnExpr.cpp
+++ b/lib/Script/RpnExpr.cpp
@@ -6,16 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Script/ExprToken.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/Operator.h>
-#include <mcld/Support/GCFactory.h>
-#include <mcld/Support/raw_ostream.h>
+#include "mcld/Script/RpnExpr.h"
+
+#include "mcld/Script/ExprToken.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/Operator.h"
+#include "mcld/Support/GCFactory.h"
+#include "mcld/Support/raw_ostream.h"
+
#include <llvm/Support/ManagedStatic.h>
#include <llvm/Support/Casting.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<RpnExpr, MCLD_SYMBOLS_PER_INPUT> ExprFactory;
static llvm::ManagedStatic<ExprFactory> g_ExprFactory;
@@ -23,16 +25,13 @@ static llvm::ManagedStatic<ExprFactory> g_ExprFactory;
//===----------------------------------------------------------------------===//
// RpnExpr
//===----------------------------------------------------------------------===//
-RpnExpr::RpnExpr()
-{
+RpnExpr::RpnExpr() {
}
-RpnExpr::~RpnExpr()
-{
+RpnExpr::~RpnExpr() {
}
-bool RpnExpr::hasDot() const
-{
+bool RpnExpr::hasDot() const {
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
if ((*it)->kind() == ExprToken::OPERAND &&
llvm::cast<Operand>(*it)->isDot())
@@ -41,52 +40,44 @@ bool RpnExpr::hasDot() const
return false;
}
-void RpnExpr::dump() const
-{
+void RpnExpr::dump() const {
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
(*it)->dump();
mcld::outs() << " ";
}
}
-void RpnExpr::push_back(ExprToken* pToken)
-{
+void RpnExpr::push_back(ExprToken* pToken) {
m_TokenQueue.push_back(pToken);
}
-RpnExpr* RpnExpr::create()
-{
+RpnExpr* RpnExpr::create() {
RpnExpr* result = g_ExprFactory->allocate();
new (result) RpnExpr();
return result;
}
-void RpnExpr::destroy(RpnExpr*& pRpnExpr)
-{
+void RpnExpr::destroy(RpnExpr*& pRpnExpr) {
g_ExprFactory->destroy(pRpnExpr);
g_ExprFactory->deallocate(pRpnExpr);
pRpnExpr = NULL;
}
-void RpnExpr::clear()
-{
+void RpnExpr::clear() {
g_ExprFactory->clear();
}
-RpnExpr::iterator RpnExpr::insert(iterator pPosition, ExprToken* pToken)
-{
+RpnExpr::iterator RpnExpr::insert(iterator pPosition, ExprToken* pToken) {
return m_TokenQueue.insert(pPosition, pToken);
}
-void RpnExpr::erase(iterator pPosition)
-{
+void RpnExpr::erase(iterator pPosition) {
m_TokenQueue.erase(pPosition);
}
// buildHelperExpr - build the helper expr:
// ADDR ( `output_sect' ) + SIZEOF ( `output_sect' )
-RpnExpr* RpnExpr::buildHelperExpr(SectionMap::iterator pIter)
-{
+RpnExpr* RpnExpr::buildHelperExpr(SectionMap::iterator pIter) {
RpnExpr* expr = RpnExpr::create();
expr->push_back(SectDescOperand::create(*pIter));
expr->push_back(&Operator::create<Operator::ADDR>());
@@ -97,9 +88,10 @@ RpnExpr* RpnExpr::buildHelperExpr(SectionMap::iterator pIter)
}
// buildHelperExpr - build the helper expr: `fragment'
-RpnExpr* RpnExpr::buildHelperExpr(Fragment& pFrag)
-{
+RpnExpr* RpnExpr::buildHelperExpr(Fragment& pFrag) {
RpnExpr* expr = RpnExpr::create();
expr->push_back(FragOperand::create(pFrag));
return expr;
}
+
+} // namespace mcld
diff --git a/lib/Script/ScriptCommand.cpp b/lib/Script/ScriptCommand.cpp
index e360645..a2d39af 100644
--- a/lib/Script/ScriptCommand.cpp
+++ b/lib/Script/ScriptCommand.cpp
@@ -6,14 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/ScriptCommand.h>
+#include "mcld/Script/ScriptCommand.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ScriptCommand
//===----------------------------------------------------------------------===//
-ScriptCommand::~ScriptCommand()
-{
+ScriptCommand::~ScriptCommand() {
}
+} // namespace mcld
diff --git a/lib/Script/ScriptFile.cpp b/lib/Script/ScriptFile.cpp
index 00a8056..7738866 100644
--- a/lib/Script/ScriptFile.cpp
+++ b/lib/Script/ScriptFile.cpp
@@ -6,36 +6,39 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/ScriptFile.h>
-#include <mcld/Script/StringList.h>
-#include <mcld/Script/ScriptCommand.h>
-#include <mcld/Script/EntryCmd.h>
-#include <mcld/Script/OutputFormatCmd.h>
-#include <mcld/Script/GroupCmd.h>
-#include <mcld/Script/OutputCmd.h>
-#include <mcld/Script/SearchDirCmd.h>
-#include <mcld/Script/OutputArchCmd.h>
-#include <mcld/Script/AssertCmd.h>
-#include <mcld/Script/SectionsCmd.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/StrToken.h>
-#include <mcld/MC/Input.h>
-#include <mcld/MC/InputBuilder.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/InputTree.h>
-#include <mcld/ADT/HashEntry.h>
-#include <mcld/ADT/HashTable.h>
-#include <mcld/ADT/StringHash.h>
+#include "mcld/Script/ScriptFile.h"
+
+#include "mcld/ADT/HashEntry.h"
+#include "mcld/ADT/HashTable.h"
+#include "mcld/ADT/StringHash.h"
+#include "mcld/Script/AssertCmd.h"
+#include "mcld/Script/EntryCmd.h"
+#include "mcld/Script/GroupCmd.h"
+#include "mcld/Script/InputCmd.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/OutputArchCmd.h"
+#include "mcld/Script/OutputCmd.h"
+#include "mcld/Script/OutputFormatCmd.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Script/ScriptCommand.h"
+#include "mcld/Script/SearchDirCmd.h"
+#include "mcld/Script/SectionsCmd.h"
+#include "mcld/Script/StringList.h"
+#include "mcld/Script/StrToken.h"
+#include "mcld/MC/Input.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/InputTree.h"
+
#include <llvm/Support/Casting.h>
#include <llvm/Support/ManagedStatic.h>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
-typedef HashEntry<std::string,
- void*,
- hash::StringCompare<std::string> > ParserStrEntry;
+typedef HashEntry<std::string, void*, hash::StringCompare<std::string> >
+ ParserStrEntry;
typedef HashTable<ParserStrEntry,
hash::StringHash<hash::DJB>,
EntryFactory<ParserStrEntry> > ParserStrPool;
@@ -45,46 +48,41 @@ static llvm::ManagedStatic<ParserStrPool> g_ParserStrPool;
// ScriptFile
//===----------------------------------------------------------------------===//
ScriptFile::ScriptFile(Kind pKind, Input& pInput, InputBuilder& pBuilder)
- : m_Kind(pKind),
- m_Input(pInput),
- m_Name(pInput.path().native()),
- m_pInputTree(NULL),
- m_Builder(pBuilder),
- m_bHasSectionsCmd(false),
- m_bInSectionsCmd(false),
- m_bInOutputSectDesc(false),
- m_pRpnExpr(NULL),
- m_pStringList(NULL),
- m_bAsNeeded(false)
-{
+ : m_Kind(pKind),
+ m_Input(pInput),
+ m_Name(pInput.path().native()),
+ m_pInputTree(NULL),
+ m_Builder(pBuilder),
+ m_bHasSectionsCmd(false),
+ m_bInSectionsCmd(false),
+ m_bInOutputSectDesc(false),
+ m_pRpnExpr(NULL),
+ m_pStringList(NULL),
+ m_bAsNeeded(false) {
// FIXME: move creation of input tree out of ScriptFile.
m_pInputTree = new InputTree();
}
-ScriptFile::~ScriptFile()
-{
+ScriptFile::~ScriptFile() {
for (iterator it = begin(), ie = end(); it != ie; ++it) {
if (*it != NULL)
delete *it;
}
- if (NULL != m_pInputTree)
+ if (m_pInputTree != NULL)
delete m_pInputTree;
}
-void ScriptFile::dump() const
-{
+void ScriptFile::dump() const {
for (const_iterator it = begin(), ie = end(); it != ie; ++it)
(*it)->dump();
}
-void ScriptFile::activate(Module& pModule)
-{
+void ScriptFile::activate(Module& pModule) {
for (const_iterator it = begin(), ie = end(); it != ie; ++it)
(*it)->activate(pModule);
}
-void ScriptFile::addEntryPoint(const std::string& pSymbol)
-{
+void ScriptFile::addEntryPoint(const std::string& pSymbol) {
EntryCmd* entry = new EntryCmd(pSymbol);
if (m_bInSectionsCmd) {
@@ -96,57 +94,63 @@ void ScriptFile::addEntryPoint(const std::string& pSymbol)
}
}
-void ScriptFile::addOutputFormatCmd(const std::string& pName)
-{
+void ScriptFile::addOutputFormatCmd(const std::string& pName) {
m_CommandQueue.push_back(new OutputFormatCmd(pName));
}
void ScriptFile::addOutputFormatCmd(const std::string& pDefault,
const std::string& pBig,
- const std::string& pLittle)
-{
+ const std::string& pLittle) {
m_CommandQueue.push_back(new OutputFormatCmd(pDefault, pBig, pLittle));
}
+void ScriptFile::addInputCmd(StringList& pStringList,
+ ObjectReader& pObjectReader,
+ ArchiveReader& pArchiveReader,
+ DynObjReader& pDynObjReader,
+ const LinkerConfig& pConfig) {
+ m_CommandQueue.push_back(new InputCmd(pStringList,
+ *m_pInputTree,
+ m_Builder,
+ pObjectReader,
+ pArchiveReader,
+ pDynObjReader,
+ pConfig));
+}
+
void ScriptFile::addGroupCmd(StringList& pStringList,
GroupReader& pGroupReader,
- const LinkerConfig& pConfig)
-{
- m_CommandQueue.push_back(
- new GroupCmd(pStringList, *m_pInputTree, m_Builder, pGroupReader, pConfig));
+ const LinkerConfig& pConfig) {
+ m_CommandQueue.push_back(new GroupCmd(
+ pStringList, *m_pInputTree, m_Builder, pGroupReader, pConfig));
}
-void ScriptFile::addOutputCmd(const std::string& pFileName)
-{
+void ScriptFile::addOutputCmd(const std::string& pFileName) {
m_CommandQueue.push_back(new OutputCmd(pFileName));
}
-void ScriptFile::addSearchDirCmd(const std::string& pPath)
-{
+void ScriptFile::addSearchDirCmd(const std::string& pPath) {
m_CommandQueue.push_back(new SearchDirCmd(pPath));
}
-void ScriptFile::addOutputArchCmd(const std::string& pArch)
-{
+void ScriptFile::addOutputArchCmd(const std::string& pArch) {
m_CommandQueue.push_back(new OutputArchCmd(pArch));
}
-void ScriptFile::addAssertCmd(RpnExpr& pRpnExpr, const std::string& pMessage)
-{
+void ScriptFile::addAssertCmd(RpnExpr& pRpnExpr, const std::string& pMessage) {
m_CommandQueue.push_back(new AssertCmd(pRpnExpr, pMessage));
}
void ScriptFile::addAssignment(const std::string& pSymbolName,
RpnExpr& pRpnExpr,
- Assignment::Type pType)
-{
+ Assignment::Type pType) {
if (m_bInSectionsCmd) {
assert(!m_CommandQueue.empty());
SectionsCmd* sections = llvm::cast<SectionsCmd>(back());
if (m_bInOutputSectDesc) {
assert(!sections->empty());
OutputSectDesc* output_desc =
- llvm::cast<OutputSectDesc>(sections->back());
+ llvm::cast<OutputSectDesc>(sections->back());
output_desc->push_back(new Assignment(Assignment::INPUT_SECTION,
pType,
*(SymOperand::create(pSymbolName)),
@@ -165,26 +169,22 @@ void ScriptFile::addAssignment(const std::string& pSymbolName,
}
}
-bool ScriptFile::hasSectionsCmd() const
-{
+bool ScriptFile::hasSectionsCmd() const {
return m_bHasSectionsCmd;
}
-void ScriptFile::enterSectionsCmd()
-{
+void ScriptFile::enterSectionsCmd() {
m_bHasSectionsCmd = true;
m_bInSectionsCmd = true;
m_CommandQueue.push_back(new SectionsCmd());
}
-void ScriptFile::leaveSectionsCmd()
-{
+void ScriptFile::leaveSectionsCmd() {
m_bInSectionsCmd = false;
}
void ScriptFile::enterOutputSectDesc(const std::string& pName,
- const OutputSectDesc::Prolog& pProlog)
-{
+ const OutputSectDesc::Prolog& pProlog) {
assert(!m_CommandQueue.empty());
assert(m_bInSectionsCmd);
SectionsCmd* sections = llvm::cast<SectionsCmd>(back());
@@ -193,8 +193,7 @@ void ScriptFile::enterOutputSectDesc(const std::string& pName,
m_bInOutputSectDesc = true;
}
-void ScriptFile::leaveOutputSectDesc(const OutputSectDesc::Epilog& pEpilog)
-{
+void ScriptFile::leaveOutputSectDesc(const OutputSectDesc::Epilog& pEpilog) {
assert(!m_CommandQueue.empty());
assert(m_bInSectionsCmd);
SectionsCmd* sections = llvm::cast<SectionsCmd>(back());
@@ -207,8 +206,7 @@ void ScriptFile::leaveOutputSectDesc(const OutputSectDesc::Epilog& pEpilog)
}
void ScriptFile::addInputSectDesc(InputSectDesc::KeepPolicy pPolicy,
- const InputSectDesc::Spec& pSpec)
-{
+ const InputSectDesc::Spec& pSpec) {
assert(!m_CommandQueue.empty());
assert(m_bInSectionsCmd);
SectionsCmd* sections = llvm::cast<SectionsCmd>(back());
@@ -219,34 +217,30 @@ void ScriptFile::addInputSectDesc(InputSectDesc::KeepPolicy pPolicy,
output_sect->push_back(new InputSectDesc(pPolicy, pSpec, *output_sect));
}
-RpnExpr* ScriptFile::createRpnExpr()
-{
+RpnExpr* ScriptFile::createRpnExpr() {
m_pRpnExpr = RpnExpr::create();
return m_pRpnExpr;
}
-StringList* ScriptFile::createStringList()
-{
+StringList* ScriptFile::createStringList() {
m_pStringList = StringList::create();
return m_pStringList;
}
-void ScriptFile::setAsNeeded(bool pEnable)
-{
+void ScriptFile::setAsNeeded(bool pEnable) {
m_bAsNeeded = pEnable;
}
const std::string& ScriptFile::createParserStr(const char* pText,
- size_t pLength)
-{
+ size_t pLength) {
bool exist = false;
ParserStrEntry* entry =
- g_ParserStrPool->insert(std::string(pText, pLength), exist);
+ g_ParserStrPool->insert(std::string(pText, pLength), exist);
return entry->key();
}
-void ScriptFile::clearParserStrPool()
-{
+void ScriptFile::clearParserStrPool() {
g_ParserStrPool->clear();
}
+} // namespace mcld
diff --git a/lib/Script/ScriptParser.yy b/lib/Script/ScriptParser.yy
index 745a4ef..0e32a44 100644
--- a/lib/Script/ScriptParser.yy
+++ b/lib/Script/ScriptParser.yy
@@ -9,16 +9,16 @@
%{
/* C/C++ Declarations */
-#include <mcld/Script/ScriptReader.h>
-#include <mcld/Script/ScriptScanner.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/Operator.h>
-#include <mcld/Script/Assignment.h>
-#include <mcld/Script/RpnExpr.h>
-#include <mcld/Script/FileToken.h>
-#include <mcld/Script/NameSpec.h>
-#include <mcld/Script/WildcardPattern.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/Script/ScriptReader.h"
+#include "mcld/Script/ScriptScanner.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/Operator.h"
+#include "mcld/Script/Assignment.h"
+#include "mcld/Script/RpnExpr.h"
+#include "mcld/Script/FileToken.h"
+#include "mcld/Script/NameSpec.h"
+#include "mcld/Script/WildcardPattern.h"
+#include "mcld/Support/MsgHandling.h"
using namespace mcld;
#undef yylex
@@ -26,10 +26,10 @@ using namespace mcld;
%}
%code requires {
-#include <mcld/Script/StrToken.h>
-#include <mcld/Script/StringList.h>
-#include <mcld/Script/OutputSectDesc.h>
-#include <mcld/Script/InputSectDesc.h>
+#include "mcld/Script/StrToken.h"
+#include "mcld/Script/StringList.h"
+#include "mcld/Script/OutputSectDesc.h"
+#include "mcld/Script/InputSectDesc.h"
#include <llvm/Support/DataTypes.h>
using namespace mcld;
@@ -50,6 +50,9 @@ using namespace mcld;
%parse-param { const class LinkerConfig& m_LDConfig }
%parse-param { class ScriptFile& m_ScriptFile }
%parse-param { class ScriptScanner& m_ScriptScanner }
+%parse-param { class ObjectReader& m_ObjectReader}
+%parse-param { class ArchiveReader& m_ArchiveReader}
+%parse-param { class DynObjReader& m_DynObjReader}
%parse-param { class GroupReader& m_GroupReader}
%lex-param { const class ScriptFile& m_ScriptFile }
@@ -215,6 +218,7 @@ linker_script : linker_script script_command
script_command : entry_command
| output_format_command
| group_command
+ | input_command
| output_command
| search_dir_command
| output_arch_command
@@ -238,6 +242,13 @@ group_command : GROUP '(' input_list ')'
{ m_ScriptFile.addGroupCmd(*$3, m_GroupReader, m_LDConfig); }
;
+input_command : INPUT '(' input_list ')'
+ {
+ m_ScriptFile.addInputCmd(*$3, m_ObjectReader, m_ArchiveReader,
+ m_DynObjReader, m_LDConfig);
+ }
+ ;
+
search_dir_command : SEARCH_DIR '(' STRING ')'
{ m_ScriptFile.addSearchDirCmd(*$3); }
;
diff --git a/lib/Script/ScriptReader.cpp b/lib/Script/ScriptReader.cpp
index 37c3ce9..00a766f 100644
--- a/lib/Script/ScriptReader.cpp
+++ b/lib/Script/ScriptReader.cpp
@@ -6,40 +6,42 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/ScriptReader.h>
-#include <mcld/Script/ScriptScanner.h>
-#include <mcld/Script/ScriptFile.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Support/MemoryArea.h>
+#include "mcld/Script/ScriptReader.h"
+
+#include "mcld/MC/Input.h"
+#include "mcld/Script/ScriptFile.h"
+#include "mcld/Script/ScriptScanner.h"
+#include "mcld/Support/MemoryArea.h"
#include <llvm/ADT/StringRef.h>
#include <istream>
#include <sstream>
-using namespace mcld;
+namespace mcld {
-ScriptReader::ScriptReader(GroupReader& pGroupReader)
- : m_GroupReader(pGroupReader)
-{
+ScriptReader::ScriptReader(ObjectReader& pObjectReader,
+ ArchiveReader& pArchiveReader,
+ DynObjReader& pDynObjReader,
+ GroupReader& pGroupReader)
+ : m_ObjectReader(pObjectReader),
+ m_ArchiveReader(pArchiveReader),
+ m_DynObjReader(pDynObjReader),
+ m_GroupReader(pGroupReader) {
}
-ScriptReader::~ScriptReader()
-{
+ScriptReader::~ScriptReader() {
}
/// isMyFormat
-bool ScriptReader::isMyFormat(Input& input, bool &doContinue) const
-{
+bool ScriptReader::isMyFormat(Input& input, bool& doContinue) const {
doContinue = true;
// always return true now
return true;
}
bool ScriptReader::readScript(const LinkerConfig& pConfig,
- ScriptFile& pScriptFile)
-{
- bool result = false;
+ ScriptFile& pScriptFile) {
Input& input = pScriptFile.input();
size_t size = input.memArea()->size();
llvm::StringRef region = input.memArea()->request(input.fileOffset(), size);
@@ -50,9 +52,11 @@ bool ScriptReader::readScript(const LinkerConfig& pConfig,
ScriptParser parser(pConfig,
pScriptFile,
scanner,
+ m_ObjectReader,
+ m_ArchiveReader,
+ m_DynObjReader,
m_GroupReader);
- result = (0 == parser.parse());;
-
- return result;
+ return parser.parse() == 0;
}
+} // namespace mcld
diff --git a/lib/Script/ScriptScanner.ll b/lib/Script/ScriptScanner.ll
index f3fd921..c1c3f74 100644
--- a/lib/Script/ScriptScanner.ll
+++ b/lib/Script/ScriptScanner.ll
@@ -10,9 +10,9 @@
%{
/* C/C++ Declarations */
-#include <mcld/Script/ScriptScanner.h>
-#include <mcld/Script/ScriptFile.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/Script/ScriptScanner.h"
+#include "mcld/Script/ScriptFile.h"
+#include "mcld/Support/MsgHandling.h"
#include <llvm/ADT/StringRef.h>
#include <string>
@@ -375,7 +375,7 @@ void ScriptScanner::popLexState()
}
}
-} /* namespace of mcld */
+} /* namespace mcld */
#ifdef yylex
#undef yylex
diff --git a/lib/Script/SearchDirCmd.cpp b/lib/Script/SearchDirCmd.cpp
index dd9a56f..53ec2dd 100644
--- a/lib/Script/SearchDirCmd.cpp
+++ b/lib/Script/SearchDirCmd.cpp
@@ -6,33 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/SearchDirCmd.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Module.h>
+#include "mcld/Script/SearchDirCmd.h"
-using namespace mcld;
+#include "mcld/Support/raw_ostream.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+
+namespace mcld {
//===----------------------------------------------------------------------===//
// SearchDirCmd
//===----------------------------------------------------------------------===//
SearchDirCmd::SearchDirCmd(const std::string& pPath)
- : ScriptCommand(ScriptCommand::SEARCH_DIR),
- m_Path(pPath)
-{
+ : ScriptCommand(ScriptCommand::SEARCH_DIR), m_Path(pPath) {
}
-SearchDirCmd::~SearchDirCmd()
-{
+SearchDirCmd::~SearchDirCmd() {
}
-void SearchDirCmd::dump() const
-{
+void SearchDirCmd::dump() const {
mcld::outs() << "SEARCH_DIR ( " << m_Path << " )\n";
}
-void SearchDirCmd::activate(Module& pModule)
-{
+void SearchDirCmd::activate(Module& pModule) {
pModule.getScript().directories().insert(m_Path);
}
+} // namespace mcld
diff --git a/lib/Script/SectionsCmd.cpp b/lib/Script/SectionsCmd.cpp
index 4ecc838..7978da4 100644
--- a/lib/Script/SectionsCmd.cpp
+++ b/lib/Script/SectionsCmd.cpp
@@ -6,89 +6,87 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/SectionsCmd.h>
-#include <mcld/Support/raw_ostream.h>
+#include "mcld/Script/SectionsCmd.h"
+
+#include "mcld/Support/raw_ostream.h"
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// SectionsCmd
//===----------------------------------------------------------------------===//
-SectionsCmd::SectionsCmd()
- : ScriptCommand(ScriptCommand::SECTIONS)
-{
+SectionsCmd::SectionsCmd() : ScriptCommand(ScriptCommand::SECTIONS) {
}
-SectionsCmd::~SectionsCmd()
-{
+SectionsCmd::~SectionsCmd() {
for (iterator it = begin(), ie = end(); it != ie; ++it) {
if (*it != NULL)
delete *it;
}
}
-void SectionsCmd::dump() const
-{
+void SectionsCmd::dump() const {
mcld::outs() << "SECTIONS\n{\n";
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
switch ((*it)->getKind()) {
- case ScriptCommand::ENTRY:
- case ScriptCommand::ASSIGNMENT:
- case ScriptCommand::OUTPUT_SECT_DESC:
- mcld::outs() << "\t";
- (*it)->dump();
- break;
- default:
- assert(0);
- break;
+ case ScriptCommand::ENTRY:
+ case ScriptCommand::ASSIGNMENT:
+ case ScriptCommand::OUTPUT_SECT_DESC:
+ mcld::outs() << "\t";
+ (*it)->dump();
+ break;
+ default:
+ assert(0);
+ break;
}
}
mcld::outs() << "}\n";
}
-void SectionsCmd::push_back(ScriptCommand* pCommand)
-{
+void SectionsCmd::push_back(ScriptCommand* pCommand) {
switch (pCommand->getKind()) {
- case ScriptCommand::ENTRY:
- case ScriptCommand::ASSIGNMENT:
- case ScriptCommand::OUTPUT_SECT_DESC:
- m_SectionCommands.push_back(pCommand);
- break;
- default:
- assert(0);
- break;
+ case ScriptCommand::ENTRY:
+ case ScriptCommand::ASSIGNMENT:
+ case ScriptCommand::OUTPUT_SECT_DESC:
+ m_SectionCommands.push_back(pCommand);
+ break;
+ default:
+ assert(0);
+ break;
}
}
-void SectionsCmd::activate(Module& pModule)
-{
+void SectionsCmd::activate(Module& pModule) {
// Assignment between output sections
SectionCommands assignments;
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
switch ((*it)->getKind()) {
- case ScriptCommand::ENTRY:
- (*it)->activate(pModule);
- break;
- case ScriptCommand::ASSIGNMENT:
- assignments.push_back(*it);
- break;
- case ScriptCommand::OUTPUT_SECT_DESC: {
- (*it)->activate(pModule);
+ case ScriptCommand::ENTRY:
+ (*it)->activate(pModule);
+ break;
+ case ScriptCommand::ASSIGNMENT:
+ assignments.push_back(*it);
+ break;
+ case ScriptCommand::OUTPUT_SECT_DESC: {
+ (*it)->activate(pModule);
- iterator assign, assignEnd = assignments.end();
- for (assign = assignments.begin(); assign != assignEnd; ++assign)
- (*assign)->activate(pModule);
- assignments.clear();
+ iterator assign, assignEnd = assignments.end();
+ for (assign = assignments.begin(); assign != assignEnd; ++assign)
+ (*assign)->activate(pModule);
+ assignments.clear();
- break;
- }
- default:
- assert(0);
- break;
+ break;
+ }
+ default:
+ assert(0);
+ break;
}
}
}
+
+} // namespace mcld
diff --git a/lib/Script/StrToken.cpp b/lib/Script/StrToken.cpp
index f886623..abcb78d 100644
--- a/lib/Script/StrToken.cpp
+++ b/lib/Script/StrToken.cpp
@@ -6,11 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/StrToken.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/Script/StrToken.h"
+
+#include "mcld/Support/GCFactory.h"
+
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<StrToken, MCLD_SYMBOLS_PER_INPUT> StrTokenFactory;
static llvm::ManagedStatic<StrTokenFactory> g_StrTokenFactory;
@@ -18,35 +20,30 @@ static llvm::ManagedStatic<StrTokenFactory> g_StrTokenFactory;
//===----------------------------------------------------------------------===//
// StrToken
//===----------------------------------------------------------------------===//
-StrToken::StrToken()
- : m_Kind(Unknown)
-{
+StrToken::StrToken() : m_Kind(Unknown) {
}
StrToken::StrToken(Kind pKind, const std::string& pString)
- : m_Kind(pKind), m_Name(pString)
-{
+ : m_Kind(pKind), m_Name(pString) {
}
-StrToken::~StrToken()
-{
+StrToken::~StrToken() {
}
-StrToken* StrToken::create(const std::string& pString)
-{
+StrToken* StrToken::create(const std::string& pString) {
StrToken* result = g_StrTokenFactory->allocate();
new (result) StrToken(String, pString);
return result;
}
-void StrToken::destroy(StrToken*& pStrToken)
-{
+void StrToken::destroy(StrToken*& pStrToken) {
g_StrTokenFactory->destroy(pStrToken);
g_StrTokenFactory->deallocate(pStrToken);
pStrToken = NULL;
}
-void StrToken::clear()
-{
+void StrToken::clear() {
g_StrTokenFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/Script/StringList.cpp b/lib/Script/StringList.cpp
index e5637fb..f52b68b 100644
--- a/lib/Script/StringList.cpp
+++ b/lib/Script/StringList.cpp
@@ -6,13 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/StringList.h>
-#include <mcld/Script/StrToken.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/Script/StringList.h"
+
+#include "mcld/Script/StrToken.h"
+#include "mcld/Support/GCFactory.h"
+#include "mcld/Support/raw_ostream.h"
+
#include <llvm/Support/ManagedStatic.h>
-using namespace mcld;
+namespace mcld {
typedef GCFactory<StringList, MCLD_SYMBOLS_PER_INPUT> StringListFactory;
static llvm::ManagedStatic<StringListFactory> g_StringListFactory;
@@ -20,41 +22,36 @@ static llvm::ManagedStatic<StringListFactory> g_StringListFactory;
//===----------------------------------------------------------------------===//
// StringList
//===----------------------------------------------------------------------===//
-StringList::StringList()
-{
+StringList::StringList() {
}
-StringList::~StringList()
-{
+StringList::~StringList() {
}
-void StringList::push_back(StrToken* pToken)
-{
+void StringList::push_back(StrToken* pToken) {
m_Tokens.push_back(pToken);
}
-void StringList::dump() const
-{
+void StringList::dump() const {
for (const_iterator it = begin(), ie = end(); it != ie; ++it)
mcld::outs() << (*it)->name() << "\t";
mcld::outs() << "\n";
}
-StringList* StringList::create()
-{
+StringList* StringList::create() {
StringList* result = g_StringListFactory->allocate();
new (result) StringList();
return result;
}
-void StringList::destroy(StringList*& pStringList)
-{
+void StringList::destroy(StringList*& pStringList) {
g_StringListFactory->destroy(pStringList);
g_StringListFactory->deallocate(pStringList);
pStringList = NULL;
}
-void StringList::clear()
-{
+void StringList::clear() {
g_StringListFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/Script/TernaryOp.cpp b/lib/Script/TernaryOp.cpp
index 131f460..12b889e 100644
--- a/lib/Script/TernaryOp.cpp
+++ b/lib/Script/TernaryOp.cpp
@@ -6,19 +6,20 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/TernaryOp.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/ADT/SizeTraits.h>
+#include "mcld/Script/TernaryOp.h"
+
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/Script/Operand.h"
+
+namespace mcld {
-using namespace mcld;
//===----------------------------------------------------------------------===//
// TernaryOp
//===----------------------------------------------------------------------===//
-template<>
-IntOperand*
-TernaryOp<Operator::TERNARY_IF>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* TernaryOp<Operator::TERNARY_IF>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
if (m_pOperand[0]->value())
res->setValue(m_pOperand[1]->value());
@@ -28,11 +29,10 @@ TernaryOp<Operator::TERNARY_IF>::eval(const Module& pModule,
}
/* DATA_SEGMENT_ALIGN(maxpagesize, commonpagesize) */
-template<>
-IntOperand*
-TernaryOp<Operator::DATA_SEGMENT_ALIGN>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* TernaryOp<Operator::DATA_SEGMENT_ALIGN>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
/* This is equivalent to either
(ALIGN(maxpagesize) + (. & (maxpagesize - 1)))
or
@@ -56,3 +56,4 @@ TernaryOp<Operator::DATA_SEGMENT_ALIGN>::eval(const Module& pModule,
return res;
}
+} // namespace mcld
diff --git a/lib/Script/UnaryOp.cpp b/lib/Script/UnaryOp.cpp
index 866bbb2..d18333d 100644
--- a/lib/Script/UnaryOp.cpp
+++ b/lib/Script/UnaryOp.cpp
@@ -6,183 +6,179 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/UnaryOp.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Object/SectionMap.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Module.h>
+#include "mcld/Script/UnaryOp.h"
+
+#include "mcld/LD/LDSection.h"
+#include "mcld/Object/SectionMap.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Module.h"
+
#include <llvm/Support/Casting.h>
+
#include <cassert>
-using namespace mcld;
+namespace mcld {
+
//===----------------------------------------------------------------------===//
// UnaryOp
//===----------------------------------------------------------------------===//
-template<>
-IntOperand* UnaryOp<Operator::UNARY_PLUS>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* UnaryOp<Operator::UNARY_PLUS>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
- res->setValue(+ m_pOperand->value());
+ res->setValue(+m_pOperand->value());
return res;
}
-template<>
-IntOperand*
-UnaryOp<Operator::UNARY_MINUS>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* UnaryOp<Operator::UNARY_MINUS>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
- res->setValue(- m_pOperand->value());
+ res->setValue(-m_pOperand->value());
return res;
}
-template<>
-IntOperand*
-UnaryOp<Operator::LOGICAL_NOT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* UnaryOp<Operator::LOGICAL_NOT>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
- res->setValue(! m_pOperand->value());
+ res->setValue(!m_pOperand->value());
return res;
}
-template<>
-IntOperand*
-UnaryOp<Operator::BITWISE_NOT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* UnaryOp<Operator::BITWISE_NOT>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
- res->setValue(~ m_pOperand->value());
+ res->setValue(~m_pOperand->value());
return res;
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::ABSOLUTE>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
// TODO
assert(0);
return result();
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::ADDR>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
const LDSection* sect = NULL;
switch (m_pOperand->type()) {
- case Operand::SECTION:
- sect = pModule.getSection(llvm::cast<SectOperand>(m_pOperand)->name());
- break;
- case Operand::SECTION_DESC:
- sect = llvm::cast<SectDescOperand>(m_pOperand)->outputDesc()->getSection();
- break;
- default:
- assert(0);
- break;
+ case Operand::SECTION:
+ sect = pModule.getSection(llvm::cast<SectOperand>(m_pOperand)->name());
+ break;
+ case Operand::SECTION_DESC:
+ sect =
+ llvm::cast<SectDescOperand>(m_pOperand)->outputDesc()->getSection();
+ break;
+ default:
+ assert(0);
+ break;
}
assert(sect != NULL);
res->setValue(sect->addr());
return res;
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::ALIGNOF>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
const LDSection* sect = NULL;
switch (m_pOperand->type()) {
- case Operand::SECTION:
- sect = pModule.getSection(llvm::cast<SectOperand>(m_pOperand)->name());
- break;
- case Operand::SECTION_DESC:
- sect = llvm::cast<SectDescOperand>(m_pOperand)->outputDesc()->getSection();
- break;
- default:
- assert(0);
- break;
+ case Operand::SECTION:
+ sect = pModule.getSection(llvm::cast<SectOperand>(m_pOperand)->name());
+ break;
+ case Operand::SECTION_DESC:
+ sect =
+ llvm::cast<SectDescOperand>(m_pOperand)->outputDesc()->getSection();
+ break;
+ default:
+ assert(0);
+ break;
}
assert(sect != NULL);
res->setValue(sect->align());
return res;
}
-template<>
-IntOperand*
-UnaryOp<Operator::DATA_SEGMENT_END>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+template <>
+IntOperand* UnaryOp<Operator::DATA_SEGMENT_END>::eval(
+ const Module& pModule,
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
res->setValue(m_pOperand->value());
return res;
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::DEFINED>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
// TODO
assert(0);
return result();
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::LENGTH>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
// TODO
assert(0);
return result();
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::LOADADDR>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
// TODO
assert(0);
return result();
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::NEXT>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
// TODO
assert(0);
return result();
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::ORIGIN>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
// TODO
assert(0);
return result();
}
-template<>
+template <>
IntOperand* UnaryOp<Operator::SIZEOF>::eval(const Module& pModule,
- const TargetLDBackend& pBackend)
-{
+ const TargetLDBackend& pBackend) {
IntOperand* res = result();
const LDSection* sect = NULL;
switch (m_pOperand->type()) {
- case Operand::SECTION:
- sect = pModule.getSection(llvm::cast<SectOperand>(m_pOperand)->name());
- break;
- case Operand::SECTION_DESC:
- sect = llvm::cast<SectDescOperand>(m_pOperand)->outputDesc()->getSection();
- break;
- default:
- assert(0);
- break;
+ case Operand::SECTION:
+ sect = pModule.getSection(llvm::cast<SectOperand>(m_pOperand)->name());
+ break;
+ case Operand::SECTION_DESC:
+ sect =
+ llvm::cast<SectDescOperand>(m_pOperand)->outputDesc()->getSection();
+ break;
+ default:
+ assert(0);
+ break;
}
assert(sect != NULL);
res->setValue(sect->size());
return res;
}
+
+} // namespace mcld
diff --git a/lib/Script/WildcardPattern.cpp b/lib/Script/WildcardPattern.cpp
index 035250e..7470edf 100644
--- a/lib/Script/WildcardPattern.cpp
+++ b/lib/Script/WildcardPattern.cpp
@@ -6,42 +6,39 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Script/WildcardPattern.h>
-#include <mcld/Support/raw_ostream.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/Script/WildcardPattern.h"
+
+#include "mcld/Support/GCFactory.h"
+#include "mcld/Support/raw_ostream.h"
+
#include <llvm/Support/ManagedStatic.h>
#include <cassert>
-using namespace mcld;
+namespace mcld {
-typedef GCFactory<WildcardPattern,
- MCLD_SYMBOLS_PER_INPUT> WildcardPatternFactory;
+typedef GCFactory<WildcardPattern, MCLD_SYMBOLS_PER_INPUT>
+ WildcardPatternFactory;
static llvm::ManagedStatic<WildcardPatternFactory> g_WildcardPatternFactory;
//===----------------------------------------------------------------------===//
// WildcardPattern
//===----------------------------------------------------------------------===//
-WildcardPattern::WildcardPattern()
- : m_bIsPrefix(false)
-{
+WildcardPattern::WildcardPattern() : m_bIsPrefix(false) {
}
WildcardPattern::WildcardPattern(const std::string& pPattern,
SortPolicy pPolicy)
- : StrToken(StrToken::Wildcard, pPattern), m_SortPolicy(pPolicy)
-{
+ : StrToken(StrToken::Wildcard, pPattern), m_SortPolicy(pPolicy) {
if (pPattern.find_first_of('*') == (pPattern.size() - 1))
m_bIsPrefix = true;
else
m_bIsPrefix = false;
}
-WildcardPattern::~WildcardPattern()
-{
+WildcardPattern::~WildcardPattern() {
}
-llvm::StringRef WildcardPattern::prefix() const
-{
+llvm::StringRef WildcardPattern::prefix() const {
if (isPrefix())
return llvm::StringRef(name().c_str(), name().size() - 1);
@@ -49,21 +46,20 @@ llvm::StringRef WildcardPattern::prefix() const
}
WildcardPattern* WildcardPattern::create(const std::string& pPattern,
- SortPolicy pPolicy)
-{
+ SortPolicy pPolicy) {
WildcardPattern* result = g_WildcardPatternFactory->allocate();
new (result) WildcardPattern(pPattern, pPolicy);
return result;
}
-void WildcardPattern::destroy(WildcardPattern*& pWildcardPattern)
-{
+void WildcardPattern::destroy(WildcardPattern*& pWildcardPattern) {
g_WildcardPatternFactory->destroy(pWildcardPattern);
g_WildcardPatternFactory->deallocate(pWildcardPattern);
pWildcardPattern = NULL;
}
-void WildcardPattern::clear()
-{
+void WildcardPattern::clear() {
g_WildcardPatternFactory->clear();
}
+
+} // namespace mcld
diff --git a/lib/Support/Android.mk b/lib/Support/Android.mk
index dfff7c9..ad36732 100644
--- a/lib/Support/Android.mk
+++ b/lib/Support/Android.mk
@@ -16,8 +16,7 @@ mcld_support_SRC_FILES := \
RealPath.cpp \
SystemUtils.cpp \
Target.cpp \
- TargetRegistry.cpp \
- ToolOutputFile.cpp
+ TargetRegistry.cpp
# For the host
# =====================================================
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp
index 033f88b..15e739c 100644
--- a/lib/Support/CommandLine.cpp
+++ b/lib/Support/CommandLine.cpp
@@ -6,44 +6,41 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/CommandLine.h>
+#include "mcld/Support/CommandLine.h"
#include <llvm/ADT/StringRef.h>
-#include <llvm/ADT/Twine.h>
#include <llvm/ADT/StringSwitch.h>
+#include <llvm/ADT/Twine.h>
#include <llvm/Support/ErrorHandling.h>
-using namespace llvm;
-using namespace llvm::cl;
-
-using namespace mcld;
-
static const size_t MaxOptWidth = 8; // arbitrary spacing for printOptionDiff
+namespace llvm {
+namespace cl {
+
//===----------------------------------------------------------------------===//
// SearchDirParser
//===----------------------------------------------------------------------===//
// parse - Return true on error.
-bool SearchDirParser::parse(Option &pOption,
+bool SearchDirParser::parse(Option& pOption,
StringRef pArgName,
StringRef pArg,
- std::string &pValue)
-{
+ std::string& pValue) {
char separator = *(pArgName.data() + 1);
- if ('=' == separator)
+ if (separator == '=')
pValue = '=';
pValue += pArg.str();
return false;
}
-void SearchDirParser::printOptionDiff(const Option &pOption,
+void SearchDirParser::printOptionDiff(const Option& pOption,
StringRef pValue,
OptVal pDefault,
- size_t pGlobalWidth) const
-{
+ size_t pGlobalWidth) const {
printOptionName(pOption, pGlobalWidth);
outs() << "= " << pValue;
- size_t NumSpaces = MaxOptWidth > pValue.size()?MaxOptWidth - pValue.size():0;
+ size_t NumSpaces =
+ MaxOptWidth > pValue.size() ? MaxOptWidth - pValue.size() : 0;
outs().indent(NumSpaces) << " (default: ";
if (pDefault.hasValue())
outs() << pDefault.getValue();
@@ -52,28 +49,26 @@ void SearchDirParser::printOptionDiff(const Option &pOption,
outs() << ")\n";
}
-void SearchDirParser::anchor()
-{
+void SearchDirParser::anchor() {
// do nothing
}
//===----------------------------------------------------------------------===//
// parser<mcld::sys::fs::Path>
//===----------------------------------------------------------------------===//
-bool parser<mcld::sys::fs::Path>::parse(llvm::cl::Option &O,
- llvm::StringRef ArgName,
- llvm::StringRef Arg,
- mcld::sys::fs::Path &Val)
-{
+bool parser<mcld::sys::fs::Path>::parse(llvm::cl::Option& O,
+ llvm::StringRef ArgName,
+ llvm::StringRef Arg,
+ mcld::sys::fs::Path& Val) {
Val.assign<llvm::StringRef::const_iterator>(Arg.begin(), Arg.end());
return false;
}
-void parser<mcld::sys::fs::Path>::printOptionDiff(const llvm::cl::Option &O,
- const mcld::sys::fs::Path &V,
- parser<mcld::sys::fs::Path>::OptVal Default,
- size_t GlobalWidth) const
-{
+void parser<mcld::sys::fs::Path>::printOptionDiff(
+ const llvm::cl::Option& O,
+ const mcld::sys::fs::Path& V,
+ parser<mcld::sys::fs::Path>::OptVal Default,
+ size_t GlobalWidth) const {
printOptionName(O, GlobalWidth);
outs() << "= " << V;
size_t VSize = V.native().size();
@@ -86,87 +81,84 @@ void parser<mcld::sys::fs::Path>::printOptionDiff(const llvm::cl::Option &O,
outs() << ")\n";
}
-void parser<mcld::sys::fs::Path>::anchor()
-{
+void parser<mcld::sys::fs::Path>::anchor() {
// do nothing
}
//===----------------------------------------------------------------------===//
// parser<mcld::ZOption>
//===----------------------------------------------------------------------===//
-bool parser<mcld::ZOption>::parse(llvm::cl::Option &O,
+bool parser<mcld::ZOption>::parse(llvm::cl::Option& O,
llvm::StringRef ArgName,
llvm::StringRef Arg,
- mcld::ZOption &Val)
-{
- if (0 == Arg.compare("combreloc"))
- Val.setKind(ZOption::CombReloc);
- else if (0 == Arg.compare("nocombreloc"))
- Val.setKind(ZOption::NoCombReloc);
- else if (0 == Arg.compare("defs"))
- Val.setKind(ZOption::Defs);
- else if (0 == Arg.compare("execstack"))
- Val.setKind(ZOption::ExecStack);
- else if (0 == Arg.compare("noexecstack"))
- Val.setKind(ZOption::NoExecStack);
- else if (0 == Arg.compare("initfirst"))
- Val.setKind(ZOption::InitFirst);
- else if (0 == Arg.compare("interpose"))
- Val.setKind(ZOption::InterPose);
- else if (0 == Arg.compare("loadfltr"))
- Val.setKind(ZOption::LoadFltr);
- else if (0 == Arg.compare("muldefs"))
- Val.setKind(ZOption::MulDefs);
- else if (0 == Arg.compare("nocopyreloc"))
- Val.setKind(ZOption::NoCopyReloc);
- else if (0 == Arg.compare("nodefaultlib"))
- Val.setKind(ZOption::NoDefaultLib);
- else if (0 == Arg.compare("nodelete"))
- Val.setKind(ZOption::NoDelete);
- else if (0 == Arg.compare("nodlopen"))
- Val.setKind(ZOption::NoDLOpen);
- else if (0 == Arg.compare("nodump"))
- Val.setKind(ZOption::NoDump);
- else if (0 == Arg.compare("relro"))
- Val.setKind(ZOption::Relro);
- else if (0 == Arg.compare("norelro"))
- Val.setKind(ZOption::NoRelro);
- else if (0 == Arg.compare("lazy"))
- Val.setKind(ZOption::Lazy);
- else if (0 == Arg.compare("now"))
- Val.setKind(ZOption::Now);
- else if (0 == Arg.compare("origin"))
- Val.setKind(ZOption::Origin);
+ mcld::ZOption& Val) {
+ if (Arg.equals("combreloc"))
+ Val.setKind(mcld::ZOption::CombReloc);
+ else if (Arg.equals("nocombreloc"))
+ Val.setKind(mcld::ZOption::NoCombReloc);
+ else if (Arg.equals("defs"))
+ Val.setKind(mcld::ZOption::Defs);
+ else if (Arg.equals("execstack"))
+ Val.setKind(mcld::ZOption::ExecStack);
+ else if (Arg.equals("noexecstack"))
+ Val.setKind(mcld::ZOption::NoExecStack);
+ else if (Arg.equals("initfirst"))
+ Val.setKind(mcld::ZOption::InitFirst);
+ else if (Arg.equals("interpose"))
+ Val.setKind(mcld::ZOption::InterPose);
+ else if (Arg.equals("loadfltr"))
+ Val.setKind(mcld::ZOption::LoadFltr);
+ else if (Arg.equals("muldefs"))
+ Val.setKind(mcld::ZOption::MulDefs);
+ else if (Arg.equals("nocopyreloc"))
+ Val.setKind(mcld::ZOption::NoCopyReloc);
+ else if (Arg.equals("nodefaultlib"))
+ Val.setKind(mcld::ZOption::NoDefaultLib);
+ else if (Arg.equals("nodelete"))
+ Val.setKind(mcld::ZOption::NoDelete);
+ else if (Arg.equals("nodlopen"))
+ Val.setKind(mcld::ZOption::NoDLOpen);
+ else if (Arg.equals("nodump"))
+ Val.setKind(mcld::ZOption::NoDump);
+ else if (Arg.equals("relro"))
+ Val.setKind(mcld::ZOption::Relro);
+ else if (Arg.equals("norelro"))
+ Val.setKind(mcld::ZOption::NoRelro);
+ else if (Arg.equals("lazy"))
+ Val.setKind(mcld::ZOption::Lazy);
+ else if (Arg.equals("now"))
+ Val.setKind(mcld::ZOption::Now);
+ else if (Arg.equals("origin"))
+ Val.setKind(mcld::ZOption::Origin);
else if (Arg.startswith("common-page-size=")) {
- Val.setKind(ZOption::CommPageSize);
+ Val.setKind(mcld::ZOption::CommPageSize);
long long unsigned size = 0;
Arg.drop_front(17).getAsInteger(0, size);
Val.setPageSize(static_cast<uint64_t>(size));
- }
- else if (Arg.startswith("max-page-size=")) {
- Val.setKind(ZOption::MaxPageSize);
+ } else if (Arg.startswith("max-page-size=")) {
+ Val.setKind(mcld::ZOption::MaxPageSize);
long long unsigned size = 0;
Arg.drop_front(14).getAsInteger(0, size);
Val.setPageSize(static_cast<uint64_t>(size));
}
- if (ZOption::Unknown == Val.kind())
- llvm::report_fatal_error(llvm::Twine("unknown -z option: `") +
- Arg +
+ if (mcld::ZOption::Unknown == Val.kind())
+ llvm::report_fatal_error(llvm::Twine("unknown -z option: `") + Arg +
llvm::Twine("'\n"));
return false;
}
-void parser<mcld::ZOption>::printOptionDiff(const llvm::cl::Option &O,
- const mcld::ZOption &V,
- parser<mcld::ZOption>::OptVal Default,
- size_t GlobalWidth) const
-{
+void parser<mcld::ZOption>::printOptionDiff(
+ const llvm::cl::Option& O,
+ const mcld::ZOption& V,
+ parser<mcld::ZOption>::OptVal Default,
+ size_t GlobalWidth) const {
// TODO
}
-void parser<mcld::ZOption>::anchor()
-{
+void parser<mcld::ZOption>::anchor() {
// do nothing
}
+} // namespace cl
+} // namespace llvm
diff --git a/lib/Support/Demangle.cpp b/lib/Support/Demangle.cpp
index 6db5c34..3a11e1d 100644
--- a/lib/Support/Demangle.cpp
+++ b/lib/Support/Demangle.cpp
@@ -6,9 +6,9 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Config/Config.h>
-#include <mcld/Support/CXADemangle.tcc>
-#include <mcld/Support/Demangle.h>
+#include "mcld/Config/Config.h"
+#include "mcld/Support/CXADemangle.tcc"
+#include "mcld/Support/Demangle.h"
#ifdef HAVE_CXXABI_H
#include <cxxabi.h>
@@ -26,9 +26,9 @@ std::string demangleName(const std::string& pName) {
// it into this helper function.
size_t output_leng;
int status;
- char* buffer = abi::__cxa_demangle(pName.c_str(), /*buffer=*/0,
- &output_leng, &status);
- if (status != 0) { // Failed
+ char* buffer =
+ abi::__cxa_demangle(pName.c_str(), /*buffer=*/0, &output_leng, &status);
+ if (status != 0) { // Failed
return pName;
}
std::string result(buffer);
@@ -40,8 +40,7 @@ std::string demangleName(const std::string& pName) {
#endif
}
-bool isCtorOrDtor(const char* pName, size_t pLength)
-{
+bool isCtorOrDtor(const char* pName, size_t pLength) {
arena<bs> a;
Db db(a);
db.cv = 0;
@@ -54,10 +53,8 @@ bool isCtorOrDtor(const char* pName, size_t pLength)
db.try_to_parse_template_args = true;
int internal_status = success;
demangle(pName, pName + pLength, db, internal_status);
- if (internal_status == success &&
- db.fix_forward_references &&
- !db.template_param.empty() &&
- !db.template_param.front().empty()) {
+ if (internal_status == success && db.fix_forward_references &&
+ !db.template_param.empty() && !db.template_param.front().empty()) {
db.fix_forward_references = false;
db.tag_templates = false;
db.names.clear();
@@ -73,4 +70,4 @@ bool isCtorOrDtor(const char* pName, size_t pLength)
return db.parsed_ctor_dtor_cv;
}
-} // namespace mcld
+} // namespace mcld
diff --git a/lib/Support/Directory.cpp b/lib/Support/Directory.cpp
index 20e974c..d13db10 100644
--- a/lib/Support/Directory.cpp
+++ b/lib/Support/Directory.cpp
@@ -6,86 +6,83 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Directory.h>
-#include <mcld/Support/FileSystem.h>
+#include "mcld/Support/Directory.h"
+#include "mcld/Support/FileSystem.h"
-using namespace mcld;
-using namespace mcld::sys::fs;
+namespace mcld {
+namespace sys {
+namespace fs {
-namespace { // anonymous
+namespace { // anonymous
-bool status_known(FileStatus f)
-{
+bool status_known(FileStatus f) {
return f.type() != StatusError;
}
-bool is_symlink(FileStatus f)
-{
+bool is_symlink(FileStatus f) {
return f.type() == SymlinkFile;
}
const Path dot_path(".");
const Path dot_dot_path("..");
-} // namespace of anonymous
+} // anonymous namespace
//===----------------------------------------------------------------------===//
// Directory
//===----------------------------------------------------------------------===//
Directory::Directory()
- : m_Path(),
- m_FileStatus(),
- m_SymLinkStatus(),
- m_Handler(0),
- m_Cache(),
- m_CacheFull(false) {
-}
-
-Directory::Directory(const Path& pPath,
- FileStatus st,
- FileStatus symlink_st)
- : m_Path(pPath),
- m_FileStatus(st),
- m_SymLinkStatus(symlink_st),
- m_Handler(0),
- m_Cache(),
- m_CacheFull(false) {
+ : m_Path(),
+ m_FileStatus(),
+ m_SymLinkStatus(),
+ m_Handler(0),
+ m_Cache(),
+ m_CacheFull(false) {
+}
+
+Directory::Directory(const Path& pPath, FileStatus st, FileStatus symlink_st)
+ : m_Path(pPath),
+ m_FileStatus(st),
+ m_SymLinkStatus(symlink_st),
+ m_Handler(0),
+ m_Cache(),
+ m_CacheFull(false) {
if (m_Path == dot_path)
detail::get_pwd(m_Path);
m_Path.m_append_separator_if_needed();
detail::open_dir(*this);
}
+Directory::Directory(const char* pPath, FileStatus st, FileStatus symlink_st)
+ : Directory(sys::fs::Path(pPath), st, symlink_st) {
+}
+
Directory::Directory(const Directory& pCopy)
- : m_Path(pCopy.m_Path),
- m_FileStatus(pCopy.m_FileStatus),
- m_SymLinkStatus(pCopy.m_SymLinkStatus),
- m_Handler(0),
- m_Cache(),
- m_CacheFull(false) {
+ : m_Path(pCopy.m_Path),
+ m_FileStatus(pCopy.m_FileStatus),
+ m_SymLinkStatus(pCopy.m_SymLinkStatus),
+ m_Handler(0),
+ m_Cache(),
+ m_CacheFull(false) {
detail::open_dir(*this);
}
-Directory::~Directory()
-{
+Directory::~Directory() {
detail::close_dir(*this);
}
-bool Directory::isGood() const
-{
+bool Directory::isGood() const {
return (0 != m_Handler);
}
-Directory& Directory::operator=(const Directory& pCopy)
-{
+Directory& Directory::operator=(const Directory& pCopy) {
assign(pCopy.m_Path, pCopy.m_FileStatus, pCopy.m_SymLinkStatus);
return *this;
}
void Directory::assign(const Path& pPath,
FileStatus st,
- FileStatus symlink_st)
-{
+ FileStatus symlink_st) {
if (isGood())
clear();
@@ -99,48 +96,39 @@ void Directory::assign(const Path& pPath,
detail::open_dir(*this);
}
-FileStatus Directory::status() const
-{
- if (!status_known(m_FileStatus))
- {
+FileStatus Directory::status() const {
+ if (!status_known(m_FileStatus)) {
// optimization: if the symlink status is known, and it isn't a symlink,
// then status and symlink_status are identical so just copy the
// symlink status to the regular status.
- if (status_known(m_SymLinkStatus)
- && !is_symlink(m_SymLinkStatus))
- {
+ if (status_known(m_SymLinkStatus) && !is_symlink(m_SymLinkStatus)) {
m_FileStatus = m_SymLinkStatus;
- }
- else detail::status(m_Path,m_FileStatus);
+ } else
+ detail::status(m_Path, m_FileStatus);
}
return m_FileStatus;
-
}
-FileStatus Directory::symlinkStatus() const
-{
+FileStatus Directory::symlinkStatus() const {
if (!status_known(m_SymLinkStatus))
- detail::symlink_status(m_Path,m_SymLinkStatus);
- return m_SymLinkStatus;
+ detail::symlink_status(m_Path, m_SymLinkStatus);
+ return m_SymLinkStatus;
}
-Directory::iterator Directory::begin()
-{
+Directory::iterator Directory::begin() {
if (m_CacheFull && m_Cache.empty())
return end();
PathCache::iterator iter = m_Cache.begin();
- if (NULL == iter.getEntry())
+ if (iter.getEntry() == NULL)
++iter;
return iterator(this, iter);
}
-Directory::iterator Directory::end()
-{
+Directory::iterator Directory::end() {
return iterator(0, m_Cache.end());
}
-void Directory::clear()
-{
+void Directory::clear() {
m_Path.native().clear();
m_FileStatus = FileStatus();
m_SymLinkStatus = FileStatus();
@@ -152,46 +140,40 @@ void Directory::clear()
// DirIterator
DirIterator::DirIterator(Directory* pParent,
const DirIterator::DirCache::iterator& pIter)
- : m_pParent(pParent),
- m_Iter(pIter) {
+ : m_pParent(pParent), m_Iter(pIter) {
m_pEntry = m_Iter.getEntry();
}
DirIterator::DirIterator(const DirIterator& pCopy)
- : m_pParent(pCopy.m_pParent),
- m_Iter(pCopy.m_Iter),
- m_pEntry(pCopy.m_pEntry) {
+ : m_pParent(pCopy.m_pParent),
+ m_Iter(pCopy.m_Iter),
+ m_pEntry(pCopy.m_pEntry) {
}
-DirIterator::~DirIterator()
-{
+DirIterator::~DirIterator() {
}
-Path* DirIterator::path()
-{
- if (NULL == m_pParent)
+Path* DirIterator::path() {
+ if (m_pParent == NULL)
return NULL;
return &m_pEntry->value();
}
-const Path* DirIterator::path() const
-{
- if (NULL == m_pParent)
+const Path* DirIterator::path() const {
+ if (m_pParent == NULL)
return NULL;
return &m_pEntry->value();
}
-DirIterator& DirIterator::operator=(const DirIterator& pCopy)
-{
+DirIterator& DirIterator::operator=(const DirIterator& pCopy) {
m_pParent = pCopy.m_pParent;
m_Iter = pCopy.m_Iter;
m_pEntry = pCopy.m_pEntry;
return (*this);
}
-DirIterator& DirIterator::operator++()
-{
- if (0 == m_pParent)
+DirIterator& DirIterator::operator++() {
+ if (m_pParent == 0)
return *this;
// move forward one step first.
@@ -200,7 +182,7 @@ DirIterator& DirIterator::operator++()
if (m_pParent->m_Cache.end() == m_Iter) {
if (!m_pParent->m_CacheFull) {
m_pEntry = detail::bring_one_into_cache(*this);
- if (0 == m_pEntry && m_pParent->m_CacheFull)
+ if (m_pEntry == 0 && m_pParent->m_CacheFull)
m_pParent = 0;
return *this;
}
@@ -212,8 +194,7 @@ DirIterator& DirIterator::operator++()
return *this;
}
-DirIterator DirIterator::operator++(int)
-{
+DirIterator DirIterator::operator++(int pIn) {
DirIterator tmp(*this);
// move forward one step first.
@@ -222,7 +203,7 @@ DirIterator DirIterator::operator++(int)
if (m_pParent->m_Cache.end() == m_Iter) {
if (!m_pParent->m_CacheFull) {
m_pEntry = detail::bring_one_into_cache(*this);
- if (0 == m_pEntry && m_pParent->m_CacheFull)
+ if (m_pEntry == 0 && m_pParent->m_CacheFull)
m_pParent = 0;
return tmp;
}
@@ -234,23 +215,24 @@ DirIterator DirIterator::operator++(int)
return tmp;
}
-bool DirIterator::operator==(const DirIterator& y) const
-{
+bool DirIterator::operator==(const DirIterator& y) const {
if (m_pParent != y.m_pParent)
return false;
- if (0 == m_pParent)
+ if (m_pParent == 0)
return true;
const Path* x_path = path();
const Path* y_path = y.path();
- if (0 == x_path && 0 == y_path)
+ if (x_path == 0 && y_path == 0)
return true;
- if (0 == x_path || 0 == y_path)
+ if (x_path == 0 || y_path == 0)
return false;
return (*x_path == *y_path);
}
-bool DirIterator::operator!=(const DirIterator& y) const
-{
+bool DirIterator::operator!=(const DirIterator& y) const {
return !this->operator==(y);
}
+} // namespace fs
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/FileHandle.cpp b/lib/Support/FileHandle.cpp
index 9c79598..e0494e8 100644
--- a/lib/Support/FileHandle.cpp
+++ b/lib/Support/FileHandle.cpp
@@ -7,40 +7,39 @@
//
//===----------------------------------------------------------------------===//
#include "mcld/Config/Config.h"
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/FileSystem.h>
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/FileSystem.h"
+
#include <errno.h>
#if defined(HAVE_UNISTD_H)
-# include <unistd.h>
+#include <unistd.h>
#endif
#if defined(HAVE_FCNTL_H)
-# include <fcntl.h>
+#include <fcntl.h>
#endif
#include <sys/stat.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// FileHandle
//===----------------------------------------------------------------------===//
FileHandle::FileHandle()
- : m_Path(),
- m_Handler(-1),
- m_Size(0),
- m_State(GoodBit),
- m_OpenMode(NotOpen) {
+ : m_Path(),
+ m_Handler(-1),
+ m_Size(0),
+ m_State(GoodBit),
+ m_OpenMode(NotOpen) {
}
-FileHandle::~FileHandle()
-{
+FileHandle::~FileHandle() {
if (isOpened())
close();
}
-inline static int oflag(FileHandle::OpenMode pMode)
-{
+inline static int oflag(FileHandle::OpenMode pMode) {
int result = 0x0;
if (FileHandle::Unknown == pMode)
return result;
@@ -64,8 +63,7 @@ inline static int oflag(FileHandle::OpenMode pMode)
return result;
}
-inline static bool get_size(int pHandler, unsigned int &pSize)
-{
+inline static bool get_size(int pHandler, unsigned int& pSize) {
struct ::stat file_stat;
if (-1 == ::fstat(pHandler, &file_stat)) {
pSize = 0;
@@ -77,8 +75,7 @@ inline static bool get_size(int pHandler, unsigned int &pSize)
bool FileHandle::open(const sys::fs::Path& pPath,
FileHandle::OpenMode pMode,
- FileHandle::Permission pPerm)
-{
+ FileHandle::Permission pPerm) {
if (isOpened() || Unknown == pMode) {
setState(BadBit);
return false;
@@ -88,11 +85,12 @@ bool FileHandle::open(const sys::fs::Path& pPath,
if (System == pPerm)
m_Handler = sys::fs::detail::open(pPath, oflag(pMode));
else
- m_Handler = sys::fs::detail::open(pPath, oflag(pMode), (int)pPerm);
+ m_Handler = sys::fs::detail::open(pPath, oflag(pMode),
+ static_cast<int>(pPerm));
m_Path = pPath;
- if (-1 == m_Handler) {
- m_OpenMode = NotOpen;
+ if (m_Handler == -1) {
+ m_OpenMode = OpenMode(NotOpen);
setState(FailBit);
return false;
}
@@ -105,15 +103,14 @@ bool FileHandle::open(const sys::fs::Path& pPath,
return true;
}
-bool FileHandle::delegate(int pFD, FileHandle::OpenMode pMode)
-{
+bool FileHandle::delegate(int pFD, FileHandle::OpenModeEnum pMode) {
if (isOpened()) {
setState(BadBit);
return false;
}
m_Handler = pFD;
- m_OpenMode = pMode;
+ m_OpenMode = OpenMode(pMode);
m_State = (GoodBit | DeputedBit);
if (!get_size(m_Handler, m_Size)) {
@@ -124,15 +121,14 @@ bool FileHandle::delegate(int pFD, FileHandle::OpenMode pMode)
return true;
}
-bool FileHandle::close()
-{
+bool FileHandle::close() {
if (!isOpened()) {
setState(BadBit);
return false;
}
if (isOwned()) {
- if (-1 == ::close(m_Handler)) {
+ if (::close(m_Handler) == -1) {
setState(FailBit);
return false;
}
@@ -140,19 +136,18 @@ bool FileHandle::close()
m_Path.native().clear();
m_Size = 0;
- m_OpenMode = NotOpen;
+ m_OpenMode = OpenMode(NotOpen);
cleanState();
return true;
}
-bool FileHandle::truncate(size_t pSize)
-{
+bool FileHandle::truncate(size_t pSize) {
if (!isOpened() || !isWritable()) {
setState(BadBit);
return false;
}
- if (-1 == sys::fs::detail::ftruncate(m_Handler, pSize)) {
+ if (sys::fs::detail::ftruncate(m_Handler, pSize) == -1) {
setState(FailBit);
return false;
}
@@ -161,22 +156,19 @@ bool FileHandle::truncate(size_t pSize)
return true;
}
-bool FileHandle::read(void* pMemBuffer, size_t pStartOffset, size_t pLength)
-{
+bool FileHandle::read(void* pMemBuffer, size_t pStartOffset, size_t pLength) {
if (!isOpened() || !isReadable()) {
setState(BadBit);
return false;
}
- if (0 == pLength)
+ if (pLength == 0)
return true;
- ssize_t read_bytes = sys::fs::detail::pread(m_Handler,
- pMemBuffer,
- pLength,
- pStartOffset);
+ ssize_t read_bytes =
+ sys::fs::detail::pread(m_Handler, pMemBuffer, pLength, pStartOffset);
- if (-1 == read_bytes) {
+ if (read_bytes == -1) {
setState(FailBit);
return false;
}
@@ -184,23 +176,21 @@ bool FileHandle::read(void* pMemBuffer, size_t pStartOffset, size_t pLength)
return true;
}
-bool FileHandle::write(const void* pMemBuffer, size_t pStartOffset, size_t pLength)
-{
+bool FileHandle::write(const void* pMemBuffer,
+ size_t pStartOffset,
+ size_t pLength) {
if (!isOpened() || !isWritable()) {
setState(BadBit);
return false;
}
- if (0 == pLength)
+ if (pLength == 0)
return true;
+ ssize_t write_bytes =
+ sys::fs::detail::pwrite(m_Handler, pMemBuffer, pLength, pStartOffset);
- ssize_t write_bytes = sys::fs::detail::pwrite(m_Handler,
- pMemBuffer,
- pLength,
- pStartOffset);
-
- if (-1 == write_bytes) {
+ if (write_bytes == -1) {
setState(FailBit);
return false;
}
@@ -208,59 +198,50 @@ bool FileHandle::write(const void* pMemBuffer, size_t pStartOffset, size_t pLeng
return true;
}
-void FileHandle::setState(FileHandle::IOState pState)
-{
+void FileHandle::setState(FileHandle::IOState pState) {
m_State |= pState;
}
-void FileHandle::cleanState(FileHandle::IOState pState)
-{
+void FileHandle::cleanState(FileHandle::IOState pState) {
m_State = pState;
}
-bool FileHandle::isOpened() const
-{
- if (-1 != m_Handler && m_OpenMode != NotOpen && isGood())
+bool FileHandle::isOpened() const {
+ if (m_Handler != -1 && m_OpenMode != NotOpen && isGood())
return true;
return false;
}
// Assume Unknown OpenMode is readable
-bool FileHandle::isReadable() const
-{
+bool FileHandle::isReadable() const {
return (m_OpenMode & ReadOnly);
}
// Assume Unknown OpenMode is writable
-bool FileHandle::isWritable() const
-{
+bool FileHandle::isWritable() const {
return (m_OpenMode & WriteOnly);
}
// Assume Unknown OpenMode is both readable and writable
-bool FileHandle::isReadWrite() const
-{
+bool FileHandle::isReadWrite() const {
return (FileHandle::ReadWrite == (m_OpenMode & FileHandle::ReadWrite));
}
-bool FileHandle::isGood() const
-{
+bool FileHandle::isGood() const {
return !(m_State & (BadBit | FailBit));
}
-bool FileHandle::isBad() const
-{
+bool FileHandle::isBad() const {
return (m_State & BadBit);
}
-bool FileHandle::isFailed() const
-{
+bool FileHandle::isFailed() const {
return (m_State & (BadBit | FailBit));
}
-bool FileHandle::isOwned() const
-{
+bool FileHandle::isOwned() const {
return !(m_State & DeputedBit);
}
+} // namespace mcld
diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp
index 4887e6b..11435ea 100644
--- a/lib/Support/FileOutputBuffer.cpp
+++ b/lib/Support/FileOutputBuffer.cpp
@@ -1,4 +1,4 @@
-//===- FileOutputBuffer.cpp ------------------------------------------------===//
+//===- FileOutputBuffer.cpp -----------------------------------------------===//
//
// The MCLinker Project
//
@@ -6,36 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/FileOutputBuffer.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/Path.h>
+#include "mcld/Support/FileOutputBuffer.h"
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/Path.h"
-using namespace mcld;
-using llvm::sys::fs::mapped_file_region;
+namespace mcld {
FileOutputBuffer::FileOutputBuffer(llvm::sys::fs::mapped_file_region* pRegion,
FileHandle& pFileHandle)
- : m_pRegion(pRegion), m_FileHandle(pFileHandle)
-{
+ : m_pRegion(pRegion), m_FileHandle(pFileHandle) {
}
-FileOutputBuffer::~FileOutputBuffer()
-{
+FileOutputBuffer::~FileOutputBuffer() {
// Unmap buffer, letting OS flush dirty pages to file on disk.
m_pRegion.reset(0);
}
-std::error_code FileOutputBuffer::create(FileHandle& pFileHandle,
- size_t pSize, std::unique_ptr<FileOutputBuffer>& pResult)
-{
+std::error_code FileOutputBuffer::create(
+ FileHandle& pFileHandle,
+ size_t pSize,
+ std::unique_ptr<FileOutputBuffer>& pResult) {
std::error_code ec;
- std::unique_ptr<mapped_file_region> mapped_file(new mapped_file_region(
- pFileHandle.handler(),
- false,
- mapped_file_region::readwrite,
- pSize,
- 0,
- ec));
+ std::unique_ptr<llvm::sys::fs::mapped_file_region> mapped_file(
+ new llvm::sys::fs::mapped_file_region(pFileHandle.handler(),
+ false, llvm::sys::fs::mapped_file_region::readwrite, pSize, 0, ec));
if (ec)
return ec;
@@ -46,14 +40,14 @@ std::error_code FileOutputBuffer::create(FileHandle& pFileHandle,
return std::error_code();
}
-MemoryRegion FileOutputBuffer::request(size_t pOffset, size_t pLength)
-{
+MemoryRegion FileOutputBuffer::request(size_t pOffset, size_t pLength) {
if (pOffset > getBufferSize() || (pOffset + pLength) > getBufferSize())
return MemoryRegion();
return MemoryRegion(getBufferStart() + pOffset, pLength);
}
-llvm::StringRef FileOutputBuffer::getPath() const
-{
+llvm::StringRef FileOutputBuffer::getPath() const {
return m_FileHandle.path().native();
}
+
+} // namespace mcld
diff --git a/lib/Support/FileSystem.cpp b/lib/Support/FileSystem.cpp
index aaed86b..8986356 100644
--- a/lib/Support/FileSystem.cpp
+++ b/lib/Support/FileSystem.cpp
@@ -6,23 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Config/Config.h>
-#include <mcld/Support/FileSystem.h>
-#include <mcld/Support/Path.h>
+#include "mcld/Config/Config.h"
+#include "mcld/Support/FileSystem.h"
+#include "mcld/Support/Path.h"
//===----------------------------------------------------------------------===//
// non-member functions
//===----------------------------------------------------------------------===//
-bool mcld::sys::fs::exists(const Path &pPath)
-{
+bool mcld::sys::fs::exists(const Path& pPath) {
mcld::sys::fs::FileStatus file_status;
mcld::sys::fs::detail::status(pPath, file_status);
return (file_status.type() != mcld::sys::fs::StatusError) &&
(file_status.type() != mcld::sys::fs::FileNotFound);
}
-bool mcld::sys::fs::is_directory(const Path &pPath)
-{
+bool mcld::sys::fs::is_directory(const Path& pPath) {
FileStatus file_status;
detail::status(pPath, file_status);
return (file_status.type() == mcld::sys::fs::DirectoryFile);
diff --git a/lib/Support/LEB128.cpp b/lib/Support/LEB128.cpp
index 02d7f24..9907e2b 100644
--- a/lib/Support/LEB128.cpp
+++ b/lib/Support/LEB128.cpp
@@ -6,15 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/LEB128.h>
+#include "mcld/Support/LEB128.h"
namespace mcld {
namespace leb128 {
//===---------------------- LEB128 Encoding APIs -------------------------===//
-template<>
-size_t encode<uint64_t>(ByteType *&pBuf, uint64_t pValue) {
+template <>
+size_t encode<uint64_t>(ByteType*& pBuf, uint64_t pValue) {
size_t size = 0;
do {
ByteType byte = pValue & 0x7f;
@@ -32,39 +32,39 @@ size_t encode<uint64_t>(ByteType *&pBuf, uint64_t pValue) {
* Fast version for encoding 32-bit integer. This unrolls the loop in the
* generic version defined above.
*/
-template<>
-size_t encode<uint32_t>(ByteType *&pBuf, uint32_t pValue) {
+template <>
+size_t encode<uint32_t>(ByteType*& pBuf, uint32_t pValue) {
if ((pValue & ~0x7f) == 0) {
*pBuf++ = static_cast<ByteType>(pValue);
return 1;
- } else if ((pValue & ~0x3fff) == 0){
- *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>((pValue >> 7) & 0x7f);
+ } else if ((pValue & ~0x3fff) == 0) {
+ *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>((pValue >> 7) & 0x7f);
return 2;
} else if ((pValue & ~0x1fffff) == 0) {
- *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>(((pValue >> 7) & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>((pValue >> 14) & 0x7f);
+ *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>(((pValue >> 7) & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>((pValue >> 14) & 0x7f);
return 3;
} else if ((pValue & ~0xfffffff) == 0) {
- *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>(((pValue >> 7) & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>(((pValue >> 7) & 0x7f) | 0x80);
*pBuf++ = static_cast<ByteType>(((pValue >> 14) & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>((pValue >> 21) & 0x7f);
+ *pBuf++ = static_cast<ByteType>((pValue >> 21) & 0x7f);
return 4;
} else {
- *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>(((pValue >> 7) & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>((pValue & 0x7f) | 0x80);
+ *pBuf++ = static_cast<ByteType>(((pValue >> 7) & 0x7f) | 0x80);
*pBuf++ = static_cast<ByteType>(((pValue >> 14) & 0x7f) | 0x80);
*pBuf++ = static_cast<ByteType>(((pValue >> 21) & 0x7f) | 0x80);
- *pBuf++ = static_cast<ByteType>((pValue >> 28) & 0x7f);
+ *pBuf++ = static_cast<ByteType>((pValue >> 28) & 0x7f);
return 5;
}
// unreachable
}
-template<>
-size_t encode<int64_t>(ByteType *&pBuf, int64_t pValue) {
+template <>
+size_t encode<int64_t>(ByteType*& pBuf, int64_t pValue) {
size_t size = 0;
bool more = true;
@@ -72,7 +72,7 @@ size_t encode<int64_t>(ByteType *&pBuf, int64_t pValue) {
ByteType byte = pValue & 0x7f;
pValue >>= 7;
- if (((pValue == 0) && ((byte & 0x40) == 0)) ||
+ if (((pValue == 0) && ((byte & 0x40) == 0)) ||
((pValue == -1) && ((byte & 0x40) == 0x40)))
more = false;
else
@@ -85,15 +85,15 @@ size_t encode<int64_t>(ByteType *&pBuf, int64_t pValue) {
return size;
}
-template<>
-size_t encode<int32_t>(ByteType *&pBuf, int32_t pValue) {
+template <>
+size_t encode<int32_t>(ByteType*& pBuf, int32_t pValue) {
return encode<int64_t>(pBuf, static_cast<int64_t>(pValue));
}
//===---------------------- LEB128 Decoding APIs -------------------------===//
-template<>
-uint64_t decode<uint64_t>(const ByteType *pBuf, size_t &pSize) {
+template <>
+uint64_t decode<uint64_t>(const ByteType* pBuf, size_t& pSize) {
uint64_t result = 0;
if ((*pBuf & 0x80) == 0) {
@@ -101,19 +101,15 @@ uint64_t decode<uint64_t>(const ByteType *pBuf, size_t &pSize) {
return *pBuf;
} else if ((*(pBuf + 1) & 0x80) == 0) {
pSize = 2;
- return ((*(pBuf + 1) & 0x7f) << 7) |
- (*pBuf & 0x7f);
+ return ((*(pBuf + 1) & 0x7f) << 7) | (*pBuf & 0x7f);
} else if ((*(pBuf + 2) & 0x80) == 0) {
pSize = 3;
- return ((*(pBuf + 2) & 0x7f) << 14) |
- ((*(pBuf + 1) & 0x7f) << 7) |
+ return ((*(pBuf + 2) & 0x7f) << 14) | ((*(pBuf + 1) & 0x7f) << 7) |
(*pBuf & 0x7f);
} else {
pSize = 4;
- result = ((*(pBuf + 3) & 0x7f) << 21) |
- ((*(pBuf + 2) & 0x7f) << 14) |
- ((*(pBuf + 1) & 0x7f) << 7) |
- (*pBuf & 0x7f);
+ result = ((*(pBuf + 3) & 0x7f) << 21) | ((*(pBuf + 2) & 0x7f) << 14) |
+ ((*(pBuf + 1) & 0x7f) << 7) | (*pBuf & 0x7f);
}
if ((*(pBuf + 3) & 0x80) != 0) {
@@ -136,8 +132,8 @@ uint64_t decode<uint64_t>(const ByteType *pBuf, size_t &pSize) {
return result;
}
-template<>
-uint64_t decode<uint64_t>(const ByteType *&pBuf) {
+template <>
+uint64_t decode<uint64_t>(const ByteType*& pBuf) {
ByteType byte;
uint64_t result;
@@ -147,7 +143,7 @@ uint64_t decode<uint64_t>(const ByteType *&pBuf) {
return result;
} else {
byte = *pBuf++;
- result |= ((byte & 0x7f) << 7);
+ result |= ((byte & 0x7f) << 7);
if ((byte & 0x80) == 0) {
return result;
} else {
@@ -184,8 +180,8 @@ uint64_t decode<uint64_t>(const ByteType *&pBuf) {
* bit if necessary. This is rarely used, therefore we don't provide unrolling
* version like decode() to save the code size.
*/
-template<>
-int64_t decode<int64_t>(const ByteType *pBuf, size_t &pSize) {
+template <>
+int64_t decode<int64_t>(const ByteType* pBuf, size_t& pSize) {
uint64_t result = 0;
ByteType byte;
unsigned shift = 0;
@@ -205,8 +201,8 @@ int64_t decode<int64_t>(const ByteType *pBuf, size_t &pSize) {
return result;
}
-template<>
-int64_t decode<int64_t>(const ByteType *&pBuf) {
+template <>
+int64_t decode<int64_t>(const ByteType*& pBuf) {
uint64_t result = 0;
ByteType byte;
unsigned shift = 0;
@@ -224,5 +220,5 @@ int64_t decode<int64_t>(const ByteType *&pBuf) {
return result;
}
-} // namespace of leb128
-} // namespace of mcld
+} // namespace leb128
+} // namespace mcld
diff --git a/lib/Support/MemoryArea.cpp b/lib/Support/MemoryArea.cpp
index d796283..c494355 100644
--- a/lib/Support/MemoryArea.cpp
+++ b/lib/Support/MemoryArea.cpp
@@ -6,47 +6,44 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
#include <llvm/Support/ErrorOr.h>
#include <cassert>
#include <system_error>
-using namespace mcld;
+namespace mcld {
//===--------------------------------------------------------------------===//
// MemoryArea
//===--------------------------------------------------------------------===//
-MemoryArea::MemoryArea(llvm::StringRef pFilename)
-{
- llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer_or_error =
- llvm::MemoryBuffer::getFile(pFilename, /*FileSize*/ -1,
+MemoryArea::MemoryArea(llvm::StringRef pFilename) {
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer> > buffer_or_error =
+ llvm::MemoryBuffer::getFile(pFilename,
+ /*FileSize*/ -1,
/*RequiresNullTerminator*/ false);
- if (std::error_code ec = buffer_or_error.getError()) {
- (void) ec;
+ if (!buffer_or_error) {
fatal(diag::fatal_cannot_read_input) << pFilename.str();
}
m_pMemoryBuffer = std::move(buffer_or_error.get());
}
-MemoryArea::MemoryArea(const char* pMemBuffer, size_t pSize)
-{
+MemoryArea::MemoryArea(const char* pMemBuffer, size_t pSize) {
llvm::StringRef mem(pMemBuffer, pSize);
- llvm::MemoryBuffer* buffer =
- llvm::MemoryBuffer::getMemBuffer(mem, /*BufferName*/ "NaN",
+ m_pMemoryBuffer =
+ llvm::MemoryBuffer::getMemBuffer(mem,
+ /*BufferName*/ "NaN",
/*RequiresNullTerminator*/ false);
- assert(buffer != NULL);
- m_pMemoryBuffer.reset(buffer);
}
-llvm::StringRef MemoryArea::request(size_t pOffset, size_t pLength)
-{
+llvm::StringRef MemoryArea::request(size_t pOffset, size_t pLength) {
return llvm::StringRef(m_pMemoryBuffer->getBufferStart() + pOffset, pLength);
}
-size_t MemoryArea::size() const
-{
+size_t MemoryArea::size() const {
return m_pMemoryBuffer->getBufferSize();
}
+
+} // namespace mcld
diff --git a/lib/Support/MemoryAreaFactory.cpp b/lib/Support/MemoryAreaFactory.cpp
index 655c525..66496d3 100644
--- a/lib/Support/MemoryAreaFactory.cpp
+++ b/lib/Support/MemoryAreaFactory.cpp
@@ -6,26 +6,24 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/MemoryAreaFactory.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/SystemUtils.h>
+#include "mcld/Support/MemoryAreaFactory.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/SystemUtils.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// MemoryAreaFactory
//===----------------------------------------------------------------------===//
MemoryAreaFactory::MemoryAreaFactory(size_t pNum)
- : GCFactory<MemoryArea, 0>(pNum) {
+ : GCFactory<MemoryArea, 0>(pNum) {
}
-MemoryAreaFactory::~MemoryAreaFactory()
-{
+MemoryAreaFactory::~MemoryAreaFactory() {
}
MemoryArea* MemoryAreaFactory::produce(const sys::fs::Path& pPath,
- FileHandle::OpenMode pMode)
-{
+ FileHandle::OpenMode pMode) {
llvm::StringRef name(pPath.native());
if (m_AreaMap.find(name) == m_AreaMap.end()) {
MemoryArea* result = allocate();
@@ -39,8 +37,7 @@ MemoryArea* MemoryAreaFactory::produce(const sys::fs::Path& pPath,
MemoryArea* MemoryAreaFactory::produce(const sys::fs::Path& pPath,
FileHandle::OpenMode pMode,
- FileHandle::Permission pPerm)
-{
+ FileHandle::Permission pPerm) {
llvm::StringRef name(pPath.native());
if (m_AreaMap.find(name) == m_AreaMap.end()) {
MemoryArea* result = allocate();
@@ -52,8 +49,7 @@ MemoryArea* MemoryAreaFactory::produce(const sys::fs::Path& pPath,
return m_AreaMap[name];
}
-MemoryArea* MemoryAreaFactory::produce(void* pMemBuffer, size_t pSize)
-{
+MemoryArea* MemoryAreaFactory::produce(void* pMemBuffer, size_t pSize) {
const char* base = reinterpret_cast<const char*>(pMemBuffer);
llvm::StringRef name(base, pSize);
if (m_AreaMap.find(name) == m_AreaMap.end()) {
@@ -66,14 +62,14 @@ MemoryArea* MemoryAreaFactory::produce(void* pMemBuffer, size_t pSize)
return m_AreaMap[name];
}
-MemoryArea* MemoryAreaFactory::produce(int pFD, FileHandle::OpenMode pMode)
-{
+MemoryArea* MemoryAreaFactory::produce(int pFD, FileHandle::OpenMode pMode) {
// TODO
return NULL;
}
-void MemoryAreaFactory::destruct(MemoryArea* pArea)
-{
+void MemoryAreaFactory::destruct(MemoryArea* pArea) {
destroy(pArea);
deallocate(pArea);
}
+
+} // namespace mcld
diff --git a/lib/Support/MsgHandling.cpp b/lib/Support/MsgHandling.cpp
index fdcf13f..e2a7dfe 100644
--- a/lib/Support/MsgHandling.cpp
+++ b/lib/Support/MsgHandling.cpp
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/DiagnosticEngine.h>
-#include <mcld/LD/DiagnosticLineInfo.h>
-#include <mcld/LD/DiagnosticPrinter.h>
-#include <mcld/LD/TextDiagnosticPrinter.h>
-#include <mcld/LD/MsgHandler.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/raw_ostream.h>
+#include "mcld/LD/DiagnosticEngine.h"
+#include "mcld/LD/DiagnosticLineInfo.h"
+#include "mcld/LD/DiagnosticPrinter.h"
+#include "mcld/LD/MsgHandler.h"
+#include "mcld/LD/TextDiagnosticPrinter.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/raw_ostream.h"
#include <llvm/Support/ManagedStatic.h>
#include <llvm/Support/raw_ostream.h>
@@ -20,35 +20,33 @@
#include <cstdlib>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// static variables
//===----------------------------------------------------------------------===//
static llvm::ManagedStatic<DiagnosticEngine> g_pEngine;
-void
-mcld::InitializeDiagnosticEngine(const mcld::LinkerConfig& pConfig,
- DiagnosticPrinter* pPrinter)
-{
+void InitializeDiagnosticEngine(const LinkerConfig& pConfig,
+ DiagnosticPrinter* pPrinter) {
g_pEngine->reset(pConfig);
- if (NULL != pPrinter)
+ if (pPrinter != NULL)
g_pEngine->setPrinter(*pPrinter, false);
else {
- DiagnosticPrinter* printer = new TextDiagnosticPrinter(mcld::errs(), pConfig);
+ DiagnosticPrinter* printer =
+ new TextDiagnosticPrinter(errs(), pConfig);
g_pEngine->setPrinter(*printer, true);
}
}
-DiagnosticEngine& mcld::getDiagnosticEngine()
-{
+DiagnosticEngine& getDiagnosticEngine() {
return *g_pEngine;
}
-bool mcld::Diagnose()
-{
+bool Diagnose() {
if (g_pEngine->getPrinter()->getNumErrors() > 0) {
- // If we reached here, we are failing ungracefully. Run the interrupt handlers
+ // If we reached here, we are failing ungracefully. Run the interrupt
+ // handlers
// to make sure any special cleanups get done, in particular that we remove
// files registered with RemoveFileOnSignal.
llvm::sys::RunInterruptHandlers();
@@ -58,8 +56,8 @@ bool mcld::Diagnose()
return true;
}
-void mcld::FinalizeDiagnosticEngine()
-{
+void FinalizeDiagnosticEngine() {
g_pEngine->getPrinter()->finish();
}
+} // namespace mcld
diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp
index 57d4bd8..1f6b1a5 100644
--- a/lib/Support/Path.cpp
+++ b/lib/Support/Path.cpp
@@ -6,146 +6,133 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Config/Config.h>
-#include <mcld/Support/FileSystem.h>
-#include <mcld/Support/Path.h>
+#include "mcld/Support/Path.h"
+
+#include "mcld/Config/Config.h"
+#include "mcld/Support/FileSystem.h"
+
#include <llvm/ADT/StringRef.h>
-#include <locale>
-#include <string.h>
#include <istream>
+#include <locale>
#include <ostream>
+#include <string.h>
-using namespace mcld;
-using namespace mcld::sys::fs;
+namespace mcld {
+namespace sys {
+namespace fs {
//===--------------------------------------------------------------------===//
// Helper
//===--------------------------------------------------------------------===//
namespace {
#if defined(MCLD_ON_WIN32)
-bool is_separator(char value)
-{
+bool is_separator(char value) {
return (value == separator || value == preferred_separator);
}
const Path::StringType separator_str("/");
#else
-bool is_separator(char value)
-{
+bool is_separator(char value) {
return (value == separator);
}
const Path::StringType separator_str("/");
#endif
-} // anonymous namespace
-
+} // anonymous namespace
//===--------------------------------------------------------------------===//
// Path
//===--------------------------------------------------------------------===//
-Path::Path()
- : m_PathName() {
+Path::Path() : m_PathName() {
}
-Path::Path(const Path::ValueType* s )
- : m_PathName(s) {
+Path::Path(const Path::ValueType* s) : m_PathName(s) {
}
-Path::Path(const Path::StringType &s )
- : m_PathName(s) {
+Path::Path(const Path::StringType& s) : m_PathName(s) {
}
-Path::Path(const Path& pCopy)
- : m_PathName(pCopy.m_PathName) {
+Path::Path(const Path& pCopy) : m_PathName(pCopy.m_PathName) {
}
-Path::~Path()
-{
+Path::~Path() {
}
-bool Path::isFromRoot() const
-{
+bool Path::isFromRoot() const {
if (m_PathName.empty())
return false;
return (separator == m_PathName[0]);
}
-bool Path::isFromPWD() const
-{
- if (2 > m_PathName.size())
+bool Path::isFromPWD() const {
+ if (m_PathName.size() < 2)
return false;
return ('.' == m_PathName[0] && separator == m_PathName[1]);
}
-Path& Path::assign(const Path::StringType &s)
-{
+Path& Path::assign(const Path::StringType& s) {
m_PathName.assign(s);
return *this;
}
-Path& Path::assign(const Path::ValueType* s, unsigned int length)
-{
- if (0 == s || 0 == length)
+Path& Path::assign(const Path::ValueType* s, unsigned int length) {
+ if (s == 0 || length == 0)
assert(0 && "assign a null or empty string to Path");
m_PathName.assign(s, length);
return *this;
}
-//a,/b a/,b a/,b/ a,b is a/b
-Path& Path::append(const Path& pPath)
-{
- //first path is a/,second path is /b
- if(m_PathName[m_PathName.length()-1] == separator &&
- pPath.native()[0] == separator) {
- unsigned int old_size = m_PathName.size()-1;
- unsigned int new_size = old_size + pPath.native().size();
-
- m_PathName.resize(new_size);
- strcpy(const_cast<ValueType*>(m_PathName.data()+old_size), pPath.native().data());
- }
- //first path is a,second path is b
- else if(this->native()[this->native().size()-1] != separator &&
- pPath.native()[0] != separator) {
+// a,/b a/,b a/,b/ a,b is a/b
+Path& Path::append(const Path& pPath) {
+ // first path is a/,second path is /b
+ if (m_PathName[m_PathName.length() - 1] == separator &&
+ pPath.native()[0] == separator) {
+ llvm::StringRef path(pPath.native());
+ m_PathName.append(path.begin() + 1, path.end());
+ } else if (this->native()[this->native().size() - 1] != separator &&
+ pPath.native()[0] != separator) {
+ // first path is a,second path is b
m_PathName.append(separator_str);
m_PathName.append(pPath.native());
- }
- // a/,b or a,/b just append
- else {
+ } else {
+ // a/,b or a,/b just append
m_PathName.append(pPath.native());
}
return *this;
}
-bool Path::empty() const
-{
+// a,/b a/,b a/,b/ a,b is a/b
+Path& Path::append(const StringType& pPath) {
+ Path path(pPath);
+ this->append(path);
+ return *this;
+}
+
+bool Path::empty() const {
return m_PathName.empty();
}
-Path::StringType Path::generic_string() const
-{
+Path::StringType Path::generic_string() const {
StringType result = m_PathName;
detail::canonicalize(result);
return result;
}
-bool Path::canonicalize()
-{
+bool Path::canonicalize() {
return detail::canonicalize(m_PathName);
}
-Path::StringType::size_type Path::m_append_separator_if_needed()
-{
+Path::StringType::size_type Path::m_append_separator_if_needed() {
#if defined(MCLD_ON_WIN32)
// On Windows platform, path can not append separator.
return 0;
#endif
StringType::value_type last_char = m_PathName[m_PathName.size() - 1];
- if (!m_PathName.empty() &&
- !is_separator(last_char)) {
+ if (!m_PathName.empty() && !is_separator(last_char)) {
StringType::size_type tmp(m_PathName.size());
m_PathName += separator_str;
return tmp;
@@ -153,11 +140,10 @@ Path::StringType::size_type Path::m_append_separator_if_needed()
return 0;
}
-void Path::m_erase_redundant_separator(Path::StringType::size_type pSepPos)
-{
- size_t begin=pSepPos;
+void Path::m_erase_redundant_separator(Path::StringType::size_type pSepPos) {
+ size_t begin = pSepPos;
// skip '/' or '\\'
- while(separator == m_PathName[pSepPos]) {
+ while (separator == m_PathName[pSepPos]) {
#if defined(MCLD_ON_WIN32)
pSepPos += 2;
#else
@@ -165,20 +151,18 @@ void Path::m_erase_redundant_separator(Path::StringType::size_type pSepPos)
#endif
}
- if(begin!=pSepPos)
- m_PathName.erase(begin+1,pSepPos-begin-1);
+ if (begin != pSepPos)
+ m_PathName.erase(begin + 1, pSepPos - begin - 1);
}
-Path Path::parent_path() const
-{
+Path Path::parent_path() const {
size_t end_pos = m_PathName.find_last_of(separator);
if (end_pos != StringType::npos)
return Path(m_PathName.substr(0, end_pos));
return Path();
}
-Path Path::filename() const
-{
+Path Path::filename() const {
size_t pos = m_PathName.find_last_of(separator);
if (pos != StringType::npos) {
++pos;
@@ -187,16 +171,14 @@ Path Path::filename() const
return Path(*this);
}
-Path Path::stem() const
-{
- size_t begin_pos = m_PathName.find_last_of(separator)+1;
- size_t end_pos = m_PathName.find_last_of(dot);
+Path Path::stem() const {
+ size_t begin_pos = m_PathName.find_last_of(separator) + 1;
+ size_t end_pos = m_PathName.find_last_of(dot);
Path result_path(m_PathName.substr(begin_pos, end_pos - begin_pos));
return result_path;
}
-Path Path::extension() const
-{
+Path Path::extension() const {
size_t pos = m_PathName.find_last_of('.');
if (pos == StringType::npos)
return Path();
@@ -206,20 +188,20 @@ Path Path::extension() const
//===--------------------------------------------------------------------===//
// non-member functions
//===--------------------------------------------------------------------===//
-bool mcld::sys::fs::operator==(const Path& pLHS,const Path& pRHS)
-{
- return (pLHS.generic_string()==pRHS.generic_string());
+bool operator==(const Path& pLHS, const Path& pRHS) {
+ return (pLHS.generic_string() == pRHS.generic_string());
}
-bool mcld::sys::fs::operator!=(const Path& pLHS,const Path& pRHS)
-{
- return !(pLHS==pRHS);
+bool operator!=(const Path& pLHS, const Path& pRHS) {
+ return !(pLHS == pRHS);
}
-Path mcld::sys::fs::operator+(const Path& pLHS, const Path& pRHS)
-{
+Path operator+(const Path& pLHS, const Path& pRHS) {
mcld::sys::fs::Path result = pLHS;
result.append(pRHS);
return result;
}
+} // namespace fs
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/RealPath.cpp b/lib/Support/RealPath.cpp
index b62f443..bac06be 100644
--- a/lib/Support/RealPath.cpp
+++ b/lib/Support/RealPath.cpp
@@ -9,45 +9,39 @@
#include "mcld/Support/RealPath.h"
#include "mcld/Support/FileSystem.h"
-using namespace mcld::sys::fs;
+namespace mcld {
+namespace sys {
+namespace fs {
//==========================
// RealPath
-RealPath::RealPath()
- : Path() {
+RealPath::RealPath() : Path() {
}
-RealPath::RealPath(const RealPath::ValueType* s )
- : Path(s) {
+RealPath::RealPath(const RealPath::ValueType* s) : Path(s) {
initialize();
}
-RealPath::RealPath(const RealPath::StringType &s )
- : Path(s) {
+RealPath::RealPath(const RealPath::StringType& s) : Path(s) {
initialize();
}
-RealPath::RealPath(const Path& pPath)
- : Path(pPath) {
+RealPath::RealPath(const Path& pPath) : Path(pPath) {
initialize();
}
-RealPath::~RealPath()
-{
+RealPath::~RealPath() {
}
-RealPath& RealPath::assign(const Path& pPath)
-{
+RealPath& RealPath::assign(const Path& pPath) {
Path::m_PathName.assign(pPath.native());
return (*this);
}
-void RealPath::initialize()
-{
+void RealPath::initialize() {
if (isFromRoot()) {
detail::canonicalize(m_PathName);
- }
- else if (isFromPWD()) {
+ } else if (isFromPWD()) {
Path path_name;
detail::get_pwd(path_name);
path_name.native() += preferred_separator;
@@ -57,3 +51,6 @@ void RealPath::initialize()
}
}
+} // namespace fs
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/SystemUtils.cpp b/lib/Support/SystemUtils.cpp
index b261db8..b80f5eb 100644
--- a/lib/Support/SystemUtils.cpp
+++ b/lib/Support/SystemUtils.cpp
@@ -7,9 +7,7 @@
//
//===----------------------------------------------------------------------===//
#include "mcld/Config/Config.h"
-#include <mcld/Support/SystemUtils.h>
-
-using namespace mcld::sys;
+#include "mcld/Support/SystemUtils.h"
//===----------------------------------------------------------------------===//
// Non-member functions
diff --git a/lib/Support/Target.cpp b/lib/Support/Target.cpp
index d0e5f29..945598c 100644
--- a/lib/Support/Target.cpp
+++ b/lib/Support/Target.cpp
@@ -6,76 +6,70 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Target.h>
+#include "mcld/Support/Target.h"
+
#include <llvm/ADT/Triple.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Target
//===----------------------------------------------------------------------===//
Target::Target()
- : Name(NULL),
- TripleMatchQualityFn(NULL),
- TargetMachineCtorFn(NULL),
- MCLinkerCtorFn(NULL),
- TargetLDBackendCtorFn(NULL),
- DiagnosticLineInfoCtorFn(NULL) {
+ : Name(NULL),
+ TripleMatchQualityFn(NULL),
+ TargetMachineCtorFn(NULL),
+ MCLinkerCtorFn(NULL),
+ TargetLDBackendCtorFn(NULL),
+ DiagnosticLineInfoCtorFn(NULL) {
}
-unsigned int Target::getTripleQuality(const llvm::Triple& pTriple) const
-{
- if (NULL == TripleMatchQualityFn)
+unsigned int Target::getTripleQuality(const llvm::Triple& pTriple) const {
+ if (TripleMatchQualityFn == NULL)
return 0;
return TripleMatchQualityFn(pTriple);
}
-MCLDTargetMachine*
-Target::createTargetMachine(const std::string& pTriple,
- const llvm::Target& pTarget,
- llvm::TargetMachine& pTM) const
-{
- if (NULL == TargetMachineCtorFn)
+MCLDTargetMachine* Target::createTargetMachine(const std::string& pTriple,
+ const llvm::Target& pTarget,
+ llvm::TargetMachine& pTM) const {
+ if (TargetMachineCtorFn == NULL)
return NULL;
return TargetMachineCtorFn(pTarget, *this, pTM, pTriple);
}
/// createMCLinker - create target-specific MCLinker
-MCLinker*
-Target::createMCLinker(const std::string &pTriple,
- LinkerConfig& pConfig,
- Module& pModule,
- FileHandle& pFileHandle) const
-{
- if (NULL == MCLinkerCtorFn)
+MCLinker* Target::createMCLinker(const std::string& pTriple,
+ LinkerConfig& pConfig,
+ Module& pModule,
+ FileHandle& pFileHandle) const {
+ if (MCLinkerCtorFn == NULL)
return NULL;
return MCLinkerCtorFn(pTriple, pConfig, pModule, pFileHandle);
}
/// emulate - given MCLinker default values for the other aspects of the
/// target system.
-bool Target::emulate(LinkerScript& pScript, LinkerConfig& pConfig) const
-{
- if (NULL == EmulationFn)
+bool Target::emulate(LinkerScript& pScript, LinkerConfig& pConfig) const {
+ if (EmulationFn == NULL)
return false;
return EmulationFn(pScript, pConfig);
}
/// createLDBackend - create target-specific LDBackend
-TargetLDBackend* Target::createLDBackend(const LinkerConfig& pConfig) const
-{
- if (NULL == TargetLDBackendCtorFn)
- return NULL;
- return TargetLDBackendCtorFn(pConfig);
+TargetLDBackend* Target::createLDBackend(const LinkerConfig& pConfig) const {
+ if (TargetLDBackendCtorFn == NULL)
+ return NULL;
+ return TargetLDBackendCtorFn(pConfig);
}
/// createDiagnosticLineInfo - create target-specific DiagnosticLineInfo
-DiagnosticLineInfo*
-Target::createDiagnosticLineInfo(const mcld::Target& pTarget,
- const std::string& pTriple) const
-{
- if (NULL == DiagnosticLineInfoCtorFn)
+DiagnosticLineInfo* Target::createDiagnosticLineInfo(
+ const mcld::Target& pTarget,
+ const std::string& pTriple) const {
+ if (DiagnosticLineInfoCtorFn == NULL)
return NULL;
return DiagnosticLineInfoCtorFn(pTarget, pTriple);
}
+} // namespace mcld
diff --git a/lib/Support/TargetRegistry.cpp b/lib/Support/TargetRegistry.cpp
index afffc5c..75fd3fc 100644
--- a/lib/Support/TargetRegistry.cpp
+++ b/lib/Support/TargetRegistry.cpp
@@ -6,9 +6,9 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/Support/TargetRegistry.h"
-using namespace mcld;
+namespace mcld {
TargetRegistry::TargetListTy mcld::TargetRegistry::s_TargetList;
@@ -17,48 +17,45 @@ TargetRegistry::TargetListTy mcld::TargetRegistry::s_TargetList;
//===----------------------------------------------------------------------===//
void TargetRegistry::RegisterTarget(Target& pTarget,
const char* pName,
- Target::TripleMatchQualityFnTy pQualityFn)
-{
+ Target::TripleMatchQualityFnTy pQualityFn) {
pTarget.Name = pName;
pTarget.TripleMatchQualityFn = pQualityFn;
s_TargetList.push_back(&pTarget);
}
-const Target* TargetRegistry::lookupTarget(const std::string &pTriple,
- std::string &pError)
-{
+const Target* TargetRegistry::lookupTarget(const std::string& pTriple,
+ std::string& pError) {
if (empty()) {
pError = "Unable to find target for this triple (no target are registered)";
return NULL;
}
llvm::Triple triple(pTriple);
- Target* best = NULL, *ambiguity = NULL;
+ Target* best = NULL, * ambiguity = NULL;
unsigned int highest = 0;
for (iterator target = begin(), ie = end(); target != ie; ++target) {
unsigned int quality = (*target)->getTripleQuality(triple);
if (quality > 0) {
- if (NULL == best || highest < quality) {
+ if (best == NULL || highest < quality) {
highest = quality;
best = *target;
ambiguity = NULL;
- }
- else if (highest == quality) {
+ } else if (highest == quality) {
ambiguity = *target;
}
}
}
- if (NULL == best) {
+ if (best == NULL) {
pError = "No availaible targets are compatible with this triple.";
return NULL;
}
if (NULL != ambiguity) {
- pError = std::string("Ambiguous targets: \"") +
- best->name() + "\" and \"" + ambiguity->name() + "\"";
+ pError = std::string("Ambiguous targets: \"") + best->name() + "\" and \"" +
+ ambiguity->name() + "\"";
return NULL;
}
@@ -67,19 +64,20 @@ const Target* TargetRegistry::lookupTarget(const std::string &pTriple,
const Target* TargetRegistry::lookupTarget(const std::string& pArchName,
llvm::Triple& pTriple,
- std::string& pError)
-{
+ std::string& pError) {
const Target* result = NULL;
if (!pArchName.empty()) {
for (mcld::TargetRegistry::iterator it = mcld::TargetRegistry::begin(),
- ie = mcld::TargetRegistry::end(); it != ie; ++it) {
+ ie = mcld::TargetRegistry::end();
+ it != ie;
+ ++it) {
if (pArchName == (*it)->name()) {
result = *it;
break;
}
}
- if (NULL == result) {
+ if (result == NULL) {
pError = std::string("invalid target '") + pArchName + "'.\n";
return NULL;
}
@@ -87,19 +85,19 @@ const Target* TargetRegistry::lookupTarget(const std::string& pArchName,
// Adjust the triple to match (if known), otherwise stick with the
// module/host triple.
llvm::Triple::ArchType type =
- llvm::Triple::getArchTypeForLLVMName(pArchName);
+ llvm::Triple::getArchTypeForLLVMName(pArchName);
if (llvm::Triple::UnknownArch != type)
pTriple.setArch(type);
- }
- else {
+ } else {
std::string error;
result = lookupTarget(pTriple.getTriple(), error);
- if (NULL == result) {
- pError = std::string("unable to get target for `") +
- pTriple.getTriple() + "'\n" +
- "(Detail: " + error + ")\n";
+ if (result == NULL) {
+ pError = std::string("unable to get target for `") + pTriple.getTriple() +
+ "'\n" + "(Detail: " + error + ")\n";
return NULL;
}
}
return result;
}
+
+} // namespace mcld
diff --git a/lib/Support/ToolOutputFile.cpp b/lib/Support/ToolOutputFile.cpp
deleted file mode 100644
index 3e4844c..0000000
--- a/lib/Support/ToolOutputFile.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-//===- ToolOutputFile.cpp -------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/Support/ToolOutputFile.h>
-
-#include <mcld/Support/Path.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/MemoryArea.h>
-
-#include <mcld/Support/SystemUtils.h>
-#include <mcld/Support/MsgHandling.h>
-
-#include <llvm/Support/FileUtilities.h>
-#include <llvm/Support/Signals.h>
-#include <llvm/Support/Path.h>
-#include <llvm/Support/FormattedStream.h>
-
-using namespace mcld;
-
-//===----------------------------------------------------------------------===//
-// CleanupInstaller
-//===----------------------------------------------------------------------===//
-ToolOutputFile::CleanupInstaller::CleanupInstaller(const sys::fs::Path& pPath)
- : Keep(false), m_Path(pPath) {
- // Arrange for the file to be deleted if the process is killed.
- if ("-" != m_Path.native())
- llvm::sys::RemoveFileOnSignal(m_Path.native());
-}
-
-ToolOutputFile::CleanupInstaller::~CleanupInstaller()
-{
- // Delete the file if the client hasn't told us not to.
- // FIXME: In Windows, some path in CJK characters can not be removed by LLVM
- // llvm::sys::Path
- if (!Keep && "_" != m_Path.native()) {
- bool Existed = false;
- llvm::sys::fs::remove(m_Path.native(), Existed);
- }
-
- // Ok, the file is successfully written and closed, or deleted. There's no
- // further need to clean it up on signals.
- if ("_" != m_Path.native())
- llvm::sys::DontRemoveFileOnSignal(m_Path.native());
-}
-
-//===----------------------------------------------------------------------===//
-// ToolOutputFile
-//===----------------------------------------------------------------------===//
-ToolOutputFile::ToolOutputFile(const sys::fs::Path& pPath,
- FileHandle::OpenMode pMode,
- FileHandle::Permission pPermission)
- : m_Installer(pPath),
- m_pFdOstream(NULL),
- m_pFormattedOstream(NULL) {
-
- if (!m_FileHandle.open(pPath, pMode, pPermission)) {
- // If open fails, no clean-up is needed.
- m_Installer.Keep = true;
- fatal(diag::err_cannot_open_output_file)
- << pPath
- << sys::strerror(m_FileHandle.error());
- return;
- }
-}
-
-ToolOutputFile::~ToolOutputFile()
-{
- if (m_pFormattedOstream != NULL)
- delete m_pFormattedOstream;
- if (m_pFdOstream != NULL)
- delete m_pFdOstream;
-}
-
-void ToolOutputFile::keep()
-{
- m_Installer.Keep = true;
-}
-
-/// os - Return the containeed raw_fd_ostream.
-/// Since os is rarely used, we lazily initialize it.
-llvm::raw_fd_ostream& ToolOutputFile::os()
-{
- if (m_pFdOstream == NULL) {
- assert(m_FileHandle.isOpened() &&
- m_FileHandle.isGood() &&
- m_FileHandle.isWritable());
- m_pFdOstream = new llvm::raw_fd_ostream(m_FileHandle.handler(), false);
- }
- return *m_pFdOstream;
-}
-
-/// formatted_os - Return the contained formatted_raw_ostream
-llvm::formatted_raw_ostream& ToolOutputFile::formatted_os()
-{
- if (m_pFormattedOstream == NULL) {
- m_pFormattedOstream = new llvm::formatted_raw_ostream(os());
- }
- return *m_pFormattedOstream;
-}
diff --git a/lib/Support/Unix/FileSystem.inc b/lib/Support/Unix/FileSystem.inc
index 811085e..67fdd73 100644
--- a/lib/Support/Unix/FileSystem.inc
+++ b/lib/Support/Unix/FileSystem.inc
@@ -6,28 +6,31 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/Directory.h"
+
+#include <llvm/Support/ErrorHandling.h>
+
#include <string>
+
+#include <dirent.h>
+#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
-#include <dirent.h>
#include <unistd.h>
-#include <fcntl.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/Directory.h>
-#include <llvm/Support/ErrorHandling.h>
-namespace mcld{
-namespace sys{
-namespace fs{
-namespace detail{
+namespace mcld {
+namespace sys {
+namespace fs {
+namespace detail {
std::string static_library_extension = ".a";
std::string shared_library_extension = ".so";
-std::string executable_extension = "";
-std::string relocatable_extension = ".o";
-std::string assembly_extension = ".s";
-std::string bitcode_extension = ".bc";
+std::string executable_extension = "";
+std::string relocatable_extension = ".o";
+std::string assembly_extension = ".s";
+std::string bitcode_extension = ".bc";
//===----------------------------------------------------------------------===//
// Helper Functions
@@ -36,10 +39,9 @@ std::string bitcode_extension = ".bc";
// @return value -1: read error
// 0: read the end
// 1: success
-static int read_dir(intptr_t& pDir, std::string& pOutFilename)
-{
+static int read_dir(intptr_t& pDir, std::string& pOutFilename) {
errno = 0;
- dirent *cur_dir = ::readdir(reinterpret_cast<DIR*>(pDir));
+ dirent* cur_dir = ::readdir(reinterpret_cast<DIR*>(pDir));
if (0 == cur_dir && 0 != errno)
return -1;
@@ -58,11 +60,10 @@ static int read_dir(intptr_t& pDir, std::string& pOutFilename)
return 1;
}
-void open_dir(Directory& pDir)
-{
+void open_dir(Directory& pDir) {
pDir.m_Handler = reinterpret_cast<intptr_t>(opendir(pDir.path().c_str()));
if (0 == pDir.m_Handler) {
- errno = 0; // opendir() will set errno if it failed to open directory.
+ errno = 0; // opendir() will set errno if it failed to open directory.
// set cache is full, then Directory::begin() can return end().
pDir.m_CacheFull = true;
return;
@@ -70,39 +71,37 @@ void open_dir(Directory& pDir)
// read one entry for advance the end element of the cache.
std::string path(pDir.path().native());
switch (read_dir(pDir.m_Handler, path)) {
- case 1: {
- // find a new directory
- bool exist = false;
- mcld::sys::fs::PathCache::entry_type* entry = pDir.m_Cache.insert(path, exist);
- if (!exist)
- entry->setValue(path);
- return;
- }
- case 0:
- // FIXME: a warning function
- pDir.m_CacheFull = true;
- return;
- default:
- case -1:
- llvm::report_fatal_error(std::string("Can't read directory: ")+
- pDir.path().native());
+ case 1: {
+ // find a new directory
+ bool exist = false;
+ mcld::sys::fs::PathCache::entry_type* entry =
+ pDir.m_Cache.insert(path, exist);
+ if (!exist)
+ entry->setValue(sys::fs::Path(path));
+ return;
+ }
+ case 0:
+ // FIXME: a warning function
+ pDir.m_CacheFull = true;
+ return;
+ default:
+ case -1:
+ llvm::report_fatal_error(std::string("Can't read directory: ") +
+ pDir.path().native());
}
}
-void close_dir(Directory& pDir)
-{
+void close_dir(Directory& pDir) {
if (pDir.m_Handler)
- closedir(reinterpret_cast<DIR *>(pDir.m_Handler));
+ closedir(reinterpret_cast<DIR*>(pDir.m_Handler));
pDir.m_Handler = 0;
}
-int open(const Path& pPath, int pOFlag)
-{
+int open(const Path& pPath, int pOFlag) {
return ::open(pPath.native().c_str(), pOFlag);
}
-int open(const Path& pPath, int pOFlag, int pPerm)
-{
+int open(const Path& pPath, int pOFlag, int pPerm) {
mode_t perm = 0;
if (pPerm & FileHandle::ReadOwner)
perm |= S_IRUSR;
@@ -126,37 +125,32 @@ int open(const Path& pPath, int pOFlag, int pPerm)
return ::open(pPath.native().c_str(), pOFlag, perm);
}
-ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset)
-{
+ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset) {
return ::pread(pFD, pBuf, pCount, pOffset);
}
-ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset)
-{
+ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset) {
return ::pwrite(pFD, pBuf, pCount, pOffset);
}
-int ftruncate(int pFD, size_t pLength)
-{
+int ftruncate(int pFD, size_t pLength) {
return ::ftruncate(pFD, pLength);
}
-void get_pwd(Path& pPWD)
-{
+void get_pwd(Path& pPWD) {
char* pwd = (char*)malloc(PATH_MAX);
pPWD.assign(getcwd(pwd, PATH_MAX));
free(pwd);
}
-} // namespace of detail
-} // namespace of fs
-} // namespace of sys
+} // namespace detail
+} // namespace fs
+} // namespace sys
//===----------------------------------------------------------------------===//
// FileHandler
//===----------------------------------------------------------------------===//
-bool FileHandle::mmap(void*& pMemBuffer, size_t pStartOffset, size_t pLength)
-{
+bool FileHandle::mmap(void*& pMemBuffer, size_t pStartOffset, size_t pLength) {
if (!isOpened()) {
setState(BadBit);
return false;
@@ -170,18 +164,15 @@ bool FileHandle::mmap(void*& pMemBuffer, size_t pStartOffset, size_t pLength)
// read-only
prot = PROT_READ;
flag = MAP_FILE | MAP_PRIVATE;
- }
- else if (!isReadable() && isWritable()) {
+ } else if (!isReadable() && isWritable()) {
// write-only
prot = PROT_WRITE;
flag = MAP_FILE | MAP_SHARED;
- }
- else if (isReadWrite()) {
+ } else if (isReadWrite()) {
// read and write
prot = PROT_READ | PROT_WRITE;
flag = MAP_FILE | MAP_SHARED;
- }
- else {
+ } else {
// can not read/write
setState(BadBit);
return false;
@@ -197,8 +188,7 @@ bool FileHandle::mmap(void*& pMemBuffer, size_t pStartOffset, size_t pLength)
return true;
}
-bool FileHandle::munmap(void* pMemBuffer, size_t pLength)
-{
+bool FileHandle::munmap(void* pMemBuffer, size_t pLength) {
if (!isOpened()) {
setState(BadBit);
return false;
@@ -212,5 +202,4 @@ bool FileHandle::munmap(void* pMemBuffer, size_t pLength)
return true;
}
-} // namespace of mcld
-
+} // namespace mcld
diff --git a/lib/Support/Unix/PathV3.inc b/lib/Support/Unix/PathV3.inc
index d7e4cbc..1e6881b 100644
--- a/lib/Support/Unix/PathV3.inc
+++ b/lib/Support/Unix/PathV3.inc
@@ -6,30 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Path.h>
-#include <mcld/Support/FileSystem.h>
+#include "mcld/Support/FileSystem.h"
+#include "mcld/Support/Path.h"
+
#include <llvm/Support/ErrorHandling.h>
#include <cerrno>
+#include <stack>
#include <stdio.h>
+#include <string>
#include <sys/stat.h>
#include <sys/types.h>
-#include <string>
-#include <stack>
#include <unistd.h>
-namespace mcld{
-namespace sys{
-namespace fs{
+namespace mcld {
+namespace sys {
+namespace fs {
//===----------------------------------------------------------------------===//
// mcld::sys::fs::detail
//===----------------------------------------------------------------------===//
-namespace detail{
+namespace detail {
// return the last charactor being handled.
-size_t canonicalize(std::string& pathname)
-{
+size_t canonicalize(std::string& pathname) {
// Variable Index //
// SepTable - stack of result separators
// LR(1) Algorithm //
@@ -54,12 +54,12 @@ size_t canonicalize(std::string& pathname)
std::stack<size_t> slash_stack;
slash_stack.push(-1);
while (handler < pathname.size()) {
- if (separator == pathname[handler]) { // handler = 1st '/'
+ if (separator == pathname[handler]) { // handler = 1st '/'
size_t next = handler + 1;
if (next >= pathname.size())
return handler;
- switch(pathname[next]) { // next = handler + 1;
- case separator: { // '//'
+ switch (pathname[next]) { // next = handler + 1;
+ case separator: { // '//'
while (next < pathname.size() && separator == pathname[next])
++next;
// next is the last not '/'
@@ -68,122 +68,112 @@ size_t canonicalize(std::string& pathname)
slash_stack.push(handler);
break;
}
- case '.': { // '/.'
- ++next; // next = handler + 2
- if (next >= pathname.size()) // '/.'
+ case '.': { // '/.'
+ ++next; // next = handler + 2
+ if (next >= pathname.size()) // '/.'
return handler;
switch (pathname[next]) {
- case separator: { // '/./'
+ case separator: { // '/./'
pathname.erase(handler, 2);
break;
}
- case '.': { // '/..'
- ++next; // next = handler + 3;
- if (next >= pathname.size()) // '/..?'
+ case '.': { // '/..'
+ ++next; // next = handler + 3;
+ if (next >= pathname.size()) // '/..?'
return handler;
- switch(pathname[next]) {
- case separator: { // '/../'
+ switch (pathname[next]) {
+ case separator: { // '/../'
handler = slash_stack.top();
slash_stack.pop();
- pathname.erase(handler+1, next-handler);
+ pathname.erase(handler + 1, next - handler);
if (static_cast<size_t>(-1) == handler) {
slash_stack.push(-1);
handler = pathname.find_first_of(separator, handler);
}
break;
}
- case '.': { // '/...', illegal
+ case '.': { // '/...', illegal
return handler;
break;
}
- default : { // '/..a'
+ default: { // '/..a'
slash_stack.push(handler);
- handler = pathname.find_first_of(separator, handler+3);
+ handler = pathname.find_first_of(separator, handler + 3);
break;
}
}
break;
}
- default : { // '/.a'
+ default: { // '/.a'
slash_stack.push(handler);
- handler = pathname.find_first_of(separator, handler+2);
+ handler = pathname.find_first_of(separator, handler + 2);
break;
}
}
break;
}
- default : { // '/a
+ default: { // '/a
slash_stack.push(handler);
- handler = pathname.find_first_of(separator, handler+1);
+ handler = pathname.find_first_of(separator, handler + 1);
break;
}
}
- }
- else {
+ } else {
handler = pathname.find_first_of(separator, handler);
}
}
return handler;
}
-bool not_found_error(int perrno)
-{
+bool not_found_error(int perrno) {
return perrno == ENOENT || perrno == ENOTDIR;
}
-void status(const Path& p, FileStatus& pFileStatus)
-{
+void status(const Path& p, FileStatus& pFileStatus) {
struct stat path_stat;
- if(stat(p.c_str(), &path_stat)!= 0)
- {
- if(not_found_error(errno))
- {
+ if (stat(p.c_str(), &path_stat) != 0) {
+ if (not_found_error(errno)) {
pFileStatus.setType(FileNotFound);
- }
- else
+ } else
pFileStatus.setType(StatusError);
- }
- else if(S_ISDIR(path_stat.st_mode))
+ } else if (S_ISDIR(path_stat.st_mode))
pFileStatus.setType(DirectoryFile);
- else if(S_ISREG(path_stat.st_mode))
+ else if (S_ISREG(path_stat.st_mode))
pFileStatus.setType(RegularFile);
- else if(S_ISBLK(path_stat.st_mode))
+ else if (S_ISBLK(path_stat.st_mode))
pFileStatus.setType(BlockFile);
- else if(S_ISCHR(path_stat.st_mode))
+ else if (S_ISCHR(path_stat.st_mode))
pFileStatus.setType(CharacterFile);
- else if(S_ISFIFO(path_stat.st_mode))
+ else if (S_ISFIFO(path_stat.st_mode))
pFileStatus.setType(FifoFile);
- else if(S_ISSOCK(path_stat.st_mode))
+ else if (S_ISSOCK(path_stat.st_mode))
pFileStatus.setType(SocketFile);
else
pFileStatus.setType(TypeUnknown);
}
-void symlink_status(const Path& p, FileStatus& pFileStatus)
-{
+void symlink_status(const Path& p, FileStatus& pFileStatus) {
struct stat path_stat;
- if(lstat(p.c_str(), &path_stat)!= 0)
- {
- if(errno == ENOENT || errno == ENOTDIR) // these are not errors
+ if (lstat(p.c_str(), &path_stat) != 0) {
+ if (errno == ENOENT || errno == ENOTDIR) // these are not errors
{
pFileStatus.setType(FileNotFound);
- }
- else
+ } else
pFileStatus.setType(StatusError);
}
- if(S_ISREG(path_stat.st_mode))
+ if (S_ISREG(path_stat.st_mode))
pFileStatus.setType(RegularFile);
- if(S_ISDIR(path_stat.st_mode))
+ if (S_ISDIR(path_stat.st_mode))
pFileStatus.setType(DirectoryFile);
- if(S_ISLNK(path_stat.st_mode))
+ if (S_ISLNK(path_stat.st_mode))
pFileStatus.setType(SymlinkFile);
- if(S_ISBLK(path_stat.st_mode))
+ if (S_ISBLK(path_stat.st_mode))
pFileStatus.setType(BlockFile);
- if(S_ISCHR(path_stat.st_mode))
+ if (S_ISCHR(path_stat.st_mode))
pFileStatus.setType(CharacterFile);
- if(S_ISFIFO(path_stat.st_mode))
+ if (S_ISFIFO(path_stat.st_mode))
pFileStatus.setType(FifoFile);
- if(S_ISSOCK(path_stat.st_mode))
+ if (S_ISSOCK(path_stat.st_mode))
pFileStatus.setType(SocketFile);
else
pFileStatus.setType(TypeUnknown);
@@ -196,33 +186,31 @@ void symlink_status(const Path& p, FileStatus& pFileStatus)
// of cache. (a real end)
// 2. Some but not all elements had been put into cache, and we stoped.
// An iterator now is staying at the end of cache. (a temporal end)
-mcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter)
-{
+mcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter) {
mcld::sys::fs::PathCache::entry_type* entry = 0;
std::string path(pIter.m_pParent->m_Path.native());
switch (read_dir(pIter.m_pParent->m_Handler, path)) {
- case 1: {
- // read one
- bool exist = false;
- entry = pIter.m_pParent->m_Cache.insert(path, exist);
- if (!exist)
- entry->setValue(path);
- break;
- }
- case 0:// meet real end
- pIter.m_pParent->m_CacheFull = true;
- break;
- default:
- case -1:
- llvm::report_fatal_error(std::string("Can't read directory: ")+
- pIter.m_pParent->path().native());
- break;
+ case 1: {
+ // read one
+ bool exist = false;
+ entry = pIter.m_pParent->m_Cache.insert(path, exist);
+ if (!exist)
+ entry->setValue(sys::fs::Path(path));
+ break;
+ }
+ case 0: // meet real end
+ pIter.m_pParent->m_CacheFull = true;
+ break;
+ default:
+ case -1:
+ llvm::report_fatal_error(std::string("Can't read directory: ") +
+ pIter.m_pParent->path().native());
+ break;
}
return entry;
}
-} // namespace of detail
-} // namespace of fs
-} // namespace of sys
-} // namespace of mcld
-
+} // namespace detail
+} // namespace fs
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/Unix/System.inc b/lib/Support/Unix/System.inc
index f2064ec..4c16ec2 100644
--- a/lib/Support/Unix/System.inc
+++ b/lib/Support/Unix/System.inc
@@ -6,27 +6,25 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include <llvm/ADT/StringRef.h>
+
+#include <fcntl.h>
+#include <cstdlib>
#include <cstring>
+#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/utsname.h>
-#include <ctype.h>
-#include <cstdlib>
-#include <fcntl.h>
#include <unistd.h>
-#include <llvm/ADT/StringRef.h>
-
-namespace mcld{
-namespace sys{
+namespace mcld {
+namespace sys {
-char *strerror(int errnum)
-{
+char* strerror(int errnum) {
return std::strerror(errnum);
}
-static std::string getOSVersion()
-{
+static std::string getOSVersion() {
struct utsname info;
if (uname(&info))
@@ -35,12 +33,13 @@ static std::string getOSVersion()
return info.release;
}
-std::string getDefaultTargetTriple()
-{
+std::string getDefaultTargetTriple() {
llvm::StringRef TargetTripleString(MCLD_DEFAULT_TARGET_TRIPLE);
- std::pair<llvm::StringRef, llvm::StringRef> ArchSplit = TargetTripleString.split('-');
+ std::pair<llvm::StringRef, llvm::StringRef> ArchSplit =
+ TargetTripleString.split('-');
- // Normalize the arch, since the target triple may not actually match the target.
+ // Normalize the arch, since the target triple may not actually match the
+ // target.
std::string Arch = ArchSplit.first;
std::string Triple(Arch);
@@ -48,8 +47,8 @@ std::string getDefaultTargetTriple()
Triple += ArchSplit.second;
// Force i<N>86 to i386.
- if (Triple[0] == 'i' && isdigit(Triple[1]) &&
- Triple[2] == '8' && Triple[3] == '6')
+ if (Triple[0] == 'i' && isdigit(Triple[1]) && Triple[2] == '8' &&
+ Triple[3] == '6')
Triple[1] = '3';
// On darwin, we want to update the version to match that of the
@@ -63,23 +62,19 @@ std::string getDefaultTargetTriple()
return Triple;
}
-int GetPageSize()
-{
+int GetPageSize() {
return getpagesize();
}
/// random - generate a random number.
-long GetRandomNum()
-{
+long GetRandomNum() {
return ::random();
}
/// srandom - set the initial seed value for future calls to random().
-void SetRandomSeed(unsigned pSeed)
-{
+void SetRandomSeed(unsigned pSeed) {
::srandom(pSeed);
}
-} // namespace of sys
-} // namespace of mcld
-
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/Windows/FileSystem.inc b/lib/Support/Windows/FileSystem.inc
index 98b1e01..f08464b 100644
--- a/lib/Support/Windows/FileSystem.inc
+++ b/lib/Support/Windows/FileSystem.inc
@@ -6,41 +6,42 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/Directory.h"
+
#include <string>
+
+#include <cstdlib>
#include <io.h>
#include <fcntl.h>
-#include <cstdlib>
-#include <windows.h>
-#include <sys/stat.h>
#include <limits.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/Directory.h>
+#include <sys/stat.h>
+#include <windows.h>
#ifndef STDIN_FILENO
-# define STDIN_FILENO 0
+#define STDIN_FILENO 0
#endif
#ifndef STDOUT_FILENO
-# define STDOUT_FILENO 1
+#define STDOUT_FILENO 1
#endif
#ifndef STDERR_FILENO
-# define STDERR_FILENO 2
+#define STDERR_FILENO 2
#endif
-namespace mcld{
-namespace sys{
-namespace fs{
-namespace detail{
+namespace mcld {
+namespace sys {
+namespace fs {
+namespace detail {
// FIXME: the extension depends on target machine, not host machine.
Path::StringType static_library_extension = ".a";
Path::StringType shared_library_extension = ".so";
-Path::StringType executable_extension = ".exe";
-Path::StringType relocatable_extension = ".o";
-Path::StringType assembly_extension = ".s";
-Path::StringType bitcode_extension = ".bc";
+Path::StringType executable_extension = ".exe";
+Path::StringType relocatable_extension = ".o";
+Path::StringType assembly_extension = ".s";
+Path::StringType bitcode_extension = ".bc";
-void open_dir(Directory& pDir)
-{
+void open_dir(Directory& pDir) {
fs::Path file_filter(pDir.path());
file_filter.append("*");
@@ -62,40 +63,34 @@ void open_dir(Directory& pDir)
entry->setValue(path);
}
-void close_dir(Directory& pDir)
-{
+void close_dir(Directory& pDir) {
if (pDir.m_Handler)
FindClose(reinterpret_cast<HANDLE>(pDir.m_Handler));
pDir.m_Handler = 0;
}
-int open(const Path& pPath, int pOFlag)
-{
+int open(const Path& pPath, int pOFlag) {
return ::_open(pPath.native().c_str(), pOFlag | _O_BINARY);
}
-int open(const Path& pPath, int pOFlag, int pPerm)
-{
+int open(const Path& pPath, int pOFlag, int pPerm) {
int perm = 0;
- if (pPerm & FileHandle::ReadOwner ||
- pPerm & FileHandle::ReadGroup ||
+ if (pPerm & FileHandle::ReadOwner || pPerm & FileHandle::ReadGroup ||
pPerm & FileHandle::ReadOther)
perm |= _S_IREAD;
- if (pPerm & FileHandle::WriteOwner ||
- pPerm & FileHandle::WriteGroup ||
+ if (pPerm & FileHandle::WriteOwner || pPerm & FileHandle::WriteGroup ||
pPerm & FileHandle::WriteOther)
perm |= _S_IWRITE;
return ::_open(pPath.native().c_str(), pOFlag | _O_BINARY, perm);
}
-ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset)
-{
+ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset) {
ssize_t ret;
off_t old_pos;
if (-1 == (old_pos = ::lseek(pFD, 0, SEEK_CUR)))
- return -1;
+ return -1;
if (-1 == ::lseek(pFD, pOffset, SEEK_SET))
return -1;
@@ -104,7 +99,7 @@ ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset)
int err = errno;
::lseek(pFD, old_pos, SEEK_SET);
errno = err;
- return -1;
+ return -1;
}
if (-1 == ::lseek(pFD, old_pos, SEEK_SET))
@@ -113,8 +108,7 @@ ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset)
return ret;
}
-ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset)
-{
+ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset) {
ssize_t ret;
off_t old_pos;
if (-1 == (old_pos = ::lseek(pFD, 0, SEEK_CUR)))
@@ -136,38 +130,33 @@ ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset)
return ret;
}
-int ftruncate(int pFD, size_t pLength)
-{
+int ftruncate(int pFD, size_t pLength) {
return ::_chsize(pFD, pLength);
}
-void get_pwd(Path& pPWD)
-{
+void get_pwd(Path& pPWD) {
char* pwd = (char*)malloc(PATH_MAX);
pPWD.assign(_getcwd(pwd, PATH_MAX));
free(pwd);
}
-} // namespace of detail
-} // namespace of fs
-} // namespace of sys
+} // namespace detail
+} // namespace fs
+} // namespace sys
//===----------------------------------------------------------------------===//
// FileHandle
//===----------------------------------------------------------------------===//
-bool FileHandle::mmap(void*& pMemBuffer, size_t pStartOffset, size_t pLength)
-{
+bool FileHandle::mmap(void*& pMemBuffer, size_t pStartOffset, size_t pLength) {
// FIXME: This implementation reduces mmap to read. Use Windows APIs.
pMemBuffer = (void*)::malloc(pLength);
return read(pMemBuffer, pStartOffset, pLength);
}
-bool FileHandle::munmap(void* pMemBuffer, size_t pLength)
-{
+bool FileHandle::munmap(void* pMemBuffer, size_t pLength) {
// FIXME: This implementation reduces mmap to read. Use Windows APIs.
free(pMemBuffer);
return true;
}
-} // namespace of mcld
-
+} // namespace mcld
diff --git a/lib/Support/Windows/PathV3.inc b/lib/Support/Windows/PathV3.inc
index 2f36c93..0372a06 100644
--- a/lib/Support/Windows/PathV3.inc
+++ b/lib/Support/Windows/PathV3.inc
@@ -6,23 +6,24 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Path.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+#include "mcld/Support/Path.h"
+
#include <stack>
-namespace mcld{
-namespace sys{
-namespace fs{
+#include <sys/stat.h>
+#include <sys/types.h>
+
+namespace mcld {
+namespace sys {
+namespace fs {
//===----------------------------------------------------------------------===//
// mcld::sys::fs::detail
//===----------------------------------------------------------------------===//
-namespace detail{
+namespace detail {
// return the last charactor being handled.
-size_t canonicalize(std::string& pathname)
-{
+size_t canonicalize(std::string& pathname) {
// Variable Index //
// SepTable - stack of result separators
// LR(1) Algorithm //
@@ -47,12 +48,12 @@ size_t canonicalize(std::string& pathname)
std::stack<size_t> slash_stack;
slash_stack.push(-1);
while (handler < pathname.size()) {
- if (separator == pathname[handler]) { // handler = 1st '/'
+ if (separator == pathname[handler]) { // handler = 1st '/'
size_t next = handler + 1;
if (next >= pathname.size())
return handler;
- switch(pathname[next]) { // next = handler + 1;
- case separator: { // '//'
+ switch (pathname[next]) { // next = handler + 1;
+ case separator: { // '//'
while (next < pathname.size() && separator == pathname[next])
++next;
// next is the last not '/'
@@ -61,97 +62,89 @@ size_t canonicalize(std::string& pathname)
slash_stack.push(handler);
break;
}
- case '.': { // '/.'
- ++next; // next = handler + 2
- if (next >= pathname.size()) // '/.'
+ case '.': { // '/.'
+ ++next; // next = handler + 2
+ if (next >= pathname.size()) // '/.'
return handler;
switch (pathname[next]) {
- case separator: { // '/./'
+ case separator: { // '/./'
pathname.erase(handler, 2);
break;
}
- case '.': { // '/..'
- ++next; // next = handler + 3;
- if (next >= pathname.size()) // '/..?'
+ case '.': { // '/..'
+ ++next; // next = handler + 3;
+ if (next >= pathname.size()) // '/..?'
return handler;
- switch(pathname[next]) {
- case separator: { // '/../'
+ switch (pathname[next]) {
+ case separator: { // '/../'
handler = slash_stack.top();
slash_stack.pop();
- pathname.erase(handler+1, next-handler);
+ pathname.erase(handler + 1, next - handler);
if (static_cast<size_t>(-1) == handler) {
slash_stack.push(-1);
handler = pathname.find_first_of(separator, handler);
}
break;
}
- case '.': { // '/...', illegal
+ case '.': { // '/...', illegal
return handler;
break;
}
- default : { // '/..a'
+ default: { // '/..a'
slash_stack.push(handler);
- handler = pathname.find_first_of(separator, handler+3);
+ handler = pathname.find_first_of(separator, handler + 3);
break;
}
}
break;
}
- default : { // '/.a'
+ default: { // '/.a'
slash_stack.push(handler);
- handler = pathname.find_first_of(separator, handler+2);
+ handler = pathname.find_first_of(separator, handler + 2);
break;
}
}
break;
}
- default : { // '/a
+ default: { // '/a
slash_stack.push(handler);
- handler = pathname.find_first_of(separator, handler+1);
+ handler = pathname.find_first_of(separator, handler + 1);
break;
}
}
- }
- else {
+ } else {
handler = pathname.find_first_of(separator, handler);
}
}
return handler;
}
-bool not_found_error(int perrno)
-{
+bool not_found_error(int perrno) {
return perrno == ENOENT || perrno == ENOTDIR;
}
-void status(const Path& p, FileStatus& pFileStatus)
-{
+void status(const Path& p, FileStatus& pFileStatus) {
struct ::_stat path_stat;
- if(::_stat(p.c_str(), &path_stat)!= 0)
- {
- if(not_found_error(errno))
- {
+ if (::_stat(p.c_str(), &path_stat) != 0) {
+ if (not_found_error(errno)) {
pFileStatus.setType(FileNotFound);
- }
- else
+ } else
pFileStatus.setType(StatusError);
- }
- else if(S_ISDIR(path_stat.st_mode))
+ } else if (S_ISDIR(path_stat.st_mode))
pFileStatus.setType(DirectoryFile);
- else if(S_ISREG(path_stat.st_mode))
+ else if (S_ISREG(path_stat.st_mode))
pFileStatus.setType(RegularFile);
- else if(S_ISBLK(path_stat.st_mode))
+ else if (S_ISBLK(path_stat.st_mode))
pFileStatus.setType(BlockFile);
- else if(S_ISCHR(path_stat.st_mode))
+ else if (S_ISCHR(path_stat.st_mode))
pFileStatus.setType(CharacterFile);
- else if(S_ISFIFO(path_stat.st_mode))
+ else if (S_ISFIFO(path_stat.st_mode))
pFileStatus.setType(FifoFile);
else
pFileStatus.setType(TypeUnknown);
}
-void symlink_status(const Path& p, FileStatus& pFileStatus)
-{
+void symlink_status(const Path& p, FileStatus& pFileStatus) {
pFileStatus.setType(FileNotFound);
}
@@ -162,8 +155,7 @@ void symlink_status(const Path& p, FileStatus& pFileStatus)
// of cache. (a real end)
// 2. Some but not all elements had beed put into cache, and we stoped.
// An iterator now is staying at the end of cache. (a temporal end)
-mcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter)
-{
+mcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter) {
mcld::sys::fs::PathCache::entry_type* entry = 0;
fs::Path file_filter(pIter.m_pParent->m_Path);
file_filter.append("*");
@@ -179,21 +171,18 @@ mcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter)
entry = pIter.m_pParent->m_Cache.insert(path, exist);
if (!exist)
entry->setValue(path);
- }
- else if (ERROR_NO_MORE_FILES == GetLastError()){
+ } else if (ERROR_NO_MORE_FILES == GetLastError()) {
// meet real end
pIter.m_pParent->m_CacheFull = true;
- }
- else {
- llvm::report_fatal_error(std::string("Can't read directory: ")+
+ } else {
+ llvm::report_fatal_error(std::string("Can't read directory: ") +
pIter.m_pParent->path().native());
}
return entry;
}
-} // namespace of detail
-} // namespace of fs
-} // namespace of sys
-} // namespace of mcld
-
+} // namespace detail
+} // namespace fs
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/Windows/System.inc b/lib/Support/Windows/System.inc
index 9102963..e45ad36 100644
--- a/lib/Support/Windows/System.inc
+++ b/lib/Support/Windows/System.inc
@@ -7,49 +7,44 @@
//
//===----------------------------------------------------------------------===//
#include <string>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
+
#include <cstdlib>
#include <cstring>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <windows.h>
-namespace mcld{
-namespace sys{
+namespace mcld {
+namespace sys {
-char* strerror(int errnum)
-{
+char* strerror(int errnum) {
return std::strerror(errnum);
}
-std::string getDefaultTargetTriple()
-{
+std::string getDefaultTargetTriple() {
return MCLD_DEFAULT_TARGET_TRIPLE;
}
-int GetPageSize()
-{
+int GetPageSize() {
static int _pagesize = 0;
- if (! _pagesize) {
+ if (!_pagesize) {
SYSTEM_INFO sysinfo;
- GetSystemInfo (&sysinfo);
+ GetSystemInfo(&sysinfo);
_pagesize = sysinfo.dwPageSize;
}
return _pagesize;
}
/// random - generate a random number.
-long GetRandomNum()
-{
+long GetRandomNum() {
return ::rand();
}
/// srandom - set the initial seed value for future calls to random().
-void SetRandomSeed(unsigned pSeed)
-{
+void SetRandomSeed(unsigned pSeed) {
::srand(pSeed);
}
-} // namespace of sys
-} // namespace of mcld
-
+} // namespace sys
+} // namespace mcld
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index 32e362a..4da1237 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -6,87 +6,80 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Config/Config.h>
-#include <mcld/Support/raw_ostream.h>
+#include "mcld/Config/Config.h"
+#include "mcld/Support/raw_ostream.h"
#if defined(HAVE_UNISTD_H)
-# include <unistd.h>
+#include <unistd.h>
#endif
-#if defined(__CYGWIN__)
+#if defined(__CYGWIN__) || defined(_MSC_VER) || defined(__MINGW32__)
#include <io.h>
#endif
#if defined(_MSC_VER) || defined(__MINGW32__)
-#include <io.h>
#ifndef STDIN_FILENO
-# define STDIN_FILENO 0
+#define STDIN_FILENO 0
#endif
#ifndef STDOUT_FILENO
-# define STDOUT_FILENO 1
+#define STDOUT_FILENO 1
#endif
#ifndef STDERR_FILENO
-# define STDERR_FILENO 2
+#define STDERR_FILENO 2
#endif
#endif
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// raw_ostream
//===----------------------------------------------------------------------===//
-mcld::raw_fd_ostream::raw_fd_ostream(const char *pFilename,
- std::string &pErrorInfo,
- llvm::sys::fs::OpenFlags pFlags)
- : llvm::raw_fd_ostream(pFilename, pErrorInfo, pFlags),
- m_bConfigColor(false),
- m_bSetColor(false) {
+raw_fd_ostream::raw_fd_ostream(const char* pFilename,
+ std::error_code& pErrorCode,
+ llvm::sys::fs::OpenFlags pFlags)
+ : llvm::raw_fd_ostream(pFilename, pErrorCode, pFlags),
+ m_bConfigColor(false),
+ m_bSetColor(false) {
}
-mcld::raw_fd_ostream::raw_fd_ostream(int pFD,
+raw_fd_ostream::raw_fd_ostream(int pFD,
bool pShouldClose,
bool pUnbuffered)
- : llvm::raw_fd_ostream(pFD, pShouldClose, pUnbuffered),
- m_bConfigColor(false),
- m_bSetColor(false) {
+ : llvm::raw_fd_ostream(pFD, pShouldClose, pUnbuffered),
+ m_bConfigColor(false),
+ m_bSetColor(false) {
}
-mcld::raw_fd_ostream::~raw_fd_ostream()
-{
+raw_fd_ostream::~raw_fd_ostream() {
}
-void mcld::raw_fd_ostream::setColor(bool pEnable)
-{
+void raw_fd_ostream::setColor(bool pEnable) {
m_bConfigColor = true;
m_bSetColor = pEnable;
}
-llvm::raw_ostream &
-mcld::raw_fd_ostream::changeColor(enum llvm::raw_ostream::Colors pColor,
- bool pBold,
- bool pBackground)
-{
+llvm::raw_ostream& raw_fd_ostream::changeColor(
+ enum llvm::raw_ostream::Colors pColor,
+ bool pBold,
+ bool pBackground) {
if (!is_displayed())
return *this;
return llvm::raw_fd_ostream::changeColor(pColor, pBold, pBackground);
}
-llvm::raw_ostream& mcld::raw_fd_ostream::resetColor()
-{
+llvm::raw_ostream& raw_fd_ostream::resetColor() {
if (!is_displayed())
return *this;
return llvm::raw_fd_ostream::resetColor();
}
-llvm::raw_ostream& mcld::raw_fd_ostream::reverseColor()
-{
+llvm::raw_ostream& raw_fd_ostream::reverseColor() {
if (!is_displayed())
return *this;
return llvm::raw_ostream::reverseColor();
}
-bool mcld::raw_fd_ostream::is_displayed() const
-{
+bool raw_fd_ostream::is_displayed() const {
if (m_bConfigColor)
return m_bSetColor;
@@ -96,15 +89,16 @@ bool mcld::raw_fd_ostream::is_displayed() const
//===----------------------------------------------------------------------===//
// outs(), errs(), nulls()
//===----------------------------------------------------------------------===//
-mcld::raw_fd_ostream& mcld::outs() {
+raw_fd_ostream& outs() {
// Set buffer settings to model stdout behavior.
- static mcld::raw_fd_ostream S(STDOUT_FILENO, false);
+ static raw_fd_ostream S(STDOUT_FILENO, false);
return S;
}
-mcld::raw_fd_ostream& mcld::errs() {
+raw_fd_ostream& errs() {
// Set standard error to be unbuffered by default.
- static mcld::raw_fd_ostream S(STDERR_FILENO, false, true);
+ static raw_fd_ostream S(STDERR_FILENO, false, true);
return S;
}
+} // namespace mcld
diff --git a/lib/Target/AArch64/AArch64.h b/lib/Target/AArch64/AArch64.h
index df389e8..189fde8 100644
--- a/lib/Target/AArch64/AArch64.h
+++ b/lib/Target/AArch64/AArch64.h
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64_H
-#define TARGET_AARCH64_AARCH64_H
+#ifndef TARGET_AARCH64_AARCH64_H_
+#define TARGET_AARCH64_AARCH64_H_
#include <string>
namespace llvm {
class Target;
-} // namespace of llvm
+} // namespace llvm
namespace mcld {
@@ -21,10 +21,9 @@ class TargetLDBackend;
extern mcld::Target TheAArch64Target;
-TargetLDBackend *createAArch64LDBackend(const llvm::Target&,
+TargetLDBackend* createAArch64LDBackend(const llvm::Target&,
const std::string&);
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_AARCH64_AARCH64_H_
diff --git a/lib/Target/AArch64/AArch64Diagnostic.cpp b/lib/Target/AArch64/AArch64Diagnostic.cpp
index 6fddce4..e99884f 100644
--- a/lib/Target/AArch64/AArch64Diagnostic.cpp
+++ b/lib/Target/AArch64/AArch64Diagnostic.cpp
@@ -6,31 +6,27 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/DWARFLineInfo.h>
+#include "mcld/LD/DWARFLineInfo.h"
+#include "mcld/Support/TargetRegistry.h"
#include "AArch64.h"
-using namespace mcld;
-
namespace mcld {
//===----------------------------------------------------------------------===//
// createAArch64Diagnostic - the help function to create corresponding
// AArch64Diagnostic
//===----------------------------------------------------------------------===//
DiagnosticLineInfo* createAArch64DiagLineInfo(const mcld::Target& pTarget,
- const std::string &pTriple)
-{
+ const std::string& pTriple) {
return new DWARFLineInfo();
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// InitializeAArch64Diagnostic
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeAArch64DiagnosticLineInfo() {
// Register the linker frontend
- mcld::TargetRegistry::RegisterDiagnosticLineInfo(TheAArch64Target,
- createAArch64DiagLineInfo);
+ mcld::TargetRegistry::RegisterDiagnosticLineInfo(
+ mcld::TheAArch64Target, mcld::createAArch64DiagLineInfo);
}
-
diff --git a/lib/Target/AArch64/AArch64ELFDynamic.cpp b/lib/Target/AArch64/AArch64ELFDynamic.cpp
index 3aa572a..d1ead4f 100644
--- a/lib/Target/AArch64/AArch64ELFDynamic.cpp
+++ b/lib/Target/AArch64/AArch64ELFDynamic.cpp
@@ -8,44 +8,39 @@
//===----------------------------------------------------------------------===//
#include "AArch64ELFDynamic.h"
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LinkerConfig.h>
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LinkerConfig.h"
-using namespace mcld;
+namespace mcld {
AArch64ELFDynamic::AArch64ELFDynamic(const GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : ELFDynamic(pParent, pConfig)
-{
+ : ELFDynamic(pParent, pConfig) {
}
-AArch64ELFDynamic::~AArch64ELFDynamic()
-{
+AArch64ELFDynamic::~AArch64ELFDynamic() {
}
-void AArch64ELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat)
-{
+void AArch64ELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat) {
// reservePLTGOT
if (config().options().hasNow()) {
if (pFormat.hasGOT())
reserveOne(llvm::ELF::DT_PLTGOT);
- }
- else {
+ } else {
if (pFormat.hasGOTPLT())
reserveOne(llvm::ELF::DT_PLTGOT);
}
}
-void AArch64ELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat)
-{
+void AArch64ELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat) {
// applyPLTGOT
if (config().options().hasNow()) {
if (pFormat.hasGOT())
applyOne(llvm::ELF::DT_PLTGOT, pFormat.getGOT().addr());
- }
- else {
+ } else {
if (pFormat.hasGOTPLT())
applyOne(llvm::ELF::DT_PLTGOT, pFormat.getGOTPLT().addr());
}
}
+} // namespace mcld
diff --git a/lib/Target/AArch64/AArch64ELFDynamic.h b/lib/Target/AArch64/AArch64ELFDynamic.h
index 7596da5..35dcd66 100644
--- a/lib/Target/AArch64/AArch64ELFDynamic.h
+++ b/lib/Target/AArch64/AArch64ELFDynamic.h
@@ -6,23 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64ELFDYNAMIC_H
-#define TARGET_AARCH64_AARCH64ELFDYNAMIC_H
+#ifndef TARGET_AARCH64_AARCH64ELFDYNAMIC_H_
+#define TARGET_AARCH64_AARCH64ELFDYNAMIC_H_
-#include <mcld/Target/ELFDynamic.h>
+#include "mcld/Target/ELFDynamic.h"
namespace mcld {
class AArch64ELFDynamic : public ELFDynamic {
-public:
+ public:
AArch64ELFDynamic(const GNULDBackend& pParent, const LinkerConfig& pConfig);
~AArch64ELFDynamic();
-private:
+ private:
void reserveTargetEntries(const ELFFileFormat& pFormat);
void applyTargetEntries(const ELFFileFormat& pFormat);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_AARCH64_AARCH64ELFDYNAMIC_H_
diff --git a/lib/Target/AArch64/AArch64ELFMCLinker.cpp b/lib/Target/AArch64/AArch64ELFMCLinker.cpp
deleted file mode 100644
index a311435..0000000
--- a/lib/Target/AArch64/AArch64ELFMCLinker.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-//===- AArch64ELFMCLinker.cpp ---------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "AArch64ELFMCLinker.h"
-
-#include <mcld/LinkerConfig.h>
-#include <mcld/Object/SectionMap.h>
-
-using namespace mcld;
-
-AArch64ELFMCLinker::AArch64ELFMCLinker(LinkerConfig& pConfig,
- mcld::Module &pModule,
- FileHandle& pFileHandle)
- : ELFMCLinker(pConfig, pModule, pFileHandle) {
-}
-
-AArch64ELFMCLinker::~AArch64ELFMCLinker()
-{
-}
-
diff --git a/lib/Target/AArch64/AArch64ELFMCLinker.h b/lib/Target/AArch64/AArch64ELFMCLinker.h
deleted file mode 100644
index 95b4884..0000000
--- a/lib/Target/AArch64/AArch64ELFMCLinker.h
+++ /dev/null
@@ -1,34 +0,0 @@
-//===- AArch64ELFMCLinker.h -----------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64ELFMCLINKER_H
-#define TARGET_AARCH64_AARCH64ELFMCLINKER_H
-#include <mcld/Target/ELFMCLinker.h>
-
-namespace mcld {
-
-class Module;
-class FileHandle;
-
-/** \class AArch64ELFMCLinker
- * \brief AArch64ELFMCLinker sets up the environment for linking.
- */
-class AArch64ELFMCLinker : public ELFMCLinker
-{
-public:
- AArch64ELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle);
-
- ~AArch64ELFMCLinker();
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/lib/Target/AArch64/AArch64Emulation.cpp b/lib/Target/AArch64/AArch64Emulation.cpp
index 02f4b01..69bc493 100644
--- a/lib/Target/AArch64/AArch64Emulation.cpp
+++ b/lib/Target/AArch64/AArch64Emulation.cpp
@@ -7,15 +7,15 @@
//
//===----------------------------------------------------------------------===//
#include "AArch64.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Target/ELFEmulation.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/ELFEmulation.h"
namespace mcld {
-static bool MCLDEmulateAArch64ELF(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+static bool MCLDEmulateAArch64ELF(LinkerScript& pScript,
+ LinkerConfig& pConfig) {
if (!MCLDEmulateELF(pScript, pConfig))
return false;
@@ -44,8 +44,7 @@ static bool MCLDEmulateAArch64ELF(LinkerScript& pScript, LinkerConfig& pConfig)
//===----------------------------------------------------------------------===//
// emulateAArch64LD - the help function to emulate AArch64 ld
//===----------------------------------------------------------------------===//
-bool emulateAArch64LD(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+bool emulateAArch64LD(LinkerScript& pScript, LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker has not supported yet");
return false;
@@ -58,7 +57,7 @@ bool emulateAArch64LD(LinkerScript& pScript, LinkerConfig& pConfig)
return MCLDEmulateAArch64ELF(pScript, pConfig);
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// AArch64Emulation
@@ -68,4 +67,3 @@ extern "C" void MCLDInitializeAArch64Emulation() {
mcld::TargetRegistry::RegisterEmulation(mcld::TheAArch64Target,
mcld::emulateAArch64LD);
}
-
diff --git a/lib/Target/AArch64/AArch64GNUInfo.h b/lib/Target/AArch64/AArch64GNUInfo.h
index 554b27c..491d189 100644
--- a/lib/Target/AArch64/AArch64GNUInfo.h
+++ b/lib/Target/AArch64/AArch64GNUInfo.h
@@ -6,18 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64GNUINFO_H
-#define TARGET_AARCH64_AARCH64GNUINFO_H
-#include <mcld/Target/GNUInfo.h>
+#ifndef TARGET_AARCH64_AARCH64GNUINFO_H_
+#define TARGET_AARCH64_AARCH64GNUINFO_H_
+#include "mcld/Target/GNUInfo.h"
#include <llvm/Support/ELF.h>
namespace mcld {
-class AArch64GNUInfo : public GNUInfo
-{
-public:
- AArch64GNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) { }
+class AArch64GNUInfo : public GNUInfo {
+ public:
+ explicit AArch64GNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) {}
uint32_t machine() const { return llvm::ELF::EM_AARCH64; }
@@ -29,7 +28,6 @@ public:
uint64_t flags() const { return 0x0; }
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_AARCH64_AARCH64GNUINFO_H_
diff --git a/lib/Target/AArch64/AArch64GOT.cpp b/lib/Target/AArch64/AArch64GOT.cpp
index 4864c07..0d4c7cd 100644
--- a/lib/Target/AArch64/AArch64GOT.cpp
+++ b/lib/Target/AArch64/AArch64GOT.cpp
@@ -8,57 +8,50 @@
//===----------------------------------------------------------------------===//
#include "AArch64GOT.h"
-#include <llvm/Support/Casting.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/Support/MsgHandling.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/Support/MsgHandling.h>
+#include <llvm/Support/Casting.h>
namespace {
- const unsigned int AArch64GOT0Num = 3;
-} // end of anonymous namespace
+const unsigned int AArch64GOT0Num = 3;
+} // end of anonymous namespace
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// AArch64GOT
AArch64GOT::AArch64GOT(LDSection& pSection)
- : GOT(pSection), m_pGOTPLTFront(NULL), m_pGOTFront(NULL)
-{
+ : GOT(pSection), m_pGOTPLTFront(NULL), m_pGOTFront(NULL) {
}
-AArch64GOT::~AArch64GOT()
-{
+AArch64GOT::~AArch64GOT() {
}
-void AArch64GOT::createGOT0()
-{
+void AArch64GOT::createGOT0() {
// create GOT0, and put them into m_SectionData immediately
for (unsigned int i = 0; i < AArch64GOT0Num; ++i)
new AArch64GOTEntry(0, m_SectionData);
}
-bool AArch64GOT::hasGOT1() const
-{
+bool AArch64GOT::hasGOT1() const {
return ((!m_GOT.empty()) || (!m_GOTPLT.empty()));
}
-AArch64GOTEntry* AArch64GOT::createGOT()
-{
+AArch64GOTEntry* AArch64GOT::createGOT() {
AArch64GOTEntry* entry = new AArch64GOTEntry(0, NULL);
m_GOT.push_back(entry);
return entry;
}
-AArch64GOTEntry* AArch64GOT::createGOTPLT()
-{
+AArch64GOTEntry* AArch64GOT::createGOTPLT() {
AArch64GOTEntry* entry = new AArch64GOTEntry(0, NULL);
m_GOTPLT.push_back(entry);
return entry;
}
-void AArch64GOT::finalizeSectionSize()
-{
+void AArch64GOT::finalizeSectionSize() {
uint32_t offset = 0;
SectionData::FragmentListType& frag_list = m_SectionData->getFragmentList();
// setup GOT0 offset
@@ -78,7 +71,6 @@ void AArch64GOT::finalizeSectionSize()
entry->setParent(m_SectionData);
entry->setOffset(offset);
offset += entry->size();
-
}
}
m_GOTPLT.clear();
@@ -101,20 +93,18 @@ void AArch64GOT::finalizeSectionSize()
m_Section.setSize(offset);
}
-void AArch64GOT::applyGOT0(uint64_t pAddress)
-{
- llvm::cast<AArch64GOTEntry>
- (*(m_SectionData->getFragmentList().begin())).setValue(pAddress);
+void AArch64GOT::applyGOT0(uint64_t pAddress) {
+ llvm::cast<AArch64GOTEntry>(*(m_SectionData->getFragmentList().begin()))
+ .setValue(pAddress);
}
-void AArch64GOT::applyGOTPLT(uint64_t pPLTBase)
-{
- if (NULL == m_pGOTPLTFront)
+void AArch64GOT::applyGOTPLT(uint64_t pPLTBase) {
+ if (m_pGOTPLTFront == NULL)
return;
SectionData::iterator entry(m_pGOTPLTFront);
SectionData::iterator e_end;
- if (NULL == m_pGOTFront)
+ if (m_pGOTFront == NULL)
e_end = m_SectionData->end();
else
e_end = SectionData::iterator(m_pGOTFront);
@@ -125,17 +115,17 @@ void AArch64GOT::applyGOTPLT(uint64_t pPLTBase)
}
}
-uint64_t AArch64GOT::emit(MemoryRegion& pRegion)
-{
+uint64_t AArch64GOT::emit(MemoryRegion& pRegion) {
uint64_t* buffer = reinterpret_cast<uint64_t*>(pRegion.begin());
AArch64GOTEntry* got = NULL;
uint64_t result = 0x0;
for (iterator it = begin(), ie = end(); it != ie; ++it, ++buffer) {
- got = &(llvm::cast<AArch64GOTEntry>((*it)));
- *buffer = static_cast<uint64_t>(got->getValue());
- result += AArch64GOTEntry::EntrySize;
+ got = &(llvm::cast<AArch64GOTEntry>((*it)));
+ *buffer = static_cast<uint64_t>(got->getValue());
+ result += AArch64GOTEntry::EntrySize;
}
return result;
}
+} // namespace mcld
diff --git a/lib/Target/AArch64/AArch64GOT.h b/lib/Target/AArch64/AArch64GOT.h
index 0e46e9e..f790e8b 100644
--- a/lib/Target/AArch64/AArch64GOT.h
+++ b/lib/Target/AArch64/AArch64GOT.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64GOT_H
-#define TARGET_AARCH64_AARCH64GOT_H
+#ifndef TARGET_AARCH64_AARCH64GOT_H_
+#define TARGET_AARCH64_AARCH64GOT_H_
-#include <mcld/Support/MemoryRegion.h>
-#include <mcld/Target/GOT.h>
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Target/GOT.h"
#include <llvm/ADT/DenseMap.h>
@@ -23,12 +23,10 @@ class LDSection;
/** \class AArch64GOTEntry
* \brief GOT Entry with size of 8 bytes
*/
-class AArch64GOTEntry : public GOT::Entry<8>
-{
-public:
+class AArch64GOTEntry : public GOT::Entry<8> {
+ public:
AArch64GOTEntry(uint64_t pContent, SectionData* pParent)
- : GOT::Entry<8>(pContent, pParent)
- {}
+ : GOT::Entry<8>(pContent, pParent) {}
};
/** \class AArch64GOT
@@ -53,10 +51,9 @@ public:
* +--------------+
*
*/
-class AArch64GOT : public GOT
-{
-public:
- AArch64GOT(LDSection &pSection);
+class AArch64GOT : public GOT {
+ public:
+ explicit AArch64GOT(LDSection& pSection);
~AArch64GOT();
@@ -78,12 +75,12 @@ public:
bool hasGOT1() const;
-private:
+ private:
typedef std::vector<AArch64GOTEntry*> EntryListType;
typedef EntryListType::iterator entry_iterator;
typedef EntryListType::const_iterator const_entry_iterator;
-private:
+ private:
AArch64GOTEntry* m_pGOTPLTFront;
AArch64GOTEntry* m_pGOTFront;
@@ -94,7 +91,6 @@ private:
EntryListType m_GOT;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_AARCH64_AARCH64GOT_H_
diff --git a/lib/Target/AArch64/AArch64LDBackend.cpp b/lib/Target/AArch64/AArch64LDBackend.cpp
index cf07428..9224275 100644
--- a/lib/Target/AArch64/AArch64LDBackend.cpp
+++ b/lib/Target/AArch64/AArch64LDBackend.cpp
@@ -12,57 +12,53 @@
#include "AArch64LDBackend.h"
#include "AArch64Relocator.h"
-#include <cstring>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/StubFactory.h"
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/ELFAttribute.h"
+#include "mcld/Target/GNUInfo.h"
+#include "mcld/Object/ObjectBuilder.h"
#include <llvm/ADT/Triple.h>
#include <llvm/ADT/Twine.h>
-#include <llvm/Support/ELF.h>
#include <llvm/Support/Casting.h>
+#include <llvm/Support/ELF.h>
+
+#include <cstring>
-#include <mcld/IRBuilder.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/Fragment/AlignFragment.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Fragment/Stub.h>
-#include <mcld/Fragment/NullFragment.h>
-#include <mcld/Support/MemoryRegion.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/LD/StubFactory.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/Target/ELFAttribute.h>
-#include <mcld/Target/GNUInfo.h>
-#include <mcld/Object/ObjectBuilder.h>
-
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// AArch64GNULDBackend
//===----------------------------------------------------------------------===//
AArch64GNULDBackend::AArch64GNULDBackend(const LinkerConfig& pConfig,
GNUInfo* pInfo)
- : GNULDBackend(pConfig, pInfo),
- m_pRelocator(NULL),
- m_pGOT(NULL),
- m_pGOTPLT(NULL),
- m_pPLT(NULL),
- m_pRelaDyn(NULL),
- m_pRelaPLT(NULL),
- // m_pAttrData(NULL),
- m_pDynamic(NULL),
- m_pGOTSymbol(NULL)
- // m_pAttributes(NULL)
-{
-}
-
-AArch64GNULDBackend::~AArch64GNULDBackend()
-{
+ : GNULDBackend(pConfig, pInfo),
+ m_pRelocator(NULL),
+ m_pGOT(NULL),
+ m_pGOTPLT(NULL),
+ m_pPLT(NULL),
+ m_pRelaDyn(NULL),
+ m_pRelaPLT(NULL),
+ m_pDynamic(NULL),
+ m_pGOTSymbol(NULL) {
+}
+
+AArch64GNULDBackend::~AArch64GNULDBackend() {
if (m_pRelocator != NULL)
delete m_pRelocator;
if (m_pGOT == m_pGOTPLT) {
@@ -85,10 +81,7 @@ AArch64GNULDBackend::~AArch64GNULDBackend()
}
void AArch64GNULDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
- // TODO
-
+ ObjectBuilder& pBuilder) {
if (LinkerConfig::Object != config().codeGenType()) {
ELFFileFormat* file_format = getOutputFormat();
@@ -101,8 +94,7 @@ void AArch64GNULDBackend::initTargetSections(Module& pModule,
// set m_pGOTPLT to the same .got
m_pGOT->createGOT0();
m_pGOTPLT = m_pGOT;
- }
- else {
+ } else {
// Otherwise, got should be seperated to two sections, .got and .got.plt
// initialize .got.plt
LDSection& gotplt = file_format->getGOTPLT();
@@ -126,93 +118,83 @@ void AArch64GNULDBackend::initTargetSections(Module& pModule,
}
void AArch64GNULDBackend::initTargetSymbols(IRBuilder& pBuilder,
- Module& pModule)
-{
+ Module& pModule) {
// Define the symbol _GLOBAL_OFFSET_TABLE_ if there is a symbol with the
// same name in input
if (LinkerConfig::Object != config().codeGenType()) {
- m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Hidden);
+ m_pGOTSymbol =
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Hidden);
}
- // TODO
}
-bool AArch64GNULDBackend::initRelocator()
-{
- if (NULL == m_pRelocator) {
+bool AArch64GNULDBackend::initRelocator() {
+ if (m_pRelocator == NULL) {
m_pRelocator = new AArch64Relocator(*this, config());
}
return true;
}
-const Relocator* AArch64GNULDBackend::getRelocator() const
-{
- assert(NULL != m_pRelocator);
+const Relocator* AArch64GNULDBackend::getRelocator() const {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-Relocator* AArch64GNULDBackend::getRelocator()
-{
- assert(NULL != m_pRelocator);
+Relocator* AArch64GNULDBackend::getRelocator() {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-void AArch64GNULDBackend::defineGOTSymbol(IRBuilder& pBuilder)
-{
+void AArch64GNULDBackend::defineGOTSymbol(IRBuilder& pBuilder) {
// define symbol _GLOBAL_OFFSET_TABLE_ when .got create
if (m_pGOTSymbol != NULL) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pGOTPLT->begin()), 0x0),
- ResolveInfo::Hidden);
- }
- else {
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pGOTPLT->begin()), 0x0),
+ ResolveInfo::Hidden);
+ } else {
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pGOTPLT->begin()), 0x0),
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pGOTPLT->begin()), 0x0),
+ ResolveInfo::Hidden);
}
}
-void AArch64GNULDBackend::doPreLayout(IRBuilder& pBuilder)
-{
+void AArch64GNULDBackend::doPreLayout(IRBuilder& pBuilder) {
// initialize .dynamic data
- if (!config().isCodeStatic() && NULL == m_pDynamic)
+ if (!config().isCodeStatic() && m_pDynamic == NULL)
m_pDynamic = new AArch64ELFDynamic(*this, config());
if (LinkerConfig::Object != config().codeGenType()) {
// set .got size
if (config().options().hasNow()) {
// when building shared object, the GOTPLT section is must
- if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ if (LinkerConfig::DynObj == config().codeGenType() || m_pGOT->hasGOT1() ||
+ m_pGOTSymbol != NULL) {
m_pGOT->finalizeSectionSize();
defineGOTSymbol(pBuilder);
}
- }
- else {
+ } else {
// when building shared object, the GOTPLT section is must
if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOTPLT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ m_pGOTPLT->hasGOT1() || m_pGOTSymbol != NULL) {
m_pGOTPLT->finalizeSectionSize();
defineGOTSymbol(pBuilder);
}
@@ -227,37 +209,38 @@ void AArch64GNULDBackend::doPreLayout(IRBuilder& pBuilder)
ELFFileFormat* file_format = getOutputFormat();
// set .rela.dyn size
if (!m_pRelaDyn->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
- file_format->getRelaDyn().setSize(
- m_pRelaDyn->numOfRelocs() * getRelaEntrySize());
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
+ file_format->getRelaDyn().setSize(m_pRelaDyn->numOfRelocs() *
+ getRelaEntrySize());
}
// set .rela.plt size
if (!m_pRelaPLT->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
- file_format->getRelaPlt().setSize(
- m_pRelaPLT->numOfRelocs() * getRelaEntrySize());
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
+ file_format->getRelaPlt().setSize(m_pRelaPLT->numOfRelocs() *
+ getRelaEntrySize());
}
}
}
-void AArch64GNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder)
-{
- const ELFFileFormat *file_format = getOutputFormat();
+void AArch64GNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder) {
+ const ELFFileFormat* file_format = getOutputFormat();
// apply PLT
if (file_format->hasPLT()) {
- assert(NULL != m_pPLT);
+ assert(m_pPLT != NULL);
m_pPLT->applyPLT0();
m_pPLT->applyPLT1();
}
// apply GOTPLT
if ((config().options().hasNow() && file_format->hasGOT()) ||
- file_format->hasGOTPLT()) {
- assert(NULL != m_pGOTPLT);
+ file_format->hasGOTPLT()) {
+ assert(m_pGOTPLT != NULL);
if (LinkerConfig::DynObj == config().codeGenType())
m_pGOTPLT->applyGOT0(file_format->getDynamic().addr());
else {
@@ -267,21 +250,18 @@ void AArch64GNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder)
}
}
-AArch64ELFDynamic& AArch64GNULDBackend::dynamic()
-{
- assert(NULL != m_pDynamic);
+AArch64ELFDynamic& AArch64GNULDBackend::dynamic() {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
-const AArch64ELFDynamic& AArch64GNULDBackend::dynamic() const
-{
- assert(NULL != m_pDynamic);
+const AArch64ELFDynamic& AArch64GNULDBackend::dynamic() const {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
uint64_t AArch64GNULDBackend::emitSectionData(const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
assert(pRegion.size() && "Size of MemoryRegion is zero!");
const ELFFileFormat* file_format = getOutputFormat();
@@ -305,9 +285,8 @@ uint64_t AArch64GNULDBackend::emitSectionData(const LDSection& pSection,
return pRegion.size();
}
-unsigned int
-AArch64GNULDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
-{
+unsigned int AArch64GNULDBackend::getTargetSectionOrder(
+ const LDSection& pSectHdr) const {
const ELFFileFormat* file_format = getOutputFormat();
if (file_format->hasGOT() && (&pSectHdr == &file_format->getGOT())) {
@@ -327,111 +306,92 @@ AArch64GNULDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
bool AArch64GNULDBackend::doRelax(Module& pModule,
IRBuilder& pBuilder,
- bool& pFinished)
-{
+ bool& pFinished) {
// TODO
return false;
}
-bool AArch64GNULDBackend::initTargetStubs()
-{
+bool AArch64GNULDBackend::initTargetStubs() {
// TODO
return true;
}
-void AArch64GNULDBackend::doCreateProgramHdrs(Module& pModule)
-{
+void AArch64GNULDBackend::doCreateProgramHdrs(Module& pModule) {
// TODO
}
-bool AArch64GNULDBackend::finalizeTargetSymbols()
-{
+bool AArch64GNULDBackend::finalizeTargetSymbols() {
// TODO
return true;
}
bool AArch64GNULDBackend::mergeSection(Module& pModule,
const Input& pInput,
- LDSection& pSection)
-{
+ LDSection& pSection) {
// TODO
return true;
}
-bool AArch64GNULDBackend::readSection(Input& pInput, SectionData& pSD)
-{
+bool AArch64GNULDBackend::readSection(Input& pInput, SectionData& pSD) {
// TODO
return true;
}
-AArch64GOT& AArch64GNULDBackend::getGOT()
-{
- assert(NULL != m_pGOT && "GOT section not exist");
+AArch64GOT& AArch64GNULDBackend::getGOT() {
+ assert(m_pGOT != NULL && "GOT section not exist");
return *m_pGOT;
}
-const AArch64GOT& AArch64GNULDBackend::getGOT() const
-{
- assert(NULL != m_pGOT && "GOT section not exist");
+const AArch64GOT& AArch64GNULDBackend::getGOT() const {
+ assert(m_pGOT != NULL && "GOT section not exist");
return *m_pGOT;
}
-AArch64GOT& AArch64GNULDBackend::getGOTPLT()
-{
- assert(NULL != m_pGOTPLT && "GOTPLT section not exist");
+AArch64GOT& AArch64GNULDBackend::getGOTPLT() {
+ assert(m_pGOTPLT != NULL && "GOTPLT section not exist");
return *m_pGOTPLT;
}
-const AArch64GOT& AArch64GNULDBackend::getGOTPLT() const
-{
- assert(NULL != m_pGOTPLT && "GOTPLT section not exist");
+const AArch64GOT& AArch64GNULDBackend::getGOTPLT() const {
+ assert(m_pGOTPLT != NULL && "GOTPLT section not exist");
return *m_pGOTPLT;
}
-AArch64PLT& AArch64GNULDBackend::getPLT()
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+AArch64PLT& AArch64GNULDBackend::getPLT() {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-const AArch64PLT& AArch64GNULDBackend::getPLT() const
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+const AArch64PLT& AArch64GNULDBackend::getPLT() const {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-OutputRelocSection& AArch64GNULDBackend::getRelaDyn()
-{
- assert(NULL != m_pRelaDyn && ".rela.dyn section not exist");
+OutputRelocSection& AArch64GNULDBackend::getRelaDyn() {
+ assert(m_pRelaDyn != NULL && ".rela.dyn section not exist");
return *m_pRelaDyn;
}
-const OutputRelocSection& AArch64GNULDBackend::getRelaDyn() const
-{
- assert(NULL != m_pRelaDyn && ".rela.dyn section not exist");
+const OutputRelocSection& AArch64GNULDBackend::getRelaDyn() const {
+ assert(m_pRelaDyn != NULL && ".rela.dyn section not exist");
return *m_pRelaDyn;
}
-OutputRelocSection& AArch64GNULDBackend::getRelaPLT()
-{
- assert(NULL != m_pRelaPLT && ".rela.plt section not exist");
+OutputRelocSection& AArch64GNULDBackend::getRelaPLT() {
+ assert(m_pRelaPLT != NULL && ".rela.plt section not exist");
return *m_pRelaPLT;
}
-const OutputRelocSection& AArch64GNULDBackend::getRelaPLT() const
-{
- assert(NULL != m_pRelaPLT && ".rela.plt section not exist");
+const OutputRelocSection& AArch64GNULDBackend::getRelaPLT() const {
+ assert(m_pRelaPLT != NULL && ".rela.plt section not exist");
return *m_pRelaPLT;
}
-namespace mcld {
-
//===----------------------------------------------------------------------===//
// createAArch64LDBackend - the help funtion to create corresponding
// AArch64LDBackend
//===----------------------------------------------------------------------===//
-TargetLDBackend* createAArch64LDBackend(const LinkerConfig& pConfig)
-{
+TargetLDBackend* createAArch64LDBackend(const LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker is not supported yet");
/**
@@ -448,18 +408,17 @@ TargetLDBackend* createAArch64LDBackend(const LinkerConfig& pConfig)
createAArch64COFFObjectWriter);
**/
}
- return new AArch64GNULDBackend(pConfig,
- new AArch64GNUInfo(pConfig.targets().triple()));
+ return new AArch64GNULDBackend(
+ pConfig, new AArch64GNUInfo(pConfig.targets().triple()));
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// Force static initialization.
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeAArch64LDBackend() {
// Register the linker backend
- mcld::TargetRegistry::RegisterTargetLDBackend(TheAArch64Target,
- createAArch64LDBackend);
+ mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheAArch64Target,
+ mcld::createAArch64LDBackend);
}
-
diff --git a/lib/Target/AArch64/AArch64LDBackend.h b/lib/Target/AArch64/AArch64LDBackend.h
index 00e14fa..b94d535 100644
--- a/lib/Target/AArch64/AArch64LDBackend.h
+++ b/lib/Target/AArch64/AArch64LDBackend.h
@@ -6,15 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64LDBACKEND_H
-#define TARGET_AARCH64_AARCH64LDBACKEND_H
+#ifndef TARGET_AARCH64_AARCH64LDBACKEND_H_
+#define TARGET_AARCH64_AARCH64LDBACKEND_H_
#include "AArch64ELFDynamic.h"
#include "AArch64GOT.h"
#include "AArch64PLT.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Target/OutputRelocSection.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/Target/GNULDBackend.h"
+#include "mcld/Target/OutputRelocSection.h"
namespace mcld {
@@ -24,17 +24,16 @@ class GNUInfo;
//===----------------------------------------------------------------------===//
/// AArch64GNULDBackend - linker backend of AArch64 target of GNU ELF format
///
-class AArch64GNULDBackend : public GNULDBackend
-{
-public:
+class AArch64GNULDBackend : public GNULDBackend {
+ public:
static const int64_t AARCH64_MAX_FWD_BRANCH_OFFSET = (((1 << 25) - 1) << 2);
static const int64_t AARCH64_MAX_BWD_BRANCH_OFFSET = (-((1 << 25) << 2));
-public:
+ public:
AArch64GNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo);
~AArch64GNULDBackend();
-public:
+ public:
/// initTargetSections - initialize target dependent sections in output.
void initTargetSections(Module& pModule, ObjectBuilder& pBuilder);
@@ -62,7 +61,6 @@ public:
/// Use co-variant return type to return its own dynamic section.
const AArch64ELFDynamic& dynamic() const;
-
/// emitSectionData - write out the section data into the memory region.
/// When writers get a LDSection whose kind is LDFileFormat::Target, writers
/// call back target backend to emit the data.
@@ -96,10 +94,11 @@ public:
OutputRelocSection& getRelaPLT();
const OutputRelocSection& getRelaPLT() const;
- LDSymbol* getGOTSymbol() { return m_pGOTSymbol; }
+ LDSymbol* getGOTSymbol() { return m_pGOTSymbol; }
const LDSymbol* getGOTSymbol() const { return m_pGOTSymbol; }
- /// getTargetSectionOrder - compute the layout order of AArch64 target sections
+ /// getTargetSectionOrder - compute the layout order of AArch64 target
+ /// sections
unsigned int getTargetSectionOrder(const LDSection& pSectHdr) const;
/// finalizeTargetSymbols - finalize the symbol value
@@ -111,7 +110,7 @@ public:
/// readSection - read target dependent sections
bool readSection(Input& pInput, SectionData& pSD);
-private:
+ private:
void defineGOTSymbol(IRBuilder& pBuilder);
int64_t maxFwdBranchOffset() { return AARCH64_MAX_FWD_BRANCH_OFFSET; }
@@ -130,18 +129,16 @@ private:
bool initTargetStubs();
/// getRelEntrySize - the size in BYTE of rel type relocation
- size_t getRelEntrySize()
- { return 16; }
+ size_t getRelEntrySize() { return 16; }
/// getRelEntrySize - the size in BYTE of rela type relocation
- size_t getRelaEntrySize()
- { return 24; }
+ size_t getRelaEntrySize() { return 24; }
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
virtual void doCreateProgramHdrs(Module& pModule);
-private:
+ private:
Relocator* m_pRelocator;
AArch64GOT* m_pGOT;
@@ -164,7 +161,7 @@ private:
// LDSection* m_pDebugOverlay; // .AArch64.debug_overlay
// LDSection* m_pOverlayTable; // .AArch64.overlay_table
};
-} // namespace of mcld
-#endif
+} // namespace mcld
+#endif // TARGET_AARCH64_AARCH64LDBACKEND_H_
diff --git a/lib/Target/AArch64/AArch64MCLinker.cpp b/lib/Target/AArch64/AArch64MCLinker.cpp
deleted file mode 100644
index 538461a..0000000
--- a/lib/Target/AArch64/AArch64MCLinker.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-//===- AArch64MCLinker.cpp-------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "AArch64ELFMCLinker.h"
-
-#include "AArch64.h"
-#include <llvm/ADT/Triple.h>
-#include <mcld/Module.h>
-#include <mcld/Support/TargetRegistry.h>
-
-using namespace mcld;
-
-namespace mcld {
-//===----------------------------------------------------------------------===//
-// createAArch64MCLinker - the help function to create corresponding
-// AArch64MCLinker
-//===----------------------------------------------------------------------===//
-MCLinker* createAArch64MCLinker(const std::string& pTriple,
- LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
-{
- llvm::Triple theTriple(pTriple);
- if (theTriple.isOSDarwin()) {
- assert(0 && "MachO linker has not supported yet");
- return NULL;
- }
- if (theTriple.isOSWindows()) {
- assert(0 && "COFF linker has not supported yet");
- return NULL;
- }
-
- return new AArch64ELFMCLinker(pConfig, pModule, pFileHandle);
-}
-
-} // namespace of mcld
-
-//===----------------------------------------------------------------------===//
-// AArch64MCLinker
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeAArch64MCLinker() {
- // Register the linker frontend
- mcld::TargetRegistry::RegisterMCLinker(TheAArch64Target,
- createAArch64MCLinker);
-}
-
diff --git a/lib/Target/AArch64/AArch64PLT.cpp b/lib/Target/AArch64/AArch64PLT.cpp
index c24327d..e9c8cee 100644
--- a/lib/Target/AArch64/AArch64PLT.cpp
+++ b/lib/Target/AArch64/AArch64PLT.cpp
@@ -10,40 +10,39 @@
#include "AArch64PLT.h"
#include "AArch64RelocationHelpers.h"
-#include <new>
+#include "mcld/LD/LDSection.h"
+#include "mcld/Support/MsgHandling.h"
#include <llvm/Support/Casting.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Support/MsgHandling.h>
+#include <new>
-using namespace mcld;
+namespace mcld {
AArch64PLT0::AArch64PLT0(SectionData& pParent)
- : PLT::Entry<sizeof(aarch64_plt0)>(pParent) {}
+ : PLT::Entry<sizeof(aarch64_plt0)>(pParent) {
+}
AArch64PLT1::AArch64PLT1(SectionData& pParent)
- : PLT::Entry<sizeof(aarch64_plt1)>(pParent) {}
+ : PLT::Entry<sizeof(aarch64_plt1)>(pParent) {
+}
//===----------------------------------------------------------------------===//
// AArch64PLT
-AArch64PLT::AArch64PLT(LDSection& pSection, AArch64GOT &pGOTPLT)
- : PLT(pSection), m_GOT(pGOTPLT) {
+AArch64PLT::AArch64PLT(LDSection& pSection, AArch64GOT& pGOTPLT)
+ : PLT(pSection), m_GOT(pGOTPLT) {
new AArch64PLT0(*m_pSectionData);
}
-AArch64PLT::~AArch64PLT()
-{
+AArch64PLT::~AArch64PLT() {
}
-bool AArch64PLT::hasPLT1() const
-{
+bool AArch64PLT::hasPLT1() const {
return (m_pSectionData->size() > 1);
}
-void AArch64PLT::finalizeSectionSize()
-{
+void AArch64PLT::finalizeSectionSize() {
uint64_t size = (m_pSectionData->size() - 1) * sizeof(aarch64_plt1) +
sizeof(aarch64_plt0);
m_Section.setSize(size);
@@ -56,16 +55,14 @@ void AArch64PLT::finalizeSectionSize()
}
}
-AArch64PLT1* AArch64PLT::create()
-{
+AArch64PLT1* AArch64PLT::create() {
AArch64PLT1* plt1_entry = new (std::nothrow) AArch64PLT1(*m_pSectionData);
if (!plt1_entry)
fatal(diag::fail_allocate_memory_plt);
return plt1_entry;
}
-void AArch64PLT::applyPLT0()
-{
+void AArch64PLT::applyPLT0() {
// malloc plt0
iterator first = m_pSectionData->getFragmentList().begin();
assert(first != m_pSectionData->getFragmentList().end() &&
@@ -87,20 +84,20 @@ void AArch64PLT::applyPLT0()
// get the address of got entry 2
uint64_t got_ent2_base = got_base + sizeof(AArch64GOTEntry::EntrySize) * 2;
// compute the immediate
- AArch64Relocator::DWord imm = helper_get_page_address(got_ent2_base) -
- helper_get_page_address(plt_base + (sizeof(AArch64PLT0::EntrySize) * 8));
+ AArch64Relocator::DWord imm =
+ helper_get_page_address(got_ent2_base) -
+ helper_get_page_address(plt_base + (sizeof(AArch64PLT0::EntrySize) * 8));
data[1] = helper_reencode_adr_imm(data[1], imm >> 12);
// apply 3rd instruction
data[2] = helper_reencode_add_imm(data[2],
helper_get_page_offset(got_ent2_base) >> 3);
// apply 4th instruction
- data[3] = helper_reencode_add_imm(data[3],
- helper_get_page_offset(got_ent2_base));
+ data[3] =
+ helper_reencode_add_imm(data[3], helper_get_page_offset(got_ent2_base));
plt0->setValue(reinterpret_cast<unsigned char*>(data));
}
-void AArch64PLT::applyPLT1()
-{
+void AArch64PLT::applyPLT1() {
uint64_t plt_base = m_Section.addr();
assert(plt_base && ".plt base address is NULL!");
@@ -117,7 +114,7 @@ void AArch64PLT::applyPLT1()
// first plt1 address
uint32_t PLTEntryAddress = plt_base + AArch64PLT0::EntrySize;
- ++it; //skip PLT0
+ ++it; // skip PLT0
uint32_t PLT1EntrySize = AArch64PLT1::EntrySize;
AArch64PLT1* plt1 = NULL;
@@ -134,8 +131,8 @@ void AArch64PLT::applyPLT1()
Out[1] = helper_reencode_add_imm(
Out[1], helper_get_page_offset(GOTEntryAddress) >> 3);
// apply 3rd instruction
- Out[2] = helper_reencode_add_imm(
- Out[2], helper_get_page_offset(GOTEntryAddress));
+ Out[2] = helper_reencode_add_imm(Out[2],
+ helper_get_page_offset(GOTEntryAddress));
plt1->setValue(reinterpret_cast<unsigned char*>(Out));
++it;
@@ -147,14 +144,14 @@ void AArch64PLT::applyPLT1()
m_GOT.applyGOTPLT(plt_base);
}
-uint64_t AArch64PLT::emit(MemoryRegion& pRegion)
-{
+uint64_t AArch64PLT::emit(MemoryRegion& pRegion) {
uint64_t result = 0x0;
iterator it = begin();
unsigned char* buffer = pRegion.begin();
- memcpy(buffer, llvm::cast<AArch64PLT0>((*it)).getValue(),
- AArch64PLT0::EntrySize);
+ memcpy(buffer,
+ llvm::cast<AArch64PLT0>((*it)).getValue(),
+ AArch64PLT0::EntrySize);
result += AArch64PLT0::EntrySize;
++it;
@@ -169,3 +166,4 @@ uint64_t AArch64PLT::emit(MemoryRegion& pRegion)
return result;
}
+} // namespace mcld
diff --git a/lib/Target/AArch64/AArch64PLT.h b/lib/Target/AArch64/AArch64PLT.h
index c63e2e0..cab067a 100644
--- a/lib/Target/AArch64/AArch64PLT.h
+++ b/lib/Target/AArch64/AArch64PLT.h
@@ -6,57 +6,50 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64PLT_H
-#define TARGET_AARCH64_AARCH64PLT_H
+#ifndef TARGET_AARCH64_AARCH64PLT_H_
+#define TARGET_AARCH64_AARCH64PLT_H_
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/PLT.h>
-#include <mcld/Support/MemoryRegion.h>
-
-namespace {
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/PLT.h"
const uint8_t aarch64_plt0[] = {
- 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
- 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
- 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
- 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
- 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
- 0x1f, 0x20, 0x03, 0xd5, /* nop */
- 0x1f, 0x20, 0x03, 0xd5, /* nop */
- 0x1f, 0x20, 0x03, 0xd5 /* nop */
+ 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
+ 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
+ 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
+ 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
+ 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
+ 0x1f, 0x20, 0x03, 0xd5, /* nop */
+ 0x1f, 0x20, 0x03, 0xd5, /* nop */
+ 0x1f, 0x20, 0x03, 0xd5 /* nop */
};
const uint8_t aarch64_plt1[] = {
- 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
- 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
- 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
- 0x20, 0x02, 0x1f, 0xd6 /* br x17. */
+ 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
+ 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
+ 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
+ 0x20, 0x02, 0x1f, 0xd6 /* br x17. */
};
-} // anonymous namespace
-
namespace mcld {
class AArch64GOT;
-class AArch64PLT0 : public PLT::Entry<sizeof(aarch64_plt0)>
-{
-public:
+class AArch64PLT0 : public PLT::Entry<sizeof(aarch64_plt0)> {
+ public:
AArch64PLT0(SectionData& pParent);
};
-class AArch64PLT1 : public PLT::Entry<sizeof(aarch64_plt1)>
-{
-public:
+class AArch64PLT1 : public PLT::Entry<sizeof(aarch64_plt1)> {
+ public:
AArch64PLT1(SectionData& pParent);
};
/** \class AArch64PLT
* \brief AArch64 Procedure Linkage Table
*/
-class AArch64PLT : public PLT
-{
-public:
+class AArch64PLT : public PLT {
+ public:
AArch64PLT(LDSection& pSection, AArch64GOT& pGOTPLT);
~AArch64PLT();
@@ -76,11 +69,10 @@ public:
uint64_t emit(MemoryRegion& pRegion);
-private:
+ private:
AArch64GOT& m_GOT;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_AARCH64_AARCH64PLT_H_
diff --git a/lib/Target/AArch64/AArch64RelocationFunctions.h b/lib/Target/AArch64/AArch64RelocationFunctions.h
index 14c8c73..65a8bc2 100644
--- a/lib/Target/AArch64/AArch64RelocationFunctions.h
+++ b/lib/Target/AArch64/AArch64RelocationFunctions.h
@@ -6,105 +6,110 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_AARCH64_AARCH64RELOCATIONFUNCTIONS_H_
+#define TARGET_AARCH64_AARCH64RELOCATIONFUNCTIONS_H_
-#define DECL_AARCH64_APPLY_RELOC_FUNC(Name) \
-static AArch64Relocator::Result Name (Relocation& pEntry, AArch64Relocator& pParent);
+#define DECL_AARCH64_APPLY_RELOC_FUNC(Name) \
+ static AArch64Relocator::Result Name(Relocation& pEntry, \
+ AArch64Relocator& pParent);
-#define DECL_AARCH64_APPLY_RELOC_FUNCS \
-DECL_AARCH64_APPLY_RELOC_FUNC(none) \
-DECL_AARCH64_APPLY_RELOC_FUNC(abs) \
-DECL_AARCH64_APPLY_RELOC_FUNC(rel) \
-DECL_AARCH64_APPLY_RELOC_FUNC(call) \
-DECL_AARCH64_APPLY_RELOC_FUNC(condbr) \
-DECL_AARCH64_APPLY_RELOC_FUNC(adr_prel_pg_hi21) \
-DECL_AARCH64_APPLY_RELOC_FUNC(add_abs_lo12) \
-DECL_AARCH64_APPLY_RELOC_FUNC(adr_got_page) \
-DECL_AARCH64_APPLY_RELOC_FUNC(ld64_got_lo12) \
-DECL_AARCH64_APPLY_RELOC_FUNC(ldst_abs_lo12) \
-DECL_AARCH64_APPLY_RELOC_FUNC(unsupport)
+#define DECL_AARCH64_APPLY_RELOC_FUNCS \
+ DECL_AARCH64_APPLY_RELOC_FUNC(none) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(abs) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(rel) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(call) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(condbr) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(adr_prel_pg_hi21) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(add_abs_lo12) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(adr_got_page) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(ld64_got_lo12) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(ldst_abs_lo12) \
+ DECL_AARCH64_APPLY_RELOC_FUNC(unsupported)
-#define DECL_AARCH64_APPLY_RELOC_FUNC_PTRS(ValueType, MappedType) \
- ValueType(0x0, MappedType(&none, "R_AARCH64_NULL")), \
- ValueType(0x100, MappedType(&none, "R_AARCH64_NONE")), \
- ValueType(0x101, MappedType(&abs, "R_AARCH64_ABS64", 64)), \
- ValueType(0x102, MappedType(&abs, "R_AARCH64_ABS32", 32)), \
- ValueType(0x103, MappedType(&abs, "R_AARCH64_ABS16", 16)), \
- ValueType(0x104, MappedType(&rel, "R_AARCH64_PREL64", 64)), \
- ValueType(0x105, MappedType(&rel, "R_AARCH64_PREL32", 32)), \
- ValueType(0x106, MappedType(&rel, "R_AARCH64_PREL16", 16)), \
- ValueType(0x107, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G0")), \
- ValueType(0x108, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G0_NC")), \
- ValueType(0x109, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G1")), \
- ValueType(0x10a, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G1_NC")), \
- ValueType(0x10b, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G2")), \
- ValueType(0x10c, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G2_NC")), \
- ValueType(0x10d, MappedType(&unsupport, "R_AARCH64_MOVW_UABS_G3")), \
- ValueType(0x10e, MappedType(&unsupport, "R_AARCH64_MOVW_SABS_G0")), \
- ValueType(0x10f, MappedType(&unsupport, "R_AARCH64_MOVW_SABS_G1")), \
- ValueType(0x110, MappedType(&unsupport, "R_AARCH64_MOVW_SABS_G2")), \
- ValueType(0x111, MappedType(&unsupport, "R_AARCH64_LD_PREL_LO19")), \
- ValueType(0x112, MappedType(&unsupport, "R_AARCH64_ADR_PREL_LO21")), \
- ValueType(0x113, MappedType(&adr_prel_pg_hi21, "R_AARCH64_ADR_PREL_PG_HI21", 32)), \
- ValueType(0x114, MappedType(&adr_prel_pg_hi21, "R_AARCH64_ADR_PREL_PG_HI21_NC", 32)), \
- ValueType(0x115, MappedType(&add_abs_lo12, "R_AARCH64_ADD_ABS_LO12_NC", 32)), \
- ValueType(0x116, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST8_ABS_LO12_NC", 32)), \
- ValueType(0x117, MappedType(&unsupport, "R_AARCH64_TSTBR14")), \
- ValueType(0x118, MappedType(&condbr, "R_AARCH64_CONDBR19", 32)), \
- ValueType(0x11a, MappedType(&call, "R_AARCH64_JUMP26", 32)), \
- ValueType(0x11b, MappedType(&call, "R_AARCH64_CALL26", 32)), \
- ValueType(0x11c, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST16_ABS_LO12_NC", 32)), \
- ValueType(0x11d, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST32_ABS_LO12_NC", 32)), \
- ValueType(0x11e, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST64_ABS_LO12_NC", 32)), \
- ValueType(0x12b, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST128_ABS_LO12_NC", 32)), \
- ValueType(0x137, MappedType(&adr_got_page, "R_AARCH64_ADR_GOT_PAGE", 32)), \
- ValueType(0x138, MappedType(&ld64_got_lo12, "R_AARCH64_LD64_GOT_LO12_NC", 32)), \
- ValueType(0x20b, MappedType(&unsupport, "R_AARCH64_TLSLD_MOVW_DTPREL_G2")), \
- ValueType(0x20c, MappedType(&unsupport, "R_AARCH64_TLSLD_MOVW_DTPREL_G1")), \
- ValueType(0x20d, MappedType(&unsupport, "R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC")), \
- ValueType(0x20e, MappedType(&unsupport, "R_AARCH64_TLSLD_MOVW_DTPREL_G0")), \
- ValueType(0x20f, MappedType(&unsupport, "R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC")), \
- ValueType(0x210, MappedType(&unsupport, "R_AARCH64_TLSLD_ADD_DTPREL_HI12")), \
- ValueType(0x211, MappedType(&unsupport, "R_AARCH64_TLSLD_ADD_DTPREL_LO12")), \
- ValueType(0x212, MappedType(&unsupport, "R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC")), \
- ValueType(0x213, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST8_DTPREL_LO12")), \
- ValueType(0x214, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC")), \
- ValueType(0x215, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST16_DTPREL_LO12")), \
- ValueType(0x216, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC")), \
- ValueType(0x217, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST32_DTPREL_LO12")), \
- ValueType(0x218, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC")), \
- ValueType(0x219, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST64_DTPREL_LO12")), \
- ValueType(0x21a, MappedType(&unsupport, "R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC")), \
- ValueType(0x21b, MappedType(&unsupport, "R_AARCH64_TLSIE_MOVW_GOTTPREL_G1")), \
- ValueType(0x21c, MappedType(&unsupport, "R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC")), \
- ValueType(0x21d, MappedType(&unsupport, "R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21")), \
- ValueType(0x21e, MappedType(&unsupport, "R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC")), \
- ValueType(0x21f, MappedType(&unsupport, "R_AARCH64_TLSIE_LD_GOTTPREL_PREL19")), \
- ValueType(0x220, MappedType(&unsupport, "R_AARCH64_TLSLE_MOVW_TPREL_G2")), \
- ValueType(0x221, MappedType(&unsupport, "R_AARCH64_TLSLE_MOVW_TPREL_G1")), \
- ValueType(0x222, MappedType(&unsupport, "R_AARCH64_TLSLE_MOVW_TPREL_G1_NC")), \
- ValueType(0x223, MappedType(&unsupport, "R_AARCH64_TLSLE_MOVW_TPREL_G0")), \
- ValueType(0x224, MappedType(&unsupport, "R_AARCH64_TLSLE_MOVW_TPREL_G0_NC")), \
- ValueType(0x225, MappedType(&unsupport, "R_AARCH64_TLSLE_ADD_TPREL_HI12")), \
- ValueType(0x226, MappedType(&unsupport, "R_AARCH64_TLSLE_ADD_TPREL_LO12")), \
- ValueType(0x227, MappedType(&unsupport, "R_AARCH64_TLSLE_ADD_TPREL_LO12_NC")), \
- ValueType(0x228, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST8_TPREL_LO12")), \
- ValueType(0x229, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC")), \
- ValueType(0x22a, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST16_TPREL_LO12")), \
- ValueType(0x22b, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC")), \
- ValueType(0x22c, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST32_TPREL_LO12")), \
- ValueType(0x22d, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC")), \
- ValueType(0x22e, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST64_TPREL_LO12")), \
- ValueType(0x22f, MappedType(&unsupport, "R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC")), \
- ValueType(0x232, MappedType(&unsupport, "R_AARCH64_TLSDESC_ADR_PAGE")), \
- ValueType(0x233, MappedType(&unsupport, "R_AARCH64_TLSDESC_LD64_LO12_NC")), \
- ValueType(0x234, MappedType(&unsupport, "R_AARCH64_TLSDESC_ADD_LO12_NC")), \
- ValueType(0x239, MappedType(&unsupport, "R_AARCH64_TLSDESC_CALL")), \
- ValueType( 1024, MappedType(&unsupport, "R_AARCH64_COPY")), \
- ValueType( 1025, MappedType(&unsupport, "R_AARCH64_GLOB_DAT")), \
- ValueType( 1026, MappedType(&unsupport, "R_AARCH64_JUMP_SLOT")), \
- ValueType( 1027, MappedType(&unsupport, "R_AARCH64_RELATIVE")), \
- ValueType( 1028, MappedType(&unsupport, "R_AARCH64_TLS_DTPREL64")), \
- ValueType( 1029, MappedType(&unsupport, "R_AARCH64_TLS_DTPMOD64")), \
- ValueType( 1030, MappedType(&unsupport, "R_AARCH64_TLS_TPREL64")), \
- ValueType( 1031, MappedType(&unsupport, "R_AARCH64_TLSDESC")), \
- ValueType( 1032, MappedType(&unsupport, "R_AARCH64_IRELATIVE"))
+#define DECL_AARCH64_APPLY_RELOC_FUNC_PTRS(ValueType, MappedType) /* NOLINT */\
+ ValueType(0x0, MappedType(&none, "R_AARCH64_NULL", 0)), /* NOLINT */\
+ ValueType(0x100, MappedType(&none, "R_AARCH64_NONE", 0)), /* NOLINT */\
+ ValueType(0x101, MappedType(&abs, "R_AARCH64_ABS64", 64)), /* NOLINT */\
+ ValueType(0x102, MappedType(&abs, "R_AARCH64_ABS32", 32)), /* NOLINT */\
+ ValueType(0x103, MappedType(&abs, "R_AARCH64_ABS16", 16)), /* NOLINT */\
+ ValueType(0x104, MappedType(&rel, "R_AARCH64_PREL64", 64)), /* NOLINT */\
+ ValueType(0x105, MappedType(&rel, "R_AARCH64_PREL32", 32)), /* NOLINT */\
+ ValueType(0x106, MappedType(&rel, "R_AARCH64_PREL16", 16)), /* NOLINT */\
+ ValueType(0x107, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G0", 0)), /* NOLINT */\
+ ValueType(0x108, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G0_NC", 0)), /* NOLINT */\
+ ValueType(0x109, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G1", 0)), /* NOLINT */\
+ ValueType(0x10a, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G1_NC", 0)), /* NOLINT */\
+ ValueType(0x10b, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G2", 0)), /* NOLINT */\
+ ValueType(0x10c, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G2_NC", 0)), /* NOLINT */\
+ ValueType(0x10d, MappedType(&unsupported, "R_AARCH64_MOVW_UABS_G3", 0)), /* NOLINT */\
+ ValueType(0x10e, MappedType(&unsupported, "R_AARCH64_MOVW_SABS_G0", 0)), /* NOLINT */\
+ ValueType(0x10f, MappedType(&unsupported, "R_AARCH64_MOVW_SABS_G1", 0)), /* NOLINT */\
+ ValueType(0x110, MappedType(&unsupported, "R_AARCH64_MOVW_SABS_G2", 0)), /* NOLINT */\
+ ValueType(0x111, MappedType(&unsupported, "R_AARCH64_LD_PREL_LO19", 0)), /* NOLINT */\
+ ValueType(0x112, MappedType(&unsupported, "R_AARCH64_ADR_PREL_LO21", 0)), /* NOLINT */\
+ ValueType(0x113, MappedType(&adr_prel_pg_hi21, "R_AARCH64_ADR_PREL_PG_HI21", 32)), /* NOLINT */\
+ ValueType(0x114, MappedType(&adr_prel_pg_hi21, "R_AARCH64_ADR_PREL_PG_HI21_NC", 32)), /* NOLINT */\
+ ValueType(0x115, MappedType(&add_abs_lo12, "R_AARCH64_ADD_ABS_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x116, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST8_ABS_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x117, MappedType(&unsupported, "R_AARCH64_TSTBR14", 0)), /* NOLINT */\
+ ValueType(0x118, MappedType(&condbr, "R_AARCH64_CONDBR19", 32)), /* NOLINT */\
+ ValueType(0x11a, MappedType(&call, "R_AARCH64_JUMP26", 32)), /* NOLINT */\
+ ValueType(0x11b, MappedType(&call, "R_AARCH64_CALL26", 32)), /* NOLINT */\
+ ValueType(0x11c, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST16_ABS_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x11d, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST32_ABS_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x11e, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST64_ABS_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x12b, MappedType(&ldst_abs_lo12, "R_AARCH64_LDST128_ABS_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x137, MappedType(&adr_got_page, "R_AARCH64_ADR_GOT_PAGE", 32)), /* NOLINT */\
+ ValueType(0x138, MappedType(&ld64_got_lo12, "R_AARCH64_LD64_GOT_LO12_NC", 32)), /* NOLINT */\
+ ValueType(0x20b, MappedType(&unsupported, "R_AARCH64_TLSLD_MOVW_DTPREL_G2", 0)), /* NOLINT */\
+ ValueType(0x20c, MappedType(&unsupported, "R_AARCH64_TLSLD_MOVW_DTPREL_G1", 0)), /* NOLINT */\
+ ValueType(0x20d, MappedType(&unsupported, "R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC", 0)), /* NOLINT */\
+ ValueType(0x20e, MappedType(&unsupported, "R_AARCH64_TLSLD_MOVW_DTPREL_G0", 0)), /* NOLINT */\
+ ValueType(0x20f, MappedType(&unsupported, "R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC", 0)), /* NOLINT */\
+ ValueType(0x210, MappedType(&unsupported, "R_AARCH64_TLSLD_ADD_DTPREL_HI12", 0)), /* NOLINT */\
+ ValueType(0x211, MappedType(&unsupported, "R_AARCH64_TLSLD_ADD_DTPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x212, MappedType(&unsupported, "R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x213, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST8_DTPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x214, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x215, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST16_DTPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x216, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x217, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST32_DTPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x218, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x219, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST64_DTPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x21a, MappedType(&unsupported, "R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x21b, MappedType(&unsupported, "R_AARCH64_TLSIE_MOVW_GOTTPREL_G1", 0)), /* NOLINT */\
+ ValueType(0x21c, MappedType(&unsupported, "R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC", 0)), /* NOLINT */\
+ ValueType(0x21d, MappedType(&unsupported, "R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21", 0)), /* NOLINT */\
+ ValueType(0x21e, MappedType(&unsupported, "R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x21f, MappedType(&unsupported, "R_AARCH64_TLSIE_LD_GOTTPREL_PREL19", 0)), /* NOLINT */\
+ ValueType(0x220, MappedType(&unsupported, "R_AARCH64_TLSLE_MOVW_TPREL_G2", 0)), /* NOLINT */\
+ ValueType(0x221, MappedType(&unsupported, "R_AARCH64_TLSLE_MOVW_TPREL_G1", 0)), /* NOLINT */\
+ ValueType(0x222, MappedType(&unsupported, "R_AARCH64_TLSLE_MOVW_TPREL_G1_NC", 0)), /* NOLINT */\
+ ValueType(0x223, MappedType(&unsupported, "R_AARCH64_TLSLE_MOVW_TPREL_G0", 0)), /* NOLINT */\
+ ValueType(0x224, MappedType(&unsupported, "R_AARCH64_TLSLE_MOVW_TPREL_G0_NC", 0)), /* NOLINT */\
+ ValueType(0x225, MappedType(&unsupported, "R_AARCH64_TLSLE_ADD_TPREL_HI12", 0)), /* NOLINT */\
+ ValueType(0x226, MappedType(&unsupported, "R_AARCH64_TLSLE_ADD_TPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x227, MappedType(&unsupported, "R_AARCH64_TLSLE_ADD_TPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x228, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST8_TPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x229, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x22a, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST16_TPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x22b, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x22c, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST32_TPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x22d, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x22e, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST64_TPREL_LO12", 0)), /* NOLINT */\
+ ValueType(0x22f, MappedType(&unsupported, "R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x232, MappedType(&unsupported, "R_AARCH64_TLSDESC_ADR_PAGE", 0)), /* NOLINT */\
+ ValueType(0x233, MappedType(&unsupported, "R_AARCH64_TLSDESC_LD64_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x234, MappedType(&unsupported, "R_AARCH64_TLSDESC_ADD_LO12_NC", 0)), /* NOLINT */\
+ ValueType(0x239, MappedType(&unsupported, "R_AARCH64_TLSDESC_CALL", 0)), /* NOLINT */\
+ ValueType(1024, MappedType(&unsupported, "R_AARCH64_COPY", 0)), /* NOLINT */\
+ ValueType(1025, MappedType(&unsupported, "R_AARCH64_GLOB_DAT", 0)), /* NOLINT */\
+ ValueType(1026, MappedType(&unsupported, "R_AARCH64_JUMP_SLOT", 0)), /* NOLINT */\
+ ValueType(1027, MappedType(&unsupported, "R_AARCH64_RELATIVE", 0)), /* NOLINT */\
+ ValueType(1028, MappedType(&unsupported, "R_AARCH64_TLS_DTPREL64", 0)), /* NOLINT */\
+ ValueType(1029, MappedType(&unsupported, "R_AARCH64_TLS_DTPMOD64", 0)), /* NOLINT */\
+ ValueType(1030, MappedType(&unsupported, "R_AARCH64_TLS_TPREL64", 0)), /* NOLINT */\
+ ValueType(1031, MappedType(&unsupported, "R_AARCH64_TLSDESC", 0)), /* NOLINT */\
+ ValueType(1032, MappedType(&unsupported, "R_AARCH64_IRELATIVE", 0)) /* NOLINT */
+
+#endif // TARGET_AARCH64_AARCH64RELOCATIONFUNCTIONS_H_
diff --git a/lib/Target/AArch64/AArch64RelocationHelpers.h b/lib/Target/AArch64/AArch64RelocationHelpers.h
index beb6be8..44c849d 100644
--- a/lib/Target/AArch64/AArch64RelocationHelpers.h
+++ b/lib/Target/AArch64/AArch64RelocationHelpers.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64RELOCATIONHELPERS_H
-#define TARGET_AARCH64_AARCH64RELOCATIONHELPERS_H
+#ifndef TARGET_AARCH64_AARCH64RELOCATIONHELPERS_H_
+#define TARGET_AARCH64_AARCH64RELOCATIONHELPERS_H_
#include "AArch64Relocator.h"
#include <llvm/Support/Host.h>
@@ -17,9 +17,8 @@ namespace mcld {
// Relocation helper functions
//===----------------------------------------------------------------------===//
// Return true if overflow
-static inline bool
-helper_check_signed_overflow(Relocator::DWord pValue, unsigned bits)
-{
+static inline bool helper_check_signed_overflow(Relocator::DWord pValue,
+ unsigned bits) {
if (bits >= sizeof(int64_t) * 8)
return false;
int64_t signed_val = static_cast<int64_t>(pValue);
@@ -30,90 +29,78 @@ helper_check_signed_overflow(Relocator::DWord pValue, unsigned bits)
return false;
}
-static inline Relocator::Address
-helper_get_page_address(Relocator::Address pValue)
-{
- return (pValue & ~ (Relocator::Address) 0xFFF);
+static inline Relocator::Address helper_get_page_address(
+ Relocator::Address pValue) {
+ return (pValue & ~(Relocator::Address)0xFFF);
}
-static inline Relocator::Address
-helper_get_page_offset(Relocator::Address pValue)
-{
- return (pValue & (Relocator::Address) 0xFFF);
+static inline Relocator::Address helper_get_page_offset(
+ Relocator::Address pValue) {
+ return (pValue & (Relocator::Address)0xFFF);
}
-static inline uint32_t get_mask(uint32_t pValue)
-{
+static inline uint32_t get_mask(uint32_t pValue) {
return ((1u << (pValue)) - 1);
}
-static inline uint32_t
-helper_reencode_adr_imm(uint32_t pInst, uint32_t pImm)
-{
- return (pInst & ~((get_mask(2) << 29) | (get_mask(19) << 5)))
- | ((pImm & get_mask(2)) << 29) | ((pImm & (get_mask(19) << 2)) << 3);
+static inline uint32_t helper_reencode_adr_imm(uint32_t pInst, uint32_t pImm) {
+ return (pInst & ~((get_mask(2) << 29) | (get_mask(19) << 5))) |
+ ((pImm & get_mask(2)) << 29) | ((pImm & (get_mask(19) << 2)) << 3);
}
// Reencode the imm field of add immediate.
-static inline uint32_t helper_reencode_add_imm(uint32_t pInst, uint32_t pImm)
-{
+static inline uint32_t helper_reencode_add_imm(uint32_t pInst, uint32_t pImm) {
return (pInst & ~(get_mask(12) << 10)) | ((pImm & get_mask(12)) << 10);
}
// Encode the 26-bit offset of unconditional branch.
-static inline uint32_t
-helper_reencode_branch_offset_26(uint32_t pInst, uint32_t pOff)
-{
+static inline uint32_t helper_reencode_branch_offset_26(uint32_t pInst,
+ uint32_t pOff) {
return (pInst & ~get_mask(26)) | (pOff & get_mask(26));
}
// Encode the 19-bit offset of conditional branch and compare & branch.
-static inline uint32_t
-helper_reencode_cond_branch_ofs_19(uint32_t pInst, uint32_t pOff)
-{
+static inline uint32_t helper_reencode_cond_branch_ofs_19(uint32_t pInst,
+ uint32_t pOff) {
return (pInst & ~(get_mask(19) << 5)) | ((pOff & get_mask(19)) << 5);
}
// Reencode the imm field of ld/st pos immediate.
-static inline uint32_t
-helper_reencode_ldst_pos_imm (uint32_t pInst, uint32_t pImm)
-{
+static inline uint32_t helper_reencode_ldst_pos_imm(uint32_t pInst,
+ uint32_t pImm) {
return (pInst & ~(get_mask(12) << 10)) | ((pImm & get_mask(12)) << 10);
}
-static inline uint32_t helper_get_upper32(Relocator::DWord pData)
-{
+static inline uint32_t helper_get_upper32(Relocator::DWord pData) {
if (llvm::sys::IsLittleEndianHost)
return pData >> 32;
return pData & 0xFFFFFFFF;
}
-static inline void helper_put_upper32(uint32_t pData, Relocator::DWord& pDes)
-{
+static inline void helper_put_upper32(uint32_t pData, Relocator::DWord& pDes) {
*(reinterpret_cast<uint32_t*>(&pDes)) = pData;
}
-static inline Relocator::Address
-helper_get_PLT_address(ResolveInfo& pSym, AArch64Relocator& pParent)
-{
+static inline Relocator::Address helper_get_PLT_address(
+ ResolveInfo& pSym,
+ AArch64Relocator& pParent) {
PLTEntryBase* plt_entry = pParent.getSymPLTMap().lookUp(pSym);
- assert(NULL != plt_entry);
+ assert(plt_entry != NULL);
return pParent.getTarget().getPLT().addr() + plt_entry->getOffset();
}
-static inline AArch64PLT1&
-helper_PLT_init(Relocation& pReloc, AArch64Relocator& pParent)
-{
+static inline AArch64PLT1& helper_PLT_init(Relocation& pReloc,
+ AArch64Relocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
AArch64GNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymPLTMap().lookUp(*rsym));
+ assert(pParent.getSymPLTMap().lookUp(*rsym) == NULL);
AArch64PLT1* plt_entry = ld_backend.getPLT().create();
pParent.getSymPLTMap().record(*rsym, *plt_entry);
// initialize plt and the corresponding gotplt and dyn rel entry.
- assert(NULL == pParent.getSymGOTPLTMap().lookUp(*rsym) &&
+ assert(pParent.getSymGOTPLTMap().lookUp(*rsym) == NULL &&
"PLT entry not exist, but DynRel entry exist!");
AArch64GOTEntry* gotplt_entry = ld_backend.getGOTPLT().createGOTPLT();
pParent.getSymGOTPLTMap().record(*rsym, *gotplt_entry);
@@ -127,18 +114,16 @@ helper_PLT_init(Relocation& pReloc, AArch64Relocator& pParent)
}
/// helper_DynRel - Get an relocation entry in .rela.dyn
-static inline Relocation&
-helper_DynRela_init(ResolveInfo* pSym,
- Fragment& pFrag,
- uint64_t pOffset,
- Relocator::Type pType,
- AArch64Relocator& pParent)
-{
+static inline Relocation& helper_DynRela_init(ResolveInfo* pSym,
+ Fragment& pFrag,
+ uint64_t pOffset,
+ Relocator::Type pType,
+ AArch64Relocator& pParent) {
AArch64GNULDBackend& ld_backend = pParent.getTarget();
Relocation& rel_entry = *ld_backend.getRelaDyn().create();
rel_entry.setType(pType);
rel_entry.targetRef().assign(pFrag, pOffset);
- if (pType == R_AARCH64_RELATIVE || NULL == pSym)
+ if (pType == R_AARCH64_RELATIVE || pSym == NULL)
rel_entry.setSymInfo(NULL);
else
rel_entry.setSymInfo(pSym);
@@ -148,40 +133,34 @@ helper_DynRela_init(ResolveInfo* pSym,
/// helper_use_relative_reloc - Check if symbol can use relocation
/// R_AARCH64_RELATIVE
-static inline bool
-helper_use_relative_reloc(const ResolveInfo& pSym,
- const AArch64Relocator& pParent)
-
-{
+static inline bool helper_use_relative_reloc(const ResolveInfo& pSym,
+ const AArch64Relocator& pParent) {
// if symbol is dynamic or undefine or preemptible
- if (pSym.isDyn() ||
- pSym.isUndef() ||
+ if (pSym.isDyn() || pSym.isUndef() ||
pParent.getTarget().isSymbolPreemptible(pSym))
return false;
return true;
}
-static inline Relocator::Address
-helper_get_GOT_address(ResolveInfo& pSym, AArch64Relocator& pParent)
-{
+static inline Relocator::Address helper_get_GOT_address(
+ ResolveInfo& pSym,
+ AArch64Relocator& pParent) {
AArch64GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(pSym);
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
return pParent.getTarget().getGOT().addr() + got_entry->getOffset();
}
-static inline Relocator::Address
-helper_GOT_ORG(AArch64Relocator& pParent)
-{
+static inline Relocator::Address helper_GOT_ORG(AArch64Relocator& pParent) {
return pParent.getTarget().getGOT().addr();
}
-static inline AArch64GOTEntry&
-helper_GOT_init(Relocation& pReloc, bool pHasRel, AArch64Relocator& pParent)
-{
+static inline AArch64GOTEntry& helper_GOT_init(Relocation& pReloc,
+ bool pHasRel,
+ AArch64Relocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
AArch64GNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymGOTMap().lookUp(*rsym));
+ assert(pParent.getSymGOTMap().lookUp(*rsym) == NULL);
AArch64GOTEntry* got_entry = ld_backend.getGOT().createGOT();
pParent.getSymGOTMap().record(*rsym, *got_entry);
@@ -190,17 +169,15 @@ helper_GOT_init(Relocation& pReloc, bool pHasRel, AArch64Relocator& pParent)
if (!pHasRel) {
// No corresponding dynamic relocation, initialize to the symbol value.
got_entry->setValue(AArch64Relocator::SymVal);
- }
- else {
+ } else {
// Initialize got_entry content and the corresponding dynamic relocation.
if (helper_use_relative_reloc(*rsym, pParent)) {
got_entry->setValue(AArch64Relocator::SymVal);
- Relocation& rel_entry = helper_DynRela_init(rsym, *got_entry, 0x0,
- R_AARCH64_RELATIVE, pParent);
+ Relocation& rel_entry = helper_DynRela_init(
+ rsym, *got_entry, 0x0, R_AARCH64_RELATIVE, pParent);
rel_entry.setAddend(AArch64Relocator::SymVal);
pParent.getRelRelMap().record(pReloc, rel_entry);
- }
- else {
+ } else {
helper_DynRela_init(rsym, *got_entry, 0x0, R_AARCH64_GLOB_DAT, pParent);
got_entry->setValue(0);
}
@@ -208,5 +185,6 @@ helper_GOT_init(Relocation& pReloc, bool pHasRel, AArch64Relocator& pParent)
return *got_entry;
}
-}
-#endif
+} // namespace mcld
+
+#endif // TARGET_AARCH64_AARCH64RELOCATIONHELPERS_H_
diff --git a/lib/Target/AArch64/AArch64Relocator.cpp b/lib/Target/AArch64/AArch64Relocator.cpp
index db99762..a884924 100644
--- a/lib/Target/AArch64/AArch64Relocator.cpp
+++ b/lib/Target/AArch64/AArch64Relocator.cpp
@@ -7,23 +7,23 @@
//
//===----------------------------------------------------------------------===//
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/Object/ObjectBuilder.h"
+
+#include "AArch64Relocator.h"
+#include "AArch64RelocationFunctions.h"
+#include "AArch64RelocationHelpers.h"
#include <llvm/ADT/Twine.h>
#include <llvm/Support/DataTypes.h>
#include <llvm/Support/ELF.h>
#include <llvm/Support/Host.h>
-#include "AArch64Relocator.h"
-#include "AArch64RelocationFunctions.h"
-#include "AArch64RelocationHelpers.h"
-
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// Relocation Functions and Tables
@@ -36,12 +36,12 @@ typedef Relocator::Result (*ApplyFunctionType)(Relocation& pReloc,
// the table entry of applying functions
class ApplyFunctionEntry {
-public:
+ public:
ApplyFunctionEntry() {}
ApplyFunctionEntry(ApplyFunctionType pFunc,
const char* pName,
size_t pSize = 0)
- : func(pFunc), name(pName), size(pSize) { }
+ : func(pFunc), name(pName), size(pSize) {}
ApplyFunctionType func;
const char* name;
size_t size;
@@ -49,29 +49,27 @@ public:
typedef std::map<Relocator::Type, ApplyFunctionEntry> ApplyFunctionMap;
static const ApplyFunctionMap::value_type ApplyFunctionList[] = {
- DECL_AARCH64_APPLY_RELOC_FUNC_PTRS(ApplyFunctionMap::value_type,
- ApplyFunctionEntry)
-};
+ DECL_AARCH64_APPLY_RELOC_FUNC_PTRS(ApplyFunctionMap::value_type,
+ ApplyFunctionEntry)};
// declare the table of applying functions
static ApplyFunctionMap ApplyFunctions(ApplyFunctionList,
- ApplyFunctionList + sizeof(ApplyFunctionList)/sizeof(ApplyFunctionList[0]));
+ ApplyFunctionList +
+ sizeof(ApplyFunctionList) /
+ sizeof(ApplyFunctionList[0]));
//===----------------------------------------------------------------------===//
// AArch64Relocator
//===----------------------------------------------------------------------===//
AArch64Relocator::AArch64Relocator(AArch64GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : Relocator(pConfig),
- m_Target(pParent) {
+ : Relocator(pConfig), m_Target(pParent) {
}
-AArch64Relocator::~AArch64Relocator()
-{
+AArch64Relocator::~AArch64Relocator() {
}
-Relocator::Result AArch64Relocator::applyRelocation(Relocation& pRelocation)
-{
+Relocator::Result AArch64Relocator::applyRelocation(Relocation& pRelocation) {
Relocation::Type type = pRelocation.type();
// valid types are 0x0, 0x100-0x239
if ((type < 0x100 || type > 0x239) && (type != 0x0)) {
@@ -81,19 +79,16 @@ Relocator::Result AArch64Relocator::applyRelocation(Relocation& pRelocation)
return ApplyFunctions[type].func(pRelocation, *this);
}
-const char* AArch64Relocator::getName(Relocator::Type pType) const
-{
+const char* AArch64Relocator::getName(Relocator::Type pType) const {
assert(ApplyFunctions.find(pType) != ApplyFunctions.end());
return ApplyFunctions[pType].name;
}
-Relocator::Size AArch64Relocator::getSize(Relocation::Type pType) const
-{
+Relocator::Size AArch64Relocator::getSize(Relocation::Type pType) const {
return ApplyFunctions[pType].size;
}
-void AArch64Relocator::addCopyReloc(ResolveInfo& pSym)
-{
+void AArch64Relocator::addCopyReloc(ResolveInfo& pSym) {
Relocation& rel_entry = *getTarget().getRelaDyn().create();
rel_entry.setType(R_AARCH64_COPY);
assert(pSym.outSymbol()->hasFragRef());
@@ -107,8 +102,7 @@ void AArch64Relocator::addCopyReloc(ResolveInfo& pSym)
/// copy.
/// This is executed at scan relocation stage.
LDSymbol& AArch64Relocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
- const ResolveInfo& pSym)
-{
+ const ResolveInfo& pSym) {
// get or create corresponding BSS LDSection
LDSection* bss_sect_hdr = NULL;
ELFFileFormat* file_format = getTarget().getOutputFormat();
@@ -140,24 +134,23 @@ LDSymbol& AArch64Relocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
// Define the copy symbol in the bss section and resolve it
LDSymbol* cpy_sym = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- pSym.name(),
- (ResolveInfo::Type)pSym.type(),
- ResolveInfo::Define,
- binding,
- pSym.size(), // size
- 0x0, // value
- FragmentRef::Create(*frag, 0x0),
- (ResolveInfo::Visibility)pSym.other());
+ pSym.name(),
+ (ResolveInfo::Type)pSym.type(),
+ ResolveInfo::Define,
+ binding,
+ pSym.size(), // size
+ 0x0, // value
+ FragmentRef::Create(*frag, 0x0),
+ (ResolveInfo::Visibility)pSym.other());
return *cpy_sym;
}
-void
-AArch64Relocator::scanLocalReloc(Relocation& pReloc, const LDSection& pSection)
-{
+void AArch64Relocator::scanLocalReloc(Relocation& pReloc,
+ const LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()) {
+ switch (pReloc.type()) {
case llvm::ELF::R_AARCH64_ABS64:
// If buiding PIC object (shared library or PIC executable),
// a dynamic relocations with RELATIVE type to this location is needed.
@@ -184,8 +177,10 @@ AArch64Relocator::scanLocalReloc(Relocation& pReloc, const LDSection& pSection)
if (config().isCodeIndep()) {
// set up the dyn rel directly
Relocation& reloc = helper_DynRela_init(rsym,
- *pReloc.targetRef().frag(),
- pReloc.targetRef().offset(), pReloc.type(), *this);
+ *pReloc.targetRef().frag(),
+ pReloc.targetRef().offset(),
+ pReloc.type(),
+ *this);
getRelRelMap().record(pReloc, reloc);
// set Rel bit
rsym->setReserved(rsym->reserved() | ReserveRel);
@@ -202,9 +197,9 @@ AArch64Relocator::scanLocalReloc(Relocation& pReloc, const LDSection& pSection)
// If building PIC object, a dynamic relocation with
// type RELATIVE is needed to relocate this GOT entry.
if (config().isCodeIndep())
- helper_GOT_init(pReloc, true, *this);
+ helper_GOT_init(pReloc, true, *this);
else
- helper_GOT_init(pReloc, false, *this);
+ helper_GOT_init(pReloc, false, *this);
// set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
return;
@@ -217,11 +212,10 @@ AArch64Relocator::scanLocalReloc(Relocation& pReloc, const LDSection& pSection)
void AArch64Relocator::scanGlobalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
- const LDSection& pSection)
-{
+ const LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()) {
+ switch (pReloc.type()) {
case llvm::ELF::R_AARCH64_ABS64:
case llvm::ELF::R_AARCH64_ABS32:
case llvm::ELF::R_AARCH64_ABS16:
@@ -229,7 +223,7 @@ void AArch64Relocator::scanGlobalReloc(Relocation& pReloc,
// dynamic relocation entry
if (getTarget().symbolNeedsPLT(*rsym)) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -239,14 +233,14 @@ void AArch64Relocator::scanGlobalReloc(Relocation& pReloc,
}
}
- if (getTarget().symbolNeedsDynRel(*rsym, (rsym->reserved() & ReservePLT),
- true)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), true)) {
// symbol needs dynamic relocation entry, set up the dynrel entry
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym);
addCopyReloc(*cpy_sym.resolveInfo());
- }
- else {
+ } else {
// set Rel bit and the dyn rel
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
@@ -258,8 +252,7 @@ void AArch64Relocator::scanGlobalReloc(Relocation& pReloc,
R_AARCH64_RELATIVE,
*this);
getRelRelMap().record(pReloc, reloc);
- }
- else {
+ } else {
Relocation& reloc = helper_DynRela_init(rsym,
*pReloc.targetRef().frag(),
pReloc.targetRef().offset(),
@@ -277,7 +270,7 @@ void AArch64Relocator::scanGlobalReloc(Relocation& pReloc,
if (getTarget().symbolNeedsPLT(*rsym) &&
LinkerConfig::DynObj != config().codeGenType()) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -293,9 +286,9 @@ void AArch64Relocator::scanGlobalReloc(Relocation& pReloc,
// All other dynamic relocations may lead to run-time relocation
// overflow.
if (getTarget().isDynamicSymbol(*rsym) &&
- getTarget().symbolNeedsDynRel(*rsym,
- (rsym->reserved() & ReservePLT),
- false) &&
+ getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), false) &&
getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym);
addCopyReloc(*cpy_sym.resolveInfo());
@@ -316,7 +309,7 @@ void AArch64Relocator::scanGlobalReloc(Relocation& pReloc,
// if symbol is defined in the ouput file and it's not
// preemptible, no need plt
if (rsym->isDefine() && !rsym->isDyn() &&
- !getTarget().isSymbolPreemptible(*rsym)) {
+ !getTarget().isSymbolPreemptible(*rsym)) {
return;
}
@@ -331,9 +324,9 @@ void AArch64Relocator::scanGlobalReloc(Relocation& pReloc,
case llvm::ELF::R_AARCH64_ADR_PREL_PG_HI21:
case R_AARCH64_ADR_PREL_PG_HI21_NC:
- if (getTarget().symbolNeedsDynRel(*rsym,
- (rsym->reserved() & ReservePLT),
- false)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), false)) {
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym);
addCopyReloc(*cpy_sym.resolveInfo());
@@ -341,7 +334,7 @@ void AArch64Relocator::scanGlobalReloc(Relocation& pReloc,
}
if (getTarget().symbolNeedsPLT(*rsym)) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -378,14 +371,13 @@ void AArch64Relocator::scanRelocation(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
LDSection& pSection,
- Input& pInput)
-{
+ Input& pInput) {
ResolveInfo* rsym = pReloc.symInfo();
- assert(NULL != rsym &&
+ assert(rsym != NULL &&
"ResolveInfo of relocation not set while scanRelocation");
- assert(NULL != pSection.getLink());
- if (0 == (pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC))
+ assert(pSection.getLink() != NULL);
+ if ((pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC) == 0)
return;
// Scan relocation type to determine if an GOT/PLT/Dynamic Relocation
@@ -405,31 +397,45 @@ void AArch64Relocator::scanRelocation(Relocation& pReloc,
issueUndefRef(pReloc, pSection, pInput);
}
+uint32_t AArch64Relocator::getDebugStringOffset(Relocation& pReloc) const {
+ if (pReloc.type() != llvm::ELF::R_AARCH64_ABS32)
+ error(diag::unsupport_reloc_for_debug_string)
+ << getName(pReloc.type()) << "mclinker@googlegroups.com";
+
+ if (pReloc.symInfo()->type() == ResolveInfo::Section)
+ return pReloc.target();
+ else
+ return pReloc.symInfo()->outSymbol()->fragRef()->offset() +
+ pReloc.target() + pReloc.addend();
+}
+
+void AArch64Relocator::applyDebugStringOffset(Relocation& pReloc,
+ uint32_t pOffset) {
+ pReloc.target() = pOffset;
+}
+
//===----------------------------------------------------------------------===//
// Each relocation function implementation
//===----------------------------------------------------------------------===//
// R_AARCH64_NONE
-Relocator::Result none(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result none(Relocation& pReloc, AArch64Relocator& pParent) {
return Relocator::OK;
}
-Relocator::Result unsupport(Relocation& pReloc, AArch64Relocator& pParent)
-{
- return Relocator::Unsupport;
+Relocator::Result unsupported(Relocation& pReloc, AArch64Relocator& pParent) {
+ return Relocator::Unsupported;
}
// R_AARCH64_ABS64: S + A
// R_AARCH64_ABS32: S + A
// R_AARCH64_ABS16: S + A
-Relocator::Result abs(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result abs(Relocation& pReloc, AArch64Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::DWord S = pReloc.symValue();
Relocation* dyn_rel = pParent.getRelRelMap().lookUp(pReloc);
- bool has_dyn_rel = (NULL != dyn_rel);
+ bool has_dyn_rel = (dyn_rel != NULL);
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
// If the flag of target section is not ALLOC, we will not scan this
@@ -455,8 +461,7 @@ Relocator::Result abs(Relocation& pReloc, AArch64Relocator& pParent)
if (llvm::ELF::R_AARCH64_ABS64 == pReloc.type() &&
R_AARCH64_RELATIVE == dyn_rel->type()) {
dyn_rel->setAddend(S + A);
- }
- else {
+ } else {
dyn_rel->setAddend(A);
return Relocator::OK;
}
@@ -471,15 +476,14 @@ Relocator::Result abs(Relocation& pReloc, AArch64Relocator& pParent)
// R_AARCH64_PREL64: S + A - P
// R_AARCH64_PREL32: S + A - P
// R_AARCH64_PREL16: S + A - P
-Relocator::Result rel(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result rel(Relocation& pReloc, AArch64Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
- Relocator::DWord A = pReloc.addend();
- Relocator::DWord P = pReloc.place();
+ Relocator::DWord A = pReloc.addend();
+ Relocator::DWord P = pReloc.place();
if (llvm::ELF::R_AARCH64_PREL64 != pReloc.type())
- A += pReloc.target() & get_mask(pParent.getSize(pReloc.type()));
+ A += pReloc.target() & get_mask(pParent.getSize(pReloc.type()));
else
A += pReloc.target();
@@ -505,11 +509,10 @@ Relocator::Result rel(Relocation& pReloc, AArch64Relocator& pParent)
}
// R_AARCH64_ADD_ABS_LO12_NC: S + A
-Relocator::Result add_abs_lo12(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result add_abs_lo12(Relocation& pReloc, AArch64Relocator& pParent) {
Relocator::Address value = 0x0;
Relocator::Address S = pReloc.symValue();
- Relocator::DWord A = pReloc.addend();
+ Relocator::DWord A = pReloc.addend();
value = helper_get_page_offset(S + A);
pReloc.target() = helper_reencode_add_imm(pReloc.target(), value);
@@ -519,9 +522,8 @@ Relocator::Result add_abs_lo12(Relocation& pReloc, AArch64Relocator& pParent)
// R_AARCH64_ADR_PREL_PG_HI21: ((PG(S + A) - PG(P)) >> 12)
// R_AARCH64_ADR_PREL_PG_HI21_NC: ((PG(S + A) - PG(P)) >> 12)
-Relocator::Result
-adr_prel_pg_hi21(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result adr_prel_pg_hi21(Relocation& pReloc,
+ AArch64Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
// if plt entry exists, the S value is the plt entry address
@@ -529,9 +531,9 @@ adr_prel_pg_hi21(Relocation& pReloc, AArch64Relocator& pParent)
S = helper_get_PLT_address(*rsym, pParent);
}
Relocator::DWord A = pReloc.addend();
- Relocator::DWord P = pReloc.place() ;
- Relocator::DWord X = helper_get_page_address(S + A) -
- helper_get_page_address(P);
+ Relocator::DWord P = pReloc.place();
+ Relocator::DWord X =
+ helper_get_page_address(S + A) - helper_get_page_address(P);
pReloc.target() = helper_reencode_adr_imm(pReloc.target(), (X >> 12));
@@ -540,13 +542,11 @@ adr_prel_pg_hi21(Relocation& pReloc, AArch64Relocator& pParent)
// R_AARCH64_CALL26: S + A - P
// R_AARCH64_JUMP26: S + A - P
-Relocator::Result call(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result call(Relocation& pReloc, AArch64Relocator& pParent) {
// If target is undefined weak symbol, we only need to jump to the
// next instruction unless it has PLT entry. Rewrite instruction
// to NOP.
- if (pReloc.symInfo()->isWeak() &&
- pReloc.symInfo()->isUndef() &&
+ if (pReloc.symInfo()->isWeak() && pReloc.symInfo()->isUndef() &&
!pReloc.symInfo()->isDyn() &&
!(pReloc.symInfo()->reserved() & AArch64Relocator::ReservePLT)) {
// change target to NOP
@@ -555,7 +555,7 @@ Relocator::Result call(Relocation& pReloc, AArch64Relocator& pParent)
}
Relocator::Address S = pReloc.symValue();
- Relocator::DWord A = pReloc.addend();
+ Relocator::DWord A = pReloc.addend();
Relocator::Address P = pReloc.place();
// S depends on PLT exists or not
@@ -571,13 +571,11 @@ Relocator::Result call(Relocation& pReloc, AArch64Relocator& pParent)
}
// R_AARCH64_CONDBR19: S + A - P
-Relocator::Result condbr(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result condbr(Relocation& pReloc, AArch64Relocator& pParent) {
// If target is undefined weak symbol, we only need to jump to the
// next instruction unless it has PLT entry. Rewrite instruction
// to NOP.
- if (pReloc.symInfo()->isWeak() &&
- pReloc.symInfo()->isUndef() &&
+ if (pReloc.symInfo()->isWeak() && pReloc.symInfo()->isUndef() &&
!pReloc.symInfo()->isDyn() &&
!(pReloc.symInfo()->reserved() & AArch64Relocator::ReservePLT)) {
// change target to NOP
@@ -586,7 +584,7 @@ Relocator::Result condbr(Relocation& pReloc, AArch64Relocator& pParent)
}
Relocator::Address S = pReloc.symValue();
- Relocator::DWord A = pReloc.addend();
+ Relocator::DWord A = pReloc.addend();
Relocator::Address P = pReloc.place();
// S depends on PLT exists or not
@@ -602,8 +600,7 @@ Relocator::Result condbr(Relocation& pReloc, AArch64Relocator& pParent)
}
// R_AARCH64_ADR_GOT_PAGE: Page(G(GDAT(S+A))) - Page(P)
-Relocator::Result adr_got_page(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result adr_got_page(Relocation& pReloc, AArch64Relocator& pParent) {
if (!(pReloc.symInfo()->reserved() & AArch64Relocator::ReserveGOT)) {
return Relocator::BadReloc;
}
@@ -611,26 +608,25 @@ Relocator::Result adr_got_page(Relocation& pReloc, AArch64Relocator& pParent)
Relocator::Address GOT_S = helper_get_GOT_address(*pReloc.symInfo(), pParent);
Relocator::DWord A = pReloc.addend();
Relocator::Address P = pReloc.place();
- Relocator::DWord X = helper_get_page_address(GOT_S + A) -
- helper_get_page_address(P);
+ Relocator::DWord X =
+ helper_get_page_address(GOT_S + A) - helper_get_page_address(P);
pReloc.target() = helper_reencode_adr_imm(pReloc.target(), (X >> 12));
// setup got entry value if needed
AArch64GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- if (NULL != got_entry && AArch64Relocator::SymVal == got_entry->getValue())
+ if (got_entry != NULL && AArch64Relocator::SymVal == got_entry->getValue())
got_entry->setValue(pReloc.symValue());
// setup relocation addend if needed
Relocation* dyn_rela = pParent.getRelRelMap().lookUp(pReloc);
- if ((NULL != dyn_rela) && (AArch64Relocator::SymVal == dyn_rela->addend())) {
+ if ((dyn_rela != NULL) && (AArch64Relocator::SymVal == dyn_rela->addend())) {
dyn_rela->setAddend(pReloc.symValue());
}
return Relocator::OK;
}
// R_AARCH64_LD64_GOT_LO12_NC: G(GDAT(S+A))
-Relocator::Result ld64_got_lo12(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result ld64_got_lo12(Relocation& pReloc, AArch64Relocator& pParent) {
if (!(pReloc.symInfo()->reserved() & AArch64Relocator::ReserveGOT)) {
return Relocator::BadReloc;
}
@@ -643,12 +639,12 @@ Relocator::Result ld64_got_lo12(Relocation& pReloc, AArch64Relocator& pParent)
// setup got entry value if needed
AArch64GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- if (NULL != got_entry && AArch64Relocator::SymVal == got_entry->getValue())
+ if (got_entry != NULL && AArch64Relocator::SymVal == got_entry->getValue())
got_entry->setValue(pReloc.symValue());
// setup relocation addend if needed
Relocation* dyn_rela = pParent.getRelRelMap().lookUp(pReloc);
- if ((NULL != dyn_rela) && (AArch64Relocator::SymVal == dyn_rela->addend())) {
+ if ((dyn_rela != NULL) && (AArch64Relocator::SymVal == dyn_rela->addend())) {
dyn_rela->setAddend(pReloc.symValue());
}
@@ -660,35 +656,31 @@ Relocator::Result ld64_got_lo12(Relocation& pReloc, AArch64Relocator& pParent)
// R_AARCH64_LDST32_ABS_LO12_NC: S + A
// R_AARCH64_LDST64_ABS_LO12_NC: S + A
// R_AARCH64_LDST128_ABS_LO12_NC: S + A
-Relocator::Result ldst_abs_lo12(Relocation& pReloc, AArch64Relocator& pParent)
-{
+Relocator::Result ldst_abs_lo12(Relocation& pReloc, AArch64Relocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord A = pReloc.addend();
Relocator::DWord X = helper_get_page_offset(S + A);
- switch(pReloc.type()) {
- case llvm::ELF::R_AARCH64_LDST8_ABS_LO12_NC:
- pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(), X);
- break;
- case llvm::ELF::R_AARCH64_LDST16_ABS_LO12_NC:
- pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(),
- (X >> 1));
- break;
- case llvm::ELF::R_AARCH64_LDST32_ABS_LO12_NC:
- pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(),
- (X >> 2));
- break;
- case llvm::ELF::R_AARCH64_LDST64_ABS_LO12_NC:
- pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(),
- (X >> 3));
- break;
- case llvm::ELF::R_AARCH64_LDST128_ABS_LO12_NC:
- pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(),
- (X >> 4));
- break;
+ switch (pReloc.type()) {
+ case llvm::ELF::R_AARCH64_LDST8_ABS_LO12_NC:
+ pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(), X);
+ break;
+ case llvm::ELF::R_AARCH64_LDST16_ABS_LO12_NC:
+ pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(), (X >> 1));
+ break;
+ case llvm::ELF::R_AARCH64_LDST32_ABS_LO12_NC:
+ pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(), (X >> 2));
+ break;
+ case llvm::ELF::R_AARCH64_LDST64_ABS_LO12_NC:
+ pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(), (X >> 3));
+ break;
+ case llvm::ELF::R_AARCH64_LDST128_ABS_LO12_NC:
+ pReloc.target() = helper_reencode_ldst_pos_imm(pReloc.target(), (X >> 4));
+ break;
default:
- break;
+ break;
}
return Relocator::OK;
}
+} // namespace mcld
diff --git a/lib/Target/AArch64/AArch64Relocator.h b/lib/Target/AArch64/AArch64Relocator.h
index 7fe8302..6116147 100644
--- a/lib/Target/AArch64/AArch64Relocator.h
+++ b/lib/Target/AArch64/AArch64Relocator.h
@@ -6,12 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64RELOCATOR_H
-#define TARGET_AARCH64_AARCH64RELOCATOR_H
+#ifndef TARGET_AARCH64_AARCH64RELOCATOR_H_
+#define TARGET_AARCH64_AARCH64RELOCATOR_H_
-#include <mcld/LD/Relocator.h>
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/KeyEntryMap.h>
+#include "mcld/LD/Relocator.h"
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/KeyEntryMap.h"
#include "AArch64LDBackend.h"
namespace mcld {
@@ -20,24 +20,23 @@ enum {
// static relocations
R_AARCH64_ADR_PREL_PG_HI21_NC = 0x114,
// dyanmic rlocations
- R_AARCH64_COPY = 1024,
- R_AARCH64_GLOB_DAT = 1025,
- R_AARCH64_JUMP_SLOT = 1026,
- R_AARCH64_RELATIVE = 1027,
- R_AARCH64_TLS_DTPREL64 = 1028,
- R_AARCH64_TLS_DTPMOD64 = 1029,
- R_AARCH64_TLS_TPREL64 = 1030,
- R_AARCH64_TLSDESC = 1031,
- R_AARCH64_IRELATIVE = 1032
+ R_AARCH64_COPY = 1024,
+ R_AARCH64_GLOB_DAT = 1025,
+ R_AARCH64_JUMP_SLOT = 1026,
+ R_AARCH64_RELATIVE = 1027,
+ R_AARCH64_TLS_DTPREL64 = 1028,
+ R_AARCH64_TLS_DTPMOD64 = 1029,
+ R_AARCH64_TLS_TPREL64 = 1030,
+ R_AARCH64_TLSDESC = 1031,
+ R_AARCH64_IRELATIVE = 1032
};
/** \class AArch64Relocator
* \brief AArch64Relocator creates and destroys the AArch64 relocations.
*
*/
-class AArch64Relocator : public Relocator
-{
-public:
+class AArch64Relocator : public Relocator {
+ public:
typedef KeyEntryMap<ResolveInfo, AArch64GOTEntry> SymGOTMap;
typedef KeyEntryMap<ResolveInfo, AArch64PLT1> SymPLTMap;
typedef KeyEntryMap<Relocation, Relocation> RelRelMap;
@@ -61,10 +60,10 @@ public:
*
*/
enum ReservedEntryType {
- None = 0,
- ReserveRel = 1,
- ReserveGOT = 2,
- ReservePLT = 4,
+ None = 0,
+ ReserveRel = 1,
+ ReserveGOT = 2,
+ ReservePLT = 4,
};
/** \enum EntryValue
@@ -72,38 +71,33 @@ public:
* layout, so we mark the entry during scanRelocation and fill up the actual
* value when applying relocations.
*/
- enum EntryValue {
- Default = 0,
- SymVal = 1
- };
+ enum EntryValue { Default = 0, SymVal = 1 };
-public:
+ public:
AArch64Relocator(AArch64GNULDBackend& pParent, const LinkerConfig& pConfig);
~AArch64Relocator();
Result applyRelocation(Relocation& pRelocation);
- AArch64GNULDBackend& getTarget()
- { return m_Target; }
+ AArch64GNULDBackend& getTarget() { return m_Target; }
- const AArch64GNULDBackend& getTarget() const
- { return m_Target; }
+ const AArch64GNULDBackend& getTarget() const { return m_Target; }
const char* getName(Relocation::Type pType) const;
Size getSize(Relocation::Type pType) const;
const SymGOTMap& getSymGOTMap() const { return m_SymGOTMap; }
- SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
+ SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
const SymPLTMap& getSymPLTMap() const { return m_SymPLTMap; }
- SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
+ SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
const SymGOTMap& getSymGOTPLTMap() const { return m_SymGOTPLTMap; }
- SymGOTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
+ SymGOTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
const RelRelMap& getRelRelMap() const { return m_RelRelMap; }
- RelRelMap& getRelRelMap() { return m_RelRelMap; }
+ RelRelMap& getRelRelMap() { return m_RelRelMap; }
/// scanRelocation - determine the empty entries are needed or not and create
/// the empty entries if needed.
@@ -117,7 +111,15 @@ public:
LDSection& pSection,
Input& pInput);
-private:
+ /// getDebugStringOffset - get the offset from the relocation target. This is
+ /// used to get the debug string offset.
+ uint32_t getDebugStringOffset(Relocation& pReloc) const;
+
+ /// applyDebugStringOffset - apply the relocation target to specific offset.
+ /// This is used to set the debug string offset.
+ void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset);
+
+ private:
void scanLocalReloc(Relocation& pReloc, const LDSection& pSection);
void scanGlobalReloc(Relocation& pReloc,
@@ -134,7 +136,7 @@ private:
LDSymbol& defineSymbolforCopyReloc(IRBuilder& pLinker,
const ResolveInfo& pSym);
-private:
+ private:
AArch64GNULDBackend& m_Target;
SymGOTMap m_SymGOTMap;
SymPLTMap m_SymPLTMap;
@@ -142,7 +144,6 @@ private:
RelRelMap m_RelRelMap;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_AARCH64_AARCH64RELOCATOR_H_
diff --git a/lib/Target/AArch64/AArch64TargetMachine.cpp b/lib/Target/AArch64/AArch64TargetMachine.cpp
deleted file mode 100644
index c0515f4..0000000
--- a/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-//===- AArch64TargetMachine.cpp -------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "AArch64TargetMachine.h"
-#include "AArch64.h"
-
-#include <mcld/Support/TargetRegistry.h>
-
-using namespace mcld;
-
-AArch64BaseTargetMachine::AArch64BaseTargetMachine(llvm::TargetMachine& pPM,
- const llvm::Target &pLLVMTarget,
- const mcld::Target &pMCLDTarget,
- const std::string& pTriple)
- : MCLDTargetMachine(pPM, pLLVMTarget, pMCLDTarget, pTriple) {
-}
-
-//===----------------------------------------------------------------------===//
-// Initialize MCLDTargetMachine
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeAArch64LDTarget() {
- // Register createTargetMachine function pointer to mcld::Target
- mcld::RegisterTargetMachine<mcld::AArch64BaseTargetMachine> X(mcld::TheAArch64Target);
-}
-
diff --git a/lib/Target/AArch64/AArch64TargetMachine.h b/lib/Target/AArch64/AArch64TargetMachine.h
deleted file mode 100644
index aee0e8c..0000000
--- a/lib/Target/AArch64/AArch64TargetMachine.h
+++ /dev/null
@@ -1,29 +0,0 @@
-//===- AArch64TargetMachine.h ---------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_AARCH64_AARCH64TARGETMACHINE_H
-#define TARGET_AARCH64_AARCH64TARGETMACHINE_H
-
-#include "AArch64.h"
-#include <mcld/CodeGen/TargetMachine.h>
-
-namespace mcld {
-
-class AArch64BaseTargetMachine : public MCLDTargetMachine
-{
-public:
- AArch64BaseTargetMachine(llvm::TargetMachine& pTM,
- const llvm::Target& pLLVMTarget,
- const mcld::Target& pMCLDTarget,
- const std::string& pTriple);
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/lib/Target/AArch64/Android.mk b/lib/Target/AArch64/Android.mk
index 31383bf..a143c53 100644
--- a/lib/Target/AArch64/Android.mk
+++ b/lib/Target/AArch64/Android.mk
@@ -3,14 +3,11 @@ LOCAL_PATH:= $(call my-dir)
mcld_aarch64_target_SRC_FILES := \
AArch64Diagnostic.cpp \
AArch64ELFDynamic.cpp \
- AArch64ELFMCLinker.cpp \
AArch64Emulation.cpp \
AArch64GOT.cpp \
AArch64LDBackend.cpp \
- AArch64MCLinker.cpp \
AArch64PLT.cpp \
- AArch64Relocator.cpp \
- AArch64TargetMachine.cpp
+ AArch64Relocator.cpp
# For the host
# =====================================================
diff --git a/lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp b/lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp
index 13472c9..6d98eba 100644
--- a/lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp
+++ b/lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Support/Target.h>
+#include "mcld/Support/Target.h"
+#include "mcld/Support/TargetRegistry.h"
namespace mcld {
@@ -18,5 +18,4 @@ extern "C" void MCLDInitializeAArch64LDTargetInfo() {
mcld::RegisterTarget<llvm::Triple::aarch64> X(TheAArch64Target, "aarch64");
}
-} // namespace of mcld
-
+} // namespace mcld
diff --git a/lib/Target/ARM/ARM.h b/lib/Target/ARM/ARM.h
index f368ba8..c79fc66 100644
--- a/lib/Target/ARM/ARM.h
+++ b/lib/Target/ARM/ARM.h
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARM_H
-#define TARGET_ARM_ARM_H
+#ifndef TARGET_ARM_ARM_H_
+#define TARGET_ARM_ARM_H_
#include <string>
namespace llvm {
class Target;
-} // namespace of llvm
+} // namespace llvm
namespace mcld {
@@ -22,9 +22,8 @@ class TargetLDBackend;
extern mcld::Target TheARMTarget;
extern mcld::Target TheThumbTarget;
-TargetLDBackend *createARMLDBackend(const llvm::Target&, const std::string&);
+TargetLDBackend* createARMLDBackend(const llvm::Target&, const std::string&);
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_ARM_ARM_H_
diff --git a/lib/Target/ARM/ARMDiagnostic.cpp b/lib/Target/ARM/ARMDiagnostic.cpp
index 77cb87e..4442a4b 100644
--- a/lib/Target/ARM/ARMDiagnostic.cpp
+++ b/lib/Target/ARM/ARMDiagnostic.cpp
@@ -6,30 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/DWARFLineInfo.h>
+#include "mcld/LD/DWARFLineInfo.h"
+#include "mcld/Support/TargetRegistry.h"
#include "ARM.h"
-using namespace mcld;
-
namespace mcld {
//===----------------------------------------------------------------------===//
// createARMDiagnostic - the help function to create corresponding ARMDiagnostic
//===----------------------------------------------------------------------===//
DiagnosticLineInfo* createARMDiagLineInfo(const mcld::Target& pTarget,
- const std::string &pTriple)
-{
+ const std::string& pTriple) {
return new DWARFLineInfo();
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// InitializeARMDiagnostic
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeARMDiagnosticLineInfo() {
// Register the linker frontend
- mcld::TargetRegistry::RegisterDiagnosticLineInfo(TheARMTarget, createARMDiagLineInfo);
- mcld::TargetRegistry::RegisterDiagnosticLineInfo(TheThumbTarget, createARMDiagLineInfo);
+ mcld::TargetRegistry::RegisterDiagnosticLineInfo(mcld::TheARMTarget,
+ mcld::createARMDiagLineInfo);
+ mcld::TargetRegistry::RegisterDiagnosticLineInfo(mcld::TheThumbTarget,
+ mcld::createARMDiagLineInfo);
}
-
diff --git a/lib/Target/ARM/ARMELFAttributeData.cpp b/lib/Target/ARM/ARMELFAttributeData.cpp
index 8656b7e..fda6991 100644
--- a/lib/Target/ARM/ARMELFAttributeData.cpp
+++ b/lib/Target/ARM/ARMELFAttributeData.cpp
@@ -8,17 +8,18 @@
//===----------------------------------------------------------------------===//
#include "ARMELFAttributeData.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Support/LEB128.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Support/LEB128.h"
+#include "mcld/Support/MsgHandling.h"
+#include <llvm/ADT/STLExtras.h>
-using namespace mcld;
+namespace mcld {
-const ELFAttributeValue *ARMELFAttributeData::getAttributeValue(TagType pTag) const
-{
+const ELFAttributeValue* ARMELFAttributeData::getAttributeValue(
+ TagType pTag) const {
if (pTag <= Tag_Max) {
- const ELFAttributeValue &attr_value = m_Attrs[pTag];
+ const ELFAttributeValue& attr_value = m_Attrs[pTag];
if (attr_value.isInitialized()) {
return &attr_value;
@@ -38,9 +39,8 @@ const ELFAttributeValue *ARMELFAttributeData::getAttributeValue(TagType pTag) co
}
std::pair<ELFAttributeValue*, bool>
-ARMELFAttributeData::getOrCreateAttributeValue(TagType pTag)
-{
- ELFAttributeValue *attr_value = NULL;
+ARMELFAttributeData::getOrCreateAttributeValue(TagType pTag) {
+ ELFAttributeValue* attr_value = NULL;
if (pTag <= Tag_Max) {
attr_value = &m_Attrs[pTag];
@@ -60,8 +60,7 @@ ARMELFAttributeData::getOrCreateAttributeValue(TagType pTag)
}
}
-unsigned int ARMELFAttributeData::GetAttributeValueType(TagType pTag)
-{
+unsigned int ARMELFAttributeData::GetAttributeValueType(TagType pTag) {
// See ARM [ABI-addenda], 2.2.6.
switch (pTag) {
case Tag_compatibility: {
@@ -78,8 +77,8 @@ unsigned int ARMELFAttributeData::GetAttributeValueType(TagType pTag)
if (pTag < 32)
return ELFAttributeValue::Int;
else
- return ((pTag & 1) ? ELFAttributeValue::String :
- ELFAttributeValue::Int);
+ return ((pTag & 1) ? ELFAttributeValue::String
+ : ELFAttributeValue::Int);
}
}
// unreachable
@@ -96,9 +95,8 @@ namespace {
*
* @ref ARM [ABI-addenda], 2.3.7.3
*/
-static int
-decode_secondary_compatibility_attribute(const ELFAttributeValue &pValue)
-{
+static int decode_secondary_compatibility_attribute(
+ const ELFAttributeValue& pValue) {
// The encoding of Tag_also_compatible_with is:
//
// Tag_also_compatible_with (=65), NTSB: data
@@ -111,7 +109,7 @@ decode_secondary_compatibility_attribute(const ELFAttributeValue &pValue)
assert((pValue.type() == ELFAttributeValue::String) &&
"Value of Tag_also_compatible_with must be a string!");
- const std::string &data = pValue.getStringValue();
+ const std::string& data = pValue.getStringValue();
// Though the integer is in LEB128 format, but they occupy only 1 byte in
// currently defined value.
@@ -135,23 +133,23 @@ decode_secondary_compatibility_attribute(const ELFAttributeValue &pValue)
* This helper array keeps the ordering of the values in attributes such as
* Tag_ABI_align_needed which are sored as 1 > 2 > 0.
*/
-static const int value_ordering_120[] = { 0, 2, 1 };
+static const int value_ordering_120[] = {0, 2, 1};
-} // anonymous namespace
+} // anonymous namespace
//===--------------------------------------------------------------------===//
// End Helper Functions for merge()
//===--------------------------------------------------------------------===//
bool ARMELFAttributeData::merge(const LinkerConfig& pConfig,
- const Input &pInput, TagType pTag,
- const ELFAttributeValue& pInAttr)
-{
+ const Input& pInput,
+ TagType pTag,
+ const ELFAttributeValue& pInAttr) {
// Pre-condition
// 1. The out_attr must be initailized and has value of the same type as
// pInAttr.
// 2. The value helf by out_attr and pInAttr must be different.
- ELFAttributeValue &out_attr = m_Attrs[pTag];
+ ELFAttributeValue& out_attr = m_Attrs[pTag];
// Attribute in the output must have value assigned.
assert(out_attr.isInitialized() && "No output attribute to be merged!");
@@ -212,7 +210,7 @@ bool ARMELFAttributeData::merge(const LinkerConfig& pConfig,
case Tag_T2EE_use: {
assert((out_attr.type() == ELFAttributeValue::Int) &&
(pInAttr.type() == ELFAttributeValue::Int) &&
- "should have integer parameeter!");
+ "should have integer parameeter!");
if (pInAttr.getIntValue() > out_attr.getIntValue())
out_attr.setIntValue(pInAttr.getIntValue());
break;
@@ -223,7 +221,7 @@ bool ARMELFAttributeData::merge(const LinkerConfig& pConfig,
case Tag_ABI_PCS_RO_data: {
assert((out_attr.type() == ELFAttributeValue::Int) &&
(pInAttr.type() == ELFAttributeValue::Int) &&
- "should have integer parameeter!");
+ "should have integer parameeter!");
if (pInAttr.getIntValue() < out_attr.getIntValue())
out_attr.setIntValue(pInAttr.getIntValue());
break;
@@ -321,8 +319,7 @@ bool ARMELFAttributeData::merge(const LinkerConfig& pConfig,
else if (pInAttr.getIntValue() != Enum_Containerized_As_Possible &&
pConfig.options().warnMismatch())
warning(diag::warn_mismatch_enum_size)
- << pInput.name() << pInAttr.getIntValue()
- << out_attr.getIntValue();
+ << pInput.name() << pInAttr.getIntValue() << out_attr.getIntValue();
break;
}
// Tag_ABI_FP_16bit_format
@@ -431,9 +428,9 @@ bool ARMELFAttributeData::merge(const LinkerConfig& pConfig,
out_attr.setIntValue(pInAttr.getIntValue());
else {
if (pConfig.options().warnMismatch())
- warning(diag::warn_mismatch_wchar_size)
- << pInput.name() << pInAttr.getIntValue()
- << out_attr.getIntValue();
+ warning(diag::warn_mismatch_wchar_size) << pInput.name()
+ << pInAttr.getIntValue()
+ << out_attr.getIntValue();
}
}
break;
@@ -474,17 +471,13 @@ namespace {
*
* @ref ARM [ABI-addenda], 2.3.7.3
*/
-static void
-encode_secondary_compatibility_attribute(ELFAttributeValue &pValue, int pArch)
-{
+static void encode_secondary_compatibility_attribute(ELFAttributeValue& pValue,
+ int pArch) {
if ((pArch < 0) || (pArch > ARMELFAttributeData::CPU_Arch_Max)) {
pValue.setStringValue("");
} else {
char new_value[] = {
- ARMELFAttributeData::Tag_CPU_arch,
- static_cast<char>(pArch),
- 0
- };
+ ARMELFAttributeData::Tag_CPU_arch, static_cast<char>(pArch), 0};
pValue.setStringValue(std::string(new_value, sizeof(new_value)));
}
return;
@@ -493,9 +486,7 @@ encode_secondary_compatibility_attribute(ELFAttributeValue &pValue, int pArch)
/*
* Combine the main and secondary CPU arch value
*/
-static int
-calculate_cpu_arch(int cpu_arch, int secondary_arch)
-{
+static int calculate_cpu_arch(int cpu_arch, int secondary_arch) {
// short-circuit
if ((secondary_arch < 0) ||
((cpu_arch + secondary_arch) != (ARMELFAttributeData::CPU_Arch_ARM_V4T +
@@ -519,32 +510,30 @@ calculate_cpu_arch(int cpu_arch, int secondary_arch)
* profile.
*/
#define CPU(C) ARMELFAttributeData::CPU_Arch_ARM_ ## C
-static const int cpu_compatibility_table[][CPU(V4T_Plus_V6_M) + 1] =
-{
- /* old\new ARM v6T2 ARM v6K ARM v7 ARM v6-M ARM v6S-M ARM v7E-M ARMv8, ARM v4t + v6-M */
- /* Pre v4 */ { CPU(V6T2), CPU(V6K), CPU(V7), -1, -1, -1, -1, -1 },
- /* ARM v4 */ { CPU(V6T2), CPU(V6K), CPU(V7), -1, -1, -1, -1, -1 },
- /* ARM v4T */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V4T) },
- /* ARM v5T */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V5T) },
- /* ARM v5TE */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V5TE) },
- /* ARM v5TEJ */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V5TEJ) },
- /* ARM v6 */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V6) },
- /* ARM v6KZ */ { CPU(V7), CPU(V6KZ), CPU(V7), CPU(V6KZ), CPU(V6KZ), CPU(V7E_M), CPU(V8), CPU(V6KZ) },
- /* ARM v6T2 */ { CPU(V6T2), CPU(V7), CPU(V7), CPU(V7), CPU(V7), CPU(V7E_M), CPU(V8), CPU(V6T2) },
- /* ARM v6K */ { 0, CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V6K) },
- /* ARM v7 */ { 0, 0, CPU(V7), CPU(V7), CPU(V7), CPU(V7E_M), CPU(V8), CPU(V7) },
- /* ARM v6-M */ { 0, 0, 0, CPU(V6_M), CPU(V6S_M), CPU(V7E_M), CPU(V8), CPU(V6_M) },
- /* ARM v6S-M */ { 0, 0, 0, 0, CPU(V6S_M), CPU(V7E_M), CPU(V8), CPU(V6S_M) },
- /* ARM v7E-M */ { 0, 0, 0, 0, 0, CPU(V7E_M), CPU(V8), CPU(V7E_M) },
- /* ARM v8 */ { 0, 0, 0, 0, 0, 0, CPU(V8), CPU(V8) },
- /* v4T + v6-M */ { 0, 0, 0, 0, 0, 0, 0, CPU(V4T_Plus_V6_M) }
+static const int cpu_compatibility_table[][CPU(V4T_Plus_V6_M) + 1] = {
+ /* old\new ARM v6T2 ARM v6K ARM v7 ARM v6-M ARM v6S-M ARM v7E-M ARMv8, ARM v4t + v6-M */ // NOLINT
+ /* Pre v4 */ { CPU(V6T2), CPU(V6K), CPU(V7), -1, -1, -1, -1, -1 }, // NOLINT
+ /* ARM v4 */ { CPU(V6T2), CPU(V6K), CPU(V7), -1, -1, -1, -1, -1 }, // NOLINT
+ /* ARM v4T */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V4T) }, // NOLINT
+ /* ARM v5T */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V5T) }, // NOLINT
+ /* ARM v5TE */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V5TE) }, // NOLINT
+ /* ARM v5TEJ */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V5TEJ) }, // NOLINT
+ /* ARM v6 */ { CPU(V6T2), CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V6) }, // NOLINT
+ /* ARM v6KZ */ { CPU(V7), CPU(V6KZ), CPU(V7), CPU(V6KZ), CPU(V6KZ), CPU(V7E_M), CPU(V8), CPU(V6KZ) }, // NOLINT
+ /* ARM v6T2 */ { CPU(V6T2), CPU(V7), CPU(V7), CPU(V7), CPU(V7), CPU(V7E_M), CPU(V8), CPU(V6T2) }, // NOLINT
+ /* ARM v6K */ { 0, CPU(V6K), CPU(V7), CPU(V6K), CPU(V6K), CPU(V7E_M), CPU(V8), CPU(V6K) }, // NOLINT
+ /* ARM v7 */ { 0, 0, CPU(V7), CPU(V7), CPU(V7), CPU(V7E_M), CPU(V8), CPU(V7) }, // NOLINT
+ /* ARM v6-M */ { 0, 0, 0, CPU(V6_M), CPU(V6S_M), CPU(V7E_M), CPU(V8), CPU(V6_M) }, // NOLINT
+ /* ARM v6S-M */ { 0, 0, 0, 0, CPU(V6S_M), CPU(V7E_M), CPU(V8), CPU(V6S_M) }, // NOLINT
+ /* ARM v7E-M */ { 0, 0, 0, 0, 0, CPU(V7E_M), CPU(V8), CPU(V7E_M) }, // NOLINT
+ /* ARM v8 */ { 0, 0, 0, 0, 0, 0, CPU(V8), CPU(V8) }, // NOLINT
+ /* v4T + v6-M */ { 0, 0, 0, 0, 0, 0, 0, CPU(V4T_Plus_V6_M) } // NOLINT
};
/*
* Helper function to determine the merge of two different CPU arch.
*/
-static int merge_cpu_arch(int out_cpu_arch, int in_cpu_arch)
-{
+static int merge_cpu_arch(int out_cpu_arch, int in_cpu_arch) {
if (out_cpu_arch > CPU(V4T_Plus_V6_M))
return in_cpu_arch;
@@ -571,21 +560,21 @@ static int merge_cpu_arch(int out_cpu_arch, int in_cpu_arch)
* merge of Tag_CPU_arch.
*/
static const char* generic_cpu_name_table[] = {
- /* Pre v4 */"Pre v4",
- /* Pre v4 */"ARM v4",
- /* ARM v4T */"ARM v4T",
- /* ARM v5T */"ARM v5T",
- /* ARM v5TE */"ARM v5TE",
- /* ARM v5TEJ */"ARM v5TEJ",
- /* ARM v6 */"ARM v6",
- /* ARM v6KZ */"ARM v6KZ",
- /* ARM v6T2 */"ARM v6T2",
- /* ARM v6K */"ARM v6K",
- /* ARM v7 */"ARM v7",
- /* ARM v6-M */"ARM v6-M",
- /* ARM v6S-M */"ARM v6S-M",
- /* ARM v7E-M */"ARM v7E-M",
- /* ARM v8 */"ARM v8",
+ /* Pre v4 */ "Pre v4",
+ /* Pre v4 */ "ARM v4",
+ /* ARM v4T */ "ARM v4T",
+ /* ARM v5T */ "ARM v5T",
+ /* ARM v5TE */ "ARM v5TE",
+ /* ARM v5TEJ */ "ARM v5TEJ",
+ /* ARM v6 */ "ARM v6",
+ /* ARM v6KZ */ "ARM v6KZ",
+ /* ARM v6T2 */ "ARM v6T2",
+ /* ARM v6K */ "ARM v6K",
+ /* ARM v7 */ "ARM v7",
+ /* ARM v6-M */ "ARM v6-M",
+ /* ARM v6S-M */ "ARM v6S-M",
+ /* ARM v7E-M */ "ARM v7E-M",
+ /* ARM v8 */ "ARM v8",
};
static const char* get_generic_cpu_name(int cpu_arch) {
@@ -601,15 +590,15 @@ static const struct fp_config_data {
int version;
int regs;
} fp_configs[] = {
- { 0, 0 },
- { 1, 16 },
- { 2, 16 },
- { 3, 32 },
- { 3, 16 },
- { 4, 32 },
- { 4, 16 },
- { 8, 32 },
- { 8, 16 },
+ {0, 0},
+ {1, 16},
+ {2, 16},
+ {3, 32},
+ {3, 16},
+ {4, 32},
+ {4, 16},
+ {8, 32},
+ {8, 16},
};
static const size_t num_fp_configs =
@@ -628,48 +617,44 @@ static const size_t num_fp_configs =
// fp_config_hash_table[ h(8, 16) = 8 ] = 8
//
// h(0, 0) = 0
-static const uint8_t fp_config_hash_table[] =
-{
+static const uint8_t fp_config_hash_table[] = {
#define UND static_cast<uint8_t>(-1)
- /* 0 */0,
- /* 1 */1,
- /* 2 */2,
- /* 3 */4,
- /* 4 */6,
- /* 5 */UND,
- /* 6 */UND,
- /* 7 */3,
- /* 8 */8,
- /* 9 */5,
- /* 10 */UND,
- /* 11 */UND,
- /* 12 */UND,
- /* 13 */UND,
- /* 14 */UND,
- /* 15 */UND,
- /* 16 */UND,
- /* 17 */7,
+ /* 0 */ 0,
+ /* 1 */ 1,
+ /* 2 */ 2,
+ /* 3 */ 4,
+ /* 4 */ 6,
+ /* 5 */ UND,
+ /* 6 */ UND,
+ /* 7 */ 3,
+ /* 8 */ 8,
+ /* 9 */ 5,
+ /* 10 */ UND,
+ /* 11 */ UND,
+ /* 12 */ UND,
+ /* 13 */ UND,
+ /* 14 */ UND,
+ /* 15 */ UND,
+ /* 16 */ UND,
+ /* 17 */ 7,
#undef UND
};
-static const size_t num_hash_table_entries =
- sizeof(fp_config_hash_table) / sizeof(fp_config_hash_table[0]);
-
-static int calculate_fp_config_hash(const struct fp_config_data &pConfig)
-{
+static int calculate_fp_config_hash(const struct fp_config_data& pConfig) {
int x = pConfig.version;
int y = pConfig.regs;
return (x * (y >> 4) + (y >> 5));
}
-static int get_fp_arch_of_config(const struct fp_config_data &pConfig)
-{
+static int get_fp_arch_of_config(const struct fp_config_data& pConfig) {
int hash = calculate_fp_config_hash(pConfig);
- assert(static_cast<size_t>(hash) < num_hash_table_entries);
+ assert(static_cast<size_t>(hash) <
+ llvm::array_lengthof(fp_config_hash_table));
return fp_config_hash_table[hash];
}
-static bool is_allowed_use_of_div(int cpu_arch, int cpu_arch_profile,
+static bool is_allowed_use_of_div(int cpu_arch,
+ int cpu_arch_profile,
int div_use) {
// 0: The code was permitted to use SDIV and UDIV in the Thumb ISA on v7-R or
// v7-M.
@@ -689,25 +674,22 @@ static bool is_allowed_use_of_div(int cpu_arch, int cpu_arch_profile,
}
case 2:
// For future proofing
- default: {
- return true;
- }
+ default: { return true; }
}
}
-} // anonymous namespace
+} // anonymous namespace
//===--------------------------------------------------------------------===//
// End Helper Functions for postMerge()
//===--------------------------------------------------------------------===//
bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
- const Input &pInput)
-{
+ const Input& pInput) {
// Process Tag_CPU_arch, Tag_CPU_name, Tag_CPU_raw_name, and
// Tag_also_compatible_with.
- ELFAttributeValue &out_cpu_arch_attr = m_Attrs[Tag_CPU_arch];
- ELFAttributeValue &out_secondary_compatibility_attr =
+ ELFAttributeValue& out_cpu_arch_attr = m_Attrs[Tag_CPU_arch];
+ ELFAttributeValue& out_secondary_compatibility_attr =
m_Attrs[Tag_also_compatible_with];
if ((m_CurrentCPUArch < 0) && out_cpu_arch_attr.isInitialized()) {
@@ -723,7 +705,7 @@ bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
int out_secondary_arch = -1;
if (out_secondary_compatibility_attr.isInitialized())
out_secondary_arch = decode_secondary_compatibility_attribute(
- out_secondary_compatibility_attr);
+ out_secondary_compatibility_attr);
m_CurrentCPUArch = calculate_cpu_arch(out_cpu_arch, out_secondary_arch);
}
@@ -736,8 +718,8 @@ bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
int result_cpu_arch = merge_cpu_arch(m_CurrentCPUArch, in_cpu_arch);
if (result_cpu_arch < 0) {
- warning(diag::warn_mismatch_cpu_arch_profile)
- << in_cpu_arch << pInput.name();
+ warning(diag::warn_mismatch_cpu_arch_profile) << in_cpu_arch
+ << pInput.name();
} else {
if (result_cpu_arch != m_CurrentCPUArch) {
// Value of Tag_CPU_arch are going to changea.
@@ -754,8 +736,8 @@ bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
out_secondary_compatibility_attr, -1);
}
- ELFAttributeValue &out_cpu_name = m_Attrs[Tag_CPU_name];
- ELFAttributeValue &out_cpu_raw_name = m_Attrs[Tag_CPU_raw_name];
+ ELFAttributeValue& out_cpu_name = m_Attrs[Tag_CPU_name];
+ ELFAttributeValue& out_cpu_raw_name = m_Attrs[Tag_CPU_raw_name];
if (m_CurrentCPUArch != in_cpu_arch) {
// Unable to guess the Tag_CPU_name. Use the generic name.
@@ -769,13 +751,13 @@ bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
} else {
// Use the value of Tag_CPU_name and Tag_CPU_raw_name from the input.
if (!m_CPUName.empty()) {
- ELFAttributeValue &out_cpu_name = m_Attrs[Tag_CPU_name];
+ ELFAttributeValue& out_cpu_name = m_Attrs[Tag_CPU_name];
assert(out_cpu_name.isInitialized() && "CPU name has never set!");
out_cpu_name.setStringValue(m_CPUName);
}
if (!m_CPURawName.empty()) {
- ELFAttributeValue &out_cpu_raw_name = m_Attrs[Tag_CPU_raw_name];
+ ELFAttributeValue& out_cpu_raw_name = m_Attrs[Tag_CPU_raw_name];
assert(out_cpu_raw_name.isInitialized() &&
"CPU raw name has never set!");
out_cpu_raw_name.setStringValue(m_CPURawName);
@@ -783,12 +765,12 @@ bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
}
}
}
- } // (m_CPUArch >= 0)
+ } // (m_CPUArch >= 0)
// Process Tag_ABI_VFP_args.
if (m_VFPArgs >= 0) {
- ELFAttributeValue &out_attr = m_Attrs[Tag_ABI_VFP_args];
- ELFAttributeValue &out_float_number_model_attr =
+ ELFAttributeValue& out_attr = m_Attrs[Tag_ABI_VFP_args];
+ ELFAttributeValue& out_float_number_model_attr =
m_Attrs[Tag_ABI_FP_number_model];
assert(out_attr.isInitialized() && "VFP args has never set!");
@@ -806,7 +788,7 @@ bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
}
// Process Tag_FP_arch.
- ELFAttributeValue &out_fp_arch_attr = m_Attrs[Tag_FP_arch];
+ ELFAttributeValue& out_fp_arch_attr = m_Attrs[Tag_FP_arch];
if (m_FPArch >= 0) {
assert(out_fp_arch_attr.isInitialized() && "FP arch has never set!");
@@ -837,26 +819,28 @@ bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
}
} else {
if (out_fp_arch_attr.getIntValue() < num_fp_configs) {
- const struct fp_config_data &input_fp_config = fp_configs[ m_FPArch ];
+ const struct fp_config_data& input_fp_config = fp_configs[m_FPArch];
- const struct fp_config_data &output_fp_config =
- fp_configs[ out_fp_arch_attr.getIntValue() ];
+ const struct fp_config_data& output_fp_config =
+ fp_configs[out_fp_arch_attr.getIntValue()];
const struct fp_config_data result_fp_config = {
- /*version*/((output_fp_config.version > input_fp_config.version) ?
- output_fp_config.version : input_fp_config.version),
- /* regs */((output_fp_config.regs > input_fp_config.regs) ?
- output_fp_config.regs : input_fp_config.regs),
+ /*version*/ ((output_fp_config.version > input_fp_config.version)
+ ? output_fp_config.version
+ : input_fp_config.version),
+ /* regs */ ((output_fp_config.regs > input_fp_config.regs)
+ ? output_fp_config.regs
+ : input_fp_config.regs),
};
// Find the attribute value corresponding the result_fp_config
out_fp_arch_attr.setIntValue(get_fp_arch_of_config(result_fp_config));
}
}
}
- } // (m_FPArch >= 0)
+ } // (m_FPArch >= 0)
// Process Tag_ABI_HardFP_use.
- ELFAttributeValue &out_hardfp_use_attr = m_Attrs[Tag_ABI_HardFP_use];
+ ELFAttributeValue& out_hardfp_use_attr = m_Attrs[Tag_ABI_HardFP_use];
if (!m_HardFPUseInitialized && out_hardfp_use_attr.isInitialized()) {
m_HardFPUse = out_hardfp_use_attr.getIntValue();
@@ -882,10 +866,10 @@ bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
}
// Move the value of Tag_MPextension_use_legacy to Tag_MPextension_use.
- ELFAttributeValue &out_mpextension_use_legacy =
+ ELFAttributeValue& out_mpextension_use_legacy =
m_Attrs[Tag_MPextension_use_legacy];
- ELFAttributeValue &out_mpextension_use = m_Attrs[Tag_MPextension_use];
+ ELFAttributeValue& out_mpextension_use = m_Attrs[Tag_MPextension_use];
// If Tag_MPextension_use_legacy has value, it must be introduced by current
// input since it is reset every time after the merge completed.
@@ -903,7 +887,7 @@ bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
// Check the consistency between m_MPextensionUse and the value of
// Tag_MPextension_use_legacy.
if (static_cast<unsigned>(m_MPextensionUse) !=
- out_mpextension_use_legacy.getIntValue()) {
+ out_mpextension_use_legacy.getIntValue()) {
error(diag::error_mismatch_mpextension_use) << pInput.name();
return false;
}
@@ -929,13 +913,13 @@ bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
assert(out_mpextension_use.isInitialized());
if (static_cast<unsigned>(m_MPextensionUse) >
- out_mpextension_use.getIntValue()) {
+ out_mpextension_use.getIntValue()) {
out_mpextension_use.setIntValue(m_MPextensionUse);
}
}
// Process Tag_DIV_use.
- ELFAttributeValue &out_div_use_attr = m_Attrs[Tag_DIV_use];
+ ELFAttributeValue& out_div_use_attr = m_Attrs[Tag_DIV_use];
if (!m_DIVUseInitialized && out_div_use_attr.isInitialized()) {
// Perform the merge by reverting value of Tag_DIV_use and setup m_DIVUse.
@@ -947,7 +931,7 @@ bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
if (m_DIVUse >= 0) {
assert(out_div_use_attr.isInitialized());
- const ELFAttributeValue &out_cpu_arch_profile_attr =
+ const ELFAttributeValue& out_cpu_arch_profile_attr =
m_Attrs[Tag_CPU_arch_profile];
int out_cpu_arch_profile = Arch_Profile_None;
@@ -958,7 +942,8 @@ bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
if (m_DIVUse == 1) {
// Input (=1) was not permitted to use SDIV and UDIV. See whether current
// output was explicitly permitted the use.
- if (!is_allowed_use_of_div(m_CurrentCPUArch, out_cpu_arch_profile,
+ if (!is_allowed_use_of_div(m_CurrentCPUArch,
+ out_cpu_arch_profile,
out_div_use_attr.getIntValue())) {
out_div_use_attr.setIntValue(1);
}
@@ -967,8 +952,8 @@ bool ARMELFAttributeData::postMerge(const LinkerConfig& pConfig,
// Output does not explicitly forbid the use of SDIV/UDIV. See whether
// the input attribute can allow it under current CPU architecture
// profile.
- if (is_allowed_use_of_div(m_CurrentCPUArch, out_cpu_arch_profile,
- m_DIVUse)) {
+ if (is_allowed_use_of_div(
+ m_CurrentCPUArch, out_cpu_arch_profile, m_DIVUse)) {
out_div_use_attr.setIntValue(m_DIVUse);
}
}
@@ -984,7 +969,7 @@ size_t ARMELFAttributeData::sizeOutput() const {
// Size contributed by known attributes
for (unsigned i = 0; i <= Tag_Max; ++i) {
TagType tag = static_cast<TagType>(i);
- const ELFAttributeValue &value = m_Attrs[tag];
+ const ELFAttributeValue& value = m_Attrs[tag];
if (value.shouldEmit()) {
result += leb128::size(static_cast<uint32_t>(tag));
@@ -994,10 +979,11 @@ size_t ARMELFAttributeData::sizeOutput() const {
// Size contributed by unknown attributes
for (UnknownAttrsMap::const_iterator unknown_attr_it = m_UnknownAttrs.begin(),
- unknown_attr_end = m_UnknownAttrs.end();
- unknown_attr_it != unknown_attr_end; ++unknown_attr_it) {
+ unknown_attr_end = m_UnknownAttrs.end();
+ unknown_attr_it != unknown_attr_end;
+ ++unknown_attr_it) {
TagType tag = unknown_attr_it->first;
- const ELFAttributeValue &value = unknown_attr_it->second;
+ const ELFAttributeValue& value = unknown_attr_it->second;
if (value.shouldEmit()) {
result += leb128::size(static_cast<uint32_t>(tag));
@@ -1008,18 +994,18 @@ size_t ARMELFAttributeData::sizeOutput() const {
return result;
}
-size_t ARMELFAttributeData::emit(char *pBuf) const {
- char *buffer = pBuf;
+size_t ARMELFAttributeData::emit(char* pBuf) const {
+ char* buffer = pBuf;
// Tag_conformance "should be emitted first in a file-scope sub-subsection of
// the first public subsection of the attribute section."
//
// See ARM [ABI-addenda], 2.3.7.4 Conformance tag
- const ELFAttributeValue &attr_conformance = m_Attrs[Tag_conformance];
+ const ELFAttributeValue& attr_conformance = m_Attrs[Tag_conformance];
if (attr_conformance.shouldEmit()) {
- if (!ELFAttributeData::WriteAttribute(Tag_conformance, attr_conformance,
- buffer)) {
+ if (!ELFAttributeData::WriteAttribute(
+ Tag_conformance, attr_conformance, buffer)) {
return 0;
}
}
@@ -1028,11 +1014,11 @@ size_t ARMELFAttributeData::emit(char *pBuf) const {
// subsection other that the conformance tag"
//
// See ARM [ABI-addenda], 2.3.7.5 No defaults tag
- const ELFAttributeValue &attr_nodefaults = m_Attrs[Tag_nodefaults];
+ const ELFAttributeValue& attr_nodefaults = m_Attrs[Tag_nodefaults];
if (attr_nodefaults.shouldEmit()) {
- if (!ELFAttributeData::WriteAttribute(Tag_nodefaults, attr_nodefaults,
- buffer)) {
+ if (!ELFAttributeData::WriteAttribute(
+ Tag_nodefaults, attr_nodefaults, buffer)) {
return 0;
}
}
@@ -1041,7 +1027,7 @@ size_t ARMELFAttributeData::emit(char *pBuf) const {
// Tag_nodefaults (=64)
for (unsigned i = 0; i < Tag_nodefaults; ++i) {
TagType tag = static_cast<TagType>(i);
- const ELFAttributeValue &value = m_Attrs[tag];
+ const ELFAttributeValue& value = m_Attrs[tag];
if (value.shouldEmit() &&
!ELFAttributeData::WriteAttribute(tag, value, buffer)) {
@@ -1051,7 +1037,7 @@ size_t ARMELFAttributeData::emit(char *pBuf) const {
for (unsigned i = (Tag_nodefaults + 1); i <= Tag_Max; ++i) {
TagType tag = static_cast<TagType>(i);
- const ELFAttributeValue &value = m_Attrs[tag];
+ const ELFAttributeValue& value = m_Attrs[tag];
if (value.shouldEmit() && (i != Tag_conformance) &&
!ELFAttributeData::WriteAttribute(tag, value, buffer)) {
@@ -1060,10 +1046,11 @@ size_t ARMELFAttributeData::emit(char *pBuf) const {
}
for (UnknownAttrsMap::const_iterator unknown_attr_it = m_UnknownAttrs.begin(),
- unknown_attr_end = m_UnknownAttrs.end();
- unknown_attr_it != unknown_attr_end; ++unknown_attr_it) {
+ unknown_attr_end = m_UnknownAttrs.end();
+ unknown_attr_it != unknown_attr_end;
+ ++unknown_attr_it) {
TagType tag = unknown_attr_it->first;
- const ELFAttributeValue &value = unknown_attr_it->second;
+ const ELFAttributeValue& value = unknown_attr_it->second;
if (value.shouldEmit() &&
!ELFAttributeData::WriteAttribute(tag, value, buffer)) {
@@ -1074,8 +1061,7 @@ size_t ARMELFAttributeData::emit(char *pBuf) const {
return (buffer - pBuf);
}
-bool ARMELFAttributeData::usingThumb() const
-{
+bool ARMELFAttributeData::usingThumb() const {
int arch = m_Attrs[Tag_CPU_arch].getIntValue();
if ((arch == CPU_Arch_ARM_V6_M) || (arch == CPU_Arch_ARM_V6S_M))
return true;
@@ -1086,8 +1072,9 @@ bool ARMELFAttributeData::usingThumb() const
return arch == Arch_Profile_Microcontroller;
}
-bool ARMELFAttributeData::usingThumb2() const
-{
+bool ARMELFAttributeData::usingThumb2() const {
int arch = m_Attrs[Tag_CPU_arch].getIntValue();
return (arch == CPU_Arch_ARM_V6T2) || (arch == CPU_Arch_ARM_V7);
}
+
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMELFAttributeData.h b/lib/Target/ARM/ARMELFAttributeData.h
index 1183b3d..19dcf21 100644
--- a/lib/Target/ARM/ARMELFAttributeData.h
+++ b/lib/Target/ARM/ARMELFAttributeData.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMELFATTRIBUTEDATA_H
-#define TARGET_ARM_ARMELFATTRIBUTEDATA_H
+#ifndef TARGET_ARM_ARMELFATTRIBUTEDATA_H_
+#define TARGET_ARM_ARMELFATTRIBUTEDATA_H_
-#include <mcld/Target/ELFAttributeData.h>
-#include <mcld/Target/ELFAttributeValue.h>
+#include "mcld/Target/ELFAttributeData.h"
+#include "mcld/Target/ELFAttributeValue.h"
#include <map>
#include <string>
@@ -23,82 +23,82 @@ namespace mcld {
*
*/
class ARMELFAttributeData : public ELFAttributeData {
-public:
+ public:
enum Tag {
// 0-3 are generic and are defined in ELFAttributeData.
- Tag_CPU_raw_name = 4,
- Tag_CPU_name = 5,
- Tag_CPU_arch = 6,
- Tag_CPU_arch_profile = 7,
- Tag_ARM_ISA_use = 8,
- Tag_THUMB_ISA_use = 9,
- Tag_FP_arch = 10,
- Tag_WMMX_arch = 11,
- Tag_Advanced_SIMD_arch = 12,
- Tag_PCS_config = 13,
- Tag_ABI_PCS_R9_use = 14,
- Tag_ABI_PCS_RW_data = 15,
- Tag_ABI_PCS_RO_data = 16,
- Tag_ABI_PCS_GOT_use = 17,
- Tag_ABI_PCS_wchar_t = 18,
- Tag_ABI_FP_rounding = 19,
- Tag_ABI_FP_denormal = 20,
- Tag_ABI_FP_exceptions = 21,
- Tag_ABI_FP_user_exceptions = 22,
- Tag_ABI_FP_number_model = 23,
- Tag_ABI_align_needed = 24,
- Tag_ABI_align_preserved = 25,
- Tag_ABI_enum_size = 26,
- Tag_ABI_HardFP_use = 27,
- Tag_ABI_VFP_args = 28,
- Tag_ABI_WMMX_args = 29,
- Tag_ABI_optimization_goals = 30,
- Tag_ABI_FP_optimization_goals = 31,
- Tag_compatibility = 32,
-
- Tag_CPU_unaligned_access = 34,
-
- Tag_FP_HP_extension = 36,
-
- Tag_ABI_FP_16bit_format = 38,
-
- Tag_MPextension_use = 42,
-
- Tag_DIV_use = 44,
-
- Tag_nodefaults = 64,
- Tag_also_compatible_with = 65,
- Tag_T2EE_use = 66,
- Tag_conformance = 67,
- Tag_Virtualization_use = 68,
-
- Tag_MPextension_use_legacy = 70,
+ Tag_CPU_raw_name = 4,
+ Tag_CPU_name = 5,
+ Tag_CPU_arch = 6,
+ Tag_CPU_arch_profile = 7,
+ Tag_ARM_ISA_use = 8,
+ Tag_THUMB_ISA_use = 9,
+ Tag_FP_arch = 10,
+ Tag_WMMX_arch = 11,
+ Tag_Advanced_SIMD_arch = 12,
+ Tag_PCS_config = 13,
+ Tag_ABI_PCS_R9_use = 14,
+ Tag_ABI_PCS_RW_data = 15,
+ Tag_ABI_PCS_RO_data = 16,
+ Tag_ABI_PCS_GOT_use = 17,
+ Tag_ABI_PCS_wchar_t = 18,
+ Tag_ABI_FP_rounding = 19,
+ Tag_ABI_FP_denormal = 20,
+ Tag_ABI_FP_exceptions = 21,
+ Tag_ABI_FP_user_exceptions = 22,
+ Tag_ABI_FP_number_model = 23,
+ Tag_ABI_align_needed = 24,
+ Tag_ABI_align_preserved = 25,
+ Tag_ABI_enum_size = 26,
+ Tag_ABI_HardFP_use = 27,
+ Tag_ABI_VFP_args = 28,
+ Tag_ABI_WMMX_args = 29,
+ Tag_ABI_optimization_goals = 30,
+ Tag_ABI_FP_optimization_goals = 31,
+ Tag_compatibility = 32,
+
+ Tag_CPU_unaligned_access = 34,
+
+ Tag_FP_HP_extension = 36,
+
+ Tag_ABI_FP_16bit_format = 38,
+
+ Tag_MPextension_use = 42,
+
+ Tag_DIV_use = 44,
+
+ Tag_nodefaults = 64,
+ Tag_also_compatible_with = 65,
+ Tag_T2EE_use = 66,
+ Tag_conformance = 67,
+ Tag_Virtualization_use = 68,
+
+ Tag_MPextension_use_legacy = 70,
Tag_Max = Tag_MPextension_use_legacy,
// Alias
- Tag_VFP_arch = Tag_FP_arch,
- Tag_ABI_align8_needed = Tag_ABI_align_needed,
- Tag_ABI_align8_preserved = Tag_ABI_align_preserved,
- Tag_VFP_HP_extension = Tag_FP_HP_extension
+ Tag_VFP_arch = Tag_FP_arch,
+ Tag_ABI_align8_needed = Tag_ABI_align_needed,
+ Tag_ABI_align8_preserved = Tag_ABI_align_preserved,
+ Tag_VFP_HP_extension = Tag_FP_HP_extension
};
// For Tag_CPU_arch
enum {
CPU_Arch_ARM_Pre_V4,
- CPU_Arch_ARM_V4, // e.g., SA110
- CPU_Arch_ARM_V4T, // e.g., ARM7TDMI
- CPU_Arch_ARM_V5T, // e.g., ARM9TDMI
- CPU_Arch_ARM_V5TE, // e.g., ARM946E-S
- CPU_Arch_ARM_V5TEJ, // e.g., ARM926EJ-S
- CPU_Arch_ARM_V6, // e.g., ARM1136J-S
- CPU_Arch_ARM_V6KZ, // e.g., ARM1176JZ-S
- CPU_Arch_ARM_V6T2, // e.g., ARM1156T2F-S
- CPU_Arch_ARM_V6K, // e.g., ARM1136J-S
- CPU_Arch_ARM_V7, // e.g., Cortex A8, Cortex M3
- CPU_Arch_ARM_V6_M, // e.g., Cortex M1
- CPU_Arch_ARM_V6S_M, // e.g., v6-M with the value of System extensions
- CPU_Arch_ARM_V7E_M, // e.g., v7-M with DSP extensions
+ CPU_Arch_ARM_V4, // e.g., SA110
+ CPU_Arch_ARM_V4T, // e.g., ARM7TDMI
+ CPU_Arch_ARM_V5T, // e.g., ARM9TDMI
+ CPU_Arch_ARM_V5TE, // e.g., ARM946E-S
+ CPU_Arch_ARM_V5TEJ, // e.g., ARM926EJ-S
+ CPU_Arch_ARM_V6, // e.g., ARM1136J-S
+ CPU_Arch_ARM_V6KZ, // e.g., ARM1176JZ-S
+ CPU_Arch_ARM_V6T2, // e.g., ARM1156T2F-S
+ CPU_Arch_ARM_V6K, // e.g., ARM1136J-S
+ CPU_Arch_ARM_V7, // e.g., Cortex A8, Cortex M3
+ CPU_Arch_ARM_V6_M, // e.g., Cortex M1
+ CPU_Arch_ARM_V6S_M, // e.g., v6-M with the value of System extensions
+ CPU_Arch_ARM_V7E_M, // e.g., v7-M with DSP extensions
CPU_Arch_ARM_V8,
CPU_Arch_Max = CPU_Arch_ARM_V8,
@@ -113,11 +113,11 @@ public:
// For Tag_CPU_arch_profile
enum {
- Arch_Profile_None = 0,
- Arch_Profile_Application = 'A',
- Arch_Profile_Realtime = 'R',
- Arch_Profile_Microcontroller = 'M',
- Arch_Profile_RealOrApp = 'S'
+ Arch_Profile_None = 0,
+ Arch_Profile_Application = 'A',
+ Arch_Profile_Realtime = 'R',
+ Arch_Profile_Microcontroller = 'M',
+ Arch_Profile_RealOrApp = 'S'
};
// For Tag_ABI_enum_size
@@ -129,12 +129,7 @@ public:
};
// For Tag_ABI_PCS_R9_use
- enum {
- R9_V6,
- R9_SB,
- R9_TLS,
- R9_Unused
- };
+ enum { R9_V6, R9_SB, R9_TLS, R9_Unused };
// For Tag_ABI_PCS_RW_data
enum {
@@ -144,20 +139,21 @@ public:
RW_data_unused
};
-public:
+ public:
// ARM [ABI-addenda], 2.2.2: A public attributes subsection is named aeabi.
ARMELFAttributeData()
- : ELFAttributeData("aeabi"), m_CurrentCPUArch(-1),
- m_DIVUseInitialized(false), m_HardFPUseInitialized(false) { }
+ : ELFAttributeData("aeabi"),
+ m_CurrentCPUArch(-1),
+ m_DIVUseInitialized(false),
+ m_HardFPUseInitialized(false) {}
-public:
- virtual const ELFAttributeValue *getAttributeValue(TagType pTag) const;
+ public:
+ virtual const ELFAttributeValue* getAttributeValue(TagType pTag) const;
- virtual std::pair<ELFAttributeValue*, bool>
- getOrCreateAttributeValue(TagType pTag);
+ virtual std::pair<ELFAttributeValue*, bool> getOrCreateAttributeValue(
+ TagType pTag);
- virtual bool preMerge(const Input &pInput)
- {
+ virtual bool preMerge(const Input& pInput) {
// Reset states.
m_CPUArch = -1;
m_CPUName.clear();
@@ -171,24 +167,26 @@ public:
return true;
}
- virtual bool merge(const LinkerConfig& pConfig, const Input &pInput,
- TagType pTag, const ELFAttributeValue& pInAttr);
+ virtual bool merge(const LinkerConfig& pConfig,
+ const Input& pInput,
+ TagType pTag,
+ const ELFAttributeValue& pInAttr);
- virtual bool postMerge(const LinkerConfig& pConfig, const Input &pInput);
+ virtual bool postMerge(const LinkerConfig& pConfig, const Input& pInput);
virtual size_t sizeOutput() const;
- virtual size_t emit(char *pBuf) const;
+ virtual size_t emit(char* pBuf) const;
virtual bool usingThumb() const;
virtual bool usingThumb2() const;
-private:
+ private:
/// GetAttributeValueType - obtain the value type of the indicated tag.
static unsigned int GetAttributeValueType(TagType pTag);
-private:
+ private:
// The storage for known tags which is indexed by the tag
ELFAttributeValue m_Attrs[Tag_Max + 1];
@@ -231,13 +229,14 @@ private:
// Record the value of input Tag_ABI_VFP_args.
int m_VFPArgs;
- // Record the value of input Tag_MPextension_use and Tag_MPextension_use_legacy.
+ // Record the value of input Tag_MPextension_use and
+ // Tag_MPextension_use_legacy.
int m_MPextensionUse;
// Record the value of input Tag_DIV_use.
int m_DIVUse;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_ARM_ARMELFATTRIBUTEDATA_H_
diff --git a/lib/Target/ARM/ARMELFDynamic.cpp b/lib/Target/ARM/ARMELFDynamic.cpp
index cbec6e8..8cddb9f 100644
--- a/lib/Target/ARM/ARMELFDynamic.cpp
+++ b/lib/Target/ARM/ARMELFDynamic.cpp
@@ -8,31 +8,28 @@
//===----------------------------------------------------------------------===//
#include "ARMELFDynamic.h"
-#include <mcld/LD/ELFFileFormat.h>
+#include "mcld/LD/ELFFileFormat.h"
-using namespace mcld;
+namespace mcld {
ARMELFDynamic::ARMELFDynamic(const GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : ELFDynamic(pParent, pConfig)
-{
+ : ELFDynamic(pParent, pConfig) {
}
-ARMELFDynamic::~ARMELFDynamic()
-{
+ARMELFDynamic::~ARMELFDynamic() {
}
-void ARMELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat)
-{
+void ARMELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat) {
// reservePLTGOT
if (pFormat.hasGOT())
reserveOne(llvm::ELF::DT_PLTGOT);
}
-void ARMELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat)
-{
+void ARMELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat) {
// applyPLTGOT
if (pFormat.hasGOT())
applyOne(llvm::ELF::DT_PLTGOT, pFormat.getGOT().addr());
}
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMELFDynamic.h b/lib/Target/ARM/ARMELFDynamic.h
index 43ec688..e876668 100644
--- a/lib/Target/ARM/ARMELFDynamic.h
+++ b/lib/Target/ARM/ARMELFDynamic.h
@@ -6,23 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMELFDYNAMIC_H
-#define TARGET_ARM_ARMELFDYNAMIC_H
+#ifndef TARGET_ARM_ARMELFDYNAMIC_H_
+#define TARGET_ARM_ARMELFDYNAMIC_H_
-#include <mcld/Target/ELFDynamic.h>
+#include "mcld/Target/ELFDynamic.h"
namespace mcld {
class ARMELFDynamic : public ELFDynamic {
-public:
+ public:
ARMELFDynamic(const GNULDBackend& pParent, const LinkerConfig& pConfig);
~ARMELFDynamic();
-private:
+ private:
void reserveTargetEntries(const ELFFileFormat& pFormat);
void applyTargetEntries(const ELFFileFormat& pFormat);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_ARM_ARMELFDYNAMIC_H_
diff --git a/lib/Target/ARM/ARMELFMCLinker.cpp b/lib/Target/ARM/ARMELFMCLinker.cpp
deleted file mode 100644
index 8e9a440..0000000
--- a/lib/Target/ARM/ARMELFMCLinker.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-//===- ARMELFMCLinker.cpp -------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "ARMELFMCLinker.h"
-
-using namespace mcld;
-
-ARMELFMCLinker::ARMELFMCLinker(LinkerConfig& pConfig,
- mcld::Module &pModule,
- FileHandle& pFileHandle)
- : ELFMCLinker(pConfig, pModule, pFileHandle) {
-}
-
-ARMELFMCLinker::~ARMELFMCLinker()
-{
-}
-
diff --git a/lib/Target/ARM/ARMELFMCLinker.h b/lib/Target/ARM/ARMELFMCLinker.h
deleted file mode 100644
index 5ee18ff..0000000
--- a/lib/Target/ARM/ARMELFMCLinker.h
+++ /dev/null
@@ -1,34 +0,0 @@
-//===- ARMELFMCLinker.h ---------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMELFMCLINKER_H
-#define TARGET_ARM_ARMELFMCLINKER_H
-#include <mcld/Target/ELFMCLinker.h>
-
-namespace mcld {
-
-class Module;
-class FileHandle;
-
-/** \class ARMELFMCLinker
- * \brief ARMELFMCLinker sets up the environment for linking.
- */
-class ARMELFMCLinker : public ELFMCLinker
-{
-public:
- ARMELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle);
-
- ~ARMELFMCLinker();
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/lib/Target/ARM/ARMEmulation.cpp b/lib/Target/ARM/ARMEmulation.cpp
index a890a87..10a714f 100644
--- a/lib/Target/ARM/ARMEmulation.cpp
+++ b/lib/Target/ARM/ARMEmulation.cpp
@@ -7,15 +7,14 @@
//
//===----------------------------------------------------------------------===//
#include "ARM.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Target/ELFEmulation.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Target/ELFEmulation.h"
+#include "mcld/Support/TargetRegistry.h"
namespace mcld {
-static bool MCLDEmulateARMELF(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+static bool MCLDEmulateARMELF(LinkerScript& pScript, LinkerConfig& pConfig) {
if (!MCLDEmulateELF(pScript, pConfig))
return false;
@@ -46,8 +45,7 @@ static bool MCLDEmulateARMELF(LinkerScript& pScript, LinkerConfig& pConfig)
//===----------------------------------------------------------------------===//
// emulateARMLD - the help function to emulate ARM ld
//===----------------------------------------------------------------------===//
-bool emulateARMLD(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+bool emulateARMLD(LinkerScript& pScript, LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker has not supported yet");
return false;
@@ -60,14 +58,15 @@ bool emulateARMLD(LinkerScript& pScript, LinkerConfig& pConfig)
return MCLDEmulateARMELF(pScript, pConfig);
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// ARMEmulation
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeARMEmulation() {
// Register the emulation
- mcld::TargetRegistry::RegisterEmulation(mcld::TheARMTarget, mcld::emulateARMLD);
- mcld::TargetRegistry::RegisterEmulation(mcld::TheThumbTarget, mcld::emulateARMLD);
+ mcld::TargetRegistry::RegisterEmulation(mcld::TheARMTarget,
+ mcld::emulateARMLD);
+ mcld::TargetRegistry::RegisterEmulation(mcld::TheThumbTarget,
+ mcld::emulateARMLD);
}
-
diff --git a/lib/Target/ARM/ARMGNUInfo.h b/lib/Target/ARM/ARMGNUInfo.h
index 79f2463..f14ed36 100644
--- a/lib/Target/ARM/ARMGNUInfo.h
+++ b/lib/Target/ARM/ARMGNUInfo.h
@@ -6,18 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMGNUINFO_H
-#define TARGET_ARM_ARMGNUINFO_H
-#include <mcld/Target/GNUInfo.h>
+#ifndef TARGET_ARM_ARMGNUINFO_H_
+#define TARGET_ARM_ARMGNUINFO_H_
+#include "mcld/Target/GNUInfo.h"
#include <llvm/Support/ELF.h>
namespace mcld {
-class ARMGNUInfo : public GNUInfo
-{
-public:
- ARMGNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) { }
+class ARMGNUInfo : public GNUInfo {
+ public:
+ explicit ARMGNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) {}
uint32_t machine() const { return llvm::ELF::EM_ARM; }
@@ -26,7 +25,6 @@ public:
uint64_t flags() const { return llvm::ELF::EF_ARM_EABI_VER5; }
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_ARM_ARMGNUINFO_H_
diff --git a/lib/Target/ARM/ARMGOT.cpp b/lib/Target/ARM/ARMGOT.cpp
index 7ad10ac..a7dd170 100644
--- a/lib/Target/ARM/ARMGOT.cpp
+++ b/lib/Target/ARM/ARMGOT.cpp
@@ -8,53 +8,47 @@
//===----------------------------------------------------------------------===//
#include "ARMGOT.h"
-#include <llvm/Support/Casting.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/Support/MsgHandling.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/Support/MsgHandling.h>
+#include <llvm/Support/Casting.h>
namespace {
- const unsigned int ARMGOT0Num = 3;
-} // end of anonymous namespace
+const unsigned int ARMGOT0Num = 3;
+} // end of anonymous namespace
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ARMGOT
ARMGOT::ARMGOT(LDSection& pSection)
- : GOT(pSection), m_pGOTPLTFront(NULL), m_pGOTFront(NULL)
-{
+ : GOT(pSection), m_pGOTPLTFront(NULL), m_pGOTFront(NULL) {
// create GOT0, and put them into m_SectionData immediately
for (unsigned int i = 0; i < ARMGOT0Num; ++i)
new ARMGOTEntry(0, m_SectionData);
}
-ARMGOT::~ARMGOT()
-{
+ARMGOT::~ARMGOT() {
}
-bool ARMGOT::hasGOT1() const
-{
+bool ARMGOT::hasGOT1() const {
return ((!m_GOT.empty()) || (!m_GOTPLT.empty()));
}
-ARMGOTEntry* ARMGOT::createGOT()
-{
+ARMGOTEntry* ARMGOT::createGOT() {
ARMGOTEntry* entry = new ARMGOTEntry(0, NULL);
m_GOT.push_back(entry);
return entry;
}
-ARMGOTEntry* ARMGOT::createGOTPLT()
-{
+ARMGOTEntry* ARMGOT::createGOTPLT() {
ARMGOTEntry* entry = new ARMGOTEntry(0, NULL);
m_GOTPLT.push_back(entry);
return entry;
}
-void ARMGOT::finalizeSectionSize()
-{
+void ARMGOT::finalizeSectionSize() {
uint32_t offset = 0;
SectionData::FragmentListType& frag_list = m_SectionData->getFragmentList();
// setup GOT0 offset
@@ -96,20 +90,18 @@ void ARMGOT::finalizeSectionSize()
m_Section.setSize(offset);
}
-void ARMGOT::applyGOT0(uint64_t pAddress)
-{
- llvm::cast<ARMGOTEntry>
- (*(m_SectionData->getFragmentList().begin())).setValue(pAddress);
+void ARMGOT::applyGOT0(uint64_t pAddress) {
+ llvm::cast<ARMGOTEntry>(*(m_SectionData->getFragmentList().begin()))
+ .setValue(pAddress);
}
-void ARMGOT::applyGOTPLT(uint64_t pPLTBase)
-{
- if (NULL == m_pGOTPLTFront)
+void ARMGOT::applyGOTPLT(uint64_t pPLTBase) {
+ if (m_pGOTPLTFront == NULL)
return;
SectionData::iterator entry(m_pGOTPLTFront);
SectionData::iterator e_end;
- if (NULL == m_pGOTFront)
+ if (m_pGOTFront == NULL)
e_end = m_SectionData->end();
else
e_end = SectionData::iterator(m_pGOTFront);
@@ -120,17 +112,17 @@ void ARMGOT::applyGOTPLT(uint64_t pPLTBase)
}
}
-uint64_t ARMGOT::emit(MemoryRegion& pRegion)
-{
+uint64_t ARMGOT::emit(MemoryRegion& pRegion) {
uint32_t* buffer = reinterpret_cast<uint32_t*>(pRegion.begin());
ARMGOTEntry* got = NULL;
uint64_t result = 0x0;
for (iterator it = begin(), ie = end(); it != ie; ++it, ++buffer) {
- got = &(llvm::cast<ARMGOTEntry>((*it)));
- *buffer = static_cast<uint32_t>(got->getValue());
- result += ARMGOTEntry::EntrySize;
+ got = &(llvm::cast<ARMGOTEntry>((*it)));
+ *buffer = static_cast<uint32_t>(got->getValue());
+ result += ARMGOTEntry::EntrySize;
}
return result;
}
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMGOT.h b/lib/Target/ARM/ARMGOT.h
index e4515a5..26d39e7 100644
--- a/lib/Target/ARM/ARMGOT.h
+++ b/lib/Target/ARM/ARMGOT.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMGOT_H
-#define TARGET_ARM_ARMGOT_H
+#ifndef TARGET_ARM_ARMGOT_H_
+#define TARGET_ARM_ARMGOT_H_
-#include <mcld/Target/GOT.h>
-#include <mcld/Support/MemoryRegion.h>
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Target/GOT.h"
#include <llvm/ADT/DenseMap.h>
#include <vector>
@@ -21,12 +21,10 @@ class LDSection;
/** \class ARMGOTEntry
* \brief GOT Entry with size of 4 bytes
*/
-class ARMGOTEntry : public GOT::Entry<4>
-{
-public:
+class ARMGOTEntry : public GOT::Entry<4> {
+ public:
ARMGOTEntry(uint64_t pContent, SectionData* pParent)
- : GOT::Entry<4>(pContent, pParent)
- {}
+ : GOT::Entry<4>(pContent, pParent) {}
};
/** \class ARMGOT
@@ -46,10 +44,9 @@ public:
* +--------------+
*
*/
-class ARMGOT : public GOT
-{
-public:
- ARMGOT(LDSection &pSection);
+class ARMGOT : public GOT {
+ public:
+ explicit ARMGOT(LDSection& pSection);
~ARMGOT();
@@ -66,12 +63,12 @@ public:
bool hasGOT1() const;
-private:
+ private:
typedef std::vector<ARMGOTEntry*> EntryListType;
typedef EntryListType::iterator entry_iterator;
typedef EntryListType::const_iterator const_entry_iterator;
-private:
+ private:
ARMGOTEntry* m_pGOTPLTFront;
ARMGOTEntry* m_pGOTFront;
@@ -82,7 +79,6 @@ private:
EntryListType m_GOT;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_ARM_ARMGOT_H_
diff --git a/lib/Target/ARM/ARMLDBackend.cpp b/lib/Target/ARM/ARMLDBackend.cpp
index 2b30df8..aa429f8 100644
--- a/lib/Target/ARM/ARMLDBackend.cpp
+++ b/lib/Target/ARM/ARMLDBackend.cpp
@@ -17,59 +17,58 @@
#include "THMToTHMStub.h"
#include "THMToARMStub.h"
-#include <mcld/IRBuilder.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/Fragment/AlignFragment.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Fragment/Stub.h>
-#include <mcld/Fragment/NullFragment.h>
-#include <mcld/Support/MemoryRegion.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/LD/StubFactory.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/Target/ELFAttribute.h>
-#include <mcld/Target/GNUInfo.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/Fragment/NullFragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/StubFactory.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/ELFAttribute.h"
+#include "mcld/Target/GNUInfo.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/Triple.h>
#include <llvm/ADT/Twine.h>
-#include <llvm/Support/ELF.h>
#include <llvm/Support/Casting.h>
+#include <llvm/Support/ELF.h>
#include <cstring>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ARMGNULDBackend
//===----------------------------------------------------------------------===//
ARMGNULDBackend::ARMGNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo)
- : GNULDBackend(pConfig, pInfo),
- m_pRelocator(NULL),
- m_pGOT(NULL),
- m_pPLT(NULL),
- m_pRelDyn(NULL),
- m_pRelPLT(NULL),
- m_pAttrData(NULL),
- m_pDynamic(NULL),
- m_pGOTSymbol(NULL),
- m_pEXIDXStart(NULL),
- m_pEXIDXEnd(NULL),
- m_pEXIDX(NULL),
- m_pEXTAB(NULL),
- m_pAttributes(NULL) {
-}
-
-ARMGNULDBackend::~ARMGNULDBackend()
-{
+ : GNULDBackend(pConfig, pInfo),
+ m_pRelocator(NULL),
+ m_pGOT(NULL),
+ m_pPLT(NULL),
+ m_pRelDyn(NULL),
+ m_pRelPLT(NULL),
+ m_pAttrData(NULL),
+ m_pDynamic(NULL),
+ m_pGOTSymbol(NULL),
+ m_pEXIDXStart(NULL),
+ m_pEXIDXEnd(NULL),
+ m_pEXIDX(NULL),
+ m_pEXTAB(NULL),
+ m_pAttributes(NULL) {
+}
+
+ARMGNULDBackend::~ARMGNULDBackend() {
delete m_pRelocator;
delete m_pGOT;
delete m_pPLT;
@@ -79,25 +78,26 @@ ARMGNULDBackend::~ARMGNULDBackend()
delete m_pAttrData;
}
-void ARMGNULDBackend::initTargetSections(Module& pModule, ObjectBuilder& pBuilder)
-{
- // FIXME: Currently we set exidx and extab to "Exception" and directly emit
- // them from input
- m_pEXIDX = pBuilder.CreateSection(".ARM.exidx",
- LDFileFormat::Target,
- llvm::ELF::SHT_ARM_EXIDX,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_LINK_ORDER,
- config().targets().bitclass() / 8);
- m_pEXTAB = pBuilder.CreateSection(".ARM.extab",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC,
- 0x1);
- m_pAttributes = pBuilder.CreateSection(".ARM.attributes",
- LDFileFormat::Target,
- llvm::ELF::SHT_ARM_ATTRIBUTES,
- 0x0,
- 0x1);
+void ARMGNULDBackend::initTargetSections(Module& pModule,
+ ObjectBuilder& pBuilder) {
+ // FIXME: Currently we set exidx and extab to "Exception" and directly emit
+ // them from input
+ m_pEXIDX =
+ pBuilder.CreateSection(".ARM.exidx",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_ARM_EXIDX,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_LINK_ORDER,
+ config().targets().bitclass() / 8);
+ m_pEXTAB = pBuilder.CreateSection(".ARM.extab",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC,
+ 0x1);
+ m_pAttributes = pBuilder.CreateSection(".ARM.attributes",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_ARM_ATTRIBUTES,
+ 0x0,
+ 0x1);
// initialize "aeabi" attributes subsection
m_pAttrData = new ARMELFAttributeData();
@@ -126,102 +126,95 @@ void ARMGNULDBackend::initTargetSections(Module& pModule, ObjectBuilder& pBuilde
}
}
-void ARMGNULDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule)
-{
+void ARMGNULDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule) {
// Define the symbol _GLOBAL_OFFSET_TABLE_ if there is a symbol with the
// same name in input
if (LinkerConfig::Object != config().codeGenType()) {
- m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Hidden);
+ m_pGOTSymbol =
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Hidden);
}
- if (NULL != m_pEXIDX && 0x0 != m_pEXIDX->size()) {
+ if (m_pEXIDX != NULL && m_pEXIDX->size() != 0x0) {
FragmentRef* exidx_start =
- FragmentRef::Create(m_pEXIDX->getSectionData()->front(), 0x0);
- FragmentRef* exidx_end =
- FragmentRef::Create(m_pEXIDX->getSectionData()->front(),
- m_pEXIDX->size());
+ FragmentRef::Create(m_pEXIDX->getSectionData()->front(), 0x0);
+ FragmentRef* exidx_end = FragmentRef::Create(
+ m_pEXIDX->getSectionData()->front(), m_pEXIDX->size());
m_pEXIDXStart =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__exidx_start",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- exidx_start, // FragRef
- ResolveInfo::Default);
-
- m_pEXIDXEnd =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__exidx_end",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- exidx_end, // FragRef
- ResolveInfo::Default);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__exidx_start",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ exidx_start, // FragRef
+ ResolveInfo::Default);
+
+ m_pEXIDXEnd = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__exidx_end",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ exidx_end, // FragRef
+ ResolveInfo::Default);
// change __exidx_start/_end to local dynamic category
- if (NULL != m_pEXIDXStart)
+ if (m_pEXIDXStart != NULL)
pModule.getSymbolTable().changeToDynamic(*m_pEXIDXStart);
- if (NULL != m_pEXIDXEnd)
+ if (m_pEXIDXEnd != NULL)
pModule.getSymbolTable().changeToDynamic(*m_pEXIDXEnd);
} else {
m_pEXIDXStart =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__exidx_start",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Default);
-
- m_pEXIDXEnd =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__exidx_end",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Default);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__exidx_start",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Default);
+
+ m_pEXIDXEnd = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__exidx_end",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Default);
}
}
-bool ARMGNULDBackend::initRelocator()
-{
- if (NULL == m_pRelocator) {
+bool ARMGNULDBackend::initRelocator() {
+ if (m_pRelocator == NULL) {
m_pRelocator = new ARMRelocator(*this, config());
}
return true;
}
-const Relocator* ARMGNULDBackend::getRelocator() const
-{
- assert(NULL != m_pRelocator);
+const Relocator* ARMGNULDBackend::getRelocator() const {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-Relocator* ARMGNULDBackend::getRelocator()
-{
- assert(NULL != m_pRelocator);
+Relocator* ARMGNULDBackend::getRelocator() {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-void ARMGNULDBackend::doPreLayout(IRBuilder& pBuilder)
-{
+void ARMGNULDBackend::doPreLayout(IRBuilder& pBuilder) {
// initialize .dynamic data
- if (!config().isCodeStatic() && NULL == m_pDynamic)
+ if (!config().isCodeStatic() && m_pDynamic == NULL)
m_pDynamic = new ARMELFDynamic(*this, config());
// set attribute section size
@@ -230,9 +223,8 @@ void ARMGNULDBackend::doPreLayout(IRBuilder& pBuilder)
// set .got size
// when building shared object, the .got section is must
if (LinkerConfig::Object != config().codeGenType()) {
- if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ if (LinkerConfig::DynObj == config().codeGenType() || m_pGOT->hasGOT1() ||
+ m_pGOTSymbol != NULL) {
m_pGOT->finalizeSectionSize();
defineGOTSymbol(pBuilder);
}
@@ -244,31 +236,32 @@ void ARMGNULDBackend::doPreLayout(IRBuilder& pBuilder)
ELFFileFormat* file_format = getOutputFormat();
// set .rel.dyn size
if (!m_pRelDyn->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
- file_format->getRelDyn().setSize(
- m_pRelDyn->numOfRelocs() * getRelEntrySize());
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
+ file_format->getRelDyn().setSize(m_pRelDyn->numOfRelocs() *
+ getRelEntrySize());
}
// set .rel.plt size
if (!m_pRelPLT->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
- file_format->getRelPlt().setSize(
- m_pRelPLT->numOfRelocs() * getRelEntrySize());
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
+ file_format->getRelPlt().setSize(m_pRelPLT->numOfRelocs() *
+ getRelEntrySize());
}
}
}
-void ARMGNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder)
-{
- const ELFFileFormat *file_format = getOutputFormat();
+void ARMGNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder) {
+ const ELFFileFormat* file_format = getOutputFormat();
// apply PLT
if (file_format->hasPLT()) {
// Since we already have the size of LDSection PLT, m_pPLT should not be
// NULL.
- assert(NULL != m_pPLT);
+ assert(m_pPLT != NULL);
m_pPLT->applyPLT0();
m_pPLT->applyPLT1();
}
@@ -276,7 +269,7 @@ void ARMGNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder)
// apply GOT
if (file_format->hasGOT()) {
// Since we already have the size of GOT, m_pGOT should not be NULL.
- assert(NULL != m_pGOT);
+ assert(m_pGOT != NULL);
if (LinkerConfig::DynObj == config().codeGenType())
m_pGOT->applyGOT0(file_format->getDynamic().addr());
else {
@@ -288,51 +281,45 @@ void ARMGNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder)
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-ARMELFDynamic& ARMGNULDBackend::dynamic()
-{
- assert(NULL != m_pDynamic);
+ARMELFDynamic& ARMGNULDBackend::dynamic() {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-const ARMELFDynamic& ARMGNULDBackend::dynamic() const
-{
- assert(NULL != m_pDynamic);
+const ARMELFDynamic& ARMGNULDBackend::dynamic() const {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
-void ARMGNULDBackend::defineGOTSymbol(IRBuilder& pBuilder)
-{
+void ARMGNULDBackend::defineGOTSymbol(IRBuilder& pBuilder) {
// define symbol _GLOBAL_OFFSET_TABLE_ when .got create
if (m_pGOTSymbol != NULL) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pGOT->begin()), 0x0),
- ResolveInfo::Hidden);
- }
- else {
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pGOT->begin()), 0x0),
+ ResolveInfo::Hidden);
+ } else {
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pGOT->begin()), 0x0),
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pGOT->begin()), 0x0),
+ ResolveInfo::Hidden);
}
-
}
uint64_t ARMGNULDBackend::emitSectionData(const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
assert(pRegion.size() && "Size of MemoryRegion is zero!");
const ELFFileFormat* file_format = getOutputFormat();
@@ -358,11 +345,10 @@ uint64_t ARMGNULDBackend::emitSectionData(const LDSection& pSection,
uint8_t* out_offset = pRegion.begin();
for (frag_iter = sect_data->begin(); frag_iter != frag_end; ++frag_iter) {
size_t size = frag_iter->size();
- switch(frag_iter->getKind()) {
+ switch (frag_iter->getKind()) {
case Fragment::Fillment: {
- const FillFragment& fill_frag =
- llvm::cast<FillFragment>(*frag_iter);
- if (0 == fill_frag.getValueSize()) {
+ const FillFragment& fill_frag = llvm::cast<FillFragment>(*frag_iter);
+ if (fill_frag.getValueSize() == 0) {
// virtual fillment, ignore it.
break;
}
@@ -372,7 +358,7 @@ uint64_t ARMGNULDBackend::emitSectionData(const LDSection& pSection,
}
case Fragment::Region: {
const RegionFragment& region_frag =
- llvm::cast<RegionFragment>(*frag_iter);
+ llvm::cast<RegionFragment>(*frag_iter);
const char* start = region_frag.getRegion().begin();
memcpy(out_offset, start, size);
break;
@@ -386,9 +372,9 @@ uint64_t ARMGNULDBackend::emitSectionData(const LDSection& pSection,
break;
default:
llvm::report_fatal_error(
- "unsupported value size for align fragment emission yet.\n");
+ "unsupported value size for align fragment emission yet.\n");
break;
- } // end switch
+ } // end switch
break;
}
case Fragment::Null: {
@@ -398,29 +384,28 @@ uint64_t ARMGNULDBackend::emitSectionData(const LDSection& pSection,
default:
llvm::report_fatal_error("unsupported fragment type.\n");
break;
- } // end switch
+ } // end switch
out_offset += size;
- } // end for
+ } // end for
return pRegion.size();
}
/// finalizeSymbol - finalize the symbol value
-bool ARMGNULDBackend::finalizeTargetSymbols()
-{
+bool ARMGNULDBackend::finalizeTargetSymbols() {
return true;
}
bool ARMGNULDBackend::mergeSection(Module& pModule,
const Input& pInput,
- LDSection& pSection)
-{
+ LDSection& pSection) {
switch (pSection.type()) {
case llvm::ELF::SHT_ARM_ATTRIBUTES: {
return attribute().merge(pInput, pSection);
}
case llvm::ELF::SHT_ARM_EXIDX: {
- assert(NULL != pSection.getLink());
- if (LDFileFormat::Ignore == pSection.getLink()->kind()) {
+ assert(pSection.getLink() != NULL);
+ if ((pSection.getLink()->kind() == LDFileFormat::Ignore) ||
+ (pSection.getLink()->kind() == LDFileFormat::Folded)) {
// if the target section of the .ARM.exidx is Ignore, then it should be
// ignored as well
pSection.setKind(LDFileFormat::Ignore);
@@ -433,19 +418,19 @@ bool ARMGNULDBackend::mergeSection(Module& pModule,
builder.MergeSection(pInput, pSection);
return true;
}
- } // end of switch
+ } // end of switch
return true;
}
-void ARMGNULDBackend::setUpReachedSectionsForGC(const Module& pModule,
- GarbageCollection::SectionReachedListMap& pSectReachedListMap) const
-{
+void ARMGNULDBackend::setUpReachedSectionsForGC(
+ const Module& pModule,
+ GarbageCollection::SectionReachedListMap& pSectReachedListMap) const {
// traverse all the input relocations to find the relocation sections applying
// .ARM.exidx sections
Module::const_obj_iterator input, inEnd = pModule.obj_end();
for (input = pModule.obj_begin(); input != inEnd; ++input) {
LDContext::const_sect_iterator rs,
- rsEnd = (*input)->context()->relocSectEnd();
+ rsEnd = (*input)->context()->relocSectEnd();
for (rs = (*input)->context()->relocSectBegin(); rs != rsEnd; ++rs) {
// bypass the discarded relocation section
// 1. its section kind is changed to Ignore. (The target section is a
@@ -464,12 +449,12 @@ void ARMGNULDBackend::setUpReachedSectionsForGC(const Module& pModule,
GarbageCollection::SectionListTy* reached_sects = NULL;
RelocData::iterator reloc_it, rEnd = reloc_sect->getRelocData()->end();
for (reloc_it = reloc_sect->getRelocData()->begin(); reloc_it != rEnd;
- ++reloc_it) {
+ ++reloc_it) {
Relocation* reloc = llvm::cast<Relocation>(reloc_it);
ResolveInfo* sym = reloc->symInfo();
// only the target symbols defined in the input fragments can make the
// reference
- if (NULL == sym)
+ if (sym == NULL)
continue;
if (!sym->isDefine() || !sym->outSymbol()->hasFragRef())
continue;
@@ -477,7 +462,7 @@ void ARMGNULDBackend::setUpReachedSectionsForGC(const Module& pModule,
// only the target symbols defined in the concerned sections can make
// the reference
const LDSection* target_sect =
- &sym->outSymbol()->fragRef()->frag()->getParent()->getSection();
+ &sym->outSymbol()->fragRef()->frag()->getParent()->getSection();
if (target_sect->kind() != LDFileFormat::TEXT &&
target_sect->kind() != LDFileFormat::DATA &&
target_sect->kind() != LDFileFormat::BSS)
@@ -501,8 +486,7 @@ void ARMGNULDBackend::setUpReachedSectionsForGC(const Module& pModule,
}
}
-bool ARMGNULDBackend::readSection(Input& pInput, SectionData& pSD)
-{
+bool ARMGNULDBackend::readSection(Input& pInput, SectionData& pSD) {
Fragment* frag = NULL;
uint32_t offset = pInput.fileOffset() + pSD.getSection().offset();
uint32_t size = pSD.getSection().size();
@@ -512,8 +496,7 @@ bool ARMGNULDBackend::readSection(Input& pInput, SectionData& pSD)
// If the input section's size is zero, we got a NULL region.
// use a virtual fill fragment
frag = new FillFragment(0x0, 0, 0);
- }
- else {
+ } else {
frag = new RegionFragment(region);
}
@@ -521,69 +504,58 @@ bool ARMGNULDBackend::readSection(Input& pInput, SectionData& pSD)
return true;
}
-ARMGOT& ARMGNULDBackend::getGOT()
-{
- assert(NULL != m_pGOT && "GOT section not exist");
+ARMGOT& ARMGNULDBackend::getGOT() {
+ assert(m_pGOT != NULL && "GOT section not exist");
return *m_pGOT;
}
-const ARMGOT& ARMGNULDBackend::getGOT() const
-{
- assert(NULL != m_pGOT && "GOT section not exist");
+const ARMGOT& ARMGNULDBackend::getGOT() const {
+ assert(m_pGOT != NULL && "GOT section not exist");
return *m_pGOT;
}
-ARMPLT& ARMGNULDBackend::getPLT()
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+ARMPLT& ARMGNULDBackend::getPLT() {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-const ARMPLT& ARMGNULDBackend::getPLT() const
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+const ARMPLT& ARMGNULDBackend::getPLT() const {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-OutputRelocSection& ARMGNULDBackend::getRelDyn()
-{
- assert(NULL != m_pRelDyn && ".rel.dyn section not exist");
+OutputRelocSection& ARMGNULDBackend::getRelDyn() {
+ assert(m_pRelDyn != NULL && ".rel.dyn section not exist");
return *m_pRelDyn;
}
-const OutputRelocSection& ARMGNULDBackend::getRelDyn() const
-{
- assert(NULL != m_pRelDyn && ".rel.dyn section not exist");
+const OutputRelocSection& ARMGNULDBackend::getRelDyn() const {
+ assert(m_pRelDyn != NULL && ".rel.dyn section not exist");
return *m_pRelDyn;
}
-OutputRelocSection& ARMGNULDBackend::getRelPLT()
-{
- assert(NULL != m_pRelPLT && ".rel.plt section not exist");
+OutputRelocSection& ARMGNULDBackend::getRelPLT() {
+ assert(m_pRelPLT != NULL && ".rel.plt section not exist");
return *m_pRelPLT;
}
-const OutputRelocSection& ARMGNULDBackend::getRelPLT() const
-{
- assert(NULL != m_pRelPLT && ".rel.plt section not exist");
+const OutputRelocSection& ARMGNULDBackend::getRelPLT() const {
+ assert(m_pRelPLT != NULL && ".rel.plt section not exist");
return *m_pRelPLT;
}
-ARMELFAttributeData& ARMGNULDBackend::getAttributeData()
-{
- assert(NULL != m_pAttrData && ".ARM.attributes section not exist");
+ARMELFAttributeData& ARMGNULDBackend::getAttributeData() {
+ assert(m_pAttrData != NULL && ".ARM.attributes section not exist");
return *m_pAttrData;
}
-const ARMELFAttributeData& ARMGNULDBackend::getAttributeData() const
-{
- assert(NULL != m_pAttrData && ".ARM.attributes section not exist");
+const ARMELFAttributeData& ARMGNULDBackend::getAttributeData() const {
+ assert(m_pAttrData != NULL && ".ARM.attributes section not exist");
return *m_pAttrData;
}
-unsigned int
-ARMGNULDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
-{
+unsigned int ARMGNULDBackend::getTargetSectionOrder(
+ const LDSection& pSectHdr) const {
const ELFFileFormat* file_format = getOutputFormat();
if (file_format->hasGOT() && (&pSectHdr == &file_format->getGOT())) {
@@ -604,10 +576,10 @@ ARMGNULDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
}
/// doRelax
-bool
-ARMGNULDBackend::doRelax(Module& pModule, IRBuilder& pBuilder, bool& pFinished)
-{
- assert(NULL != getStubFactory() && NULL != getBRIslandFactory());
+bool ARMGNULDBackend::doRelax(Module& pModule,
+ IRBuilder& pBuilder,
+ bool& pFinished) {
+ assert(getStubFactory() != NULL && getBRIslandFactory() != NULL);
bool isRelaxed = false;
ELFFileFormat* file_format = getOutputFormat();
@@ -637,40 +609,43 @@ ARMGNULDBackend::doRelax(Module& pModule, IRBuilder& pBuilder, bool& pFinished)
if (symbol->hasFragRef()) {
uint64_t value = symbol->fragRef()->getOutputOffset();
uint64_t addr =
- symbol->fragRef()->frag()->getParent()->getSection().addr();
+ symbol->fragRef()->frag()->getParent()->getSection().addr();
sym_value = addr + value;
}
- if (relocation->symInfo()->isGlobal() &&
- (relocation->symInfo()->reserved() & ARMRelocator::ReservePLT) != 0x0) {
- // FIXME: we need to find out the address of the specific plt entry
+ if ((relocation->symInfo()->reserved() &
+ ARMRelocator::ReservePLT) != 0x0) {
+ // FIXME: we need to find out the address of the specific plt
+ // entry
assert(file_format->hasPLT());
sym_value = file_format->getPLT().addr();
}
-
- Stub* stub = getStubFactory()->create(*relocation, // relocation
- sym_value, // symbol value
+ Stub* stub = getStubFactory()->create(*relocation, // relocation
+ sym_value, // symbol value
pBuilder,
*getBRIslandFactory());
- if (NULL != stub) {
+ if (stub != NULL) {
switch (config().options().getStripSymbolMode()) {
case GeneralOptions::StripAllSymbols:
case GeneralOptions::StripLocals:
break;
default: {
// a stub symbol should be local
- assert(NULL != stub->symInfo() && stub->symInfo()->isLocal());
+ assert(stub->symInfo() != NULL && stub->symInfo()->isLocal());
LDSection& symtab = file_format->getSymTab();
LDSection& strtab = file_format->getStrTab();
// increase the size of .symtab and .strtab if needed
if (config().targets().is32Bits())
- symtab.setSize(symtab.size() + sizeof(llvm::ELF::Elf32_Sym));
+ symtab.setSize(symtab.size() +
+ sizeof(llvm::ELF::Elf32_Sym));
else
- symtab.setSize(symtab.size() + sizeof(llvm::ELF::Elf64_Sym));
+ symtab.setSize(symtab.size() +
+ sizeof(llvm::ELF::Elf64_Sym));
symtab.setInfo(symtab.getInfo() + 1);
- strtab.setSize(strtab.size() + stub->symInfo()->nameSize() + 1);
+ strtab.setSize(strtab.size() + stub->symInfo()->nameSize() +
+ 1);
}
- } // end of switch
+ } // end of switch
isRelaxed = true;
}
break;
@@ -680,17 +655,18 @@ ARMGNULDBackend::doRelax(Module& pModule, IRBuilder& pBuilder, bool& pFinished)
break;
default:
break;
- } // end of switch
-
- } // for all relocations
- } // for all relocation section
- } // for all inputs
+ } // end of switch
+ } // for all relocations
+ } // for all relocation section
+ } // for all inputs
// find the first fragment w/ invalid offset due to stub insertion
Fragment* invalid = NULL;
pFinished = true;
for (BranchIslandFactory::iterator island = getBRIslandFactory()->begin(),
- island_end = getBRIslandFactory()->end(); island != island_end; ++island) {
+ island_end = getBRIslandFactory()->end();
+ island != island_end;
+ ++island) {
if ((*island).end() == file_format->getText().getSectionData()->end())
break;
@@ -703,7 +679,7 @@ ARMGNULDBackend::doRelax(Module& pModule, IRBuilder& pBuilder, bool& pFinished)
}
// reset the offset of invalid fragments
- while (NULL != invalid) {
+ while (invalid != NULL) {
invalid->setOffset(invalid->getPrevNode()->getOffset() +
invalid->getPrevNode()->size());
invalid = invalid->getNextNode();
@@ -712,16 +688,15 @@ ARMGNULDBackend::doRelax(Module& pModule, IRBuilder& pBuilder, bool& pFinished)
// reset the size of .text
if (isRelaxed) {
file_format->getText().setSize(
- file_format->getText().getSectionData()->back().getOffset() +
- file_format->getText().getSectionData()->back().size());
+ file_format->getText().getSectionData()->back().getOffset() +
+ file_format->getText().getSectionData()->back().size());
}
return isRelaxed;
}
/// initTargetStubs
-bool ARMGNULDBackend::initTargetStubs()
-{
- if (NULL != getStubFactory()) {
+bool ARMGNULDBackend::initTargetStubs() {
+ if (getStubFactory() != NULL) {
getStubFactory()->addPrototype(new ARMToARMStub(config().isCodeIndep()));
getStubFactory()->addPrototype(new ARMToTHMStub(config().isCodeIndep()));
getStubFactory()->addPrototype(
@@ -734,8 +709,7 @@ bool ARMGNULDBackend::initTargetStubs()
}
/// maxFwdBranchOffset
-int64_t ARMGNULDBackend::maxFwdBranchOffset()
-{
+int64_t ARMGNULDBackend::maxFwdBranchOffset() {
if (m_pAttrData->usingThumb2()) {
return THM2_MAX_FWD_BRANCH_OFFSET;
} else {
@@ -744,8 +718,7 @@ int64_t ARMGNULDBackend::maxFwdBranchOffset()
}
/// maxBwdBranchOffset
-int64_t ARMGNULDBackend::maxBwdBranchOffset()
-{
+int64_t ARMGNULDBackend::maxBwdBranchOffset() {
if (m_pAttrData->usingThumb2()) {
return THM2_MAX_BWD_BRANCH_OFFSET;
} else {
@@ -755,36 +728,28 @@ int64_t ARMGNULDBackend::maxBwdBranchOffset()
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
-void ARMGNULDBackend::doCreateProgramHdrs(Module& pModule)
-{
- if (NULL != m_pEXIDX && 0x0 != m_pEXIDX->size()) {
- // make PT_ARM_EXIDX
- ELFSegment* exidx_seg = elfSegmentTable().produce(llvm::ELF::PT_ARM_EXIDX,
- llvm::ELF::PF_R);
- exidx_seg->append(m_pEXIDX);
- }
+void ARMGNULDBackend::doCreateProgramHdrs(Module& pModule) {
+ if (m_pEXIDX != NULL && m_pEXIDX->size() != 0x0) {
+ // make PT_ARM_EXIDX
+ ELFSegment* exidx_seg =
+ elfSegmentTable().produce(llvm::ELF::PT_ARM_EXIDX, llvm::ELF::PF_R);
+ exidx_seg->append(m_pEXIDX);
+ }
}
/// mayHaveUnsafeFunctionPointerAccess - check if the section may have unsafe
/// function pointer access
-bool
-ARMGNULDBackend::mayHaveUnsafeFunctionPointerAccess(const LDSection& pSection)
- const
-{
+bool ARMGNULDBackend::mayHaveUnsafeFunctionPointerAccess(
+ const LDSection& pSection) const {
llvm::StringRef name(pSection.name());
- return !name.startswith(".ARM.exidx") &&
- !name.startswith(".ARM.extab") &&
+ return !name.startswith(".ARM.exidx") && !name.startswith(".ARM.extab") &&
GNULDBackend::mayHaveUnsafeFunctionPointerAccess(pSection);
}
-
-namespace mcld {
-
//===----------------------------------------------------------------------===//
/// createARMLDBackend - the help funtion to create corresponding ARMLDBackend
///
-TargetLDBackend* createARMLDBackend(const LinkerConfig& pConfig)
-{
+TargetLDBackend* createARMLDBackend(const LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker is not supported yet");
/**
@@ -801,17 +766,19 @@ TargetLDBackend* createARMLDBackend(const LinkerConfig& pConfig)
createARMCOFFObjectWriter);
**/
}
- return new ARMGNULDBackend(pConfig, new ARMGNUInfo(pConfig.targets().triple()));
+ return new ARMGNULDBackend(pConfig,
+ new ARMGNUInfo(pConfig.targets().triple()));
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// Force static initialization.
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeARMLDBackend() {
// Register the linker backend
- mcld::TargetRegistry::RegisterTargetLDBackend(TheARMTarget, createARMLDBackend);
- mcld::TargetRegistry::RegisterTargetLDBackend(TheThumbTarget, createARMLDBackend);
+ mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheARMTarget,
+ mcld::createARMLDBackend);
+ mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheThumbTarget,
+ mcld::createARMLDBackend);
}
-
diff --git a/lib/Target/ARM/ARMLDBackend.h b/lib/Target/ARM/ARMLDBackend.h
index 14d3fde..aad31e8 100644
--- a/lib/Target/ARM/ARMLDBackend.h
+++ b/lib/Target/ARM/ARMLDBackend.h
@@ -6,45 +6,43 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMLDBACKEND_H
-#define TARGET_ARM_ARMLDBACKEND_H
+#ifndef TARGET_ARM_ARMLDBACKEND_H_
+#define TARGET_ARM_ARMLDBACKEND_H_
#include "ARMELFDynamic.h"
#include "ARMGOT.h"
#include "ARMPLT.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Target/OutputRelocSection.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/Target/GNULDBackend.h"
+#include "mcld/Target/OutputRelocSection.h"
namespace mcld {
class ARMELFAttributeData;
-class LinkerConfig;
class GNUInfo;
+class LinkerConfig;
//===----------------------------------------------------------------------===//
/// ARMGNULDBackend - linker backend of ARM target of GNU ELF format
///
-class ARMGNULDBackend : public GNULDBackend
-{
-public:
+class ARMGNULDBackend : public GNULDBackend {
+ public:
// max branch offsets for ARM, THUMB, and THUMB2
- // @ref gold/arm.cc:99
static const int32_t ARM_MAX_FWD_BRANCH_OFFSET = ((((1 << 23) - 1) << 2) + 8);
static const int32_t ARM_MAX_BWD_BRANCH_OFFSET = ((-((1 << 23) << 2)) + 8);
- static const int32_t THM_MAX_FWD_BRANCH_OFFSET = ((1 << 22) -2 + 4);
+ static const int32_t THM_MAX_FWD_BRANCH_OFFSET = ((1 << 22) - 2 + 4);
static const int32_t THM_MAX_BWD_BRANCH_OFFSET = (-(1 << 22) + 4);
static const int32_t THM2_MAX_FWD_BRANCH_OFFSET = (((1 << 24) - 2) + 4);
static const int32_t THM2_MAX_BWD_BRANCH_OFFSET = (-(1 << 24) + 4);
-public:
+ public:
ARMGNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo);
~ARMGNULDBackend();
-public:
+ public:
typedef std::vector<llvm::ELF::Elf32_Dyn*> ELF32DynList;
-public:
+ public:
/// initTargetSections - initialize target dependent sections in output.
void initTargetSections(Module& pModule, ObjectBuilder& pBuilder);
@@ -72,7 +70,6 @@ public:
/// Use co-variant return type to return its own dynamic section.
const ARMELFDynamic& dynamic() const;
-
/// emitSectionData - write out the section data into the memory region.
/// When writers get a LDSection whose kind is LDFileFormat::Target, writers
/// call back target backend to emit the data.
@@ -106,7 +103,7 @@ public:
ARMELFAttributeData& getAttributeData();
const ARMELFAttributeData& getAttributeData() const;
- LDSymbol* getGOTSymbol() { return m_pGOTSymbol; }
+ LDSymbol* getGOTSymbol() { return m_pGOTSymbol; }
const LDSymbol* getGOTSymbol() const { return m_pGOTSymbol; }
/// getTargetSectionOrder - compute the layout order of ARM target sections
@@ -120,8 +117,9 @@ public:
/// setUpReachedSectionsForGC - set the reference from section XXX to
/// .ARM.exidx.XXX to make sure GC correctly handle section exidx
- void setUpReachedSectionsForGC(const Module& pModule,
- GarbageCollection::SectionReachedListMap& pSectReachedListMap) const;
+ void setUpReachedSectionsForGC(
+ const Module& pModule,
+ GarbageCollection::SectionReachedListMap& pSectReachedListMap) const;
/// readSection - read target dependent sections
bool readSection(Input& pInput, SectionData& pSD);
@@ -130,7 +128,7 @@ public:
/// function pointer access
bool mayHaveUnsafeFunctionPointerAccess(const LDSection& pSection) const;
-private:
+ private:
void defineGOTSymbol(IRBuilder& pBuilder);
/// maxFwdBranchOffset
@@ -151,18 +149,19 @@ private:
bool initTargetStubs();
/// getRelEntrySize - the size in BYTE of rel type relocation
- size_t getRelEntrySize()
- { return 8; }
+ size_t getRelEntrySize() { return 8; }
/// getRelEntrySize - the size in BYTE of rela type relocation
- size_t getRelaEntrySize()
- { assert(0 && "ARM backend with Rela type relocation\n"); return 12; }
+ size_t getRelaEntrySize() {
+ assert(0 && "ARM backend with Rela type relocation\n");
+ return 12;
+ }
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
virtual void doCreateProgramHdrs(Module& pModule);
-private:
+ private:
Relocator* m_pRelocator;
ARMGOT* m_pGOT;
@@ -181,14 +180,13 @@ private:
LDSymbol* m_pEXIDXEnd;
// variable name : ELF
- LDSection* m_pEXIDX; // .ARM.exidx
- LDSection* m_pEXTAB; // .ARM.extab
- LDSection* m_pAttributes; // .ARM.attributes
-// LDSection* m_pPreemptMap; // .ARM.preemptmap
-// LDSection* m_pDebugOverlay; // .ARM.debug_overlay
-// LDSection* m_pOverlayTable; // .ARM.overlay_table
+ LDSection* m_pEXIDX; // .ARM.exidx
+ LDSection* m_pEXTAB; // .ARM.extab
+ LDSection* m_pAttributes; // .ARM.attributes
+ // LDSection* m_pPreemptMap; // .ARM.preemptmap
+ // LDSection* m_pDebugOverlay; // .ARM.debug_overlay
+ // LDSection* m_pOverlayTable; // .ARM.overlay_table
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_ARM_ARMLDBACKEND_H_
diff --git a/lib/Target/ARM/ARMMCLinker.cpp b/lib/Target/ARM/ARMMCLinker.cpp
deleted file mode 100644
index dcee683..0000000
--- a/lib/Target/ARM/ARMMCLinker.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-//===- ARMMCLinker.cpp ----------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "ARMELFMCLinker.h"
-
-#include "ARM.h"
-#include <llvm/ADT/Triple.h>
-#include <mcld/Module.h>
-#include <mcld/Support/TargetRegistry.h>
-
-using namespace mcld;
-
-namespace mcld {
-//===----------------------------------------------------------------------===//
-// createARMMCLinker - the help function to create corresponding ARMMCLinker
-//===----------------------------------------------------------------------===//
-MCLinker* createARMMCLinker(const std::string& pTriple,
- LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
-{
- llvm::Triple theTriple(pTriple);
- if (theTriple.isOSDarwin()) {
- assert(0 && "MachO linker has not supported yet");
- return NULL;
- }
- if (theTriple.isOSWindows()) {
- assert(0 && "COFF linker has not supported yet");
- return NULL;
- }
-
- return new ARMELFMCLinker(pConfig, pModule, pFileHandle);
-}
-
-} // namespace of mcld
-
-//===----------------------------------------------------------------------===//
-// ARMMCLinker
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeARMMCLinker() {
- // Register the linker frontend
- mcld::TargetRegistry::RegisterMCLinker(TheARMTarget, createARMMCLinker);
- mcld::TargetRegistry::RegisterMCLinker(TheThumbTarget, createARMMCLinker);
-}
-
diff --git a/lib/Target/ARM/ARMPLT.cpp b/lib/Target/ARM/ARMPLT.cpp
index 9ca2af1..b1b87e2 100644
--- a/lib/Target/ARM/ARMPLT.cpp
+++ b/lib/Target/ARM/ARMPLT.cpp
@@ -1,4 +1,4 @@
-//===- ARMPLT.cpp -----------------------------------------------------------===//
+//===- ARMPLT.cpp ---------------------------------------------------------===//
//
// The MCLinker Project
//
@@ -9,42 +9,39 @@
#include "ARMGOT.h"
#include "ARMPLT.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <new>
#include <llvm/Support/Casting.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Support/MsgHandling.h>
-
-using namespace mcld;
+namespace mcld {
-ARMPLT0::ARMPLT0(SectionData& pParent)
- : PLT::Entry<sizeof(arm_plt0)>(pParent) {}
+ARMPLT0::ARMPLT0(SectionData& pParent) : PLT::Entry<sizeof(arm_plt0)>(pParent) {
+}
-ARMPLT1::ARMPLT1(SectionData& pParent)
- : PLT::Entry<sizeof(arm_plt1)>(pParent) {}
+ARMPLT1::ARMPLT1(SectionData& pParent) : PLT::Entry<sizeof(arm_plt1)>(pParent) {
+}
//===----------------------------------------------------------------------===//
// ARMPLT
-ARMPLT::ARMPLT(LDSection& pSection, ARMGOT &pGOTPLT)
- : PLT(pSection), m_GOT(pGOTPLT) {
+ARMPLT::ARMPLT(LDSection& pSection, ARMGOT& pGOTPLT)
+ : PLT(pSection), m_GOT(pGOTPLT) {
new ARMPLT0(*m_pSectionData);
}
-ARMPLT::~ARMPLT()
-{
+ARMPLT::~ARMPLT() {
}
-bool ARMPLT::hasPLT1() const
-{
+bool ARMPLT::hasPLT1() const {
return (m_pSectionData->size() > 1);
}
-void ARMPLT::finalizeSectionSize()
-{
- uint64_t size = (m_pSectionData->size() - 1) * sizeof(arm_plt1) +
- sizeof(arm_plt0);
+void ARMPLT::finalizeSectionSize() {
+ uint64_t size =
+ (m_pSectionData->size() - 1) * sizeof(arm_plt1) + sizeof(arm_plt0);
m_Section.setSize(size);
uint32_t offset = 0;
@@ -55,16 +52,14 @@ void ARMPLT::finalizeSectionSize()
}
}
-ARMPLT1* ARMPLT::create()
-{
+ARMPLT1* ARMPLT::create() {
ARMPLT1* plt1_entry = new (std::nothrow) ARMPLT1(*m_pSectionData);
if (!plt1_entry)
fatal(diag::fail_allocate_memory_plt);
return plt1_entry;
}
-void ARMPLT::applyPLT0()
-{
+void ARMPLT::applyPLT0() {
uint64_t plt_base = m_Section.addr();
assert(plt_base && ".plt base address is NULL!");
@@ -97,8 +92,7 @@ void ARMPLT::applyPLT0()
plt0->setValue(reinterpret_cast<unsigned char*>(data));
}
-void ARMPLT::applyPLT1()
-{
+void ARMPLT::applyPLT1() {
uint64_t plt_base = m_Section.addr();
assert(plt_base && ".plt base address is NULL!");
@@ -110,13 +104,11 @@ void ARMPLT::applyPLT1()
assert(it != ie && "FragmentList is empty, applyPLT1 failed!");
uint32_t GOTEntrySize = ARMGOTEntry::EntrySize;
- uint32_t GOTEntryAddress =
- got_base + GOTEntrySize * 3;
+ uint32_t GOTEntryAddress = got_base + GOTEntrySize * 3;
- uint64_t PLTEntryAddress =
- plt_base + ARMPLT0::EntrySize; //Offset of PLT0
+ uint64_t PLTEntryAddress = plt_base + ARMPLT0::EntrySize; // Offset of PLT0
- ++it; //skip PLT0
+ ++it; // skip PLT0
uint64_t PLT1EntrySize = ARMPLT1::EntrySize;
ARMPLT1* plt1 = NULL;
@@ -146,8 +138,7 @@ void ARMPLT::applyPLT1()
m_GOT.applyGOTPLT(plt_base);
}
-uint64_t ARMPLT::emit(MemoryRegion& pRegion)
-{
+uint64_t ARMPLT::emit(MemoryRegion& pRegion) {
uint64_t result = 0x0;
iterator it = begin();
@@ -167,3 +158,4 @@ uint64_t ARMPLT::emit(MemoryRegion& pRegion)
return result;
}
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMPLT.h b/lib/Target/ARM/ARMPLT.h
index bacda93..2d5883c 100644
--- a/lib/Target/ARM/ARMPLT.h
+++ b/lib/Target/ARM/ARMPLT.h
@@ -6,53 +6,46 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMPLT_H
-#define TARGET_ARM_ARMPLT_H
+#ifndef TARGET_ARM_ARMPLT_H_
+#define TARGET_ARM_ARMPLT_H_
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/PLT.h>
-#include <mcld/Support/MemoryRegion.h>
-
-namespace {
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/PLT.h"
+#include "mcld/Support/MemoryRegion.h"
const uint32_t arm_plt0[] = {
- 0xe52de004, // str lr, [sp, #-4]!
- 0xe59fe004, // ldr lr, [pc, #4]
- 0xe08fe00e, // add lr, pc, lr
- 0xe5bef008, // ldr pc, [lr, #8]!
- 0x00000000 // &GOT[0] - .
+ 0xe52de004, // str lr, [sp, #-4]!
+ 0xe59fe004, // ldr lr, [pc, #4]
+ 0xe08fe00e, // add lr, pc, lr
+ 0xe5bef008, // ldr pc, [lr, #8]!
+ 0x00000000 // &GOT[0] - .
};
const uint32_t arm_plt1[] = {
- 0xe28fc600, // add ip, pc, #0xNN00000
- 0xe28cca00, // add ip, ip, #0xNN000
- 0xe5bcf000 // ldr pc, [ip, #0xNNN]!
+ 0xe28fc600, // add ip, pc, #0xNN00000
+ 0xe28cca00, // add ip, ip, #0xNN000
+ 0xe5bcf000 // ldr pc, [ip, #0xNNN]!
};
-} // anonymous namespace
-
namespace mcld {
class ARMGOT;
-class ARMPLT0 : public PLT::Entry<sizeof(arm_plt0)>
-{
-public:
+class ARMPLT0 : public PLT::Entry<sizeof(arm_plt0)> {
+ public:
ARMPLT0(SectionData& pParent);
};
-class ARMPLT1 : public PLT::Entry<sizeof(arm_plt1)>
-{
-public:
+class ARMPLT1 : public PLT::Entry<sizeof(arm_plt1)> {
+ public:
ARMPLT1(SectionData& pParent);
};
/** \class ARMPLT
* \brief ARM Procedure Linkage Table
*/
-class ARMPLT : public PLT
-{
-public:
+class ARMPLT : public PLT {
+ public:
ARMPLT(LDSection& pSection, ARMGOT& pGOTPLT);
~ARMPLT();
@@ -72,11 +65,10 @@ public:
uint64_t emit(MemoryRegion& pRegion);
-private:
+ private:
ARMGOT& m_GOT;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_ARM_ARMPLT_H_
diff --git a/lib/Target/ARM/ARMRelocationFunctions.h b/lib/Target/ARM/ARMRelocationFunctions.h
index 58f00ce..141d8a7 100644
--- a/lib/Target/ARM/ARMRelocationFunctions.h
+++ b/lib/Target/ARM/ARMRelocationFunctions.h
@@ -6,167 +6,169 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_ARM_ARMRELOCATIONFUNCTIONS_H_
+#define TARGET_ARM_ARMRELOCATIONFUNCTIONS_H_
#define DECL_ARM_APPLY_RELOC_FUNC(Name) \
-static ARMRelocator::Result Name (Relocation& pEntry, \
- ARMRelocator& pParent);
+ static ARMRelocator::Result Name(Relocation& pEntry, ARMRelocator& pParent);
-#define DECL_ARM_APPLY_RELOC_FUNCS \
-DECL_ARM_APPLY_RELOC_FUNC(none) \
-DECL_ARM_APPLY_RELOC_FUNC(abs32) \
-DECL_ARM_APPLY_RELOC_FUNC(rel32) \
-DECL_ARM_APPLY_RELOC_FUNC(gotoff32) \
-DECL_ARM_APPLY_RELOC_FUNC(base_prel) \
-DECL_ARM_APPLY_RELOC_FUNC(got_brel) \
-DECL_ARM_APPLY_RELOC_FUNC(call) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_call) \
-DECL_ARM_APPLY_RELOC_FUNC(movw_prel_nc) \
-DECL_ARM_APPLY_RELOC_FUNC(movw_abs_nc) \
-DECL_ARM_APPLY_RELOC_FUNC(movt_abs) \
-DECL_ARM_APPLY_RELOC_FUNC(movt_prel) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_movw_abs_nc) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_movw_prel_nc) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_movw_brel) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_movt_abs) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_movt_prel) \
-DECL_ARM_APPLY_RELOC_FUNC(prel31) \
-DECL_ARM_APPLY_RELOC_FUNC(got_prel) \
-DECL_ARM_APPLY_RELOC_FUNC(tls) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_jump8) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_jump11) \
-DECL_ARM_APPLY_RELOC_FUNC(thm_jump19) \
-DECL_ARM_APPLY_RELOC_FUNC(unsupport)
+#define DECL_ARM_APPLY_RELOC_FUNCS \
+ DECL_ARM_APPLY_RELOC_FUNC(none) \
+ DECL_ARM_APPLY_RELOC_FUNC(abs32) \
+ DECL_ARM_APPLY_RELOC_FUNC(rel32) \
+ DECL_ARM_APPLY_RELOC_FUNC(gotoff32) \
+ DECL_ARM_APPLY_RELOC_FUNC(base_prel) \
+ DECL_ARM_APPLY_RELOC_FUNC(got_brel) \
+ DECL_ARM_APPLY_RELOC_FUNC(call) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_call) \
+ DECL_ARM_APPLY_RELOC_FUNC(movw_prel_nc) \
+ DECL_ARM_APPLY_RELOC_FUNC(movw_abs_nc) \
+ DECL_ARM_APPLY_RELOC_FUNC(movt_abs) \
+ DECL_ARM_APPLY_RELOC_FUNC(movt_prel) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_movw_abs_nc) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_movw_prel_nc) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_movw_brel) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_movt_abs) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_movt_prel) \
+ DECL_ARM_APPLY_RELOC_FUNC(prel31) \
+ DECL_ARM_APPLY_RELOC_FUNC(got_prel) \
+ DECL_ARM_APPLY_RELOC_FUNC(tls) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_jump8) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_jump11) \
+ DECL_ARM_APPLY_RELOC_FUNC(thm_jump19) \
+ DECL_ARM_APPLY_RELOC_FUNC(unsupported)
+#define DECL_ARM_APPLY_RELOC_FUNC_PTRS \
+ { &none, 0, "R_ARM_NONE" }, \
+ { &call, 1, "R_ARM_PC24" }, \
+ { &abs32, 2, "R_ARM_ABS32" }, \
+ { &rel32, 3, "R_ARM_REL32" }, \
+ { &unsupported, 4, "R_ARM_LDR_PC_G0" }, \
+ { &unsupported, 5, "R_ARM_ABS16" }, \
+ { &unsupported, 6, "R_ARM_ABS12" }, \
+ { &unsupported, 7, "R_ARM_THM_ABS5" }, \
+ { &unsupported, 8, "R_ARM_ABS8" }, \
+ { &unsupported, 9, "R_ARM_SBREL32" }, \
+ { &thm_call, 10, "R_ARM_THM_CALL" }, \
+ { &unsupported, 11, "R_ARM_THM_PC8" }, \
+ { &unsupported, 12, "R_ARM_BREL_ADJ" }, \
+ { &unsupported, 13, "R_ARM_TLS_DESC" }, \
+ { &unsupported, 14, "R_ARM_THM_SWI8" }, \
+ { &unsupported, 15, "R_ARM_XPC25" }, \
+ { &unsupported, 16, "R_ARM_THM_XPC22" }, \
+ { &unsupported, 17, "R_ARM_TLS_DTPMOD32" }, \
+ { &unsupported, 18, "R_ARM_TLS_DTPOFF32" }, \
+ { &unsupported, 19, "R_ARM_TLS_TPOFF32" }, \
+ { &unsupported, 20, "R_ARM_COPY" }, \
+ { &unsupported, 21, "R_ARM_GLOB_DAT" }, \
+ { &unsupported, 22, "R_ARM_JUMP_SLOT" }, \
+ { &unsupported, 23, "R_ARM_RELATIVE" }, \
+ { &gotoff32, 24, "R_ARM_GOTOFF32" }, \
+ { &base_prel, 25, "R_ARM_BASE_PREL" }, \
+ { &got_brel, 26, "R_ARM_GOT_BREL" }, \
+ { &call, 27, "R_ARM_PLT32" }, \
+ { &call, 28, "R_ARM_CALL" }, \
+ { &call, 29, "R_ARM_JUMP24" }, \
+ { &thm_call, 30, "R_ARM_THM_JUMP24" }, \
+ { &unsupported, 31, "R_ARM_BASE_ABS" }, \
+ { &unsupported, 32, "R_ARM_ALU_PCREL_7_0" }, \
+ { &unsupported, 33, "R_ARM_ALU_PCREL_15_8" }, \
+ { &unsupported, 34, "R_ARM_ALU_PCREL_23_15" }, \
+ { &unsupported, 35, "R_ARM_LDR_SBREL_11_0_NC" }, \
+ { &unsupported, 36, "R_ARM_ALU_SBREL_19_12_NC" }, \
+ { &unsupported, 37, "R_ARM_ALU_SBREL_27_20_CK" }, \
+ { &abs32, 38, "R_ARM_TARGET1" }, \
+ { &unsupported, 39, "R_ARM_SBREL31" }, \
+ { &none, 40, "R_ARM_V4BX" }, \
+ { &got_prel, 41, "R_ARM_TARGET2" }, \
+ { &prel31, 42, "R_ARM_PREL31" }, \
+ { &movw_abs_nc, 43, "R_ARM_MOVW_ABS_NC" }, \
+ { &movt_abs, 44, "R_ARM_MOVT_ABS" }, \
+ { &movw_prel_nc, 45, "R_ARM_MOVW_PREL_NC" }, \
+ { &movt_prel, 46, "R_ARM_MOVT_PREL" }, \
+ { &thm_movw_abs_nc, 47, "R_ARM_THM_MOVW_ABS_NC" }, \
+ { &thm_movt_abs, 48, "R_ARM_THM_MOVT_ABS" }, \
+ { &thm_movw_prel_nc, 49, "R_ARM_THM_MOVW_PREL_NC" }, \
+ { &thm_movt_prel, 50, "R_ARM_THM_MOVT_PREL" }, \
+ { &thm_jump19, 51, "R_ARM_THM_JUMP19" }, \
+ { &unsupported, 52, "R_ARM_THM_JUMP6" }, \
+ { &unsupported, 53, "R_ARM_THM_ALU_PREL_11_0" }, \
+ { &unsupported, 54, "R_ARM_THM_PC12" }, \
+ { &unsupported, 55, "R_ARM_ABS32_NOI" }, \
+ { &unsupported, 56, "R_ARM_REL32_NOI" }, \
+ { &unsupported, 57, "R_ARM_ALU_PC_G0_NC" }, \
+ { &unsupported, 58, "R_ARM_ALU_PC_G0" }, \
+ { &unsupported, 59, "R_ARM_ALU_PC_G1_NC" }, \
+ { &unsupported, 60, "R_ARM_ALU_PC_G1" }, \
+ { &unsupported, 61, "R_ARM_ALU_PC_G2" }, \
+ { &unsupported, 62, "R_ARM_LDR_PC_G1" }, \
+ { &unsupported, 63, "R_ARM_LDR_PC_G2" }, \
+ { &unsupported, 64, "R_ARM_LDRS_PC_G0" }, \
+ { &unsupported, 65, "R_ARM_LDRS_PC_G1" }, \
+ { &unsupported, 66, "R_ARM_LDRS_PC_G2" }, \
+ { &unsupported, 67, "R_ARM_LDC_PC_G0" }, \
+ { &unsupported, 68, "R_ARM_LDC_PC_G1" }, \
+ { &unsupported, 69, "R_ARM_LDC_PC_G2" }, \
+ { &unsupported, 70, "R_ARM_ALU_SB_G0_NC" }, \
+ { &unsupported, 71, "R_ARM_ALU_SB_G0" }, \
+ { &unsupported, 72, "R_ARM_ALU_SB_G1_NC" }, \
+ { &unsupported, 73, "R_ARM_ALU_SB_G1" }, \
+ { &unsupported, 74, "R_ARM_ALU_SB_G2" }, \
+ { &unsupported, 75, "R_ARM_LDR_SB_G0" }, \
+ { &unsupported, 76, "R_ARM_LDR_SB_G1" }, \
+ { &unsupported, 77, "R_ARM_LDR_SB_G2" }, \
+ { &unsupported, 78, "R_ARM_LDRS_SB_G0" }, \
+ { &unsupported, 79, "R_ARM_LDRS_SB_G1" }, \
+ { &unsupported, 80, "R_ARM_LDRS_SB_G2" }, \
+ { &unsupported, 81, "R_ARM_LDC_SB_G0" }, \
+ { &unsupported, 82, "R_ARM_LDC_SB_G1" }, \
+ { &unsupported, 83, "R_ARM_LDC_SB_G2" }, \
+ { &unsupported, 84, "R_ARM_MOVW_BREL_NC" }, \
+ { &unsupported, 85, "R_ARM_MOVT_BREL" }, \
+ { &unsupported, 86, "R_ARM_MOVW_BREL" }, \
+ { &thm_movw_brel, 87, "R_ARM_THM_MOVW_BREL_NC" }, \
+ { &thm_movt_prel, 88, "R_ARM_THM_MOVT_BREL" }, \
+ { &thm_movw_brel, 89, "R_ARM_THM_MOVW_BREL" }, \
+ { &unsupported, 90, "R_ARM_TLS_GOTDESC" }, \
+ { &unsupported, 91, "R_ARM_TLS_CALL" }, \
+ { &unsupported, 92, "R_ARM_TLS_DESCSEQ" }, \
+ { &unsupported, 93, "R_ARM_THM_TLS_CALL" }, \
+ { &unsupported, 94, "R_ARM_PLT32_ABS" }, \
+ { &unsupported, 95, "R_ARM_GOT_ABS" }, \
+ { &got_prel, 96, "R_ARM_GOT_PREL" }, \
+ { &unsupported, 97, "R_ARM_GOT_PREL12" }, \
+ { &unsupported, 98, "R_ARM_GOTOFF12" }, \
+ { &unsupported, 99, "R_ARM_GOTRELAX" }, \
+ { &unsupported, 100, "R_ARM_GNU_VTENTRY" }, \
+ { &unsupported, 101, "R_ARM_GNU_VTINERIT" }, \
+ { &thm_jump11, 102, "R_ARM_THM_JUMP11" }, \
+ { &thm_jump8, 103, "R_ARM_THM_JUMP8" }, \
+ { &tls, 104, "R_ARM_TLS_GD32" }, \
+ { &unsupported, 105, "R_ARM_TLS_LDM32" }, \
+ { &unsupported, 106, "R_ARM_TLS_LDO32" }, \
+ { &tls, 107, "R_ARM_TLS_IE32" }, \
+ { &tls, 108, "R_ARM_TLS_LE32" }, \
+ { &unsupported, 109, "R_ARM_TLS_LDO12" }, \
+ { &unsupported, 110, "R_ARM_TLS_LE12" }, \
+ { &unsupported, 111, "R_ARM_TLS_IE12GP" }, \
+ { &unsupported, 112, "R_ARM_PRIVATE_0" }, \
+ { &unsupported, 113, "R_ARM_PRIVATE_1" }, \
+ { &unsupported, 114, "R_ARM_PRIVATE_2" }, \
+ { &unsupported, 115, "R_ARM_PRIVATE_3" }, \
+ { &unsupported, 116, "R_ARM_PRIVATE_4" }, \
+ { &unsupported, 117, "R_ARM_PRIVATE_5" }, \
+ { &unsupported, 118, "R_ARM_PRIVATE_6" }, \
+ { &unsupported, 119, "R_ARM_PRIVATE_7" }, \
+ { &unsupported, 120, "R_ARM_PRIVATE_8" }, \
+ { &unsupported, 121, "R_ARM_PRIVATE_9" }, \
+ { &unsupported, 122, "R_ARM_PRIVATE_10" }, \
+ { &unsupported, 123, "R_ARM_PRIVATE_11" }, \
+ { &unsupported, 124, "R_ARM_PRIVATE_12" }, \
+ { &unsupported, 125, "R_ARM_PRIVATE_13" }, \
+ { &unsupported, 126, "R_ARM_PRIVATE_14" }, \
+ { &unsupported, 127, "R_ARM_PRIVATE_15" }, \
+ { &unsupported, 128, "R_ARM_ME_TOO" }, \
+ { &unsupported, 129, "R_ARM_THM_TLS_DESCSEQ16" }, \
+ { &unsupported, 130, "R_ARM_THM_TLS_DESCSEQ32" }
-#define DECL_ARM_APPLY_RELOC_FUNC_PTRS \
- { &none, 0, "R_ARM_NONE" }, \
- { &call, 1, "R_ARM_PC24" }, \
- { &abs32, 2, "R_ARM_ABS32" }, \
- { &rel32, 3, "R_ARM_REL32" }, \
- { &unsupport, 4, "R_ARM_LDR_PC_G0" }, \
- { &unsupport, 5, "R_ARM_ABS16" }, \
- { &unsupport, 6, "R_ARM_ABS12" }, \
- { &unsupport, 7, "R_ARM_THM_ABS5" }, \
- { &unsupport, 8, "R_ARM_ABS8" }, \
- { &unsupport, 9, "R_ARM_SBREL32" }, \
- { &thm_call, 10, "R_ARM_THM_CALL" }, \
- { &unsupport, 11, "R_ARM_THM_PC8" }, \
- { &unsupport, 12, "R_ARM_BREL_ADJ" }, \
- { &unsupport, 13, "R_ARM_TLS_DESC" }, \
- { &unsupport, 14, "R_ARM_THM_SWI8" }, \
- { &unsupport, 15, "R_ARM_XPC25" }, \
- { &unsupport, 16, "R_ARM_THM_XPC22" }, \
- { &unsupport, 17, "R_ARM_TLS_DTPMOD32" }, \
- { &unsupport, 18, "R_ARM_TLS_DTPOFF32" }, \
- { &unsupport, 19, "R_ARM_TLS_TPOFF32" }, \
- { &unsupport, 20, "R_ARM_COPY" }, \
- { &unsupport, 21, "R_ARM_GLOB_DAT" }, \
- { &unsupport, 22, "R_ARM_JUMP_SLOT" }, \
- { &unsupport, 23, "R_ARM_RELATIVE" }, \
- { &gotoff32, 24, "R_ARM_GOTOFF32" }, \
- { &base_prel, 25, "R_ARM_BASE_PREL" }, \
- { &got_brel, 26, "R_ARM_GOT_BREL" }, \
- { &call, 27, "R_ARM_PLT32" }, \
- { &call, 28, "R_ARM_CALL" }, \
- { &call, 29, "R_ARM_JUMP24" }, \
- { &thm_call, 30, "R_ARM_THM_JUMP24" }, \
- { &unsupport, 31, "R_ARM_BASE_ABS" }, \
- { &unsupport, 32, "R_ARM_ALU_PCREL_7_0" }, \
- { &unsupport, 33, "R_ARM_ALU_PCREL_15_8" }, \
- { &unsupport, 34, "R_ARM_ALU_PCREL_23_15" }, \
- { &unsupport, 35, "R_ARM_LDR_SBREL_11_0_NC" }, \
- { &unsupport, 36, "R_ARM_ALU_SBREL_19_12_NC"}, \
- { &unsupport, 37, "R_ARM_ALU_SBREL_27_20_CK"}, \
- { &abs32, 38, "R_ARM_TARGET1" }, \
- { &unsupport, 39, "R_ARM_SBREL31" }, \
- { &none, 40, "R_ARM_V4BX" }, \
- { &got_prel, 41, "R_ARM_TARGET2" }, \
- { &prel31, 42, "R_ARM_PREL31" }, \
- { &movw_abs_nc, 43, "R_ARM_MOVW_ABS_NC" }, \
- { &movt_abs, 44, "R_ARM_MOVT_ABS" }, \
- { &movw_prel_nc, 45, "R_ARM_MOVW_PREL_NC" }, \
- { &movt_prel, 46, "R_ARM_MOVT_PREL" }, \
- { &thm_movw_abs_nc, 47, "R_ARM_THM_MOVW_ABS_NC" }, \
- { &thm_movt_abs, 48, "R_ARM_THM_MOVT_ABS" }, \
- { &thm_movw_prel_nc, 49, "R_ARM_THM_MOVW_PREL_NC" }, \
- { &thm_movt_prel, 50, "R_ARM_THM_MOVT_PREL" }, \
- { &thm_jump19, 51, "R_ARM_THM_JUMP19" }, \
- { &unsupport, 52, "R_ARM_THM_JUMP6" }, \
- { &unsupport, 53, "R_ARM_THM_ALU_PREL_11_0" }, \
- { &unsupport, 54, "R_ARM_THM_PC12" }, \
- { &unsupport, 55, "R_ARM_ABS32_NOI" }, \
- { &unsupport, 56, "R_ARM_REL32_NOI" }, \
- { &unsupport, 57, "R_ARM_ALU_PC_G0_NC" }, \
- { &unsupport, 58, "R_ARM_ALU_PC_G0" }, \
- { &unsupport, 59, "R_ARM_ALU_PC_G1_NC" }, \
- { &unsupport, 60, "R_ARM_ALU_PC_G1" }, \
- { &unsupport, 61, "R_ARM_ALU_PC_G2" }, \
- { &unsupport, 62, "R_ARM_LDR_PC_G1" }, \
- { &unsupport, 63, "R_ARM_LDR_PC_G2" }, \
- { &unsupport, 64, "R_ARM_LDRS_PC_G0" }, \
- { &unsupport, 65, "R_ARM_LDRS_PC_G1" }, \
- { &unsupport, 66, "R_ARM_LDRS_PC_G2" }, \
- { &unsupport, 67, "R_ARM_LDC_PC_G0" }, \
- { &unsupport, 68, "R_ARM_LDC_PC_G1" }, \
- { &unsupport, 69, "R_ARM_LDC_PC_G2" }, \
- { &unsupport, 70, "R_ARM_ALU_SB_G0_NC" }, \
- { &unsupport, 71, "R_ARM_ALU_SB_G0" }, \
- { &unsupport, 72, "R_ARM_ALU_SB_G1_NC" }, \
- { &unsupport, 73, "R_ARM_ALU_SB_G1" }, \
- { &unsupport, 74, "R_ARM_ALU_SB_G2" }, \
- { &unsupport, 75, "R_ARM_LDR_SB_G0" }, \
- { &unsupport, 76, "R_ARM_LDR_SB_G1" }, \
- { &unsupport, 77, "R_ARM_LDR_SB_G2" }, \
- { &unsupport, 78, "R_ARM_LDRS_SB_G0" }, \
- { &unsupport, 79, "R_ARM_LDRS_SB_G1" }, \
- { &unsupport, 80, "R_ARM_LDRS_SB_G2" }, \
- { &unsupport, 81, "R_ARM_LDC_SB_G0" }, \
- { &unsupport, 82, "R_ARM_LDC_SB_G1" }, \
- { &unsupport, 83, "R_ARM_LDC_SB_G2" }, \
- { &unsupport, 84, "R_ARM_MOVW_BREL_NC" }, \
- { &unsupport, 85, "R_ARM_MOVT_BREL" }, \
- { &unsupport, 86, "R_ARM_MOVW_BREL" }, \
- { &thm_movw_brel, 87, "R_ARM_THM_MOVW_BREL_NC" }, \
- { &thm_movt_prel, 88, "R_ARM_THM_MOVT_BREL" }, \
- { &thm_movw_brel, 89, "R_ARM_THM_MOVW_BREL" }, \
- { &unsupport, 90, "R_ARM_TLS_GOTDESC" }, \
- { &unsupport, 91, "R_ARM_TLS_CALL" }, \
- { &unsupport, 92, "R_ARM_TLS_DESCSEQ" }, \
- { &unsupport, 93, "R_ARM_THM_TLS_CALL" }, \
- { &unsupport, 94, "R_ARM_PLT32_ABS" }, \
- { &unsupport, 95, "R_ARM_GOT_ABS" }, \
- { &got_prel, 96, "R_ARM_GOT_PREL" }, \
- { &unsupport, 97, "R_ARM_GOT_PREL12" }, \
- { &unsupport, 98, "R_ARM_GOTOFF12" }, \
- { &unsupport, 99, "R_ARM_GOTRELAX" }, \
- { &unsupport, 100, "R_ARM_GNU_VTENTRY" }, \
- { &unsupport, 101, "R_ARM_GNU_VTINERIT" }, \
- { &thm_jump11, 102, "R_ARM_THM_JUMP11" }, \
- { &thm_jump8, 103, "R_ARM_THM_JUMP8" }, \
- { &tls, 104, "R_ARM_TLS_GD32" }, \
- { &unsupport, 105, "R_ARM_TLS_LDM32" }, \
- { &unsupport, 106, "R_ARM_TLS_LDO32" }, \
- { &tls, 107, "R_ARM_TLS_IE32" }, \
- { &tls, 108, "R_ARM_TLS_LE32" }, \
- { &unsupport, 109, "R_ARM_TLS_LDO12" }, \
- { &unsupport, 110, "R_ARM_TLS_LE12" }, \
- { &unsupport, 111, "R_ARM_TLS_IE12GP" }, \
- { &unsupport, 112, "R_ARM_PRIVATE_0" }, \
- { &unsupport, 113, "R_ARM_PRIVATE_1" }, \
- { &unsupport, 114, "R_ARM_PRIVATE_2" }, \
- { &unsupport, 115, "R_ARM_PRIVATE_3" }, \
- { &unsupport, 116, "R_ARM_PRIVATE_4" }, \
- { &unsupport, 117, "R_ARM_PRIVATE_5" }, \
- { &unsupport, 118, "R_ARM_PRIVATE_6" }, \
- { &unsupport, 119, "R_ARM_PRIVATE_7" }, \
- { &unsupport, 120, "R_ARM_PRIVATE_8" }, \
- { &unsupport, 121, "R_ARM_PRIVATE_9" }, \
- { &unsupport, 122, "R_ARM_PRIVATE_10" }, \
- { &unsupport, 123, "R_ARM_PRIVATE_11" }, \
- { &unsupport, 124, "R_ARM_PRIVATE_12" }, \
- { &unsupport, 125, "R_ARM_PRIVATE_13" }, \
- { &unsupport, 126, "R_ARM_PRIVATE_14" }, \
- { &unsupport, 127, "R_ARM_PRIVATE_15" }, \
- { &unsupport, 128, "R_ARM_ME_TOO" }, \
- { &unsupport, 129, "R_ARM_THM_TLS_DESCSEQ16" }, \
- { &unsupport, 130, "R_ARM_THM_TLS_DESCSEQ32" }
+#endif // TARGET_ARM_ARMRELOCATIONFUNCTIONS_H_
diff --git a/lib/Target/ARM/ARMRelocator.cpp b/lib/Target/ARM/ARMRelocator.cpp
index 248c528..2605664 100644
--- a/lib/Target/ARM/ARMRelocator.cpp
+++ b/lib/Target/ARM/ARMRelocator.cpp
@@ -1,47 +1,46 @@
-//===- ARMRelocator.cpp ----------------------------------------===//
+//===- ARMRelocator.cpp --------------------------------------------------===//
//
// The MCLinker Project
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+#include "ARMRelocator.h"
+#include "ARMRelocationFunctions.h"
+
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MsgHandling.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
#include <llvm/ADT/Twine.h>
#include <llvm/Support/DataTypes.h>
#include <llvm/Support/ELF.h>
#include <llvm/Support/Host.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include "ARMRelocator.h"
-#include "ARMRelocationFunctions.h"
-using namespace mcld;
+namespace mcld {
//=========================================//
// Relocation helper function //
//=========================================//
-static Relocator::DWord getThumbBit(const Relocation& pReloc)
-{
+static Relocator::DWord getThumbBit(const Relocation& pReloc) {
// Set thumb bit if
// - symbol has type of STT_FUNC, is defined and with bit 0 of its value set
Relocator::DWord thumbBit =
- ((!pReloc.symInfo()->isUndef() || pReloc.symInfo()->isDyn()) &&
- (pReloc.symInfo()->type() == ResolveInfo::Function) &&
- ((pReloc.symValue() & 0x1) != 0))?
- 1:0;
+ ((!pReloc.symInfo()->isUndef() || pReloc.symInfo()->isDyn()) &&
+ (pReloc.symInfo()->type() == ResolveInfo::Function) &&
+ ((pReloc.symValue() & 0x1) != 0))
+ ? 1
+ : 0;
return thumbBit;
}
// Using uint64_t to make sure those complicate operations won't cause
// undefined behavior.
-static
-uint64_t helper_sign_extend(uint64_t pVal, uint64_t pOri_width)
-{
+static uint64_t helper_sign_extend(uint64_t pVal, uint64_t pOri_width) {
assert(pOri_width <= 64);
if (pOri_width == 64)
return pVal;
@@ -53,49 +52,39 @@ uint64_t helper_sign_extend(uint64_t pVal, uint64_t pOri_width)
return (pVal ^ sign_bit) - sign_bit;
}
-static
-uint64_t helper_bit_select(uint64_t pA, uint64_t pB, uint64_t pMask)
-{
- return (pA & ~pMask) | (pB & pMask) ;
+static uint64_t helper_bit_select(uint64_t pA, uint64_t pB, uint64_t pMask) {
+ return (pA & ~pMask) | (pB & pMask);
}
// Check if symbol can use relocation R_ARM_RELATIVE
-static bool
-helper_use_relative_reloc(const ResolveInfo& pSym,
- const ARMRelocator& pFactory)
-{
+static bool helper_use_relative_reloc(const ResolveInfo& pSym,
+ const ARMRelocator& pFactory) {
// if symbol is dynamic or undefine or preemptible
- if (pSym.isDyn() ||
- pSym.isUndef() ||
+ if (pSym.isDyn() || pSym.isUndef() ||
pFactory.getTarget().isSymbolPreemptible(pSym))
return false;
return true;
}
// Strip LSB (THUMB bit) if "S" is a THUMB target.
-static inline void helper_clear_thumb_bit(Relocator::DWord& pValue)
-{
+static inline void helper_clear_thumb_bit(Relocator::DWord& pValue) {
pValue &= (~0x1);
}
-static
-Relocator::Address helper_get_GOT_address(ResolveInfo& pSym,
- ARMRelocator& pParent)
-{
+static Relocator::Address helper_get_GOT_address(ResolveInfo& pSym,
+ ARMRelocator& pParent) {
ARMGOTEntry* got_entry = pParent.getSymGOTMap().lookUp(pSym);
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
return pParent.getTarget().getGOT().addr() + got_entry->getOffset();
}
-static
-ARMGOTEntry& helper_GOT_init(Relocation& pReloc,
- bool pHasRel,
- ARMRelocator& pParent)
-{
+static ARMGOTEntry& helper_GOT_init(Relocation& pReloc,
+ bool pHasRel,
+ ARMRelocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
ARMGNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymGOTMap().lookUp(*rsym));
+ assert(pParent.getSymGOTMap().lookUp(*rsym) == NULL);
ARMGOTEntry* got_entry = ld_backend.getGOT().createGOT();
pParent.getSymGOTMap().record(*rsym, *got_entry);
@@ -103,8 +92,7 @@ ARMGOTEntry& helper_GOT_init(Relocation& pReloc,
if (!pHasRel) {
// No corresponding dynamic relocation, initialize to the symbol value.
got_entry->setValue(ARMRelocator::SymVal);
- }
- else {
+ } else {
// Initialize corresponding dynamic relocation.
Relocation& rel_entry = *ld_backend.getRelDyn().create();
if (rsym->isLocal() || helper_use_relative_reloc(*rsym, pParent)) {
@@ -112,8 +100,7 @@ ARMGOTEntry& helper_GOT_init(Relocation& pReloc,
got_entry->setValue(ARMRelocator::SymVal);
rel_entry.setType(llvm::ELF::R_ARM_RELATIVE);
rel_entry.setSymInfo(NULL);
- }
- else {
+ } else {
// Initialize got entry to 0 for corresponding dynamic relocation.
got_entry->setValue(0);
rel_entry.setType(llvm::ELF::R_ARM_GLOB_DAT);
@@ -124,34 +111,28 @@ ARMGOTEntry& helper_GOT_init(Relocation& pReloc,
return *got_entry;
}
-static
-Relocator::Address helper_GOT_ORG(ARMRelocator& pParent)
-{
+static Relocator::Address helper_GOT_ORG(ARMRelocator& pParent) {
return pParent.getTarget().getGOT().addr();
}
-static
-Relocator::Address helper_get_PLT_address(ResolveInfo& pSym,
- ARMRelocator& pParent)
-{
+static Relocator::Address helper_get_PLT_address(ResolveInfo& pSym,
+ ARMRelocator& pParent) {
ARMPLT1* plt_entry = pParent.getSymPLTMap().lookUp(pSym);
- assert(NULL != plt_entry);
+ assert(plt_entry != NULL);
return pParent.getTarget().getPLT().addr() + plt_entry->getOffset();
}
-static
-ARMPLT1& helper_PLT_init(Relocation& pReloc, ARMRelocator& pParent)
-{
+static ARMPLT1& helper_PLT_init(Relocation& pReloc, ARMRelocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
ARMGNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymPLTMap().lookUp(*rsym));
+ assert(pParent.getSymPLTMap().lookUp(*rsym) == NULL);
// initialize the plt and the corresponding gotplt and dyn relocation
ARMPLT1* plt_entry = ld_backend.getPLT().create();
pParent.getSymPLTMap().record(*rsym, *plt_entry);
- assert(NULL == pParent.getSymGOTPLTMap().lookUp(*rsym) &&
+ assert(pParent.getSymGOTPLTMap().lookUp(*rsym) == NULL &&
"PLT entry not exist, but DynRel entry exist!");
ARMGOTEntry* gotplt_entry = ld_backend.getGOT().createGOTPLT();
pParent.getSymGOTPLTMap().record(*rsym, *gotplt_entry);
@@ -167,11 +148,9 @@ ARMPLT1& helper_PLT_init(Relocation& pReloc, ARMRelocator& pParent)
// Get an relocation entry in .rel.dyn and set its type to pType,
// its FragmentRef to pReloc->targetFrag() and its ResolveInfo to
// pReloc->symInfo()
-static
-void helper_DynRel_init(Relocation& pReloc,
- Relocator::Type pType,
- ARMRelocator& pParent)
-{
+static void helper_DynRel_init(Relocation& pReloc,
+ Relocator::Type pType,
+ ARMRelocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
ARMGNULDBackend& ld_backend = pParent.getTarget();
@@ -186,18 +165,16 @@ void helper_DynRel_init(Relocation& pReloc,
rel_entry.setSymInfo(rsym);
}
-static Relocator::DWord
-helper_extract_movw_movt_addend(Relocator::DWord pTarget)
-{
+static Relocator::DWord helper_extract_movw_movt_addend(
+ Relocator::DWord pTarget) {
// imm16: [19-16][11-0]
return helper_sign_extend((((pTarget >> 4)) & 0xf000U) | (pTarget & 0xfffU),
16);
}
-static Relocator::DWord
-helper_insert_val_movw_movt_inst(Relocator::DWord pTarget,
- Relocator::DWord pImm)
-{
+static Relocator::DWord helper_insert_val_movw_movt_inst(
+ Relocator::DWord pTarget,
+ Relocator::DWord pImm) {
// imm16: [19-16][11-0]
pTarget &= 0xfff0f000U;
pTarget |= pImm & 0x0fffU;
@@ -205,21 +182,18 @@ helper_insert_val_movw_movt_inst(Relocator::DWord pTarget,
return pTarget;
}
-static Relocator::DWord
-helper_extract_thumb_movw_movt_addend(Relocator::DWord pValue)
-{
+static Relocator::DWord helper_extract_thumb_movw_movt_addend(
+ Relocator::DWord pValue) {
// imm16: [19-16][26][14-12][7-0]
- return helper_sign_extend((((pValue >> 4) & 0xf000U) |
- ((pValue >> 15) & 0x0800U) |
- ((pValue >> 4) & 0x0700U) |
- (pValue& 0x00ffU)),
- 16);
+ return helper_sign_extend(
+ (((pValue >> 4) & 0xf000U) | ((pValue >> 15) & 0x0800U) |
+ ((pValue >> 4) & 0x0700U) | (pValue & 0x00ffU)),
+ 16);
}
-static Relocator::DWord
-helper_insert_val_thumb_movw_movt_inst(Relocator::DWord pValue,
- Relocator::DWord pImm)
-{
+static Relocator::DWord helper_insert_val_thumb_movw_movt_inst(
+ Relocator::DWord pValue,
+ Relocator::DWord pImm) {
// imm16: [19-16][26][14-12][7-0]
pValue &= 0xfbf08f00U;
pValue |= (pImm & 0xf000U) << 4;
@@ -229,48 +203,39 @@ helper_insert_val_thumb_movw_movt_inst(Relocator::DWord pValue,
return pValue;
}
-static Relocator::DWord
-helper_thumb32_branch_offset(Relocator::DWord pUpper16,
- Relocator::DWord pLower16)
-{
- Relocator::DWord s = (pUpper16 & (1U << 10)) >> 10, // 26 bit
- u = pUpper16 & 0x3ffU, // 25-16
- l = pLower16 & 0x7ffU, // 10-0
- j1 = (pLower16 & (1U << 13)) >> 13, // 13
- j2 = (pLower16 & (1U << 11)) >> 11; // 11
- Relocator::DWord i1 = j1 ^ s? 0: 1,
- i2 = j2 ^ s? 0: 1;
+static Relocator::DWord helper_thumb32_branch_offset(
+ Relocator::DWord pUpper16,
+ Relocator::DWord pLower16) {
+ Relocator::DWord s = (pUpper16 & (1U << 10)) >> 10, // 26 bit
+ u = pUpper16 & 0x3ffU, // 25-16
+ l = pLower16 & 0x7ffU, // 10-0
+ j1 = (pLower16 & (1U << 13)) >> 13, // 13
+ j2 = (pLower16 & (1U << 11)) >> 11; // 11
+
+ Relocator::DWord i1 = j1 ^ s ? 0 : 1, i2 = j2 ^ s ? 0 : 1;
// [31-25][24][23][22][21-12][11-1][0]
// 0 s i1 i2 u l 0
- return helper_sign_extend((s << 24) | (i1 << 23) | (i2 << 22) |
- (u << 12) | (l << 1),
- 25);
+ return helper_sign_extend(
+ (s << 24) | (i1 << 23) | (i2 << 22) | (u << 12) | (l << 1), 25);
}
-static Relocator::DWord
-helper_thumb32_branch_upper(Relocator::DWord pUpper16,
- Relocator::DWord pOffset)
-{
+static Relocator::DWord helper_thumb32_branch_upper(Relocator::DWord pUpper16,
+ Relocator::DWord pOffset) {
uint32_t sign = ((pOffset & 0x80000000U) >> 31);
return (pUpper16 & ~0x7ffU) | ((pOffset >> 12) & 0x3ffU) | (sign << 10);
}
-static Relocator::DWord
-helper_thumb32_branch_lower(Relocator::DWord pLower16,
- Relocator::DWord pOffset)
-{
+static Relocator::DWord helper_thumb32_branch_lower(Relocator::DWord pLower16,
+ Relocator::DWord pOffset) {
uint32_t sign = ((pOffset & 0x80000000U) >> 31);
- return ((pLower16 & ~0x2fffU) |
- ((((pOffset >> 23) & 1) ^ !sign) << 13) |
- ((((pOffset >> 22) & 1) ^ !sign) << 11) |
- ((pOffset >> 1) & 0x7ffU));
+ return ((pLower16 & ~0x2fffU) | ((((pOffset >> 23) & 1) ^ !sign) << 13) |
+ ((((pOffset >> 22) & 1) ^ !sign) << 11) | ((pOffset >> 1) & 0x7ffU));
}
-static Relocator::DWord
-helper_thumb32_cond_branch_offset(Relocator::DWord pUpper16,
- Relocator::DWord pLower16)
-{
+static Relocator::DWord helper_thumb32_cond_branch_offset(
+ Relocator::DWord pUpper16,
+ Relocator::DWord pLower16) {
uint32_t s = (pUpper16 & 0x0400U) >> 10;
uint32_t j1 = (pLower16 & 0x2000U) >> 13;
uint32_t j2 = (pLower16 & 0x0800U) >> 11;
@@ -279,18 +244,16 @@ helper_thumb32_cond_branch_offset(Relocator::DWord pUpper16,
return helper_sign_extend((upper << 12) | (lower << 1), 21);
}
-static Relocator::DWord
-helper_thumb32_cond_branch_upper(Relocator::DWord pUpper16,
- Relocator::DWord pOffset)
-{
+static Relocator::DWord helper_thumb32_cond_branch_upper(
+ Relocator::DWord pUpper16,
+ Relocator::DWord pOffset) {
uint32_t sign = ((pOffset & 0x80000000U) >> 31);
return (pUpper16 & 0xfbc0U) | (sign << 10) | ((pOffset & 0x0003f000U) >> 12);
}
-static Relocator::DWord
-helper_thumb32_cond_branch_lower(Relocator::DWord pLower16,
- Relocator::DWord pOffset)
-{
+static Relocator::DWord helper_thumb32_cond_branch_lower(
+ Relocator::DWord pLower16,
+ Relocator::DWord pOffset) {
uint32_t j2 = (pOffset & 0x00080000U) >> 19;
uint32_t j1 = (pOffset & 0x00040000U) >> 18;
uint32_t lo = (pOffset & 0x00000ffeU) >> 1;
@@ -298,10 +261,8 @@ helper_thumb32_cond_branch_lower(Relocator::DWord pLower16,
}
// Return true if overflow
-static bool
-helper_check_signed_overflow(Relocator::DWord pValue,
- unsigned bits)
-{
+static bool helper_check_signed_overflow(Relocator::DWord pValue,
+ unsigned bits) {
int32_t signed_val = static_cast<int32_t>(pValue);
int32_t max = (1 << (bits - 1)) - 1;
int32_t min = -(1 << (bits - 1));
@@ -312,10 +273,9 @@ helper_check_signed_overflow(Relocator::DWord pValue,
}
}
-
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
// Relocation Functions and Tables
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
DECL_ARM_APPLY_RELOC_FUNCS
/// the prototype of applying function
@@ -323,8 +283,7 @@ typedef Relocator::Result (*ApplyFunctionType)(Relocation& pReloc,
ARMRelocator& pParent);
// the table entry of applying functions
-struct ApplyFunctionTriple
-{
+struct ApplyFunctionTriple {
ApplyFunctionType func;
unsigned int type;
const char* name;
@@ -332,45 +291,37 @@ struct ApplyFunctionTriple
// declare the table of applying functions
static const ApplyFunctionTriple ApplyFunctions[] = {
- DECL_ARM_APPLY_RELOC_FUNC_PTRS
-};
+ DECL_ARM_APPLY_RELOC_FUNC_PTRS};
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
// ARMRelocator
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
ARMRelocator::ARMRelocator(ARMGNULDBackend& pParent,
const LinkerConfig& pConfig)
- : Relocator(pConfig),
- m_Target(pParent) {
+ : Relocator(pConfig), m_Target(pParent) {
}
-ARMRelocator::~ARMRelocator()
-{
+ARMRelocator::~ARMRelocator() {
}
-Relocator::Result
-ARMRelocator::applyRelocation(Relocation& pRelocation)
-{
+Relocator::Result ARMRelocator::applyRelocation(Relocation& pRelocation) {
Relocation::Type type = pRelocation.type();
- if (type > 130) { // 131-255 doesn't noted in ARM spec
+ if (type > 130) { // 131-255 doesn't noted in ARM spec
return Relocator::Unknown;
}
return ApplyFunctions[type].func(pRelocation, *this);
}
-const char* ARMRelocator::getName(Relocator::Type pType) const
-{
+const char* ARMRelocator::getName(Relocator::Type pType) const {
return ApplyFunctions[pType].name;
}
-Relocator::Size ARMRelocator::getSize(Relocation::Type pType) const
-{
+Relocator::Size ARMRelocator::getSize(Relocation::Type pType) const {
return 32;
}
-void ARMRelocator::addCopyReloc(ResolveInfo& pSym)
-{
+void ARMRelocator::addCopyReloc(ResolveInfo& pSym) {
Relocation& rel_entry = *getTarget().getRelDyn().create();
rel_entry.setType(llvm::ELF::R_ARM_COPY);
assert(pSym.outSymbol()->hasFragRef());
@@ -383,10 +334,8 @@ void ARMRelocator::addCopyReloc(ResolveInfo& pSym)
/// section and all other reference to this symbol should refer to this
/// copy.
/// This is executed at scan relocation stage.
-LDSymbol&
-ARMRelocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
- const ResolveInfo& pSym)
-{
+LDSymbol& ARMRelocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
+ const ResolveInfo& pSym) {
// get or create corresponding BSS LDSection
LDSection* bss_sect_hdr = NULL;
ELFFileFormat* file_format = getTarget().getOutputFormat();
@@ -408,9 +357,7 @@ ARMRelocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
// allocate space in BSS for the copy symbol
Fragment* frag = new FillFragment(0x0, 1, pSym.size());
- uint64_t size = ObjectBuilder::AppendFragment(*frag,
- *bss_data,
- addralign);
+ uint64_t size = ObjectBuilder::AppendFragment(*frag, *bss_data, addralign);
bss_sect_hdr->setSize(bss_sect_hdr->size() + size);
// change symbol binding to Global if it's a weak symbol
@@ -420,27 +367,25 @@ ARMRelocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
// Define the copy symbol in the bss section and resolve it
LDSymbol* cpy_sym = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- pSym.name(),
- (ResolveInfo::Type)pSym.type(),
- ResolveInfo::Define,
- binding,
- pSym.size(), // size
- 0x0, // value
- FragmentRef::Create(*frag, 0x0),
- (ResolveInfo::Visibility)pSym.other());
-
+ pSym.name(),
+ (ResolveInfo::Type)pSym.type(),
+ ResolveInfo::Define,
+ binding,
+ pSym.size(), // size
+ 0x0, // value
+ FragmentRef::Create(*frag, 0x0),
+ (ResolveInfo::Visibility)pSym.other());
return *cpy_sym;
}
/// checkValidReloc - When we attempt to generate a dynamic relocation for
/// ouput file, check if the relocation is supported by dynamic linker.
-void ARMRelocator::checkValidReloc(Relocation& pReloc) const
-{
+void ARMRelocator::checkValidReloc(Relocation& pReloc) const {
// If not PIC object, no relocation type is invalid
if (!config().isCodeIndep())
return;
- switch(pReloc.type()) {
+ switch (pReloc.type()) {
case llvm::ELF::R_ARM_RELATIVE:
case llvm::ELF::R_ARM_COPY:
case llvm::ELF::R_ARM_GLOB_DAT:
@@ -454,14 +399,14 @@ void ARMRelocator::checkValidReloc(Relocation& pReloc) const
break;
default:
- error(diag::non_pic_relocation) << (int)pReloc.type()
+ error(diag::non_pic_relocation) << getName(pReloc.type())
<< pReloc.symInfo()->name();
break;
}
}
-bool ARMRelocator::mayHaveFunctionPointerAccess(const Relocation& pReloc) const
-{
+bool ARMRelocator::mayHaveFunctionPointerAccess(
+ const Relocation& pReloc) const {
switch (pReloc.type()) {
case llvm::ELF::R_ARM_PC24:
case llvm::ELF::R_ARM_THM_CALL:
@@ -477,26 +422,21 @@ bool ARMRelocator::mayHaveFunctionPointerAccess(const Relocation& pReloc) const
case llvm::ELF::R_ARM_THM_JUMP8: {
return false;
}
- default: {
- return true;
- }
+ default: { return true; }
}
}
-void
-ARMRelocator::scanLocalReloc(Relocation& pReloc, const LDSection& pSection)
-{
+void ARMRelocator::scanLocalReloc(Relocation& pReloc,
+ const LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()){
-
+ switch (pReloc.type()) {
// Set R_ARM_TARGET1 to R_ARM_ABS32
- // Ref: GNU gold 1.11 arm.cc, line 9892
// FIXME: R_ARM_TARGET1 should be set by option --target1-rel
// or --target1-rel
case llvm::ELF::R_ARM_TARGET1:
- pReloc.setType(llvm::ELF::R_ARM_ABS32);
+ pReloc.setType(llvm::ELF::R_ARM_ABS32);
case llvm::ELF::R_ARM_ABS32:
case llvm::ELF::R_ARM_ABS32_NOI: {
// If buiding PIC object (shared library or PIC executable),
@@ -522,7 +462,7 @@ ARMRelocator::scanLocalReloc(Relocation& pReloc, const LDSection& pSection)
case llvm::ELF::R_ARM_THM_MOVT_ABS: {
// PIC code should not contain these kinds of relocation
if (config().isCodeIndep()) {
- error(diag::non_pic_relocation) << (int)pReloc.type()
+ error(diag::non_pic_relocation) << getName(pReloc.type())
<< pReloc.symInfo()->name();
}
return;
@@ -534,7 +474,6 @@ ARMRelocator::scanLocalReloc(Relocation& pReloc, const LDSection& pSection)
}
// Set R_ARM_TARGET2 to R_ARM_GOT_PREL
- // Ref: GNU gold 1.11 arm.cc, line 9892
// FIXME: R_ARM_TARGET2 should be set by option --target2
case llvm::ELF::R_ARM_TARGET2:
pReloc.setType(llvm::ELF::R_ARM_GOT_PREL);
@@ -548,9 +487,9 @@ ARMRelocator::scanLocalReloc(Relocation& pReloc, const LDSection& pSection)
// If building PIC object, a dynamic relocation with
// type RELATIVE is needed to relocate this GOT entry.
if (config().isCodeIndep())
- helper_GOT_init(pReloc, true, *this);
+ helper_GOT_init(pReloc, true, *this);
else
- helper_GOT_init(pReloc, false, *this);
+ helper_GOT_init(pReloc, false, *this);
// set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
return;
@@ -560,7 +499,8 @@ ARMRelocator::scanLocalReloc(Relocation& pReloc, const LDSection& pSection)
// FIXME: Currently we only support R_ARM_BASE_PREL against
// symbol _GLOBAL_OFFSET_TABLE_
if (rsym != getTarget().getGOTSymbol()->resolveInfo())
- fatal(diag::base_relocation) << (int)pReloc.type() << rsym->name()
+ fatal(diag::base_relocation) << static_cast<int>(pReloc.type())
+ << rsym->name()
<< "mclinker@googlegroups.com";
return;
}
@@ -570,26 +510,21 @@ ARMRelocator::scanLocalReloc(Relocation& pReloc, const LDSection& pSection)
case llvm::ELF::R_ARM_RELATIVE: {
// These are relocation type for dynamic linker, shold not
// appear in object file.
- fatal(diag::dynamic_relocation) << (int)pReloc.type();
- break;
- }
- default: {
+ fatal(diag::dynamic_relocation) << static_cast<int>(pReloc.type());
break;
}
- } // end switch
+ default: { break; }
+ } // end switch
}
void ARMRelocator::scanGlobalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
- const LDSection& pSection)
-{
+ const LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()) {
-
+ switch (pReloc.type()) {
// Set R_ARM_TARGET1 to R_ARM_ABS32
- // Ref: GNU gold 1.11 arm.cc, line 9892
// FIXME: R_ARM_TARGET1 should be set by option --target1-rel
// or --target1-rel
case llvm::ELF::R_ARM_TARGET1:
@@ -609,7 +544,7 @@ void ARMRelocator::scanGlobalReloc(Relocation& pReloc,
// dynamic relocation entry
if (getTarget().symbolNeedsPLT(*rsym)) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need to reserve a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -619,13 +554,13 @@ void ARMRelocator::scanGlobalReloc(Relocation& pReloc,
}
}
- if (getTarget().symbolNeedsDynRel(*rsym,
- (rsym->reserved() & ReservePLT), true)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), true)) {
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym);
addCopyReloc(*cpy_sym.resolveInfo());
- }
- else {
+ } else {
checkValidReloc(pReloc);
// set Rel bit
if (helper_use_relative_reloc(*rsym, *this))
@@ -652,7 +587,8 @@ void ARMRelocator::scanGlobalReloc(Relocation& pReloc,
// FIXME: Currently we only support these relocations against
// symbol _GLOBAL_OFFSET_TABLE_
if (rsym != getTarget().getGOTSymbol()->resolveInfo()) {
- fatal(diag::base_relocation) << (int)pReloc.type() << rsym->name()
+ fatal(diag::base_relocation) << static_cast<int>(pReloc.type())
+ << rsym->name()
<< "mclinker@googlegroups.com";
}
case llvm::ELF::R_ARM_REL32:
@@ -697,17 +633,17 @@ void ARMRelocator::scanGlobalReloc(Relocation& pReloc,
case llvm::ELF::R_ARM_MOVT_BREL:
case llvm::ELF::R_ARM_MOVW_BREL: {
// Relative addressing relocation, may needs dynamic relocation
- if (getTarget().symbolNeedsDynRel(*rsym, (rsym->reserved() & ReservePLT),
- false)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), false)) {
// symbol needs dynamic relocation entry, reserve an entry in .rel.dyn
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym);
addCopyReloc(*cpy_sym.resolveInfo());
- }
- else {
+ } else {
checkValidReloc(pReloc);
// set Rel bit
- //helper_DynRel_init(pReloc, pReloc.type(), *this);
+ helper_DynRel_init(pReloc, pReloc.type(), *this);
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
}
@@ -755,7 +691,6 @@ void ARMRelocator::scanGlobalReloc(Relocation& pReloc,
}
// Set R_ARM_TARGET2 to R_ARM_GOT_PREL
- // Ref: GNU gold 1.11 arm.cc, line 9892
// FIXME: R_ARM_TARGET2 should be set by option --target2
case llvm::ELF::R_ARM_TARGET2:
pReloc.setType(llvm::ELF::R_ARM_GOT_PREL);
@@ -783,28 +718,25 @@ void ARMRelocator::scanGlobalReloc(Relocation& pReloc,
case llvm::ELF::R_ARM_RELATIVE: {
// These are relocation type for dynamic linker, shold not
// appear in object file.
- fatal(diag::dynamic_relocation) << (int)pReloc.type();
- break;
- }
- default: {
+ fatal(diag::dynamic_relocation) << static_cast<int>(pReloc.type());
break;
}
- } // end switch
+ default: { break; }
+ } // end switch
}
void ARMRelocator::scanRelocation(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
LDSection& pSection,
- Input& pInput)
-{
+ Input& pInput) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- assert(NULL != rsym &&
+ assert(rsym != NULL &&
"ResolveInfo of relocation not set while scanRelocation");
- assert(NULL != pSection.getLink());
- if (0 == (pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC))
+ assert(pSection.getLink() != NULL);
+ if ((pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC) == 0)
return;
// Scan relocation type to determine if an GOT/PLT/Dynamic Relocation
@@ -825,19 +757,34 @@ void ARMRelocator::scanRelocation(Relocation& pReloc,
issueUndefRef(pReloc, pSection, pInput);
}
+uint32_t ARMRelocator::getDebugStringOffset(Relocation& pReloc) const {
+ if (pReloc.type() != llvm::ELF::R_ARM_ABS32)
+ error(diag::unsupport_reloc_for_debug_string)
+ << getName(pReloc.type()) << "mclinker@googlegroups.com";
+
+ if (pReloc.symInfo()->type() == ResolveInfo::Section)
+ return pReloc.target();
+ else
+ return pReloc.symInfo()->outSymbol()->fragRef()->offset() +
+ pReloc.target() + pReloc.addend();
+}
+
+void ARMRelocator::applyDebugStringOffset(Relocation& pReloc,
+ uint32_t pOffset) {
+ pReloc.target() = pOffset;
+}
+
//=========================================//
// Each relocation function implementation //
//=========================================//
// R_ARM_NONE
-ARMRelocator::Result none(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result none(Relocation& pReloc, ARMRelocator& pParent) {
return Relocator::OK;
}
// R_ARM_ABS32: (S + A) | T
-ARMRelocator::Result abs32(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result abs32(Relocation& pReloc, ARMRelocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord A = pReloc.target() + pReloc.addend();
@@ -845,10 +792,11 @@ ARMRelocator::Result abs32(Relocation& pReloc, ARMRelocator& pParent)
if (T != 0x0)
helper_clear_thumb_bit(S);
- // If the flag of target section is not ALLOC, we will not scan this relocation
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation
// but perform static relocation. (e.g., applying .debug section)
- if (0x0 == (llvm::ELF::SHF_ALLOC &
- pReloc.targetRef().frag()->getParent()->getSection().flag())) {
+ if ((llvm::ELF::SHF_ALLOC &
+ pReloc.targetRef().frag()->getParent()->getSection().flag()) == 0) {
pReloc.target() = (S + A) | T;
return Relocator::OK;
}
@@ -857,7 +805,7 @@ ARMRelocator::Result abs32(Relocation& pReloc, ARMRelocator& pParent)
if (!rsym->isLocal()) {
if (rsym->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*rsym, pParent);
- T = 0 ; // PLT is not thumb
+ T = 0; // PLT is not thumb
}
// If we generate a dynamic relocation (except R_ARM_RELATIVE)
// for a place, we should not perform static relocation on it
@@ -873,12 +821,11 @@ ARMRelocator::Result abs32(Relocation& pReloc, ARMRelocator& pParent)
}
// R_ARM_REL32: ((S + A) | T) - P
-ARMRelocator::Result rel32(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result rel32(Relocation& pReloc, ARMRelocator& pParent) {
// perform static relocation
Relocator::Address S = pReloc.symValue();
- Relocator::DWord T = getThumbBit(pReloc);
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::DWord T = getThumbBit(pReloc);
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
// An external symbol may need PLT (this reloc is from a stub/veneer)
if (!pReloc.symInfo()->isLocal()) {
@@ -898,8 +845,7 @@ ARMRelocator::Result rel32(Relocation& pReloc, ARMRelocator& pParent)
}
// R_ARM_BASE_PREL: B(S) + A - P
-ARMRelocator::Result base_prel(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result base_prel(Relocation& pReloc, ARMRelocator& pParent) {
// perform static relocation
Relocator::DWord A = pReloc.target() + pReloc.addend();
pReloc.target() = pReloc.symValue() + A - pReloc.place();
@@ -907,8 +853,7 @@ ARMRelocator::Result base_prel(Relocation& pReloc, ARMRelocator& pParent)
}
// R_ARM_GOTOFF32: ((S + A) | T) - GOT_ORG
-ARMRelocator::Result gotoff32(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result gotoff32(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address GOT_ORG = helper_GOT_ORG(pParent);
@@ -921,50 +866,47 @@ ARMRelocator::Result gotoff32(Relocation& pReloc, ARMRelocator& pParent)
}
// R_ARM_GOT_BREL: GOT(S) + A - GOT_ORG
-ARMRelocator::Result got_brel(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result got_brel(Relocation& pReloc, ARMRelocator& pParent) {
if (!(pReloc.symInfo()->reserved() & ARMRelocator::ReserveGOT))
return Relocator::BadReloc;
Relocator::Address GOT_S = helper_get_GOT_address(*pReloc.symInfo(), pParent);
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address GOT_ORG = helper_GOT_ORG(pParent);
// Apply relocation.
pReloc.target() = GOT_S + A - GOT_ORG;
// setup got entry value if needed
ARMGOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- if (NULL != got_entry && ARMRelocator::SymVal == got_entry->getValue())
+ if (got_entry != NULL && ARMRelocator::SymVal == got_entry->getValue())
got_entry->setValue(pReloc.symValue());
return Relocator::OK;
}
// R_ARM_GOT_PREL: GOT(S) + A - P
-ARMRelocator::Result got_prel(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result got_prel(Relocation& pReloc, ARMRelocator& pParent) {
if (!(pReloc.symInfo()->reserved() & ARMRelocator::ReserveGOT)) {
return Relocator::BadReloc;
}
Relocator::Address GOT_S = helper_get_GOT_address(*pReloc.symInfo(), pParent);
- Relocator::DWord A = pReloc.target() + pReloc.addend();
- Relocator::Address P = pReloc.place();
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::Address P = pReloc.place();
// Apply relocation.
pReloc.target() = GOT_S + A - P;
// setup got entry value if needed
ARMGOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- if (NULL != got_entry && ARMRelocator::SymVal == got_entry->getValue())
+ if (got_entry != NULL && ARMRelocator::SymVal == got_entry->getValue())
got_entry->setValue(pReloc.symValue());
return Relocator::OK;
}
// R_ARM_THM_JUMP8: S + A - P
-ARMRelocator::Result thm_jump8(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_jump8(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::DWord P = pReloc.place();
- Relocator::DWord A = helper_sign_extend((pReloc.target() & 0x00ff) << 1, 8) +
- pReloc.addend();
+ Relocator::DWord A =
+ helper_sign_extend((pReloc.target() & 0x00ff) << 1, 8) + pReloc.addend();
// S depends on PLT exists or not
Relocator::Address S = pReloc.symValue();
if (pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT)
@@ -979,11 +921,10 @@ ARMRelocator::Result thm_jump8(Relocation& pReloc, ARMRelocator& pParent)
}
// R_ARM_THM_JUMP11: S + A - P
-ARMRelocator::Result thm_jump11(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_jump11(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::DWord P = pReloc.place();
- Relocator::DWord A = helper_sign_extend((pReloc.target() & 0x07ff) << 1, 11) +
- pReloc.addend();
+ Relocator::DWord A =
+ helper_sign_extend((pReloc.target() & 0x07ff) << 1, 11) + pReloc.addend();
// S depends on PLT exists or not
Relocator::Address S = pReloc.symValue();
if (pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT)
@@ -998,31 +939,30 @@ ARMRelocator::Result thm_jump11(Relocation& pReloc, ARMRelocator& pParent)
}
// R_ARM_THM_JUMP19: ((S + A) | T) - P
-ARMRelocator::Result thm_jump19(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_jump19(Relocation& pReloc, ARMRelocator& pParent) {
// get lower and upper 16 bit instructions from relocation targetData
uint16_t upper_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()));
uint16_t lower_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1);
Relocator::DWord T = getThumbBit(pReloc);
- Relocator::DWord A = helper_thumb32_cond_branch_offset(upper_inst,
- lower_inst);
+ Relocator::DWord A =
+ helper_thumb32_cond_branch_offset(upper_inst, lower_inst);
Relocator::Address P = pReloc.place();
Relocator::Address S;
// if symbol has plt
if (pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*pReloc.symInfo(), pParent);
T = 0; // PLT is not thumb.
- }
- else {
+ } else {
S = pReloc.symValue();
if (T != 0x0)
helper_clear_thumb_bit(S);
}
- if (0x0 == T) {
+ if (T == 0x0) {
// FIXME: conditional branch to PLT in THUMB-2 not supported yet
- error(diag::unsupport_cond_branch_reloc) << (int)pReloc.type();
+ error(diag::unsupported_cond_branch_reloc)
+ << static_cast<int>(pReloc.type());
return Relocator::BadReloc;
}
@@ -1043,13 +983,11 @@ ARMRelocator::Result thm_jump19(Relocation& pReloc, ARMRelocator& pParent)
// R_ARM_PLT32: ((S + A) | T) - P
// R_ARM_JUMP24: ((S + A) | T) - P
// R_ARM_CALL: ((S + A) | T) - P
-ARMRelocator::Result call(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result call(Relocation& pReloc, ARMRelocator& pParent) {
// If target is undefined weak symbol, we only need to jump to the
// next instruction unless it has PLT entry. Rewrite instruction
// to NOP.
- if (pReloc.symInfo()->isWeak() &&
- pReloc.symInfo()->isUndef() &&
+ if (pReloc.symInfo()->isWeak() && pReloc.symInfo()->isUndef() &&
!pReloc.symInfo()->isDyn() &&
!(pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT)) {
// change target to NOP : mov r0, r0
@@ -1057,10 +995,10 @@ ARMRelocator::Result call(Relocation& pReloc, ARMRelocator& pParent)
return Relocator::OK;
}
- Relocator::DWord T = getThumbBit(pReloc);
- Relocator::DWord A =
- helper_sign_extend((pReloc.target() & 0x00FFFFFFu) << 2, 26) +
- pReloc.addend();
+ Relocator::DWord T = getThumbBit(pReloc);
+ Relocator::DWord A =
+ helper_sign_extend((pReloc.target() & 0x00FFFFFFu) << 2, 26) +
+ pReloc.addend();
Relocator::Address P = pReloc.place();
Relocator::Address S = pReloc.symValue();
if (T != 0x0)
@@ -1083,9 +1021,8 @@ ARMRelocator::Result call(Relocation& pReloc, ARMRelocator& pParent)
if (pReloc.type() == llvm::ELF::R_ARM_PC24)
return Relocator::BadReloc;
- pReloc.target() = (pReloc.target() & 0xffffff) |
- 0xfa000000 |
- (((S + A - P) & 2) << 23);
+ pReloc.target() =
+ (pReloc.target() & 0xffffff) | 0xfa000000 | (((S + A - P) & 2) << 23);
}
Relocator::DWord X = ((S + A) | T) - P;
@@ -1099,13 +1036,11 @@ ARMRelocator::Result call(Relocation& pReloc, ARMRelocator& pParent)
// R_ARM_THM_CALL: ((S + A) | T) - P
// R_ARM_THM_JUMP24: ((S + A) | T) - P
-ARMRelocator::Result thm_call(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_call(Relocation& pReloc, ARMRelocator& pParent) {
// If target is undefined weak symbol, we only need to jump to the
// next instruction unless it has PLT entry. Rewrite instruction
// to NOP.
- if (pReloc.symInfo()->isWeak() &&
- pReloc.symInfo()->isUndef() &&
+ if (pReloc.symInfo()->isWeak() && pReloc.symInfo()->isUndef() &&
!pReloc.symInfo()->isDyn() &&
!(pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT)) {
pReloc.target() = (0xe000U << 16) | 0xbf00U;
@@ -1125,8 +1060,7 @@ ARMRelocator::Result thm_call(Relocation& pReloc, ARMRelocator& pParent)
if (pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*pReloc.symInfo(), pParent);
T = 0; // PLT is not thumb.
- }
- else {
+ } else {
S = pReloc.symValue();
if (T != 0x0)
helper_clear_thumb_bit(S);
@@ -1148,8 +1082,7 @@ ARMRelocator::Result thm_call(Relocation& pReloc, ARMRelocator& pParent)
S = helper_bit_select(S, P, 0x2);
// rewrite instruction to BLX
lower_inst &= ~0x1000U;
- }
- else {
+ } else {
// otherwise, the instruction should be BL
lower_inst |= 0x1000U;
}
@@ -1171,13 +1104,12 @@ ARMRelocator::Result thm_call(Relocation& pReloc, ARMRelocator& pParent)
}
// R_ARM_MOVW_ABS_NC: (S + A) | T
-ARMRelocator::Result movw_abs_nc(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result movw_abs_nc(Relocation& pReloc, ARMRelocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord A =
- helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
+ helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
if (T != 0x0)
helper_clear_thumb_bit(S);
@@ -1185,29 +1117,28 @@ ARMRelocator::Result movw_abs_nc(Relocation& pReloc, ARMRelocator& pParent)
// If the flag of target section is not ALLOC, we will not scan this
// relocation but perform static relocation. (e.g., applying .debug section)
- if (0x0 != (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) != 0x0) {
// use plt
if (rsym->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*rsym, pParent);
- T = 0 ; // PLT is not thumb
+ T = 0; // PLT is not thumb
}
}
// perform static relocation
Relocator::DWord X = (S + A) | T;
- pReloc.target() = helper_insert_val_movw_movt_inst(
- pReloc.target() + pReloc.addend(), X);
+ pReloc.target() =
+ helper_insert_val_movw_movt_inst(pReloc.target() + pReloc.addend(), X);
return Relocator::OK;
}
// R_ARM_MOVW_PREL_NC: ((S + A) | T) - P
-ARMRelocator::Result movw_prel_nc(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result movw_prel_nc(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord P = pReloc.place();
Relocator::DWord A =
- helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
+ helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
if (T != 0x0)
helper_clear_thumb_bit(S);
Relocator::DWord X = ((S + A) | T) - P;
@@ -1221,18 +1152,18 @@ ARMRelocator::Result movw_prel_nc(Relocation& pReloc, ARMRelocator& pParent)
}
// R_ARM_MOVT_ABS: S + A
-ARMRelocator::Result movt_abs(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result movt_abs(Relocation& pReloc, ARMRelocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
Relocator::DWord A =
- helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
+ helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation
// but perform static relocation. (e.g., applying .debug section)
- if (0x0 != (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) != 0x0) {
// use plt
if (rsym->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*rsym, pParent);
@@ -1247,12 +1178,11 @@ ARMRelocator::Result movt_abs(Relocation& pReloc, ARMRelocator& pParent)
}
// R_ARM_MOVT_PREL: S + A - P
-ARMRelocator::Result movt_prel(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result movt_prel(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord P = pReloc.place();
Relocator::DWord A =
- helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
+ helper_extract_movw_movt_addend(pReloc.target()) + pReloc.addend();
Relocator::DWord X = S + A - P;
X >>= 16;
@@ -1261,8 +1191,8 @@ ARMRelocator::Result movt_prel(Relocation& pReloc, ARMRelocator& pParent)
}
// R_ARM_THM_MOVW_ABS_NC: (S + A) | T
-ARMRelocator::Result thm_movw_abs_nc(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_movw_abs_nc(Relocation& pReloc,
+ ARMRelocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
Relocator::DWord T = getThumbBit(pReloc);
@@ -1274,16 +1204,17 @@ ARMRelocator::Result thm_movw_abs_nc(Relocation& pReloc, ARMRelocator& pParent)
uint16_t lower_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1);
Relocator::DWord val = ((upper_inst) << 16) | (lower_inst);
Relocator::DWord A =
- helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
+ helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation
// but perform static relocation. (e.g., applying .debug section)
- if (0x0 != (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) != 0x0) {
// use plt
if (rsym->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*rsym, pParent);
- T = 0; // PLT is not thumb
+ T = 0; // PLT is not thumb
}
}
Relocator::DWord X = (S + A) | T;
@@ -1296,8 +1227,8 @@ ARMRelocator::Result thm_movw_abs_nc(Relocation& pReloc, ARMRelocator& pParent)
}
// R_ARM_THM_MOVW_PREL_NC: ((S + A) | T) - P
-ARMRelocator::Result thm_movw_prel_nc(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_movw_prel_nc(Relocation& pReloc,
+ ARMRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord P = pReloc.place();
@@ -1309,7 +1240,7 @@ ARMRelocator::Result thm_movw_prel_nc(Relocation& pReloc, ARMRelocator& pParent)
uint16_t lower_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1);
Relocator::DWord val = ((upper_inst) << 16) | (lower_inst);
Relocator::DWord A =
- helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
+ helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
Relocator::DWord X = ((S + A) | T) - P;
val = helper_insert_val_thumb_movw_movt_inst(val, X);
@@ -1321,8 +1252,7 @@ ARMRelocator::Result thm_movw_prel_nc(Relocation& pReloc, ARMRelocator& pParent)
// R_ARM_THM_MOVW_BREL_NC: ((S + A) | T) - B(S)
// R_ARM_THM_MOVW_BREL: ((S + A) | T) - B(S)
-ARMRelocator::Result thm_movw_brel(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_movw_brel(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord P = pReloc.place();
@@ -1334,7 +1264,7 @@ ARMRelocator::Result thm_movw_brel(Relocation& pReloc, ARMRelocator& pParent)
uint16_t lower_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1);
Relocator::DWord val = ((upper_inst) << 16) | (lower_inst);
Relocator::DWord A =
- helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
+ helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
Relocator::DWord X = ((S + A) | T) - P;
@@ -1346,8 +1276,7 @@ ARMRelocator::Result thm_movw_brel(Relocation& pReloc, ARMRelocator& pParent)
}
// R_ARM_THM_MOVT_ABS: S + A
-ARMRelocator::Result thm_movt_abs(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_movt_abs(Relocation& pReloc, ARMRelocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
@@ -1356,12 +1285,12 @@ ARMRelocator::Result thm_movt_abs(Relocation& pReloc, ARMRelocator& pParent)
uint16_t lower_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1);
Relocator::DWord val = ((upper_inst) << 16) | (lower_inst);
Relocator::DWord A =
- helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
+ helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
// If the flag of target section is not ALLOC, we will not scan this
// relocation but perform static relocation. (e.g., applying .debug section)
- if (0x0 != (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) != 0x0) {
// use plt
if (rsym->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*rsym, pParent);
@@ -1378,13 +1307,11 @@ ARMRelocator::Result thm_movt_abs(Relocation& pReloc, ARMRelocator& pParent)
*(reinterpret_cast<uint16_t*>(&pReloc.target())) = val >> 16;
*(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1) = val & 0xFFFFu;
return Relocator::OK;
-
}
// R_ARM_THM_MOVT_PREL: S + A - P
// R_ARM_THM_MOVT_BREL: S + A - B(S)
-ARMRelocator::Result thm_movt_prel(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result thm_movt_prel(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord P = pReloc.place();
@@ -1393,7 +1320,7 @@ ARMRelocator::Result thm_movt_prel(Relocation& pReloc, ARMRelocator& pParent)
uint16_t lower_inst = *(reinterpret_cast<uint16_t*>(&pReloc.target()) + 1);
Relocator::DWord val = ((upper_inst) << 16) | (lower_inst);
Relocator::DWord A =
- helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
+ helper_extract_thumb_movw_movt_addend(val) + pReloc.addend();
Relocator::DWord X = S + A - P;
X >>= 16;
@@ -1405,8 +1332,7 @@ ARMRelocator::Result thm_movt_prel(Relocation& pReloc, ARMRelocator& pParent)
}
// R_ARM_PREL31: ((S + A) | T) - P
-ARMRelocator::Result prel31(Relocation& pReloc, ARMRelocator& pParent)
-{
+ARMRelocator::Result prel31(Relocation& pReloc, ARMRelocator& pParent) {
Relocator::DWord target = pReloc.target();
Relocator::DWord T = getThumbBit(pReloc);
Relocator::DWord A = helper_sign_extend(target, 31) + pReloc.addend();
@@ -1416,7 +1342,7 @@ ARMRelocator::Result prel31(Relocation& pReloc, ARMRelocator& pParent)
helper_clear_thumb_bit(S);
// if symbol has plt
- if ( pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT) {
+ if (pReloc.symInfo()->reserved() & ARMRelocator::ReservePLT) {
S = helper_get_PLT_address(*pReloc.symInfo(), pParent);
T = 0; // PLT is not thumb.
}
@@ -1431,12 +1357,12 @@ ARMRelocator::Result prel31(Relocation& pReloc, ARMRelocator& pParent)
// R_ARM_TLS_GD32: GOT(S) + A - P
// R_ARM_TLS_IE32: GOT(S) + A - P
// R_ARM_TLS_LE32: S + A - tp
-ARMRelocator::Result tls(Relocation& pReloc, ARMRelocator& pParent)
-{
- return Relocator::Unsupport;
+ARMRelocator::Result tls(Relocation& pReloc, ARMRelocator& pParent) {
+ return Relocator::Unsupported;
}
-ARMRelocator::Result unsupport(Relocation& pReloc, ARMRelocator& pParent)
-{
- return Relocator::Unsupport;
+ARMRelocator::Result unsupported(Relocation& pReloc, ARMRelocator& pParent) {
+ return Relocator::Unsupported;
}
+
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMRelocator.h b/lib/Target/ARM/ARMRelocator.h
index 9c3156b..1be9ed4 100644
--- a/lib/Target/ARM/ARMRelocator.h
+++ b/lib/Target/ARM/ARMRelocator.h
@@ -6,12 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMRELOCATOR_H
-#define TARGET_ARM_ARMRELOCATOR_H
+#ifndef TARGET_ARM_ARMRELOCATOR_H_
+#define TARGET_ARM_ARMRELOCATOR_H_
-#include <mcld/LD/Relocator.h>
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/KeyEntryMap.h>
+#include "mcld/LD/Relocator.h"
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/KeyEntryMap.h"
#include "ARMLDBackend.h"
namespace mcld {
@@ -20,9 +20,8 @@ namespace mcld {
* \brief ARMRelocator creates and destroys the ARM relocations.
*
*/
-class ARMRelocator : public Relocator
-{
-public:
+class ARMRelocator : public Relocator {
+ public:
typedef KeyEntryMap<ResolveInfo, ARMGOTEntry> SymGOTMap;
typedef KeyEntryMap<ResolveInfo, ARMPLT1> SymPLTMap;
@@ -45,10 +44,10 @@ public:
*
*/
enum ReservedEntryType {
- None = 0,
- ReserveRel = 1,
- ReserveGOT = 2,
- ReservePLT = 4,
+ None = 0,
+ ReserveRel = 1,
+ ReserveGOT = 2,
+ ReservePLT = 4,
};
/** \enum EntryValue
@@ -56,35 +55,30 @@ public:
* layout, so we mark the entry during scanRelocation and fill up the actual
* value when applying relocations.
*/
- enum EntryValue {
- Default = 0,
- SymVal = 1
- };
+ enum EntryValue { Default = 0, SymVal = 1 };
-public:
+ public:
ARMRelocator(ARMGNULDBackend& pParent, const LinkerConfig& pConfig);
~ARMRelocator();
Result applyRelocation(Relocation& pRelocation);
- ARMGNULDBackend& getTarget()
- { return m_Target; }
+ ARMGNULDBackend& getTarget() { return m_Target; }
- const ARMGNULDBackend& getTarget() const
- { return m_Target; }
+ const ARMGNULDBackend& getTarget() const { return m_Target; }
const char* getName(Relocation::Type pType) const;
Size getSize(Relocation::Type pType) const;
const SymGOTMap& getSymGOTMap() const { return m_SymGOTMap; }
- SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
+ SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
const SymPLTMap& getSymPLTMap() const { return m_SymPLTMap; }
- SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
+ SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
const SymGOTMap& getSymGOTPLTMap() const { return m_SymGOTPLTMap; }
- SymGOTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
+ SymGOTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
/// scanRelocation - determine the empty entries are needed or not and create
/// the empty entries if needed.
@@ -98,12 +92,19 @@ public:
LDSection& pSection,
Input& pInput);
-
/// mayHaveFunctionPointerAccess - check if the given reloc would possibly
/// access a function pointer.
virtual bool mayHaveFunctionPointerAccess(const Relocation& pReloc) const;
-private:
+ /// getDebugStringOffset - get the offset from the relocation target. This is
+ /// used to get the debug string offset.
+ uint32_t getDebugStringOffset(Relocation& pReloc) const;
+
+ /// applyDebugStringOffset - apply the relocation target to specific offset.
+ /// This is used to set the debug string offset.
+ void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset);
+
+ private:
void scanLocalReloc(Relocation& pReloc, const LDSection& pSection);
void scanGlobalReloc(Relocation& pReloc,
@@ -122,14 +123,13 @@ private:
LDSymbol& defineSymbolforCopyReloc(IRBuilder& pLinker,
const ResolveInfo& pSym);
-private:
+ private:
ARMGNULDBackend& m_Target;
SymGOTMap m_SymGOTMap;
SymPLTMap m_SymPLTMap;
SymGOTMap m_SymGOTPLTMap;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_ARM_ARMRELOCATOR_H_
diff --git a/lib/Target/ARM/ARMTargetMachine.cpp b/lib/Target/ARM/ARMTargetMachine.cpp
deleted file mode 100644
index 25caa56..0000000
--- a/lib/Target/ARM/ARMTargetMachine.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-//===- ARMTargetMachine.cpp -----------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "ARMTargetMachine.h"
-#include "ARM.h"
-
-#include <mcld/Support/TargetRegistry.h>
-
-using namespace mcld;
-
-ARMBaseTargetMachine::ARMBaseTargetMachine(llvm::TargetMachine& pPM,
- const llvm::Target &pLLVMTarget,
- const mcld::Target &pMCLDTarget,
- const std::string& pTriple)
- : MCLDTargetMachine(pPM, pLLVMTarget, pMCLDTarget, pTriple) {
-}
-
-//===----------------------------------------------------------------------===//
-// Initialize MCLDTargetMachine
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeARMLDTarget() {
- // Register createTargetMachine function pointer to mcld::Target
- mcld::RegisterTargetMachine<mcld::ARMBaseTargetMachine> X(mcld::TheARMTarget);
- mcld::RegisterTargetMachine<mcld::ARMBaseTargetMachine> Y(mcld::TheThumbTarget);
-}
-
diff --git a/lib/Target/ARM/ARMTargetMachine.h b/lib/Target/ARM/ARMTargetMachine.h
deleted file mode 100644
index ddcf73d..0000000
--- a/lib/Target/ARM/ARMTargetMachine.h
+++ /dev/null
@@ -1,29 +0,0 @@
-//===- ARMTargetMachine.h -------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_ARM_ARMTARGETMACHINE_H
-#define TARGET_ARM_ARMTARGETMACHINE_H
-
-#include "ARM.h"
-#include <mcld/CodeGen/TargetMachine.h>
-
-namespace mcld {
-
-class ARMBaseTargetMachine : public MCLDTargetMachine
-{
-public:
- ARMBaseTargetMachine(llvm::TargetMachine& pTM,
- const llvm::Target& pLLVMTarget,
- const mcld::Target& pMCLDTarget,
- const std::string& pTriple);
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/lib/Target/ARM/ARMToARMStub.cpp b/lib/Target/ARM/ARMToARMStub.cpp
index ba3acf4..1c4b976 100644
--- a/lib/Target/ARM/ARMToARMStub.cpp
+++ b/lib/Target/ARM/ARMToARMStub.cpp
@@ -10,36 +10,35 @@
#include "ARMToARMStub.h"
#include "ARMLDBackend.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
+
#include <llvm/Support/ELF.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Fragment/Relocation.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ARMToARMStub
//===----------------------------------------------------------------------===//
const uint32_t ARMToARMStub::PIC_TEMPLATE[] = {
- 0xe59fc000, // ldr r12, [pc]
- 0xe08ff00c, // add pc, pc, ip
- 0x0 // dcd R_ARM_REL32(X-4)
+ 0xe59fc000, // ldr r12, [pc]
+ 0xe08ff00c, // add pc, pc, ip
+ 0x0 // dcd R_ARM_REL32(X-4)
};
const uint32_t ARMToARMStub::TEMPLATE[] = {
- 0xe51ff004, // ldr pc, [pc, #-4]
- 0x0 // dcd R_ARM_ABS32(X)
+ 0xe51ff004, // ldr pc, [pc, #-4]
+ 0x0 // dcd R_ARM_ABS32(X)
};
ARMToARMStub::ARMToARMStub(bool pIsOutputPIC)
- : m_pData(NULL), m_Name("A2A_prototype"), m_Size(0x0)
-{
+ : m_pData(NULL), m_Name("A2A_prototype"), m_Size(0x0) {
if (pIsOutputPIC) {
m_pData = PIC_TEMPLATE;
m_Size = sizeof(PIC_TEMPLATE);
addFixup(8u, -4, llvm::ELF::R_ARM_REL32);
- }
- else {
+ } else {
m_pData = TEMPLATE;
m_Size = sizeof(TEMPLATE);
addFixup(4u, 0x0, llvm::ELF::R_ARM_ABS32);
@@ -51,20 +50,17 @@ ARMToARMStub::ARMToARMStub(const uint32_t* pData,
size_t pSize,
const_fixup_iterator pBegin,
const_fixup_iterator pEnd)
- : m_pData(pData), m_Name("A2A_veneer"), m_Size(pSize)
-{
+ : m_pData(pData), m_Name("A2A_veneer"), m_Size(pSize) {
for (const_fixup_iterator it = pBegin, ie = pEnd; it != ie; ++it)
addFixup(**it);
}
-ARMToARMStub::~ARMToARMStub()
-{
+ARMToARMStub::~ARMToARMStub() {
}
bool ARMToARMStub::isMyDuty(const class Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue) const
-{
+ uint64_t pTargetSymValue) const {
bool result = false;
// Check if the branch target is ARM
if ((pTargetSymValue & 0x1) == 0x0) {
@@ -78,7 +74,7 @@ bool ARMToARMStub::isMyDuty(const class Relocation& pReloc,
int64_t branch_offset = static_cast<int64_t>(dest) - pSource;
if ((branch_offset > ARMGNULDBackend::ARM_MAX_FWD_BRANCH_OFFSET) ||
(branch_offset < ARMGNULDBackend::ARM_MAX_BWD_BRANCH_OFFSET)) {
- result = true;
+ result = true;
}
break;
}
@@ -89,27 +85,24 @@ bool ARMToARMStub::isMyDuty(const class Relocation& pReloc,
return result;
}
-const std::string& ARMToARMStub::name() const
-{
+const std::string& ARMToARMStub::name() const {
return m_Name;
}
-const uint8_t* ARMToARMStub::getContent() const
-{
+const uint8_t* ARMToARMStub::getContent() const {
return reinterpret_cast<const uint8_t*>(m_pData);
}
-size_t ARMToARMStub::size() const
-{
+size_t ARMToARMStub::size() const {
return m_Size;
}
-size_t ARMToARMStub::alignment() const
-{
+size_t ARMToARMStub::alignment() const {
return 4u;
}
-Stub* ARMToARMStub::doClone()
-{
+Stub* ARMToARMStub::doClone() {
return new ARMToARMStub(m_pData, m_Size, fixup_begin(), fixup_end());
}
+
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMToARMStub.h b/lib/Target/ARM/ARMToARMStub.h
index afb26a8..2dc6acc 100644
--- a/lib/Target/ARM/ARMToARMStub.h
+++ b/lib/Target/ARM/ARMToARMStub.h
@@ -6,17 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_ARM_ARMTOARMSTUB_H_
+#define TARGET_ARM_ARMTOARMSTUB_H_
-#ifndef TARGET_ARM_ARMTOARMSTUB_H
-#define TARGET_ARM_ARMTOARMSTUB_H
-
+#include "mcld/Fragment/Stub.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Fragment/Stub.h>
#include <string>
#include <vector>
-namespace mcld
-{
+namespace mcld {
class Relocation;
class ResolveInfo;
@@ -25,10 +23,9 @@ class ResolveInfo;
* \brief ARM stub for long call from ARM source to ARM target
*
*/
-class ARMToARMStub : public Stub
-{
-public:
- ARMToARMStub(bool pIsOutputPIC);
+class ARMToARMStub : public Stub {
+ public:
+ explicit ARMToARMStub(bool pIsOutputPIC);
~ARMToARMStub();
@@ -46,7 +43,7 @@ public:
size_t alignment() const;
-private:
+ private:
ARMToARMStub(const ARMToARMStub&);
ARMToARMStub& operator=(const ARMToARMStub&);
@@ -60,7 +57,7 @@ private:
/// doClone
Stub* doClone();
-private:
+ private:
static const uint32_t PIC_TEMPLATE[];
static const uint32_t TEMPLATE[];
const uint32_t* m_pData;
@@ -68,6 +65,6 @@ private:
size_t m_Size;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_ARM_ARMTOARMSTUB_H_
diff --git a/lib/Target/ARM/ARMToTHMStub.cpp b/lib/Target/ARM/ARMToTHMStub.cpp
index a46a0c8..b53c747 100644
--- a/lib/Target/ARM/ARMToTHMStub.cpp
+++ b/lib/Target/ARM/ARMToTHMStub.cpp
@@ -10,38 +10,37 @@
#include "ARMToTHMStub.h"
#include "ARMLDBackend.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
+
#include <llvm/Support/ELF.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Fragment/Relocation.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ARMToTHMStub
//===----------------------------------------------------------------------===//
const uint32_t ARMToTHMStub::PIC_TEMPLATE[] = {
- 0xe59fc004, // ldr r12, [pc, #4]
- 0xe08fc00c, // add ip, pc, ip
- 0xe12fff1c, // bx ip
- 0x0 // dcd R_ARM_REL32(X)
+ 0xe59fc004, // ldr r12, [pc, #4]
+ 0xe08fc00c, // add ip, pc, ip
+ 0xe12fff1c, // bx ip
+ 0x0 // dcd R_ARM_REL32(X)
};
const uint32_t ARMToTHMStub::TEMPLATE[] = {
- 0xe59fc000, // ldr ip, [pc, #0]
- 0xe12fff1c, // bx ip
- 0x0 // dcd R_ARM_ABS32(X)
+ 0xe59fc000, // ldr ip, [pc, #0]
+ 0xe12fff1c, // bx ip
+ 0x0 // dcd R_ARM_ABS32(X)
};
ARMToTHMStub::ARMToTHMStub(bool pIsOutputPIC)
- : m_pData(NULL), m_Name("A2T_prototype"), m_Size(0x0)
-{
+ : m_pData(NULL), m_Name("A2T_prototype"), m_Size(0x0) {
if (pIsOutputPIC) {
m_pData = PIC_TEMPLATE;
m_Size = sizeof(PIC_TEMPLATE);
addFixup(12u, 0x0, llvm::ELF::R_ARM_REL32);
- }
- else {
+ } else {
m_pData = TEMPLATE;
m_Size = sizeof(TEMPLATE);
addFixup(8u, 0x0, llvm::ELF::R_ARM_ABS32);
@@ -53,20 +52,17 @@ ARMToTHMStub::ARMToTHMStub(const uint32_t* pData,
size_t pSize,
const_fixup_iterator pBegin,
const_fixup_iterator pEnd)
- : m_pData(pData), m_Name("A2T_veneer"), m_Size(pSize)
-{
+ : m_pData(pData), m_Name("A2T_veneer"), m_Size(pSize) {
for (const_fixup_iterator it = pBegin, ie = pEnd; it != ie; ++it)
addFixup(**it);
}
-ARMToTHMStub::~ARMToTHMStub()
-{
+ARMToTHMStub::~ARMToTHMStub() {
}
bool ARMToTHMStub::isMyDuty(const class Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue) const
-{
+ uint64_t pTargetSymValue) const {
bool result = false;
// Check if the branch target is THUMB
if ((pTargetSymValue & 0x1) != 0x0) {
@@ -97,27 +93,24 @@ bool ARMToTHMStub::isMyDuty(const class Relocation& pReloc,
return result;
}
-const std::string& ARMToTHMStub::name() const
-{
+const std::string& ARMToTHMStub::name() const {
return m_Name;
}
-const uint8_t* ARMToTHMStub::getContent() const
-{
+const uint8_t* ARMToTHMStub::getContent() const {
return reinterpret_cast<const uint8_t*>(m_pData);
}
-size_t ARMToTHMStub::size() const
-{
+size_t ARMToTHMStub::size() const {
return m_Size;
}
-size_t ARMToTHMStub::alignment() const
-{
+size_t ARMToTHMStub::alignment() const {
return 4u;
}
-Stub* ARMToTHMStub::doClone()
-{
+Stub* ARMToTHMStub::doClone() {
return new ARMToTHMStub(m_pData, m_Size, fixup_begin(), fixup_end());
}
+
+} // namespace mcld
diff --git a/lib/Target/ARM/ARMToTHMStub.h b/lib/Target/ARM/ARMToTHMStub.h
index e7a44bf..5521baf 100644
--- a/lib/Target/ARM/ARMToTHMStub.h
+++ b/lib/Target/ARM/ARMToTHMStub.h
@@ -6,17 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_ARM_ARMTOTHMSTUB_H_
+#define TARGET_ARM_ARMTOTHMSTUB_H_
-#ifndef TARGET_ARM_ARMTOTHMSTUB_H
-#define TARGET_ARM_ARMTOTHMSTUB_H
-
+#include "mcld/Fragment/Stub.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Fragment/Stub.h>
#include <string>
#include <vector>
-namespace mcld
-{
+namespace mcld {
class Relocation;
class ResolveInfo;
@@ -25,10 +23,9 @@ class ResolveInfo;
* \brief ARM stub for long call from ARM source to ARM target
*
*/
-class ARMToTHMStub : public Stub
-{
-public:
- ARMToTHMStub(bool pIsOutputPIC);
+class ARMToTHMStub : public Stub {
+ public:
+ explicit ARMToTHMStub(bool pIsOutputPIC);
~ARMToTHMStub();
@@ -46,7 +43,7 @@ public:
size_t alignment() const;
-private:
+ private:
ARMToTHMStub(const ARMToTHMStub&);
ARMToTHMStub& operator=(const ARMToTHMStub&);
@@ -60,7 +57,7 @@ private:
/// doClone
Stub* doClone();
-private:
+ private:
static const uint32_t PIC_TEMPLATE[];
static const uint32_t TEMPLATE[];
const uint32_t* m_pData;
@@ -68,6 +65,6 @@ private:
size_t m_Size;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_ARM_ARMTOTHMSTUB_H_
diff --git a/lib/Target/ARM/Android.mk b/lib/Target/ARM/Android.mk
index 31fe7af..cd83704 100644
--- a/lib/Target/ARM/Android.mk
+++ b/lib/Target/ARM/Android.mk
@@ -4,14 +4,11 @@ mcld_arm_target_SRC_FILES := \
ARMDiagnostic.cpp \
ARMELFAttributeData.cpp \
ARMELFDynamic.cpp \
- ARMELFMCLinker.cpp \
ARMEmulation.cpp \
ARMGOT.cpp \
ARMLDBackend.cpp \
- ARMMCLinker.cpp \
ARMPLT.cpp \
ARMRelocator.cpp \
- ARMTargetMachine.cpp \
ARMToARMStub.cpp \
ARMToTHMStub.cpp \
THMToARMStub.cpp \
diff --git a/lib/Target/ARM/THMToARMStub.cpp b/lib/Target/ARM/THMToARMStub.cpp
index 34e0cbf..c8c7951 100644
--- a/lib/Target/ARM/THMToARMStub.cpp
+++ b/lib/Target/ARM/THMToARMStub.cpp
@@ -10,35 +10,35 @@
#include "THMToARMStub.h"
#include "ARMLDBackend.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
+
#include <llvm/Support/ELF.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Fragment/Relocation.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// THMToARMStub
//===----------------------------------------------------------------------===//
const uint32_t THMToARMStub::PIC_TEMPLATE[] = {
- 0x46c04778, // bx pc ... nop
- 0xe59fc000, // ldr ip, [pc, #0]
- 0xe08cf00f, // add pc, ip, pc
- 0x0 // dcd R_ARM_REL32(X)
+ 0x46c04778, // bx pc ... nop
+ 0xe59fc000, // ldr ip, [pc, #0]
+ 0xe08cf00f, // add pc, ip, pc
+ 0x0 // dcd R_ARM_REL32(X)
};
const uint32_t THMToARMStub::TEMPLATE[] = {
- 0x46c04778, // bx pc ... nop
- 0xe51ff004, // ldr pc, [pc, #-4]
- 0x0 // dcd R_ARM_ABS32(X)
+ 0x46c04778, // bx pc ... nop
+ 0xe51ff004, // ldr pc, [pc, #-4]
+ 0x0 // dcd R_ARM_ABS32(X)
};
THMToARMStub::THMToARMStub(bool pIsOutputPIC, bool pUsingThumb2)
- : m_pData(NULL),
- m_Name("T2A_prototype"),
- m_Size(0x0),
- m_bUsingThumb2(pUsingThumb2)
-{
+ : m_pData(NULL),
+ m_Name("T2A_prototype"),
+ m_Size(0x0),
+ m_bUsingThumb2(pUsingThumb2) {
if (pIsOutputPIC) {
m_pData = PIC_TEMPLATE;
m_Size = sizeof(PIC_TEMPLATE);
@@ -56,23 +56,20 @@ THMToARMStub::THMToARMStub(const uint32_t* pData,
const_fixup_iterator pBegin,
const_fixup_iterator pEnd,
bool pUsingThumb2)
- : m_pData(pData),
- m_Name("T2A_veneer"),
- m_Size(pSize),
- m_bUsingThumb2(pUsingThumb2)
-{
+ : m_pData(pData),
+ m_Name("T2A_veneer"),
+ m_Size(pSize),
+ m_bUsingThumb2(pUsingThumb2) {
for (const_fixup_iterator it = pBegin, ie = pEnd; it != ie; ++it)
addFixup(**it);
}
-THMToARMStub::~THMToARMStub()
-{
+THMToARMStub::~THMToARMStub() {
}
bool THMToARMStub::isMyDuty(const class Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue) const
-{
+ uint64_t pTargetSymValue) const {
bool result = false;
// Check if the branch target is ARM
if ((pTargetSymValue & 0x1) == 0x0) {
@@ -109,37 +106,30 @@ bool THMToARMStub::isMyDuty(const class Relocation& pReloc,
return result;
}
-const std::string& THMToARMStub::name() const
-{
+const std::string& THMToARMStub::name() const {
return m_Name;
}
-const uint8_t* THMToARMStub::getContent() const
-{
+const uint8_t* THMToARMStub::getContent() const {
return reinterpret_cast<const uint8_t*>(m_pData);
}
-size_t THMToARMStub::size() const
-{
+size_t THMToARMStub::size() const {
return m_Size;
}
-size_t THMToARMStub::alignment() const
-{
+size_t THMToARMStub::alignment() const {
return 4u;
}
// for T bit of this stub
-uint64_t THMToARMStub::initSymValue() const
-{
+uint64_t THMToARMStub::initSymValue() const {
return 0x1;
}
-Stub* THMToARMStub::doClone()
-{
- return new THMToARMStub(m_pData,
- m_Size,
- fixup_begin(),
- fixup_end(),
- m_bUsingThumb2);
+Stub* THMToARMStub::doClone() {
+ return new THMToARMStub(
+ m_pData, m_Size, fixup_begin(), fixup_end(), m_bUsingThumb2);
}
+
+} // namespace mcld
diff --git a/lib/Target/ARM/THMToARMStub.h b/lib/Target/ARM/THMToARMStub.h
index af5a926..3272810 100644
--- a/lib/Target/ARM/THMToARMStub.h
+++ b/lib/Target/ARM/THMToARMStub.h
@@ -6,16 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_ARM_THMTOARMSTUB_H_
+#define TARGET_ARM_THMTOARMSTUB_H_
-#ifndef TARGET_ARM_THMTOARMSTUB_H
-#define TARGET_ARM_THMTOARMSTUB_H
-
+#include "mcld/Fragment/Stub.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Fragment/Stub.h>
#include <string>
-namespace mcld
-{
+namespace mcld {
class Relocation;
class ResolveInfo;
@@ -24,9 +22,8 @@ class ResolveInfo;
* \brief ARM stub for long call from ARM source to ARM target
*
*/
-class THMToARMStub : public Stub
-{
-public:
+class THMToARMStub : public Stub {
+ public:
THMToARMStub(bool pIsOutputPIC, bool pUsingThumb2);
~THMToARMStub();
@@ -48,7 +45,7 @@ public:
// for T bit of this stub
uint64_t initSymValue() const;
-private:
+ private:
THMToARMStub(const THMToARMStub&);
THMToARMStub& operator=(const THMToARMStub&);
@@ -63,7 +60,7 @@ private:
/// doClone
Stub* doClone();
-private:
+ private:
static const uint32_t PIC_TEMPLATE[];
static const uint32_t TEMPLATE[];
const uint32_t* m_pData;
@@ -72,6 +69,6 @@ private:
bool m_bUsingThumb2;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_ARM_THMTOARMSTUB_H_
diff --git a/lib/Target/ARM/THMToTHMStub.cpp b/lib/Target/ARM/THMToTHMStub.cpp
index f167f28..acf35ed 100644
--- a/lib/Target/ARM/THMToTHMStub.cpp
+++ b/lib/Target/ARM/THMToTHMStub.cpp
@@ -10,37 +10,37 @@
#include "THMToTHMStub.h"
#include "ARMLDBackend.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/ResolveInfo.h"
+
#include <llvm/Support/ELF.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Fragment/Relocation.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// THMToTHMStub
//===----------------------------------------------------------------------===//
const uint32_t THMToTHMStub::PIC_TEMPLATE[] = {
- 0x46c04778, // bx pc ... nop
- 0xe59fc004, // ldr r12, [pc, #4]
- 0xe08fc00c, // add ip, pc, ip
- 0xe12fff1c, // bx ip
- 0x0 // dcd R_ARM_REL32(X)
+ 0x46c04778, // bx pc ... nop
+ 0xe59fc004, // ldr r12, [pc, #4]
+ 0xe08fc00c, // add ip, pc, ip
+ 0xe12fff1c, // bx ip
+ 0x0 // dcd R_ARM_REL32(X)
};
const uint32_t THMToTHMStub::TEMPLATE[] = {
- 0x46c04778, // bx pc ... nop
- 0xe59fc000, // ldr ip, [pc, #0]
- 0xe12fff1c, // bx ip
- 0x0 // dcd R_ARM_ABS32(X)
+ 0x46c04778, // bx pc ... nop
+ 0xe59fc000, // ldr ip, [pc, #0]
+ 0xe12fff1c, // bx ip
+ 0x0 // dcd R_ARM_ABS32(X)
};
THMToTHMStub::THMToTHMStub(bool pIsOutputPIC, bool pUsingThumb2)
- : m_pData(NULL),
- m_Name("T2T_prototype"),
- m_Size(0x0),
- m_bUsingThumb2(pUsingThumb2)
-{
+ : m_pData(NULL),
+ m_Name("T2T_prototype"),
+ m_Size(0x0),
+ m_bUsingThumb2(pUsingThumb2) {
if (pIsOutputPIC) {
m_pData = PIC_TEMPLATE;
m_Size = sizeof(PIC_TEMPLATE);
@@ -58,23 +58,20 @@ THMToTHMStub::THMToTHMStub(const uint32_t* pData,
const_fixup_iterator pBegin,
const_fixup_iterator pEnd,
bool pUsingThumb2)
- : m_pData(pData),
- m_Name("T2T_veneer"),
- m_Size(pSize),
- m_bUsingThumb2(pUsingThumb2)
-{
+ : m_pData(pData),
+ m_Name("T2T_veneer"),
+ m_Size(pSize),
+ m_bUsingThumb2(pUsingThumb2) {
for (const_fixup_iterator it = pBegin, ie = pEnd; it != ie; ++it)
addFixup(**it);
}
-THMToTHMStub::~THMToTHMStub()
-{
+THMToTHMStub::~THMToTHMStub() {
}
bool THMToTHMStub::isMyDuty(const class Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue) const
-{
+ uint64_t pTargetSymValue) const {
bool result = false;
// Check if the branch target is THUMB
if ((pTargetSymValue & 0x1) != 0x0) {
@@ -85,11 +82,11 @@ bool THMToTHMStub::isMyDuty(const class Relocation& pReloc,
uint64_t dest = pTargetSymValue + pReloc.addend() + 4u;
int64_t branch_offset = static_cast<int64_t>(dest) - pSource;
if (m_bUsingThumb2) {
- if ((branch_offset > ARMGNULDBackend::THM2_MAX_FWD_BRANCH_OFFSET) ||
- (branch_offset < ARMGNULDBackend::THM2_MAX_BWD_BRANCH_OFFSET)) {
- result = true;
- break;
- }
+ if ((branch_offset > ARMGNULDBackend::THM2_MAX_FWD_BRANCH_OFFSET) ||
+ (branch_offset < ARMGNULDBackend::THM2_MAX_BWD_BRANCH_OFFSET)) {
+ result = true;
+ break;
+ }
} else {
if ((branch_offset > ARMGNULDBackend::THM_MAX_FWD_BRANCH_OFFSET) ||
(branch_offset < ARMGNULDBackend::THM_MAX_BWD_BRANCH_OFFSET)) {
@@ -106,36 +103,29 @@ bool THMToTHMStub::isMyDuty(const class Relocation& pReloc,
return result;
}
-const std::string& THMToTHMStub::name() const
-{
+const std::string& THMToTHMStub::name() const {
return m_Name;
}
-const uint8_t* THMToTHMStub::getContent() const
-{
+const uint8_t* THMToTHMStub::getContent() const {
return reinterpret_cast<const uint8_t*>(m_pData);
}
-size_t THMToTHMStub::size() const
-{
+size_t THMToTHMStub::size() const {
return m_Size;
}
-size_t THMToTHMStub::alignment() const
-{
+size_t THMToTHMStub::alignment() const {
return 4u;
}
-uint64_t THMToTHMStub::initSymValue() const
-{
+uint64_t THMToTHMStub::initSymValue() const {
return 0x1;
}
-Stub* THMToTHMStub::doClone()
-{
- return new THMToTHMStub(m_pData,
- m_Size,
- fixup_begin(),
- fixup_end(),
- m_bUsingThumb2);
+Stub* THMToTHMStub::doClone() {
+ return new THMToTHMStub(
+ m_pData, m_Size, fixup_begin(), fixup_end(), m_bUsingThumb2);
}
+
+} // namespace mcld
diff --git a/lib/Target/ARM/THMToTHMStub.h b/lib/Target/ARM/THMToTHMStub.h
index 4f3f363..dc8ff90 100644
--- a/lib/Target/ARM/THMToTHMStub.h
+++ b/lib/Target/ARM/THMToTHMStub.h
@@ -6,16 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_ARM_THMTOTHMSTUB_H_
+#define TARGET_ARM_THMTOTHMSTUB_H_
-#ifndef TARGET_ARM_THMTOTHMSTUB_H
-#define TARGET_ARM_THMTOTHMSTUB_H
-
+#include "mcld/Fragment/Stub.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Fragment/Stub.h>
#include <string>
-namespace mcld
-{
+namespace mcld {
class Relocation;
class ResolveInfo;
@@ -24,9 +22,8 @@ class ResolveInfo;
* \brief ARM stub for long call from ARM source to ARM target
*
*/
-class THMToTHMStub : public Stub
-{
-public:
+class THMToTHMStub : public Stub {
+ public:
THMToTHMStub(bool pIsOutputPIC, bool pUsingThumb2);
~THMToTHMStub();
@@ -48,7 +45,7 @@ public:
// for T bit of this stub
uint64_t initSymValue() const;
-private:
+ private:
THMToTHMStub(const THMToTHMStub&);
THMToTHMStub& operator=(const THMToTHMStub&);
@@ -63,7 +60,7 @@ private:
/// doClone
Stub* doClone();
-private:
+ private:
static const uint32_t PIC_TEMPLATE[];
static const uint32_t TEMPLATE[];
const uint32_t* m_pData;
@@ -72,6 +69,6 @@ private:
bool m_bUsingThumb2;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_ARM_THMTOTHMSTUB_H_
diff --git a/lib/Target/ARM/TargetInfo/ARMTargetInfo.cpp b/lib/Target/ARM/TargetInfo/ARMTargetInfo.cpp
index de43662..cc50932 100644
--- a/lib/Target/ARM/TargetInfo/ARMTargetInfo.cpp
+++ b/lib/Target/ARM/TargetInfo/ARMTargetInfo.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Support/Target.h>
+#include "mcld/Support/Target.h"
+#include "mcld/Support/TargetRegistry.h"
namespace mcld {
@@ -20,5 +20,4 @@ extern "C" void MCLDInitializeARMLDTargetInfo() {
mcld::RegisterTarget<llvm::Triple::thumb> Y(TheThumbTarget, "thumb");
}
-} // namespace of mcld
-
+} // namespace mcld
diff --git a/lib/Target/Android.mk b/lib/Target/Android.mk
index e46a09f..aaeb589 100644
--- a/lib/Target/Android.mk
+++ b/lib/Target/Android.mk
@@ -6,7 +6,6 @@ mcld_target_SRC_FILES := \
ELFAttributeValue.cpp \
ELFDynamic.cpp \
ELFEmulation.cpp \
- ELFMCLinker.cpp \
GNUInfo.cpp \
GNULDBackend.cpp \
GOT.cpp \
diff --git a/lib/Target/ELFAttribute.cpp b/lib/Target/ELFAttribute.cpp
index ccffab7..04976bb 100644
--- a/lib/Target/ELFAttribute.cpp
+++ b/lib/Target/ELFAttribute.cpp
@@ -6,38 +6,36 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/ELFAttribute.h>
-
-#include <mcld/ADT/SizeTraits.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Support/LEB128.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Target/ELFAttributeValue.h>
-#include <mcld/Target/GNULDBackend.h>
+#include "mcld/Target/ELFAttribute.h"
+
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Support/LEB128.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/ELFAttributeValue.h"
+#include "mcld/Target/GNULDBackend.h"
#include <llvm/ADT/STLExtras.h>
#include <llvm/Support/Host.h>
#include <cstring>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// ELFAttribute
//===----------------------------------------------------------------------===//
-ELFAttribute::~ELFAttribute()
-{
+ELFAttribute::~ELFAttribute() {
llvm::DeleteContainerPointers(m_Subsections);
return;
}
-bool ELFAttribute::merge(const Input &pInput, LDSection &pInputAttrSectHdr)
-{
+bool ELFAttribute::merge(const Input& pInput, LDSection& pInputAttrSectHdr) {
// Skip corrupt subsection
if (pInputAttrSectHdr.size() < MinimalELFAttributeSectionSize)
return true;
@@ -63,7 +61,7 @@ bool ELFAttribute::merge(const Input &pInput, LDSection &pInputAttrSectHdr)
// [ <uint32: subsection-length> NTBS: vendor-name
// <bytes: vendor-data>
// ]*
- const char *attribute_data = region.begin();
+ const char* attribute_data = region.begin();
// format-version
if (attribute_data[0] != FormatVersion) {
@@ -76,13 +74,13 @@ bool ELFAttribute::merge(const Input &pInput, LDSection &pInputAttrSectHdr)
// Iterate all subsections containing in this attribute section.
do {
- const char *subsection_data = region.begin() + subsection_offset;
+ const char* subsection_data = region.begin() + subsection_offset;
// subsection-length
uint32_t subsection_length =
*reinterpret_cast<const uint32_t*>(subsection_data);
- if(llvm::sys::IsLittleEndianHost != m_Config.targets().isLittleEndian())
+ if (llvm::sys::IsLittleEndianHost != m_Config.targets().isLittleEndian())
bswap32(subsection_length);
// vendor-name
@@ -95,19 +93,18 @@ bool ELFAttribute::merge(const Input &pInput, LDSection &pInputAttrSectHdr)
return true;
// Select the attribute subsection.
- Subsection *subsection = getSubsection(vendor_name);
+ Subsection* subsection = getSubsection(vendor_name);
// Only process the subsections whose vendor can be recognized.
if (subsection == NULL) {
- warning(diag::warn_unrecognized_vendor_subsection)
- << vendor_name << pInput.name();
+ warning(diag::warn_unrecognized_vendor_subsection) << vendor_name
+ << pInput.name();
} else {
// vendor-data
- size_t vendor_data_offset = subsection_offset +
- SubsectionLengthFieldSize +
- vendor_name_length;
- size_t vendor_data_size = subsection_length - SubsectionLengthFieldSize -
- vendor_name_length;
+ size_t vendor_data_offset =
+ subsection_offset + SubsectionLengthFieldSize + vendor_name_length;
+ size_t vendor_data_size =
+ subsection_length - SubsectionLengthFieldSize - vendor_name_length;
ConstAddress vendor_data =
reinterpret_cast<ConstAddress>(region.begin()) + vendor_data_offset;
@@ -118,25 +115,26 @@ bool ELFAttribute::merge(const Input &pInput, LDSection &pInputAttrSectHdr)
}
subsection_offset += subsection_length;
- } while ((subsection_offset + SubsectionLengthFieldSize) < pInputAttrSectHdr.size());
+ } while ((subsection_offset + SubsectionLengthFieldSize) <
+ pInputAttrSectHdr.size());
return true;
}
-size_t ELFAttribute::sizeOutput() const
-{
+size_t ELFAttribute::sizeOutput() const {
size_t total_size = FormatVersionFieldSize;
for (llvm::SmallVectorImpl<Subsection*>::const_iterator
- subsec_it = m_Subsections.begin(), subsec_end = m_Subsections.end();
- subsec_it != subsec_end; ++subsec_it) {
+ subsec_it = m_Subsections.begin(),
+ subsec_end = m_Subsections.end();
+ subsec_it != subsec_end;
+ ++subsec_it) {
total_size += (*subsec_it)->sizeOutput();
}
return total_size;
}
-size_t ELFAttribute::emit(MemoryRegion &pRegion) const
-{
+size_t ELFAttribute::emit(MemoryRegion& pRegion) const {
// ARM [ABI-addenda], 2.2.3
uint64_t total_size = 0;
@@ -146,8 +144,10 @@ size_t ELFAttribute::emit(MemoryRegion &pRegion) const
total_size += FormatVersionFieldSize;
for (llvm::SmallVectorImpl<Subsection*>::const_iterator
- subsec_it = m_Subsections.begin(), subsec_end = m_Subsections.end();
- subsec_it != subsec_end; ++subsec_it) {
+ subsec_it = m_Subsections.begin(),
+ subsec_end = m_Subsections.end();
+ subsec_it != subsec_end;
+ ++subsec_it) {
// Write out subsection.
total_size += (*subsec_it)->emit(buffer + total_size);
}
@@ -155,21 +155,21 @@ size_t ELFAttribute::emit(MemoryRegion &pRegion) const
return total_size;
}
-void ELFAttribute::registerAttributeData(ELFAttributeData& pAttrData)
-{
+void ELFAttribute::registerAttributeData(ELFAttributeData& pAttrData) {
assert((getSubsection(pAttrData.getVendorName()) == NULL) &&
"Multiple attribute data for a vendor!");
m_Subsections.push_back(new Subsection(*this, pAttrData));
return;
}
-ELFAttribute::Subsection *
-ELFAttribute::getSubsection(llvm::StringRef pVendorName) const
-{
+ELFAttribute::Subsection* ELFAttribute::getSubsection(
+ llvm::StringRef pVendorName) const {
// Search m_Subsections linearly.
for (llvm::SmallVectorImpl<Subsection*>::const_iterator
- subsec_it = m_Subsections.begin(), subsec_end = m_Subsections.end();
- subsec_it != subsec_end; ++subsec_it) {
+ subsec_it = m_Subsections.begin(),
+ subsec_end = m_Subsections.end();
+ subsec_it != subsec_end;
+ ++subsec_it) {
Subsection* const subsection = *subsec_it;
if (subsection->isMyAttribute(pVendorName)) {
return subsection;
@@ -183,12 +183,11 @@ ELFAttribute::getSubsection(llvm::StringRef pVendorName) const
//===----------------------------------------------------------------------===//
// ELFAttribute::Subsection
//===----------------------------------------------------------------------===//
-bool ELFAttribute::Subsection::merge(const Input &pInput,
+bool ELFAttribute::Subsection::merge(const Input& pInput,
ConstAddress pData,
- size_t pSize)
-{
+ size_t pSize) {
const bool need_swap = (llvm::sys::IsLittleEndianHost !=
- m_Parent.config().targets().isLittleEndian());
+ m_Parent.config().targets().isLittleEndian());
// Read attribute sub-subsection from vendor data.
//
// ARM [ABI-addenda], 2.2.4:
@@ -197,7 +196,7 @@ bool ELFAttribute::Subsection::merge(const Input &pInput,
// | Tag_Section (=2) <uint32: byte-size> <section number>* 0 <attribute>*
// | Tag_symbol (=3) <unit32: byte-size> <symbol number>* 0 <attribute>*
// ] +
- const char *subsubsection_data = reinterpret_cast<const char*>(pData);
+ const char* subsubsection_data = reinterpret_cast<const char*>(pData);
size_t remaining_size = pSize;
if (!m_AttrData.preMerge(pInput)) {
@@ -238,7 +237,7 @@ bool ELFAttribute::Subsection::merge(const Input &pInput,
if (!ELFAttributeData::ReadTag(tag, attr_buf, attr_size))
break;
- ELFAttributeValue *out_attr;
+ ELFAttributeValue* out_attr;
bool is_newly_created;
std::tie(out_attr, is_newly_created) =
@@ -277,49 +276,44 @@ bool ELFAttribute::Subsection::merge(const Input &pInput,
case ELFAttributeData::Tag_Section:
case ELFAttributeData::Tag_Symbol:
// Skip any unknown tags.
- default: {
- break;
- }
+ default: { break; }
}
// Update subsubsection_data and remaining_size for next.
subsubsection_data += subsubsection_length;
remaining_size -= subsubsection_length;
- } // while (remaining_size > ELFAttribute::MinimalELFAttributeSubsectionSize)
+ } // while (remaining_size > ELFAttribute::MinimalELFAttributeSubsectionSize)
return m_AttrData.postMerge(m_Parent.config(), pInput);
}
-size_t ELFAttribute::Subsection::sizeOutput() const
-{
+size_t ELFAttribute::Subsection::sizeOutput() const {
// ARM [ABI-addenda], 2.2.3 and 2.2.4
return ELFAttribute::SubsectionLengthFieldSize +
- m_AttrData.getVendorName().length() /* vendor-name */ +
- 1 /* NULL-terminator for vendor-name */ +
- 1 /* Tag_File */ +
- sizeof(uint32_t) /* length of sub-subsection */ +
- m_AttrData.sizeOutput();
+ m_AttrData.getVendorName().length() /* vendor-name */ +
+ 1 /* NULL-terminator for vendor-name */ + 1 /* Tag_File */ +
+ sizeof(uint32_t) /* length of sub-subsection */ +
+ m_AttrData.sizeOutput();
}
-size_t ELFAttribute::Subsection::emit(char *pBuf) const
-{
+size_t ELFAttribute::Subsection::emit(char* pBuf) const {
// ARM [ABI-addenda], 2.2.3 and 2.2.4
const bool need_swap = (llvm::sys::IsLittleEndianHost !=
- m_Parent.config().targets().isLittleEndian());
+ m_Parent.config().targets().isLittleEndian());
- char *buffer = pBuf;
+ char* buffer = pBuf;
// The subsection-length and byte-size field in sub-subsection will be patched
// later after writing out all attribute data.
- char *subsection_length_hole = NULL;
- char *subsubsection_length_hole = NULL;
+ char* subsection_length_hole = NULL;
+ char* subsubsection_length_hole = NULL;
// Reserve space for subsection-length.
subsection_length_hole = buffer;
buffer += 4;
// Write vendor-name.
- const std::string &vendor_name = m_AttrData.getVendorName();
+ const std::string& vendor_name = m_AttrData.getVendorName();
::memcpy(buffer, vendor_name.c_str(), vendor_name.length());
buffer += vendor_name.length();
@@ -348,13 +342,13 @@ size_t ELFAttribute::Subsection::emit(char *pBuf) const
// Patch subsubsection_length_hole.
assert(subsubsection_length_hole != NULL);
- if(need_swap)
+ if (need_swap)
bswap32(subsubsection_length);
::memcpy(subsubsection_length_hole, &subsubsection_length, sizeof(uint32_t));
// Write subsection-length in subsection_length_hole.
- if(need_swap)
+ if (need_swap)
bswap32(subsection_length);
assert(subsection_length_hole != NULL);
@@ -362,3 +356,5 @@ size_t ELFAttribute::Subsection::emit(char *pBuf) const
return subsection_length;
}
+
+} // namespace mcld
diff --git a/lib/Target/ELFAttributeData.cpp b/lib/Target/ELFAttributeData.cpp
index c41918b..4e3e279 100644
--- a/lib/Target/ELFAttributeData.cpp
+++ b/lib/Target/ELFAttributeData.cpp
@@ -6,22 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/ELFAttributeData.h>
+#include "mcld/Target/ELFAttributeData.h"
-#include <mcld/Support/LEB128.h>
-#include <mcld/Target/ELFAttributeValue.h>
+#include "mcld/Support/LEB128.h"
+#include "mcld/Target/ELFAttributeValue.h"
#include <cstring>
#include <cassert>
-using namespace mcld;
+namespace mcld {
-bool ELFAttributeData::ReadTag(TagType& pTag, const char* &pBuf,
- size_t &pBufSize)
-{
+bool ELFAttributeData::ReadTag(TagType& pTag,
+ const char*& pBuf,
+ size_t& pBufSize) {
size_t size = 0;
pTag = static_cast<ELFAttributeData::TagType>(
- leb128::decode<uint64_t>(pBuf, size));
+ leb128::decode<uint64_t>(pBuf, size));
if (size > pBufSize)
return false;
@@ -32,9 +32,9 @@ bool ELFAttributeData::ReadTag(TagType& pTag, const char* &pBuf,
return true;
}
-bool ELFAttributeData::ReadValue(ELFAttributeValue& pValue, const char* &pBuf,
- size_t &pBufSize)
-{
+bool ELFAttributeData::ReadValue(ELFAttributeValue& pValue,
+ const char*& pBuf,
+ size_t& pBufSize) {
// An ULEB128-encoded value
if (pValue.isIntValue()) {
size_t size = 0;
@@ -63,8 +63,7 @@ bool ELFAttributeData::ReadValue(ELFAttributeValue& pValue, const char* &pBuf,
bool ELFAttributeData::WriteAttribute(TagType pTag,
const ELFAttributeValue& pValue,
- char* &pBuf)
-{
+ char*& pBuf) {
// Write the attribute tag.
leb128::encode<uint32_t>(pBuf, pTag);
@@ -86,3 +85,5 @@ bool ELFAttributeData::WriteAttribute(TagType pTag,
return true;
}
+
+} // namespace mcld
diff --git a/lib/Target/ELFAttributeValue.cpp b/lib/Target/ELFAttributeValue.cpp
index 0f99325..fff6c7d 100644
--- a/lib/Target/ELFAttributeValue.cpp
+++ b/lib/Target/ELFAttributeValue.cpp
@@ -7,16 +7,15 @@
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/ELFAttributeValue.h>
+#include "mcld/Target/ELFAttributeValue.h"
#include <llvm/Support/ErrorHandling.h>
-#include <mcld/Support/LEB128.h>
+#include "mcld/Support/LEB128.h"
-using namespace mcld;
+namespace mcld {
-size_t ELFAttributeValue::getSize() const
-{
+size_t ELFAttributeValue::getSize() const {
size_t size = 0;
if (isIntValue())
@@ -32,8 +31,7 @@ size_t ELFAttributeValue::getSize() const
return size;
}
-bool ELFAttributeValue::isDefaultValue() const
-{
+bool ELFAttributeValue::isDefaultValue() const {
if (isUninitialized()) {
// Uninitialized attribute means default value
return true;
@@ -51,8 +49,7 @@ bool ELFAttributeValue::isDefaultValue() const
// unreachable
}
-bool ELFAttributeValue::equals(const ELFAttributeValue& pValue) const
-{
+bool ELFAttributeValue::equals(const ELFAttributeValue& pValue) const {
if ((pValue.type() != m_Type) || isUninitialized())
return false;
@@ -64,3 +61,5 @@ bool ELFAttributeValue::equals(const ELFAttributeValue& pValue) const
return true;
}
+
+} // namespace mcld
diff --git a/lib/Target/ELFDynamic.cpp b/lib/Target/ELFDynamic.cpp
index 86de446..4318bfa 100644
--- a/lib/Target/ELFDynamic.cpp
+++ b/lib/Target/ELFDynamic.cpp
@@ -6,160 +6,151 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <llvm/Support/Host.h>
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/ELFDynamic.h"
+#include "mcld/Target/GNULDBackend.h"
+#include "mcld/LinkerConfig.h"
+
#include <llvm/Support/ErrorHandling.h>
-#include <mcld/Target/ELFDynamic.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Support/MsgHandling.h>
+#include <llvm/Support/Host.h>
-using namespace mcld;
-using namespace elf_dynamic;
+namespace mcld {
+namespace elf_dynamic {
//===----------------------------------------------------------------------===//
// elf_dynamic::EntryIF
//===----------------------------------------------------------------------===//
-EntryIF::EntryIF()
-{
+EntryIF::EntryIF() {
}
-EntryIF::~EntryIF()
-{
+EntryIF::~EntryIF() {
}
+} // namespace elf_dynamic
+
//===----------------------------------------------------------------------===//
// ELFDynamic
//===----------------------------------------------------------------------===//
-ELFDynamic::ELFDynamic(const GNULDBackend& pParent,
- const LinkerConfig& pConfig)
- : m_pEntryFactory(NULL), m_Backend(pParent), m_Config(pConfig), m_Idx(0) {
+ELFDynamic::ELFDynamic(const GNULDBackend& pParent, const LinkerConfig& pConfig)
+ : m_pEntryFactory(NULL), m_Backend(pParent), m_Config(pConfig), m_Idx(0) {
// FIXME: support big-endian machine.
if (m_Config.targets().is32Bits()) {
if (m_Config.targets().isLittleEndian())
- m_pEntryFactory = new Entry<32, true>();
+ m_pEntryFactory = new elf_dynamic::Entry<32, true>();
} else if (m_Config.targets().is64Bits()) {
if (m_Config.targets().isLittleEndian())
- m_pEntryFactory = new Entry<64, true>();
+ m_pEntryFactory = new elf_dynamic::Entry<64, true>();
} else {
fatal(diag::unsupported_bitclass) << m_Config.targets().triple().str()
<< m_Config.targets().bitclass();
}
}
-
-ELFDynamic::~ELFDynamic()
-{
- if (NULL != m_pEntryFactory)
+ELFDynamic::~ELFDynamic() {
+ if (m_pEntryFactory != NULL)
delete m_pEntryFactory;
EntryListType::iterator entry, entryEnd = m_EntryList.end();
for (entry = m_EntryList.begin(); entry != entryEnd; ++entry) {
- if (NULL != *entry)
+ if (*entry != NULL)
delete (*entry);
}
entryEnd = m_NeedList.end();
for (entry = m_NeedList.begin(); entry != entryEnd; ++entry) {
- if (NULL != *entry)
+ if (*entry != NULL)
delete (*entry);
}
}
-size_t ELFDynamic::size() const
-{
+size_t ELFDynamic::size() const {
return (m_NeedList.size() + m_EntryList.size());
}
-size_t ELFDynamic::numOfBytes() const
-{
- return size()*entrySize();
+size_t ELFDynamic::numOfBytes() const {
+ return size() * entrySize();
}
-size_t ELFDynamic::entrySize() const
-{
+size_t ELFDynamic::entrySize() const {
return m_pEntryFactory->size();
}
-void ELFDynamic::reserveOne(uint64_t pTag)
-{
- assert(NULL != m_pEntryFactory);
+void ELFDynamic::reserveOne(uint64_t pTag) {
+ assert(m_pEntryFactory != NULL);
m_EntryList.push_back(m_pEntryFactory->clone());
}
-void ELFDynamic::applyOne(uint64_t pTag, uint64_t pValue)
-{
+void ELFDynamic::applyOne(uint64_t pTag, uint64_t pValue) {
assert(m_Idx < m_EntryList.size());
m_EntryList[m_Idx]->setValue(pTag, pValue);
++m_Idx;
}
/// reserveEntries - reserve entries
-void ELFDynamic::reserveEntries(const ELFFileFormat& pFormat)
-{
+void ELFDynamic::reserveEntries(const ELFFileFormat& pFormat) {
if (LinkerConfig::DynObj == m_Config.codeGenType()) {
- reserveOne(llvm::ELF::DT_SONAME); // DT_SONAME
+ reserveOne(llvm::ELF::DT_SONAME);
if (m_Config.options().Bsymbolic())
- reserveOne(llvm::ELF::DT_SYMBOLIC); // DT_SYMBOLIC
+ reserveOne(llvm::ELF::DT_SYMBOLIC);
}
if (pFormat.hasInit())
- reserveOne(llvm::ELF::DT_INIT); // DT_INIT
+ reserveOne(llvm::ELF::DT_INIT);
if (pFormat.hasFini())
- reserveOne(llvm::ELF::DT_FINI); // DT_FINI
+ reserveOne(llvm::ELF::DT_FINI);
if (pFormat.hasPreInitArray()) {
- reserveOne(llvm::ELF::DT_PREINIT_ARRAY); // DT_PREINIT_ARRAY
- reserveOne(llvm::ELF::DT_PREINIT_ARRAYSZ); // DT_PREINIT_ARRAYSZ
+ reserveOne(llvm::ELF::DT_PREINIT_ARRAY);
+ reserveOne(llvm::ELF::DT_PREINIT_ARRAYSZ);
}
if (pFormat.hasInitArray()) {
- reserveOne(llvm::ELF::DT_INIT_ARRAY); // DT_INIT_ARRAY
- reserveOne(llvm::ELF::DT_INIT_ARRAYSZ); // DT_INIT_ARRAYSZ
+ reserveOne(llvm::ELF::DT_INIT_ARRAY);
+ reserveOne(llvm::ELF::DT_INIT_ARRAYSZ);
}
if (pFormat.hasFiniArray()) {
- reserveOne(llvm::ELF::DT_FINI_ARRAY); // DT_FINI_ARRAY
- reserveOne(llvm::ELF::DT_FINI_ARRAYSZ); // DT_FINI_ARRAYSZ
+ reserveOne(llvm::ELF::DT_FINI_ARRAY);
+ reserveOne(llvm::ELF::DT_FINI_ARRAYSZ);
}
if (pFormat.hasHashTab())
- reserveOne(llvm::ELF::DT_HASH); // DT_HASH
+ reserveOne(llvm::ELF::DT_HASH);
- // FIXME: use llvm enum constant
if (pFormat.hasGNUHashTab())
- reserveOne(0x6ffffef5); // DT_GNU_HASH
+ reserveOne(llvm::ELF::DT_GNU_HASH);
if (pFormat.hasDynSymTab()) {
- reserveOne(llvm::ELF::DT_SYMTAB); // DT_SYMTAB
- reserveOne(llvm::ELF::DT_SYMENT); // DT_SYMENT
+ reserveOne(llvm::ELF::DT_SYMTAB);
+ reserveOne(llvm::ELF::DT_SYMENT);
}
if (pFormat.hasDynStrTab()) {
- reserveOne(llvm::ELF::DT_STRTAB); // DT_STRTAB
- reserveOne(llvm::ELF::DT_STRSZ); // DT_STRSZ
+ reserveOne(llvm::ELF::DT_STRTAB);
+ reserveOne(llvm::ELF::DT_STRSZ);
}
- reserveTargetEntries(pFormat); // DT_PLTGOT
+ reserveTargetEntries(pFormat);
if (pFormat.hasRelPlt() || pFormat.hasRelaPlt()) {
- reserveOne(llvm::ELF::DT_PLTREL); // DT_PLTREL
- reserveOne(llvm::ELF::DT_JMPREL); // DT_JMPREL
- reserveOne(llvm::ELF::DT_PLTRELSZ); // DT_PLTRELSZ
+ reserveOne(llvm::ELF::DT_PLTREL);
+ reserveOne(llvm::ELF::DT_JMPREL);
+ reserveOne(llvm::ELF::DT_PLTRELSZ);
}
if (pFormat.hasRelDyn()) {
- reserveOne(llvm::ELF::DT_REL); // DT_REL
- reserveOne(llvm::ELF::DT_RELSZ); // DT_RELSZ
- reserveOne(llvm::ELF::DT_RELENT); // DT_RELENT
+ reserveOne(llvm::ELF::DT_REL);
+ reserveOne(llvm::ELF::DT_RELSZ);
+ reserveOne(llvm::ELF::DT_RELENT);
}
if (pFormat.hasRelaDyn()) {
- reserveOne(llvm::ELF::DT_RELA); // DT_RELA
- reserveOne(llvm::ELF::DT_RELASZ); // DT_RELASZ
- reserveOne(llvm::ELF::DT_RELAENT); // DT_RELAENT
+ reserveOne(llvm::ELF::DT_RELA);
+ reserveOne(llvm::ELF::DT_RELASZ);
+ reserveOne(llvm::ELF::DT_RELAENT);
}
uint64_t dt_flags = 0x0;
@@ -175,111 +166,96 @@ void ELFDynamic::reserveEntries(const ELFFileFormat& pFormat)
(LinkerConfig::DynObj == m_Config.codeGenType()))
dt_flags |= llvm::ELF::DF_STATIC_TLS;
- if ((m_Config.options().hasNewDTags() && 0x0 != dt_flags) ||
- 0 != (dt_flags & llvm::ELF::DF_STATIC_TLS))
- reserveOne(llvm::ELF::DT_FLAGS); // DT_FLAGS
+ if ((m_Config.options().hasNewDTags() && dt_flags != 0x0) ||
+ (dt_flags & llvm::ELF::DF_STATIC_TLS) != 0x0)
+ reserveOne(llvm::ELF::DT_FLAGS);
if (m_Backend.hasTextRel())
- reserveOne(llvm::ELF::DT_TEXTREL); // DT_TEXTREL
-
- if (m_Config.options().hasNow() ||
- m_Config.options().hasLoadFltr() ||
- m_Config.options().hasOrigin() ||
- m_Config.options().hasInterPose() ||
- m_Config.options().hasNoDefaultLib() ||
- m_Config.options().hasNoDump() ||
- m_Config.options().Bgroup() ||
+ reserveOne(llvm::ELF::DT_TEXTREL);
+
+ if (m_Config.options().hasNow() || m_Config.options().hasLoadFltr() ||
+ m_Config.options().hasOrigin() || m_Config.options().hasInterPose() ||
+ m_Config.options().hasNoDefaultLib() || m_Config.options().hasNoDump() ||
+ m_Config.options().Bgroup() ||
((LinkerConfig::DynObj == m_Config.codeGenType()) &&
- (m_Config.options().hasNoDelete() ||
- m_Config.options().hasInitFirst() ||
+ (m_Config.options().hasNoDelete() || m_Config.options().hasInitFirst() ||
m_Config.options().hasNoDLOpen()))) {
- reserveOne(llvm::ELF::DT_FLAGS_1); // DT_FLAGS_1
+ reserveOne(llvm::ELF::DT_FLAGS_1);
}
- reserveOne(llvm::ELF::DT_NULL); // for DT_NULL
+ reserveOne(llvm::ELF::DT_NULL);
}
/// applyEntries - apply entries
-void ELFDynamic::applyEntries(const ELFFileFormat& pFormat)
-{
+void ELFDynamic::applyEntries(const ELFFileFormat& pFormat) {
if (LinkerConfig::DynObj == m_Config.codeGenType() &&
m_Config.options().Bsymbolic()) {
- applyOne(llvm::ELF::DT_SYMBOLIC, 0x0); // DT_SYMBOLIC
+ applyOne(llvm::ELF::DT_SYMBOLIC, 0x0);
}
if (pFormat.hasInit())
- applyOne(llvm::ELF::DT_INIT, pFormat.getInit().addr()); // DT_INIT
+ applyOne(llvm::ELF::DT_INIT, pFormat.getInit().addr());
if (pFormat.hasFini())
- applyOne(llvm::ELF::DT_FINI, pFormat.getFini().addr()); // DT_FINI
+ applyOne(llvm::ELF::DT_FINI, pFormat.getFini().addr());
if (pFormat.hasPreInitArray()) {
- // DT_PREINIT_ARRAY
applyOne(llvm::ELF::DT_PREINIT_ARRAY, pFormat.getPreInitArray().addr());
- // DT_PREINIT_ARRAYSZ
applyOne(llvm::ELF::DT_PREINIT_ARRAYSZ, pFormat.getPreInitArray().size());
}
if (pFormat.hasInitArray()) {
- // DT_INIT_ARRAY
applyOne(llvm::ELF::DT_INIT_ARRAY, pFormat.getInitArray().addr());
-
- // DT_INIT_ARRAYSZ
applyOne(llvm::ELF::DT_INIT_ARRAYSZ, pFormat.getInitArray().size());
}
if (pFormat.hasFiniArray()) {
- // DT_FINI_ARRAY
applyOne(llvm::ELF::DT_FINI_ARRAY, pFormat.getFiniArray().addr());
-
- // DT_FINI_ARRAYSZ
applyOne(llvm::ELF::DT_FINI_ARRAYSZ, pFormat.getFiniArray().size());
}
if (pFormat.hasHashTab())
- applyOne(llvm::ELF::DT_HASH, pFormat.getHashTab().addr()); // DT_HASH
+ applyOne(llvm::ELF::DT_HASH, pFormat.getHashTab().addr());
- // FIXME: use llvm enum constant
if (pFormat.hasGNUHashTab())
- applyOne(0x6ffffef5, pFormat.getGNUHashTab().addr()); // DT_GNU_HASH
+ applyOne(llvm::ELF::DT_GNU_HASH, pFormat.getGNUHashTab().addr());
if (pFormat.hasDynSymTab()) {
- applyOne(llvm::ELF::DT_SYMTAB, pFormat.getDynSymTab().addr()); // DT_SYMTAB
- applyOne(llvm::ELF::DT_SYMENT, symbolSize()); // DT_SYMENT
+ applyOne(llvm::ELF::DT_SYMTAB, pFormat.getDynSymTab().addr());
+ applyOne(llvm::ELF::DT_SYMENT, symbolSize());
}
if (pFormat.hasDynStrTab()) {
- applyOne(llvm::ELF::DT_STRTAB, pFormat.getDynStrTab().addr()); // DT_STRTAB
- applyOne(llvm::ELF::DT_STRSZ, pFormat.getDynStrTab().size()); // DT_STRSZ
+ applyOne(llvm::ELF::DT_STRTAB, pFormat.getDynStrTab().addr());
+ applyOne(llvm::ELF::DT_STRSZ, pFormat.getDynStrTab().size());
}
- applyTargetEntries(pFormat); // DT_PLTGOT
+ applyTargetEntries(pFormat);
if (pFormat.hasRelPlt()) {
- applyOne(llvm::ELF::DT_PLTREL, llvm::ELF::DT_REL); // DT_PLTREL
- applyOne(llvm::ELF::DT_JMPREL, pFormat.getRelPlt().addr()); // DT_JMPREL
- applyOne(llvm::ELF::DT_PLTRELSZ, pFormat.getRelPlt().size()); // DT_PLTRELSZ
- }
- else if (pFormat.hasRelaPlt()) {
- applyOne(llvm::ELF::DT_PLTREL, llvm::ELF::DT_RELA); // DT_PLTREL
- applyOne(llvm::ELF::DT_JMPREL, pFormat.getRelaPlt().addr()); // DT_JMPREL
- applyOne(llvm::ELF::DT_PLTRELSZ, pFormat.getRelaPlt().size()); // DT_PLTRELSZ
+ applyOne(llvm::ELF::DT_PLTREL, llvm::ELF::DT_REL);
+ applyOne(llvm::ELF::DT_JMPREL, pFormat.getRelPlt().addr());
+ applyOne(llvm::ELF::DT_PLTRELSZ, pFormat.getRelPlt().size());
+ } else if (pFormat.hasRelaPlt()) {
+ applyOne(llvm::ELF::DT_PLTREL, llvm::ELF::DT_RELA);
+ applyOne(llvm::ELF::DT_JMPREL, pFormat.getRelaPlt().addr());
+ applyOne(llvm::ELF::DT_PLTRELSZ, pFormat.getRelaPlt().size());
}
if (pFormat.hasRelDyn()) {
- applyOne(llvm::ELF::DT_REL, pFormat.getRelDyn().addr()); // DT_REL
- applyOne(llvm::ELF::DT_RELSZ, pFormat.getRelDyn().size()); // DT_RELSZ
- applyOne(llvm::ELF::DT_RELENT, m_pEntryFactory->relSize()); // DT_RELENT
+ applyOne(llvm::ELF::DT_REL, pFormat.getRelDyn().addr());
+ applyOne(llvm::ELF::DT_RELSZ, pFormat.getRelDyn().size());
+ applyOne(llvm::ELF::DT_RELENT, m_pEntryFactory->relSize());
}
if (pFormat.hasRelaDyn()) {
- applyOne(llvm::ELF::DT_RELA, pFormat.getRelaDyn().addr()); // DT_RELA
- applyOne(llvm::ELF::DT_RELASZ, pFormat.getRelaDyn().size()); // DT_RELASZ
- applyOne(llvm::ELF::DT_RELAENT, m_pEntryFactory->relaSize()); // DT_RELAENT
+ applyOne(llvm::ELF::DT_RELA, pFormat.getRelaDyn().addr());
+ applyOne(llvm::ELF::DT_RELASZ, pFormat.getRelaDyn().size());
+ applyOne(llvm::ELF::DT_RELAENT, m_pEntryFactory->relaSize());
}
if (m_Backend.hasTextRel()) {
- applyOne(llvm::ELF::DT_TEXTREL, 0x0); // DT_TEXTREL
+ applyOne(llvm::ELF::DT_TEXTREL, 0x0);
if (m_Config.options().warnSharedTextrel() &&
LinkerConfig::DynObj == m_Config.codeGenType())
@@ -299,9 +275,9 @@ void ELFDynamic::applyEntries(const ELFFileFormat& pFormat)
(LinkerConfig::DynObj == m_Config.codeGenType()))
dt_flags |= llvm::ELF::DF_STATIC_TLS;
- if ((m_Config.options().hasNewDTags() && 0x0 != dt_flags) ||
- 0 != (dt_flags & llvm::ELF::DF_STATIC_TLS))
- applyOne(llvm::ELF::DT_FLAGS, dt_flags); // DT_FLAGS
+ if ((m_Config.options().hasNewDTags() && dt_flags != 0x0) ||
+ (dt_flags & llvm::ELF::DF_STATIC_TLS) != 0)
+ applyOne(llvm::ELF::DT_FLAGS, dt_flags);
uint64_t dt_flags_1 = 0x0;
if (m_Config.options().hasNow())
@@ -326,33 +302,30 @@ void ELFDynamic::applyEntries(const ELFFileFormat& pFormat)
if (m_Config.options().hasNoDLOpen())
dt_flags_1 |= llvm::ELF::DF_1_NOOPEN;
}
- if (0x0 != dt_flags_1)
- applyOne(llvm::ELF::DT_FLAGS_1, dt_flags_1); // DT_FLAGS_1
+ if (dt_flags_1 != 0x0)
+ applyOne(llvm::ELF::DT_FLAGS_1, dt_flags_1);
- applyOne(llvm::ELF::DT_NULL, 0x0); // for DT_NULL
+ applyOne(llvm::ELF::DT_NULL, 0x0);
}
/// symbolSize
-size_t ELFDynamic::symbolSize() const
-{
+size_t ELFDynamic::symbolSize() const {
return m_pEntryFactory->symbolSize();
}
/// reserveNeedEntry - reserve on DT_NEED entry.
-void ELFDynamic::reserveNeedEntry()
-{
+void ELFDynamic::reserveNeedEntry() {
m_NeedList.push_back(m_pEntryFactory->clone());
}
/// emit
-void ELFDynamic::emit(const LDSection& pSection, MemoryRegion& pRegion) const
-{
+void ELFDynamic::emit(const LDSection& pSection, MemoryRegion& pRegion) const {
if (pRegion.size() < pSection.size()) {
llvm::report_fatal_error(llvm::Twine("the given memory is smaller") +
llvm::Twine(" than the section's demaind.\n"));
}
- uint8_t* address = (uint8_t*)pRegion.begin();
+ uint8_t* address = reinterpret_cast<uint8_t*>(pRegion.begin());
EntryListType::const_iterator entry, entryEnd = m_NeedList.end();
for (entry = m_NeedList.begin(); entry != entryEnd; ++entry)
address += (*entry)->emit(address);
@@ -362,8 +335,8 @@ void ELFDynamic::emit(const LDSection& pSection, MemoryRegion& pRegion) const
address += (*entry)->emit(address);
}
-void ELFDynamic::applySoname(uint64_t pStrTabIdx)
-{
- applyOne(llvm::ELF::DT_SONAME, pStrTabIdx); // DT_SONAME
+void ELFDynamic::applySoname(uint64_t pStrTabIdx) {
+ applyOne(llvm::ELF::DT_SONAME, pStrTabIdx);
}
+} // namespace mcld
diff --git a/lib/Target/ELFEmulation.cpp b/lib/Target/ELFEmulation.cpp
index a68e485..019c4ac 100644
--- a/lib/Target/ELFEmulation.cpp
+++ b/lib/Target/ELFEmulation.cpp
@@ -6,78 +6,76 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/ELFEmulation.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Script/InputSectDesc.h>
+#include "mcld/Target/ELFEmulation.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Script/InputSectDesc.h"
#include <llvm/Support/Host.h>
-using namespace mcld;
+namespace mcld {
struct NameMap {
- const char* from; ///< the prefix of the input string. (match FROM*)
- const char* to; ///< the output string.
- InputSectDesc::KeepPolicy policy; /// mark whether the input is kept in GC
+ const char* from; ///< the prefix of the input string. (match FROM*)
+ const char* to; ///< the output string.
+ InputSectDesc::KeepPolicy policy; /// mark whether the input is kept in GC
};
-static const NameMap map[] =
-{
- {".text*", ".text", InputSectDesc::NoKeep},
- {".rodata*", ".rodata", InputSectDesc::NoKeep},
- {".data.rel.ro.local*", ".data.rel.ro.local", InputSectDesc::NoKeep},
- {".data.rel.ro*", ".data.rel.ro", InputSectDesc::NoKeep},
- {".data*", ".data", InputSectDesc::NoKeep},
- {".bss*", ".bss", InputSectDesc::NoKeep},
- {".tdata*", ".tdata", InputSectDesc::NoKeep},
- {".tbss*", ".tbss", InputSectDesc::NoKeep},
- {".init", ".init", InputSectDesc::Keep},
- {".fini", ".fini", InputSectDesc::Keep},
- {".preinit_array*", ".preinit_array", InputSectDesc::Keep},
- {".init_array*", ".init_array", InputSectDesc::Keep},
- {".fini_array*", ".fini_array", InputSectDesc::Keep},
- // TODO: Support DT_INIT_ARRAY for all constructors?
- {".ctors*", ".ctors", InputSectDesc::Keep},
- {".dtors*", ".dtors", InputSectDesc::Keep},
- {".jcr", ".jcr", InputSectDesc::Keep},
- // FIXME: in GNU ld, if we are creating a shared object .sdata2 and .sbss2
- // sections would be handled differently.
- {".sdata2*", ".sdata", InputSectDesc::NoKeep},
- {".sbss2*", ".sbss", InputSectDesc::NoKeep},
- {".sdata*", ".sdata", InputSectDesc::NoKeep},
- {".sbss*", ".sbss", InputSectDesc::NoKeep},
- {".lrodata*", ".lrodata", InputSectDesc::NoKeep},
- {".ldata*", ".ldata", InputSectDesc::NoKeep},
- {".lbss*", ".lbss", InputSectDesc::NoKeep},
- {".gcc_except_table*", ".gcc_except_table", InputSectDesc::Keep},
- {".gnu.linkonce.d.rel.ro.local*", ".data.rel.ro.local", InputSectDesc::NoKeep},
- {".gnu.linkonce.d.rel.ro*", ".data.rel.ro", InputSectDesc::NoKeep},
- {".gnu.linkonce.r*", ".rodata", InputSectDesc::NoKeep},
- {".gnu.linkonce.d*", ".data", InputSectDesc::NoKeep},
- {".gnu.linkonce.b*", ".bss", InputSectDesc::NoKeep},
- {".gnu.linkonce.sb2*", ".sbss", InputSectDesc::NoKeep},
- {".gnu.linkonce.sb*", ".sbss", InputSectDesc::NoKeep},
- {".gnu.linkonce.s2*", ".sdata", InputSectDesc::NoKeep},
- {".gnu.linkonce.s*", ".sdata", InputSectDesc::NoKeep},
- {".gnu.linkonce.wi*", ".debug_info", InputSectDesc::NoKeep},
- {".gnu.linkonce.td*", ".tdata", InputSectDesc::NoKeep},
- {".gnu.linkonce.tb*", ".tbss", InputSectDesc::NoKeep},
- {".gnu.linkonce.t*", ".text", InputSectDesc::NoKeep},
- {".gnu.linkonce.lr*", ".lrodata", InputSectDesc::NoKeep},
- {".gnu.linkonce.lb*", ".lbss", InputSectDesc::NoKeep},
- {".gnu.linkonce.l*", ".ldata", InputSectDesc::NoKeep},
+static const NameMap map[] = {
+ {".text*", ".text", InputSectDesc::NoKeep},
+ {".rodata*", ".rodata", InputSectDesc::NoKeep},
+ {".data.rel.ro.local*", ".data.rel.ro.local", InputSectDesc::NoKeep},
+ {".data.rel.ro*", ".data.rel.ro", InputSectDesc::NoKeep},
+ {".data*", ".data", InputSectDesc::NoKeep},
+ {".bss*", ".bss", InputSectDesc::NoKeep},
+ {".tdata*", ".tdata", InputSectDesc::NoKeep},
+ {".tbss*", ".tbss", InputSectDesc::NoKeep},
+ {".init", ".init", InputSectDesc::Keep},
+ {".fini", ".fini", InputSectDesc::Keep},
+ {".preinit_array*", ".preinit_array", InputSectDesc::Keep},
+ {".init_array*", ".init_array", InputSectDesc::Keep},
+ {".fini_array*", ".fini_array", InputSectDesc::Keep},
+ // TODO: Support DT_INIT_ARRAY for all constructors?
+ {".ctors*", ".ctors", InputSectDesc::Keep},
+ {".dtors*", ".dtors", InputSectDesc::Keep},
+ {".jcr", ".jcr", InputSectDesc::Keep},
+ // FIXME: in GNU ld, if we are creating a shared object .sdata2 and .sbss2
+ // sections would be handled differently.
+ {".sdata2*", ".sdata", InputSectDesc::NoKeep},
+ {".sbss2*", ".sbss", InputSectDesc::NoKeep},
+ {".sdata*", ".sdata", InputSectDesc::NoKeep},
+ {".sbss*", ".sbss", InputSectDesc::NoKeep},
+ {".lrodata*", ".lrodata", InputSectDesc::NoKeep},
+ {".ldata*", ".ldata", InputSectDesc::NoKeep},
+ {".lbss*", ".lbss", InputSectDesc::NoKeep},
+ {".gcc_except_table*", ".gcc_except_table", InputSectDesc::Keep},
+ {".gnu.linkonce.d.rel.ro.local*", ".data.rel.ro.local", InputSectDesc::NoKeep}, // NOLINT
+ {".gnu.linkonce.d.rel.ro*", ".data.rel.ro", InputSectDesc::NoKeep},
+ {".gnu.linkonce.r*", ".rodata", InputSectDesc::NoKeep},
+ {".gnu.linkonce.d*", ".data", InputSectDesc::NoKeep},
+ {".gnu.linkonce.b*", ".bss", InputSectDesc::NoKeep},
+ {".gnu.linkonce.sb2*", ".sbss", InputSectDesc::NoKeep},
+ {".gnu.linkonce.sb*", ".sbss", InputSectDesc::NoKeep},
+ {".gnu.linkonce.s2*", ".sdata", InputSectDesc::NoKeep},
+ {".gnu.linkonce.s*", ".sdata", InputSectDesc::NoKeep},
+ {".gnu.linkonce.wi*", ".debug_info", InputSectDesc::NoKeep},
+ {".gnu.linkonce.td*", ".tdata", InputSectDesc::NoKeep},
+ {".gnu.linkonce.tb*", ".tbss", InputSectDesc::NoKeep},
+ {".gnu.linkonce.t*", ".text", InputSectDesc::NoKeep},
+ {".gnu.linkonce.lr*", ".lrodata", InputSectDesc::NoKeep},
+ {".gnu.linkonce.lb*", ".lbss", InputSectDesc::NoKeep},
+ {".gnu.linkonce.l*", ".ldata", InputSectDesc::NoKeep},
};
-bool mcld::MCLDEmulateELF(LinkerScript& pScript, LinkerConfig& pConfig)
// FIXME: LinkerConfig& pConfig should be constant
-{
+bool MCLDEmulateELF(LinkerScript& pScript, LinkerConfig& pConfig) {
// set up section map
if (pConfig.options().getScriptList().empty() &&
pConfig.codeGenType() != LinkerConfig::Object) {
- const unsigned int map_size = (sizeof(map) / sizeof(map[0]) );
+ const unsigned int map_size = (sizeof(map) / sizeof(map[0]));
for (unsigned int i = 0; i < map_size; ++i) {
std::pair<SectionMap::mapping, bool> res =
- pScript.sectionMap().insert(map[i].from, map[i].to, map[i].policy);
+ pScript.sectionMap().insert(map[i].from, map[i].to, map[i].policy);
if (!res.second)
return false;
}
@@ -94,7 +92,7 @@ bool mcld::MCLDEmulateELF(LinkerScript& pScript, LinkerConfig& pConfig)
case llvm::Triple::NetBSD:
pScript.directories().insert("=/usr/lib");
break;
- case llvm::Triple::MinGW32:
+ case llvm::Triple::Win32:
pScript.directories().insert("=/mingw/lib");
break;
default:
@@ -106,3 +104,4 @@ bool mcld::MCLDEmulateELF(LinkerScript& pScript, LinkerConfig& pConfig)
return true;
}
+} // namespace mcld
diff --git a/lib/Target/ELFMCLinker.cpp b/lib/Target/ELFMCLinker.cpp
deleted file mode 100644
index fae5c8c..0000000
--- a/lib/Target/ELFMCLinker.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-//===- ELFMCLinker.cpp ----------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include <mcld/Target/ELFMCLinker.h>
-
-using namespace mcld;
-
-//===----------------------------------------------------------------------===//
-// ELFMCLinker
-//===----------------------------------------------------------------------===//
-ELFMCLinker::ELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
- : MCLinker(pConfig, pModule, pFileHandle) {
-
-}
-
-ELFMCLinker::~ELFMCLinker()
-{
- // MCLinker will delete m_pLDBackend and m_pLDDriver;
-}
-
diff --git a/lib/Target/GNUInfo.cpp b/lib/Target/GNUInfo.cpp
index 75234b0..0ff1925 100644
--- a/lib/Target/GNUInfo.cpp
+++ b/lib/Target/GNUInfo.cpp
@@ -6,19 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/GNUInfo.h>
+#include "mcld/Target/GNUInfo.h"
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// GNUInfo
//===----------------------------------------------------------------------===//
-GNUInfo::GNUInfo(const llvm::Triple& pTriple)
- : m_Triple(pTriple) {
+GNUInfo::GNUInfo(const llvm::Triple& pTriple) : m_Triple(pTriple) {
}
-uint8_t GNUInfo::OSABI() const
-{
+uint8_t GNUInfo::OSABI() const {
switch (m_Triple.getOS()) {
case llvm::Triple::FreeBSD:
return llvm::ELF::ELFOSABI_FREEBSD;
@@ -29,3 +27,4 @@ uint8_t GNUInfo::OSABI() const
}
}
+} // namespace mcld
diff --git a/lib/Target/GNULDBackend.cpp b/lib/Target/GNULDBackend.cpp
index 7021c5f..cc38e94 100644
--- a/lib/Target/GNULDBackend.cpp
+++ b/lib/Target/GNULDBackend.cpp
@@ -6,41 +6,41 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/GNULDBackend.h>
-
-#include <mcld/Module.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/InputTree.h>
-#include <mcld/Config/Config.h>
-#include <mcld/ADT/SizeTraits.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/EhFrame.h>
-#include <mcld/LD/EhFrameHdr.h>
-#include <mcld/LD/RelocData.h>
-#include <mcld/LD/RelocationFactory.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/LD/StubFactory.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/ELFObjectFileFormat.h>
-#include <mcld/LD/ELFDynObjFileFormat.h>
-#include <mcld/LD/ELFExecFileFormat.h>
-#include <mcld/Target/ELFAttribute.h>
-#include <mcld/Target/ELFDynamic.h>
-#include <mcld/Target/GNUInfo.h>
-#include <mcld/Support/FileOutputBuffer.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/Object/SectionMap.h>
-#include <mcld/Script/RpnEvaluator.h>
-#include <mcld/Script/Operand.h>
-#include <mcld/Script/OutputSectDesc.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/MC/Attribute.h>
+#include "mcld/Target/GNULDBackend.h"
+
+#include "mcld/IRBuilder.h"
+#include "mcld/InputTree.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Module.h"
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/Config/Config.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/EhFrame.h"
+#include "mcld/LD/EhFrameHdr.h"
+#include "mcld/LD/ELFDynObjFileFormat.h"
+#include "mcld/LD/ELFExecFileFormat.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFObjectFileFormat.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/LD/RelocData.h"
+#include "mcld/LD/RelocationFactory.h"
+#include "mcld/LD/StubFactory.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Object/SectionMap.h"
+#include "mcld/Script/Operand.h"
+#include "mcld/Script/OutputSectDesc.h"
+#include "mcld/Script/RpnEvaluator.h"
+#include "mcld/Support/FileOutputBuffer.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/ELFAttribute.h"
+#include "mcld/Target/ELFDynamic.h"
+#include "mcld/Target/GNUInfo.h"
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/Host.h>
@@ -54,69 +54,67 @@
namespace {
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
// non-member functions
//===----------------------------------------------------------------------===//
static const std::string simple_c_identifier_allowed_chars =
- "0123456789"
- "ABCDEFGHIJKLMNOPWRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz"
- "_";
+ "0123456789"
+ "ABCDEFGHIJKLMNOPWRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "_";
/// isCIdentifier - return if the pName is a valid C identifier
-static bool isCIdentifier(const std::string& pName)
-{
- return (pName.find_first_not_of(simple_c_identifier_allowed_chars)
- == std::string::npos);
+static bool isCIdentifier(const std::string& pName) {
+ return (pName.find_first_not_of(simple_c_identifier_allowed_chars) ==
+ std::string::npos);
}
-} // anonymous namespace
+} // anonymous namespace
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// GNULDBackend
//===----------------------------------------------------------------------===//
GNULDBackend::GNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo)
- : TargetLDBackend(pConfig),
- m_pObjectReader(NULL),
- m_pDynObjFileFormat(NULL),
- m_pExecFileFormat(NULL),
- m_pObjectFileFormat(NULL),
- m_pInfo(pInfo),
- m_pELFSegmentTable(NULL),
- m_pBRIslandFactory(NULL),
- m_pStubFactory(NULL),
- m_pEhFrameHdr(NULL),
- m_pAttribute(NULL),
- m_bHasTextRel(false),
- m_bHasStaticTLS(false),
- f_pPreInitArrayStart(NULL),
- f_pPreInitArrayEnd(NULL),
- f_pInitArrayStart(NULL),
- f_pInitArrayEnd(NULL),
- f_pFiniArrayStart(NULL),
- f_pFiniArrayEnd(NULL),
- f_pStack(NULL),
- f_pDynamic(NULL),
- f_pTDATA(NULL),
- f_pTBSS(NULL),
- f_pExecutableStart(NULL),
- f_pEText(NULL),
- f_p_EText(NULL),
- f_p__EText(NULL),
- f_pEData(NULL),
- f_p_EData(NULL),
- f_pBSSStart(NULL),
- f_pEnd(NULL),
- f_p_End(NULL) {
+ : TargetLDBackend(pConfig),
+ m_pObjectReader(NULL),
+ m_pDynObjFileFormat(NULL),
+ m_pExecFileFormat(NULL),
+ m_pObjectFileFormat(NULL),
+ m_pInfo(pInfo),
+ m_pELFSegmentTable(NULL),
+ m_pBRIslandFactory(NULL),
+ m_pStubFactory(NULL),
+ m_pEhFrameHdr(NULL),
+ m_pAttribute(NULL),
+ m_bHasTextRel(false),
+ m_bHasStaticTLS(false),
+ f_pPreInitArrayStart(NULL),
+ f_pPreInitArrayEnd(NULL),
+ f_pInitArrayStart(NULL),
+ f_pInitArrayEnd(NULL),
+ f_pFiniArrayStart(NULL),
+ f_pFiniArrayEnd(NULL),
+ f_pStack(NULL),
+ f_pDynamic(NULL),
+ f_pTDATA(NULL),
+ f_pTBSS(NULL),
+ f_pExecutableStart(NULL),
+ f_pEText(NULL),
+ f_p_EText(NULL),
+ f_p__EText(NULL),
+ f_pEData(NULL),
+ f_p_EData(NULL),
+ f_pBSSStart(NULL),
+ f_pEnd(NULL),
+ f_p_End(NULL) {
m_pELFSegmentTable = new ELFSegmentFactory();
m_pSymIndexMap = new HashTableType(1024);
m_pAttribute = new ELFAttribute(*this, pConfig);
}
-GNULDBackend::~GNULDBackend()
-{
+GNULDBackend::~GNULDBackend() {
delete m_pELFSegmentTable;
delete m_pInfo;
delete m_pDynObjFileFormat;
@@ -129,8 +127,7 @@ GNULDBackend::~GNULDBackend()
delete m_pStubFactory;
}
-size_t GNULDBackend::sectionStartOffset() const
-{
+size_t GNULDBackend::sectionStartOffset() const {
if (LinkerConfig::Binary == config().codeGenType())
return 0x0;
@@ -148,10 +145,9 @@ size_t GNULDBackend::sectionStartOffset() const
}
}
-uint64_t GNULDBackend::getSegmentStartAddr(const LinkerScript& pScript) const
-{
+uint64_t GNULDBackend::getSegmentStartAddr(const LinkerScript& pScript) const {
LinkerScript::AddressMap::const_iterator mapping =
- pScript.addressMap().find(".text");
+ pScript.addressMap().find(".text");
if (pScript.addressMap().end() != mapping)
return mapping.getEntry()->value();
else if (config().isCodeIndep())
@@ -160,39 +156,32 @@ uint64_t GNULDBackend::getSegmentStartAddr(const LinkerScript& pScript) const
return m_pInfo->defaultTextSegmentAddr();
}
-GNUArchiveReader*
-GNULDBackend::createArchiveReader(Module& pModule)
-{
- assert(NULL != m_pObjectReader);
+GNUArchiveReader* GNULDBackend::createArchiveReader(Module& pModule) {
+ assert(m_pObjectReader != NULL);
return new GNUArchiveReader(pModule, *m_pObjectReader);
}
-ELFObjectReader* GNULDBackend::createObjectReader(IRBuilder& pBuilder)
-{
+ELFObjectReader* GNULDBackend::createObjectReader(IRBuilder& pBuilder) {
m_pObjectReader = new ELFObjectReader(*this, pBuilder, config());
return m_pObjectReader;
}
-ELFDynObjReader* GNULDBackend::createDynObjReader(IRBuilder& pBuilder)
-{
+ELFDynObjReader* GNULDBackend::createDynObjReader(IRBuilder& pBuilder) {
return new ELFDynObjReader(*this, pBuilder, config());
}
-ELFBinaryReader* GNULDBackend::createBinaryReader(IRBuilder& pBuilder)
-{
+ELFBinaryReader* GNULDBackend::createBinaryReader(IRBuilder& pBuilder) {
return new ELFBinaryReader(pBuilder, config());
}
-ELFObjectWriter* GNULDBackend::createWriter()
-{
+ELFObjectWriter* GNULDBackend::createWriter() {
return new ELFObjectWriter(*this, config());
}
-bool GNULDBackend::initStdSections(ObjectBuilder& pBuilder)
-{
+bool GNULDBackend::initStdSections(ObjectBuilder& pBuilder) {
switch (config().codeGenType()) {
case LinkerConfig::DynObj: {
- if (NULL == m_pDynObjFileFormat)
+ if (m_pDynObjFileFormat == NULL)
m_pDynObjFileFormat = new ELFDynObjFileFormat();
m_pDynObjFileFormat->initStdSections(pBuilder,
config().targets().bitclass());
@@ -200,14 +189,14 @@ bool GNULDBackend::initStdSections(ObjectBuilder& pBuilder)
}
case LinkerConfig::Exec:
case LinkerConfig::Binary: {
- if (NULL == m_pExecFileFormat)
+ if (m_pExecFileFormat == NULL)
m_pExecFileFormat = new ELFExecFileFormat();
m_pExecFileFormat->initStdSections(pBuilder,
config().targets().bitclass());
return true;
}
case LinkerConfig::Object: {
- if (NULL == m_pObjectFileFormat)
+ if (m_pObjectFileFormat == NULL)
m_pObjectFileFormat = new ELFObjectFileFormat();
m_pObjectFileFormat->initStdSections(pBuilder,
config().targets().bitclass());
@@ -221,15 +210,12 @@ bool GNULDBackend::initStdSections(ObjectBuilder& pBuilder)
/// initStandardSymbols - define and initialize standard symbols.
/// This function is called after section merging but before read relocations.
-bool GNULDBackend::initStandardSymbols(IRBuilder& pBuilder,
- Module& pModule)
-{
+bool GNULDBackend::initStandardSymbols(IRBuilder& pBuilder, Module& pModule) {
if (LinkerConfig::Object == config().codeGenType())
return true;
// GNU extension: define __start and __stop symbols for the sections whose
// name can be presented as C symbol
- // ref: GNU gold, Layout::define_section_symbols
Module::iterator iter, iterEnd = pModule.end();
for (iter = pModule.begin(); iter != iterEnd; ++iter) {
LDSection* section = *iter;
@@ -245,34 +231,35 @@ bool GNULDBackend::initStandardSymbols(IRBuilder& pBuilder,
if (!section->hasSectionData())
continue;
break;
- } // end of switch
+ } // end of switch
if (isCIdentifier(section->name())) {
std::string start_name = "__start_" + section->name();
- FragmentRef* start_fragref = FragmentRef::Create(
- section->getSectionData()->front(), 0x0);
+ FragmentRef* start_fragref =
+ FragmentRef::Create(section->getSectionData()->front(), 0x0);
+
pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- start_name,
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- start_fragref, // FragRef
- ResolveInfo::Default);
+ start_name,
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ start_fragref, // FragRef
+ ResolveInfo::Default);
std::string stop_name = "__stop_" + section->name();
FragmentRef* stop_fragref = FragmentRef::Create(
- section->getSectionData()->front(), section->size());
+ section->getSectionData()->front(), section->size());
pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- stop_name,
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- stop_fragref, // FragRef
- ResolveInfo::Default);
+ stop_name,
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ stop_fragref, // FragRef
+ ResolveInfo::Default);
}
}
@@ -283,402 +270,373 @@ bool GNULDBackend::initStandardSymbols(IRBuilder& pBuilder,
FragmentRef* preinit_array = NULL;
if (file_format->hasPreInitArray()) {
preinit_array = FragmentRef::Create(
- file_format->getPreInitArray().getSectionData()->front(),
- 0x0);
- }
- else {
+ file_format->getPreInitArray().getSectionData()->front(), 0x0);
+ } else {
preinit_array = FragmentRef::Null();
}
+
f_pPreInitArrayStart =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__preinit_array_start",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- preinit_array, // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__preinit_array_start",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ preinit_array, // FragRef
+ ResolveInfo::Hidden);
+
f_pPreInitArrayEnd =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__preinit_array_end",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__preinit_array_end",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Hidden);
// .init_array
FragmentRef* init_array = NULL;
if (file_format->hasInitArray()) {
init_array = FragmentRef::Create(
- file_format->getInitArray().getSectionData()->front(),
- 0x0);
- }
- else {
+ file_format->getInitArray().getSectionData()->front(), 0x0);
+ } else {
init_array = FragmentRef::Null();
}
f_pInitArrayStart =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__init_array_start",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- init_array, // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__init_array_start",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ init_array, // FragRef
+ ResolveInfo::Hidden);
+
f_pInitArrayEnd =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__init_array_end",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- init_array, // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__init_array_end",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ init_array, // FragRef
+ ResolveInfo::Hidden);
// .fini_array
FragmentRef* fini_array = NULL;
if (file_format->hasFiniArray()) {
fini_array = FragmentRef::Create(
- file_format->getFiniArray().getSectionData()->front(),
- 0x0);
- }
- else {
+ file_format->getFiniArray().getSectionData()->front(), 0x0);
+ } else {
fini_array = FragmentRef::Null();
}
f_pFiniArrayStart =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__fini_array_start",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- fini_array, // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__fini_array_start",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ fini_array, // FragRef
+ ResolveInfo::Hidden);
+
f_pFiniArrayEnd =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__fini_array_end",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- fini_array, // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__fini_array_end",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ fini_array, // FragRef
+ ResolveInfo::Hidden);
// .stack
FragmentRef* stack = NULL;
if (file_format->hasStack()) {
stack = FragmentRef::Create(
- file_format->getStack().getSectionData()->front(),
- 0x0);
- }
- else {
+ file_format->getStack().getSectionData()->front(), 0x0);
+ } else {
stack = FragmentRef::Null();
}
- f_pStack =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__stack",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Global,
- 0x0, // size
- 0x0, // value
- stack, // FragRef
- ResolveInfo::Hidden);
+ f_pStack = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__stack",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
+ 0x0, // size
+ 0x0, // value
+ stack, // FragRef
+ ResolveInfo::Hidden);
// _DYNAMIC
// TODO: add SectionData for .dynamic section, and then we can get the correct
// symbol section index for _DYNAMIC. Now it will be ABS.
- f_pDynamic =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_DYNAMIC",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Hidden);
+ f_pDynamic = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_DYNAMIC",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Hidden);
// ----- segment symbols ----- //
f_pExecutableStart =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__executable_start",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
- f_pEText =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "etext",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
- f_p_EText =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_etext",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
- f_p__EText =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__etext",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
- f_pEData =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "edata",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
-
- f_pEnd =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "end",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__executable_start",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
+
+ f_pEText = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "etext",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
+
+ f_p_EText = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_etext",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
+ f_p__EText = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "__etext",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
+ f_pEData = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "edata",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
+
+ f_pEnd = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "end",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
// _edata is defined forcefully.
- // @ref Google gold linker: defstd.cc: 186
- f_p_EData =
- pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_edata",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
+ f_p_EData = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
+ "_edata",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
// __bss_start is defined forcefully.
- // @ref Google gold linker: defstd.cc: 214
- f_pBSSStart =
- pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "__bss_start",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
+ f_pBSSStart = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
+ "__bss_start",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
// _end is defined forcefully.
- // @ref Google gold linker: defstd.cc: 228
- f_p_End =
- pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_end",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
+ f_p_End = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
+ "_end",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
return true;
}
-bool GNULDBackend::finalizeStandardSymbols()
-{
+bool GNULDBackend::finalizeStandardSymbols() {
if (LinkerConfig::Object == config().codeGenType())
return true;
ELFFileFormat* file_format = getOutputFormat();
// ----- section symbols ----- //
- if (NULL != f_pPreInitArrayStart) {
+ if (f_pPreInitArrayStart != NULL) {
if (!f_pPreInitArrayStart->hasFragRef()) {
f_pPreInitArrayStart->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pPreInitArrayStart->setValue(0x0);
}
}
- if (NULL != f_pPreInitArrayEnd) {
+ if (f_pPreInitArrayEnd != NULL) {
if (f_pPreInitArrayEnd->hasFragRef()) {
f_pPreInitArrayEnd->setValue(f_pPreInitArrayEnd->value() +
file_format->getPreInitArray().size());
- }
- else {
+ } else {
f_pPreInitArrayEnd->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pPreInitArrayEnd->setValue(0x0);
}
}
- if (NULL != f_pInitArrayStart) {
+ if (f_pInitArrayStart != NULL) {
if (!f_pInitArrayStart->hasFragRef()) {
f_pInitArrayStart->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pInitArrayStart->setValue(0x0);
}
}
- if (NULL != f_pInitArrayEnd) {
+ if (f_pInitArrayEnd != NULL) {
if (f_pInitArrayEnd->hasFragRef()) {
f_pInitArrayEnd->setValue(f_pInitArrayEnd->value() +
file_format->getInitArray().size());
- }
- else {
+ } else {
f_pInitArrayEnd->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pInitArrayEnd->setValue(0x0);
}
}
- if (NULL != f_pFiniArrayStart) {
+ if (f_pFiniArrayStart != NULL) {
if (!f_pFiniArrayStart->hasFragRef()) {
f_pFiniArrayStart->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pFiniArrayStart->setValue(0x0);
}
}
- if (NULL != f_pFiniArrayEnd) {
+ if (f_pFiniArrayEnd != NULL) {
if (f_pFiniArrayEnd->hasFragRef()) {
f_pFiniArrayEnd->setValue(f_pFiniArrayEnd->value() +
file_format->getFiniArray().size());
- }
- else {
+ } else {
f_pFiniArrayEnd->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pFiniArrayEnd->setValue(0x0);
}
}
- if (NULL != f_pStack) {
+ if (f_pStack != NULL) {
if (!f_pStack->hasFragRef()) {
f_pStack->resolveInfo()->setBinding(ResolveInfo::Absolute);
f_pStack->setValue(0x0);
}
}
- if (NULL != f_pDynamic) {
+ if (f_pDynamic != NULL) {
f_pDynamic->resolveInfo()->setBinding(ResolveInfo::Local);
f_pDynamic->setValue(file_format->getDynamic().addr());
f_pDynamic->setSize(file_format->getDynamic().size());
}
// ----- segment symbols ----- //
- if (NULL != f_pExecutableStart) {
+ if (f_pExecutableStart != NULL) {
ELFSegmentFactory::const_iterator exec_start =
- elfSegmentTable().find(llvm::ELF::PT_LOAD, 0x0, 0x0);
+ elfSegmentTable().find(llvm::ELF::PT_LOAD, 0x0, 0x0);
if (elfSegmentTable().end() != exec_start) {
if (ResolveInfo::ThreadLocal != f_pExecutableStart->type()) {
f_pExecutableStart->setValue(f_pExecutableStart->value() +
(*exec_start)->vaddr());
}
- }
- else
+ } else {
f_pExecutableStart->setValue(0x0);
+ }
}
- if (NULL != f_pEText || NULL != f_p_EText || NULL !=f_p__EText) {
- ELFSegmentFactory::const_iterator etext =
- elfSegmentTable().find(llvm::ELF::PT_LOAD,
- llvm::ELF::PF_X,
- llvm::ELF::PF_W);
+ if (f_pEText != NULL || f_p_EText != NULL || f_p__EText != NULL) {
+ ELFSegmentFactory::const_iterator etext = elfSegmentTable().find(
+ llvm::ELF::PT_LOAD, llvm::ELF::PF_X, llvm::ELF::PF_W);
if (elfSegmentTable().end() != etext) {
- if (NULL != f_pEText && ResolveInfo::ThreadLocal != f_pEText->type()) {
- f_pEText->setValue(f_pEText->value() +
- (*etext)->vaddr() +
+ if (f_pEText != NULL && ResolveInfo::ThreadLocal != f_pEText->type()) {
+ f_pEText->setValue(f_pEText->value() + (*etext)->vaddr() +
(*etext)->memsz());
}
- if (NULL != f_p_EText && ResolveInfo::ThreadLocal != f_p_EText->type()) {
- f_p_EText->setValue(f_p_EText->value() +
- (*etext)->vaddr() +
+ if (f_p_EText != NULL && ResolveInfo::ThreadLocal != f_p_EText->type()) {
+ f_p_EText->setValue(f_p_EText->value() + (*etext)->vaddr() +
(*etext)->memsz());
}
- if (NULL != f_p__EText && ResolveInfo::ThreadLocal != f_p__EText->type()) {
- f_p__EText->setValue(f_p__EText->value() +
- (*etext)->vaddr() +
- (*etext)->memsz());
+ if (f_p__EText != NULL &&
+ ResolveInfo::ThreadLocal != f_p__EText->type()) {
+ f_p__EText->setValue(f_p__EText->value() + (*etext)->vaddr() +
+ (*etext)->memsz());
}
- }
- else {
- if (NULL != f_pEText)
+ } else {
+ if (f_pEText != NULL)
f_pEText->setValue(0x0);
- if (NULL != f_p_EText)
+ if (f_p_EText != NULL)
f_p_EText->setValue(0x0);
- if (NULL != f_p__EText)
+ if (f_p__EText != NULL)
f_p__EText->setValue(0x0);
}
}
- if (NULL != f_pEData || NULL != f_p_EData || NULL != f_pBSSStart ||
- NULL != f_pEnd || NULL != f_p_End) {
+ if (f_pEData != NULL || f_p_EData != NULL || f_pBSSStart != NULL ||
+ f_pEnd != NULL || f_p_End != NULL) {
ELFSegmentFactory::const_iterator edata =
- elfSegmentTable().find(llvm::ELF::PT_LOAD, llvm::ELF::PF_W, 0x0);
+ elfSegmentTable().find(llvm::ELF::PT_LOAD, llvm::ELF::PF_W, 0x0);
if (elfSegmentTable().end() != edata) {
- if (NULL != f_pEData && ResolveInfo::ThreadLocal != f_pEData->type()) {
- f_pEData->setValue(f_pEData->value() +
- (*edata)->vaddr() +
+ if (f_pEData != NULL && ResolveInfo::ThreadLocal != f_pEData->type()) {
+ f_pEData->setValue(f_pEData->value() + (*edata)->vaddr() +
(*edata)->filesz());
}
- if (NULL != f_p_EData && ResolveInfo::ThreadLocal != f_p_EData->type()) {
- f_p_EData->setValue(f_p_EData->value() +
- (*edata)->vaddr() +
+ if (f_p_EData != NULL && ResolveInfo::ThreadLocal != f_p_EData->type()) {
+ f_p_EData->setValue(f_p_EData->value() + (*edata)->vaddr() +
(*edata)->filesz());
}
- if (NULL != f_pBSSStart && ResolveInfo::ThreadLocal != f_pBSSStart->type()) {
- f_pBSSStart->setValue(f_pBSSStart->value() +
- (*edata)->vaddr() +
+ if (f_pBSSStart != NULL &&
+ ResolveInfo::ThreadLocal != f_pBSSStart->type()) {
+ f_pBSSStart->setValue(f_pBSSStart->value() + (*edata)->vaddr() +
(*edata)->filesz());
}
- if (NULL != f_pEnd && ResolveInfo::ThreadLocal != f_pEnd->type()) {
- f_pEnd->setValue(f_pEnd->value() +
- (*edata)->vaddr() +
+ if (f_pEnd != NULL && ResolveInfo::ThreadLocal != f_pEnd->type()) {
+ f_pEnd->setValue(f_pEnd->value() + (*edata)->vaddr() +
(*edata)->memsz());
}
- if (NULL != f_p_End && ResolveInfo::ThreadLocal != f_p_End->type()) {
- f_p_End->setValue(f_p_End->value() +
- (*edata)->vaddr() +
+ if (f_p_End != NULL && ResolveInfo::ThreadLocal != f_p_End->type()) {
+ f_p_End->setValue(f_p_End->value() + (*edata)->vaddr() +
(*edata)->memsz());
}
- }
- else {
- if (NULL != f_pEData)
+ } else {
+ if (f_pEData != NULL)
f_pEData->setValue(0x0);
- if (NULL != f_p_EData)
+ if (f_p_EData != NULL)
f_p_EData->setValue(0x0);
- if (NULL != f_pBSSStart)
+ if (f_pBSSStart != NULL)
f_pBSSStart->setValue(0x0);
- if (NULL != f_pEnd)
+ if (f_pEnd != NULL)
f_pEnd->setValue(0x0);
- if (NULL != f_p_End)
+ if (f_p_End != NULL)
f_p_End->setValue(0x0);
}
}
@@ -686,34 +644,32 @@ bool GNULDBackend::finalizeStandardSymbols()
return true;
}
-bool GNULDBackend::finalizeTLSSymbol(LDSymbol& pSymbol)
-{
+bool GNULDBackend::finalizeTLSSymbol(LDSymbol& pSymbol) {
// ignore if symbol has no fragRef
if (!pSymbol.hasFragRef())
return true;
// the value of a TLS symbol is the offset to the TLS segment
ELFSegmentFactory::iterator tls_seg =
- elfSegmentTable().find(llvm::ELF::PT_TLS, llvm::ELF::PF_R, 0x0);
+ elfSegmentTable().find(llvm::ELF::PT_TLS, llvm::ELF::PF_R, 0x0);
assert(tls_seg != elfSegmentTable().end());
uint64_t value = pSymbol.fragRef()->getOutputOffset();
- uint64_t addr = pSymbol.fragRef()->frag()->getParent()->getSection().addr();
+ uint64_t addr = pSymbol.fragRef()->frag()->getParent()->getSection().addr();
pSymbol.setValue(value + addr - (*tls_seg)->vaddr());
return true;
}
-ELFFileFormat* GNULDBackend::getOutputFormat()
-{
+ELFFileFormat* GNULDBackend::getOutputFormat() {
switch (config().codeGenType()) {
case LinkerConfig::DynObj:
- assert(NULL != m_pDynObjFileFormat);
+ assert(m_pDynObjFileFormat != NULL);
return m_pDynObjFileFormat;
case LinkerConfig::Exec:
case LinkerConfig::Binary:
- assert(NULL != m_pExecFileFormat);
+ assert(m_pExecFileFormat != NULL);
return m_pExecFileFormat;
case LinkerConfig::Object:
- assert(NULL != m_pObjectFileFormat);
+ assert(m_pObjectFileFormat != NULL);
return m_pObjectFileFormat;
default:
fatal(diag::unrecognized_output_file) << config().codeGenType();
@@ -721,18 +677,17 @@ ELFFileFormat* GNULDBackend::getOutputFormat()
}
}
-const ELFFileFormat* GNULDBackend::getOutputFormat() const
-{
+const ELFFileFormat* GNULDBackend::getOutputFormat() const {
switch (config().codeGenType()) {
case LinkerConfig::DynObj:
- assert(NULL != m_pDynObjFileFormat);
+ assert(m_pDynObjFileFormat != NULL);
return m_pDynObjFileFormat;
case LinkerConfig::Exec:
case LinkerConfig::Binary:
- assert(NULL != m_pExecFileFormat);
+ assert(m_pExecFileFormat != NULL);
return m_pExecFileFormat;
case LinkerConfig::Object:
- assert(NULL != m_pObjectFileFormat);
+ assert(m_pObjectFileFormat != NULL);
return m_pObjectFileFormat;
default:
fatal(diag::unrecognized_output_file) << config().codeGenType();
@@ -741,35 +696,33 @@ const ELFFileFormat* GNULDBackend::getOutputFormat() const
}
/// sizeShstrtab - compute the size of .shstrtab
-void GNULDBackend::sizeShstrtab(Module& pModule)
-{
+void GNULDBackend::sizeShstrtab(Module& pModule) {
size_t shstrtab = 0;
// compute the size of .shstrtab section.
Module::const_iterator sect, sectEnd = pModule.end();
for (sect = pModule.begin(); sect != sectEnd; ++sect) {
shstrtab += (*sect)->name().size() + 1;
- } // end of for
+ } // end of for
getOutputFormat()->getShStrTab().setSize(shstrtab);
}
/// sizeNamePools - compute the size of regular name pools
/// In ELF executable files, regular name pools are .symtab, .strtab,
/// .dynsym, .dynstr, .hash and .shstrtab.
-void GNULDBackend::sizeNamePools(Module& pModule)
-{
+void GNULDBackend::sizeNamePools(Module& pModule) {
assert(LinkerConfig::Unset != config().codePosition());
// number of entries in symbol tables starts from 1 to hold the special entry
// at index 0 (STN_UNDEF). See ELF Spec Book I, p1-21.
size_t symtab = 1;
- size_t dynsym = config().isCodeStatic()? 0 : 1;
+ size_t dynsym = config().isCodeStatic() ? 0 : 1;
// size of string tables starts from 1 to hold the null character in their
// first byte
- size_t strtab = 1;
- size_t dynstr = config().isCodeStatic()? 0 : 1;
- size_t hash = 0;
- size_t gnuhash = 0;
+ size_t strtab = 1;
+ size_t dynstr = config().isCodeStatic() ? 0 : 1;
+ size_t hash = 0;
+ size_t gnuhash = 0;
// number of local symbol in the .symtab and .dynsym
size_t symtab_local_cnt = 0;
@@ -799,11 +752,11 @@ void GNULDBackend::sizeNamePools(Module& pModule)
symbols.numOfLocalDyns();
break;
}
- } // end of switch
+ } // end of switch
ELFFileFormat* file_format = getOutputFormat();
- switch(config().codeGenType()) {
+ switch (config().codeGenType()) {
case LinkerConfig::DynObj: {
// soname
dynstr += config().options().soname().size() + 1;
@@ -822,7 +775,7 @@ void GNULDBackend::sizeNamePools(Module& pModule)
dynsym_local_cnt = 1 + symbols.numOfLocalDyns();
// compute .gnu.hash
- if (GeneralOptions::GNU == config().options().getHashStyle() ||
+ if (GeneralOptions::GNU == config().options().getHashStyle() ||
GeneralOptions::Both == config().options().getHashStyle()) {
// count the number of dynsym to hash
size_t hashed_sym_cnt = 0;
@@ -862,9 +815,9 @@ void GNULDBackend::sizeNamePools(Module& pModule)
if (!config().options().getRpathList().empty()) {
dynamic().reserveNeedEntry();
GeneralOptions::const_rpath_iterator rpath,
- rpathEnd = config().options().rpath_end();
- for (rpath = config().options().rpath_begin();
- rpath != rpathEnd; ++rpath)
+ rpathEnd = config().options().rpath_end();
+ for (rpath = config().options().rpath_begin(); rpath != rpathEnd;
+ ++rpath)
dynstr += (*rpath).size() + 1;
}
@@ -894,9 +847,9 @@ void GNULDBackend::sizeNamePools(Module& pModule)
/* fall through */
case LinkerConfig::Object: {
if (config().targets().is32Bits())
- file_format->getSymTab().setSize(symtab*sizeof(llvm::ELF::Elf32_Sym));
+ file_format->getSymTab().setSize(symtab * sizeof(llvm::ELF::Elf32_Sym));
else
- file_format->getSymTab().setSize(symtab*sizeof(llvm::ELF::Elf64_Sym));
+ file_format->getSymTab().setSize(symtab * sizeof(llvm::ELF::Elf64_Sym));
file_format->getStrTab().setSize(strtab);
// set .symtab sh_info to one greater than the symbol table
@@ -911,7 +864,7 @@ void GNULDBackend::sizeNamePools(Module& pModule)
default:
fatal(diag::fatal_illegal_codegen_type) << pModule.name();
break;
- } // end of switch
+ } // end of switch
}
/// emitSymbol32 - emit an ELF32 symbol
@@ -919,22 +872,20 @@ void GNULDBackend::emitSymbol32(llvm::ELF::Elf32_Sym& pSym,
LDSymbol& pSymbol,
char* pStrtab,
size_t pStrtabsize,
- size_t pSymtabIdx)
-{
- // FIXME: check the endian between host and target
- // write out symbol
- if (hasEntryInStrTab(pSymbol)) {
- pSym.st_name = pStrtabsize;
- strcpy((pStrtab + pStrtabsize), pSymbol.name());
- }
- else {
- pSym.st_name = 0;
- }
- pSym.st_value = pSymbol.value();
- pSym.st_size = getSymbolSize(pSymbol);
- pSym.st_info = getSymbolInfo(pSymbol);
- pSym.st_other = pSymbol.visibility();
- pSym.st_shndx = getSymbolShndx(pSymbol);
+ size_t pSymtabIdx) {
+ // FIXME: check the endian between host and target
+ // write out symbol
+ if (hasEntryInStrTab(pSymbol)) {
+ pSym.st_name = pStrtabsize;
+ ::memcpy((pStrtab + pStrtabsize), pSymbol.name(), pSymbol.nameSize());
+ } else {
+ pSym.st_name = 0;
+ }
+ pSym.st_value = pSymbol.value();
+ pSym.st_size = getSymbolSize(pSymbol);
+ pSym.st_info = getSymbolInfo(pSymbol);
+ pSym.st_other = pSymbol.visibility();
+ pSym.st_shndx = getSymbolShndx(pSymbol);
}
/// emitSymbol64 - emit an ELF64 symbol
@@ -942,22 +893,20 @@ void GNULDBackend::emitSymbol64(llvm::ELF::Elf64_Sym& pSym,
LDSymbol& pSymbol,
char* pStrtab,
size_t pStrtabsize,
- size_t pSymtabIdx)
-{
- // FIXME: check the endian between host and target
- // write out symbol
- if (hasEntryInStrTab(pSymbol)) {
- pSym.st_name = pStrtabsize;
- strcpy((pStrtab + pStrtabsize), pSymbol.name());
- }
- else {
- pSym.st_name = 0;
- }
- pSym.st_value = pSymbol.value();
- pSym.st_size = getSymbolSize(pSymbol);
- pSym.st_info = getSymbolInfo(pSymbol);
- pSym.st_other = pSymbol.visibility();
- pSym.st_shndx = getSymbolShndx(pSymbol);
+ size_t pSymtabIdx) {
+ // FIXME: check the endian between host and target
+ // write out symbol
+ if (hasEntryInStrTab(pSymbol)) {
+ pSym.st_name = pStrtabsize;
+ ::memcpy((pStrtab + pStrtabsize), pSymbol.name(), pSymbol.nameSize());
+ } else {
+ pSym.st_name = 0;
+ }
+ pSym.st_value = pSymbol.value();
+ pSym.st_size = getSymbolSize(pSymbol);
+ pSym.st_info = getSymbolInfo(pSymbol);
+ pSym.st_other = pSymbol.visibility();
+ pSym.st_shndx = getSymbolShndx(pSymbol);
}
/// emitRegNamePools - emit regular name pools - .symtab, .strtab
@@ -965,8 +914,7 @@ void GNULDBackend::emitSymbol64(llvm::ELF::Elf64_Sym& pSym,
/// the size of these tables should be computed before layout
/// layout should computes the start offset of these tables
void GNULDBackend::emitRegNamePools(const Module& pModule,
- FileOutputBuffer& pOutput)
-{
+ FileOutputBuffer& pOutput) {
ELFFileFormat* file_format = getOutputFormat();
if (!file_format->hasSymTab())
return;
@@ -974,10 +922,10 @@ void GNULDBackend::emitRegNamePools(const Module& pModule,
LDSection& symtab_sect = file_format->getSymTab();
LDSection& strtab_sect = file_format->getStrTab();
- MemoryRegion symtab_region = pOutput.request(symtab_sect.offset(),
- symtab_sect.size());
- MemoryRegion strtab_region = pOutput.request(strtab_sect.offset(),
- strtab_sect.size());
+ MemoryRegion symtab_region =
+ pOutput.request(symtab_sect.offset(), symtab_sect.size());
+ MemoryRegion strtab_region =
+ pOutput.request(strtab_sect.offset(), strtab_sect.size());
// set up symtab_region
llvm::ELF::Elf32_Sym* symtab32 = NULL;
@@ -992,7 +940,7 @@ void GNULDBackend::emitRegNamePools(const Module& pModule,
}
// set up strtab_region
- char* strtab = (char*)strtab_region.begin();
+ char* strtab = reinterpret_cast<char*>(strtab_region.begin());
// emit the first ELF symbol
if (config().targets().is32Bits())
@@ -1033,11 +981,10 @@ void GNULDBackend::emitRegNamePools(const Module& pModule,
///
/// the size of these tables should be computed before layout
/// layout should computes the start offset of these tables
-void GNULDBackend::emitDynNamePools(Module& pModule, FileOutputBuffer& pOutput)
-{
+void GNULDBackend::emitDynNamePools(Module& pModule,
+ FileOutputBuffer& pOutput) {
ELFFileFormat* file_format = getOutputFormat();
- if (!file_format->hasDynSymTab() ||
- !file_format->hasDynStrTab() ||
+ if (!file_format->hasDynSymTab() || !file_format->hasDynStrTab() ||
!file_format->hasDynamic())
return;
@@ -1046,14 +993,13 @@ void GNULDBackend::emitDynNamePools(Module& pModule, FileOutputBuffer& pOutput)
LDSection& symtab_sect = file_format->getDynSymTab();
LDSection& strtab_sect = file_format->getDynStrTab();
- LDSection& dyn_sect = file_format->getDynamic();
-
- MemoryRegion symtab_region = pOutput.request(symtab_sect.offset(),
- symtab_sect.size());
- MemoryRegion strtab_region = pOutput.request(strtab_sect.offset(),
- strtab_sect.size());
- MemoryRegion dyn_region = pOutput.request(dyn_sect.offset(),
- dyn_sect.size());
+ LDSection& dyn_sect = file_format->getDynamic();
+
+ MemoryRegion symtab_region =
+ pOutput.request(symtab_sect.offset(), symtab_sect.size());
+ MemoryRegion strtab_region =
+ pOutput.request(strtab_sect.offset(), strtab_sect.size());
+ MemoryRegion dyn_region = pOutput.request(dyn_sect.offset(), dyn_sect.size());
// set up symtab_region
llvm::ELF::Elf32_Sym* symtab32 = NULL;
llvm::ELF::Elf64_Sym* symtab64 = NULL;
@@ -1067,7 +1013,7 @@ void GNULDBackend::emitDynNamePools(Module& pModule, FileOutputBuffer& pOutput)
}
// set up strtab_region
- char* strtab = (char*)strtab_region.begin();
+ char* strtab = reinterpret_cast<char*>(strtab_region.begin());
// emit the first ELF symbol
if (config().targets().is32Bits())
@@ -1080,7 +1026,7 @@ void GNULDBackend::emitDynNamePools(Module& pModule, FileOutputBuffer& pOutput)
Module::SymbolTable& symbols = pModule.getSymbolTable();
// emit .gnu.hash
- if (GeneralOptions::GNU == config().options().getHashStyle() ||
+ if (GeneralOptions::GNU == config().options().getHashStyle() ||
GeneralOptions::Both == config().options().getHashStyle())
emitGNUHashTab(symbols, pOutput);
@@ -1111,7 +1057,9 @@ void GNULDBackend::emitDynNamePools(Module& pModule, FileOutputBuffer& pOutput)
Module::const_lib_iterator lib, libEnd = pModule.lib_end();
for (lib = pModule.lib_begin(); lib != libEnd; ++lib) {
if (!(*lib)->attribute()->isAsNeeded() || (*lib)->isNeeded()) {
- strcpy((strtab + strtabsize), (*lib)->name().c_str());
+ ::memcpy((strtab + strtabsize),
+ (*lib)->name().c_str(),
+ (*lib)->name().size());
(*dt_need)->setValue(llvm::ELF::DT_NEEDED, strtabsize);
strtabsize += (*lib)->name().size() + 1;
++dt_need;
@@ -1126,7 +1074,7 @@ void GNULDBackend::emitDynNamePools(Module& pModule, FileOutputBuffer& pOutput)
++dt_need;
GeneralOptions::const_rpath_iterator rpath,
- rpathEnd = config().options().rpath_end();
+ rpathEnd = config().options().rpath_end();
for (rpath = config().options().rpath_begin(); rpath != rpathEnd; ++rpath) {
memcpy((strtab + strtabsize), (*rpath).data(), (*rpath).size());
strtabsize += (*rpath).size();
@@ -1144,36 +1092,37 @@ void GNULDBackend::emitDynNamePools(Module& pModule, FileOutputBuffer& pOutput)
// emit soname
if (LinkerConfig::DynObj == config().codeGenType()) {
- strcpy((strtab + strtabsize), config().options().soname().c_str());
+ ::memcpy((strtab + strtabsize),
+ config().options().soname().c_str(),
+ config().options().soname().size());
strtabsize += config().options().soname().size() + 1;
}
}
/// emitELFHashTab - emit .hash
void GNULDBackend::emitELFHashTab(const Module::SymbolTable& pSymtab,
- FileOutputBuffer& pOutput)
-{
+ FileOutputBuffer& pOutput) {
ELFFileFormat* file_format = getOutputFormat();
if (!file_format->hasHashTab())
return;
LDSection& hash_sect = file_format->getHashTab();
- MemoryRegion hash_region = pOutput.request(hash_sect.offset(),
- hash_sect.size());
+ MemoryRegion hash_region =
+ pOutput.request(hash_sect.offset(), hash_sect.size());
// both 32 and 64 bits hash table use 32-bit entry
// set up hash_region
- uint32_t* word_array = (uint32_t*)hash_region.begin();
+ uint32_t* word_array = reinterpret_cast<uint32_t*>(hash_region.begin());
uint32_t& nbucket = word_array[0];
- uint32_t& nchain = word_array[1];
+ uint32_t& nchain = word_array[1];
size_t dynsymSize = 1 + pSymtab.numOfLocalDyns() + pSymtab.numOfDynamics();
nbucket = getHashBucketCount(dynsymSize, false);
- nchain = dynsymSize;
+ nchain = dynsymSize;
uint32_t* bucket = (word_array + 2);
- uint32_t* chain = (bucket + nbucket);
+ uint32_t* chain = (bucket + nbucket);
// initialize bucket
- memset((void*)bucket, 0, nbucket);
+ memset(reinterpret_cast<void*>(bucket), 0, nbucket);
hash::StringHash<hash::ELF> hash_func;
@@ -1190,55 +1139,55 @@ void GNULDBackend::emitELFHashTab(const Module::SymbolTable& pSymtab,
/// emitGNUHashTab - emit .gnu.hash
void GNULDBackend::emitGNUHashTab(Module::SymbolTable& pSymtab,
- FileOutputBuffer& pOutput)
-{
+ FileOutputBuffer& pOutput) {
ELFFileFormat* file_format = getOutputFormat();
if (!file_format->hasGNUHashTab())
return;
MemoryRegion gnuhash_region =
- pOutput.request(file_format->getGNUHashTab().offset(),
- file_format->getGNUHashTab().size());
+ pOutput.request(file_format->getGNUHashTab().offset(),
+ file_format->getGNUHashTab().size());
- uint32_t* word_array = (uint32_t*)gnuhash_region.begin();
+ uint32_t* word_array = reinterpret_cast<uint32_t*>(gnuhash_region.begin());
// fixed-length fields
- uint32_t& nbucket = word_array[0];
- uint32_t& symidx = word_array[1];
+ uint32_t& nbucket = word_array[0];
+ uint32_t& symidx = word_array[1];
uint32_t& maskwords = word_array[2];
- uint32_t& shift2 = word_array[3];
+ uint32_t& shift2 = word_array[3];
// variable-length fields
- uint8_t* bitmask = (uint8_t*)(word_array + 4);
- uint32_t* bucket = NULL;
- uint32_t* chain = NULL;
+ uint8_t* bitmask = reinterpret_cast<uint8_t*>(word_array + 4);
+ uint32_t* bucket = NULL;
+ uint32_t* chain = NULL;
// count the number of dynsym to hash
size_t unhashed_sym_cnt = pSymtab.numOfLocalDyns();
- size_t hashed_sym_cnt = pSymtab.numOfDynamics();
+ size_t hashed_sym_cnt = pSymtab.numOfDynamics();
Module::const_sym_iterator symbol, symEnd = pSymtab.dynamicEnd();
for (symbol = pSymtab.dynamicBegin(); symbol != symEnd; ++symbol) {
if (DynsymCompare().needGNUHash(**symbol))
break;
- ++unhashed_sym_cnt;
- --hashed_sym_cnt;
+ ++unhashed_sym_cnt;
+ --hashed_sym_cnt;
}
// special case for the empty hash table
if (hashed_sym_cnt == 0) {
- nbucket = 1; // one empty bucket
- symidx = 1 + unhashed_sym_cnt; // symidx above unhashed symbols
- maskwords = 1; // bitmask length
- shift2 = 0; // bloom filter
+ nbucket = 1; // one empty bucket
+ symidx = 1 + unhashed_sym_cnt; // symidx above unhashed symbols
+ maskwords = 1; // bitmask length
+ shift2 = 0; // bloom filter
if (config().targets().is32Bits()) {
- uint32_t* maskval = (uint32_t*)bitmask;
- *maskval = 0; // no valid hashes
+ uint32_t* maskval = reinterpret_cast<uint32_t*>(bitmask);
+ *maskval = 0; // no valid hashes
} else {
// must be 64
- uint64_t* maskval = (uint64_t*)bitmask;
- *maskval = 0; // no valid hashes
+ uint64_t* maskval = reinterpret_cast<uint64_t*>(bitmask);
+ *maskval = 0; // no valid hashes
}
- bucket = (uint32_t*)(bitmask + config().targets().bitclass() / 8);
- *bucket = 0; // no hash in the only bucket
+ bucket = reinterpret_cast<uint32_t*>(bitmask +
+ config().targets().bitclass() / 8);
+ *bucket = 0; // no hash in the only bucket
return;
}
@@ -1247,22 +1196,21 @@ void GNULDBackend::emitGNUHashTab(Module::SymbolTable& pSymtab,
uint32_t shift1 = config().targets().is32Bits() ? 5 : 6;
uint32_t mask = (1u << shift1) - 1;
- nbucket = getHashBucketCount(hashed_sym_cnt, true);
- symidx = 1 + unhashed_sym_cnt;
+ nbucket = getHashBucketCount(hashed_sym_cnt, true);
+ symidx = 1 + unhashed_sym_cnt;
maskwords = 1 << (maskbitslog2 - shift1);
- shift2 = maskbitslog2;
+ shift2 = maskbitslog2;
// setup bucket and chain
- bucket = (uint32_t*)(bitmask + maskbits / 8);
- chain = (bucket + nbucket);
+ bucket = reinterpret_cast<uint32_t*>(bitmask + maskbits / 8);
+ chain = (bucket + nbucket);
// build the gnu style hash table
- typedef std::multimap<uint32_t,
- std::pair<LDSymbol*, uint32_t> > SymMapType;
+ typedef std::multimap<uint32_t, std::pair<LDSymbol*, uint32_t> > SymMapType;
SymMapType symmap;
symEnd = pSymtab.dynamicEnd();
for (symbol = pSymtab.localDynBegin() + symidx - 1; symbol != symEnd;
- ++symbol) {
+ ++symbol) {
hash::StringHash<hash::DJB> hasher;
uint32_t djbhash = hasher((*symbol)->name());
uint32_t hash = djbhash % nbucket;
@@ -1276,7 +1224,7 @@ void GNULDBackend::emitGNUHashTab(Module::SymbolTable& pSymtab,
size_t count = 0;
std::pair<SymMapType::iterator, SymMapType::iterator> ret;
ret = symmap.equal_range(idx);
- for (SymMapType::iterator it = ret.first; it != ret.second; ) {
+ for (SymMapType::iterator it = ret.first; it != ret.second;) {
// rearrange the hashed symbol ordering
*(pSymtab.localDynBegin() + hashedidx - 1) = it->second.first;
uint32_t djbhash = it->second.second;
@@ -1303,20 +1251,19 @@ void GNULDBackend::emitGNUHashTab(Module::SymbolTable& pSymtab,
// write the bitmasks
if (config().targets().is32Bits()) {
- uint32_t* maskval = (uint32_t*)bitmask;
+ uint32_t* maskval = reinterpret_cast<uint32_t*>(bitmask);
for (size_t i = 0; i < maskwords; ++i)
std::memcpy(maskval + i, &bitmasks[i], 4);
} else {
// must be 64
- uint64_t* maskval = (uint64_t*)bitmask;
+ uint64_t* maskval = reinterpret_cast<uint64_t*>(bitmask);
for (size_t i = 0; i < maskwords; ++i)
std::memcpy(maskval + i, &bitmasks[i], 8);
}
}
/// sizeInterp - compute the size of the .interp section
-void GNULDBackend::sizeInterp()
-{
+void GNULDBackend::sizeInterp() {
const char* dyld_name;
if (config().options().hasDyld())
dyld_name = config().options().dyld().c_str();
@@ -1328,8 +1275,7 @@ void GNULDBackend::sizeInterp()
}
/// emitInterp - emit the .interp
-void GNULDBackend::emitInterp(FileOutputBuffer& pOutput)
-{
+void GNULDBackend::emitInterp(FileOutputBuffer& pOutput) {
if (getOutputFormat()->hasInterp()) {
const LDSection& interp = getOutputFormat()->getInterp();
MemoryRegion region = pOutput.request(interp.offset(), interp.size());
@@ -1343,27 +1289,24 @@ void GNULDBackend::emitInterp(FileOutputBuffer& pOutput)
}
}
-bool GNULDBackend::hasEntryInStrTab(const LDSymbol& pSym) const
-{
+bool GNULDBackend::hasEntryInStrTab(const LDSymbol& pSym) const {
return ResolveInfo::Section != pSym.type();
}
-void GNULDBackend::orderSymbolTable(Module& pModule)
-{
+void GNULDBackend::orderSymbolTable(Module& pModule) {
Module::SymbolTable& symbols = pModule.getSymbolTable();
- if (GeneralOptions::GNU == config().options().getHashStyle() ||
+ if (GeneralOptions::GNU == config().options().getHashStyle() ||
GeneralOptions::Both == config().options().getHashStyle())
// Currently we may add output symbols after sizeNamePools(), and a
// non-stable sort is used in SymbolCategory::arrange(), so we just
// sort .dynsym right before emitting .gnu.hash
- std::stable_sort(symbols.dynamicBegin(), symbols.dynamicEnd(),
- DynsymCompare());
+ std::stable_sort(
+ symbols.dynamicBegin(), symbols.dynamicEnd(), DynsymCompare());
}
/// getSectionOrder
-unsigned int GNULDBackend::getSectionOrder(const LDSection& pSectHdr) const
-{
+unsigned int GNULDBackend::getSectionOrder(const LDSection& pSectHdr) const {
const ELFFileFormat* file_format = getOutputFormat();
// NULL section should be the "1st" section
@@ -1401,8 +1344,15 @@ unsigned int GNULDBackend::getSectionOrder(const LDSection& pSectHdr) const
&pSectHdr == &file_format->getJCR() ||
&pSectHdr == &file_format->getDataRelRo())
return SHO_RELRO;
+
if (&pSectHdr == &file_format->getDataRelRoLocal())
return SHO_RELRO_LOCAL;
+
+ // Make special sections that end with .rel.ro suffix as RELRO.
+ llvm::StringRef name(pSectHdr.name());
+ if (name.endswith(".rel.ro")) {
+ return SHO_RELRO;
+ }
}
if ((pSectHdr.flag() & llvm::ELF::SHF_TLS) != 0x0) {
return SHO_TLS_DATA;
@@ -1449,15 +1399,14 @@ unsigned int GNULDBackend::getSectionOrder(const LDSection& pSectHdr) const
case LDFileFormat::MetaData:
case LDFileFormat::Debug:
+ case LDFileFormat::DebugString:
default:
return SHO_UNDEFINED;
}
}
/// getSymbolSize
-uint64_t GNULDBackend::getSymbolSize(const LDSymbol& pSymbol) const
-{
- // @ref Google gold linker: symtab.cc: 2780
+uint64_t GNULDBackend::getSymbolSize(const LDSymbol& pSymbol) const {
// undefined and dynamic symbols should have zero size.
if (pSymbol.isDyn() || pSymbol.desc() == ResolveInfo::Undefined)
return 0x0;
@@ -1465,8 +1414,7 @@ uint64_t GNULDBackend::getSymbolSize(const LDSymbol& pSymbol) const
}
/// getSymbolInfo
-uint64_t GNULDBackend::getSymbolInfo(const LDSymbol& pSymbol) const
-{
+uint64_t GNULDBackend::getSymbolInfo(const LDSymbol& pSymbol) const {
// set binding
uint8_t bind = 0x0;
if (pSymbol.resolveInfo()->isLocal())
@@ -1482,7 +1430,7 @@ uint64_t GNULDBackend::getSymbolInfo(const LDSymbol& pSymbol) const
if (config().codeGenType() != LinkerConfig::Object &&
(pSymbol.visibility() == llvm::ELF::STV_INTERNAL ||
- pSymbol.visibility() == llvm::ELF::STV_HIDDEN))
+ pSymbol.visibility() == llvm::ELF::STV_HIDDEN))
bind = llvm::ELF::STB_LOCAL;
uint32_t type = pSymbol.resolveInfo()->type();
@@ -1494,8 +1442,7 @@ uint64_t GNULDBackend::getSymbolInfo(const LDSymbol& pSymbol) const
}
/// getSymbolValue - this function is called after layout()
-uint64_t GNULDBackend::getSymbolValue(const LDSymbol& pSymbol) const
-{
+uint64_t GNULDBackend::getSymbolValue(const LDSymbol& pSymbol) const {
if (pSymbol.isDyn())
return 0x0;
@@ -1503,9 +1450,7 @@ uint64_t GNULDBackend::getSymbolValue(const LDSymbol& pSymbol) const
}
/// getSymbolShndx - this function is called after layout()
-uint64_t
-GNULDBackend::getSymbolShndx(const LDSymbol& pSymbol) const
-{
+uint64_t GNULDBackend::getSymbolShndx(const LDSymbol& pSymbol) const {
if (pSymbol.resolveInfo()->isAbsolute())
return llvm::ELF::SHN_ABS;
if (pSymbol.resolveInfo()->isCommon())
@@ -1516,21 +1461,22 @@ GNULDBackend::getSymbolShndx(const LDSymbol& pSymbol) const
if (pSymbol.resolveInfo()->isDefine() && !pSymbol.hasFragRef())
return llvm::ELF::SHN_ABS;
- assert(pSymbol.hasFragRef() && "symbols must have fragment reference to get its index");
+ assert(pSymbol.hasFragRef() &&
+ "symbols must have fragment reference to get its index");
return pSymbol.fragRef()->frag()->getParent()->getSection().index();
}
/// getSymbolIdx - called by emitRelocation to get the ouput symbol table index
-size_t GNULDBackend::getSymbolIdx(const LDSymbol* pSymbol) const
-{
- HashTableType::iterator entry = m_pSymIndexMap->find(const_cast<LDSymbol *>(pSymbol));
- assert(entry != m_pSymIndexMap->end() && "symbol not found in the symbol table");
- return entry.getEntry()->value();
+size_t GNULDBackend::getSymbolIdx(const LDSymbol* pSymbol) const {
+ HashTableType::iterator entry =
+ m_pSymIndexMap->find(const_cast<LDSymbol*>(pSymbol));
+ assert(entry != m_pSymIndexMap->end() &&
+ "symbol not found in the symbol table");
+ return entry.getEntry()->value();
}
/// isTemporary - Whether pSymbol is a local label.
-bool GNULDBackend::isTemporary(const LDSymbol& pSymbol) const
-{
+bool GNULDBackend::isTemporary(const LDSymbol& pSymbol) const {
if (ResolveInfo::Local != pSymbol.binding())
return false;
@@ -1542,13 +1488,11 @@ bool GNULDBackend::isTemporary(const LDSymbol& pSymbol) const
return true;
// UnixWare 2.1 cc generate DWARF debugging symbols with `..' prefix.
- // @ref Google gold linker, target.cc:39 @@ Target::do_is_local_label_name()
if (name[0] == '.' && name[1] == '.')
return true;
// Work arround for gcc's bug
// gcc sometimes generate symbols with '_.L_' prefix.
- // @ref Google gold linker, target.cc:39 @@ Target::do_is_local_label_name()
if (pSymbol.nameSize() < 4)
return false;
@@ -1560,10 +1504,7 @@ bool GNULDBackend::isTemporary(const LDSymbol& pSymbol) const
/// allocateCommonSymbols - allocate common symbols in the corresponding
/// sections. This is executed at pre-layout stage.
-/// @refer Google gold linker: common.cc: 214
-bool
-GNULDBackend::allocateCommonSymbols(Module& pModule)
-{
+bool GNULDBackend::allocateCommonSymbols(Module& pModule) {
SymbolCategory& symbol_list = pModule.getSymbolTable();
if (symbol_list.emptyCommons() && symbol_list.emptyFiles() &&
@@ -1594,7 +1535,7 @@ GNULDBackend::allocateCommonSymbols(Module& pModule)
tbss_sect_data = IRBuilder::CreateSectionData(tbss_sect);
// remember original BSS size
- uint64_t bss_offset = bss_sect.size();
+ uint64_t bss_offset = bss_sect.size();
uint64_t tbss_offset = tbss_sect.size();
// allocate all local common symbols
@@ -1612,16 +1553,13 @@ GNULDBackend::allocateCommonSymbols(Module& pModule)
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
- tbss_offset += ObjectBuilder::AppendFragment(*frag,
- *tbss_sect_data,
- (*com_sym)->value());
+ tbss_offset += ObjectBuilder::AppendFragment(
+ *frag, *tbss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(tbss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- }
- else {
- bss_offset += ObjectBuilder::AppendFragment(*frag,
- *bss_sect_data,
- (*com_sym)->value());
+ } else {
+ bss_offset += ObjectBuilder::AppendFragment(
+ *frag, *bss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(bss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
}
@@ -1641,16 +1579,13 @@ GNULDBackend::allocateCommonSymbols(Module& pModule)
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
- tbss_offset += ObjectBuilder::AppendFragment(*frag,
- *tbss_sect_data,
- (*com_sym)->value());
+ tbss_offset += ObjectBuilder::AppendFragment(
+ *frag, *tbss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(tbss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- }
- else {
- bss_offset += ObjectBuilder::AppendFragment(*frag,
- *bss_sect_data,
- (*com_sym)->value());
+ } else {
+ bss_offset += ObjectBuilder::AppendFragment(
+ *frag, *bss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(bss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
}
@@ -1664,16 +1599,11 @@ GNULDBackend::allocateCommonSymbols(Module& pModule)
/// updateSectionFlags - update pTo's flags when merging pFrom
/// update the output section flags based on input section flags.
-/// @ref The Google gold linker:
-/// output.cc: 2809: Output_section::update_flags_for_input_section
-bool GNULDBackend::updateSectionFlags(LDSection& pTo, const LDSection& pFrom)
-{
+bool GNULDBackend::updateSectionFlags(LDSection& pTo, const LDSection& pFrom) {
// union the flags from input
uint32_t flags = pTo.flag();
- flags |= (pFrom.flag() &
- (llvm::ELF::SHF_WRITE |
- llvm::ELF::SHF_ALLOC |
- llvm::ELF::SHF_EXECINSTR));
+ flags |= (pFrom.flag() & (llvm::ELF::SHF_WRITE | llvm::ELF::SHF_ALLOC |
+ llvm::ELF::SHF_EXECINSTR));
// if there is an input section is not SHF_MERGE, clean this flag
if (0 == (pFrom.flag() & llvm::ELF::SHF_MERGE))
@@ -1691,16 +1621,14 @@ bool GNULDBackend::updateSectionFlags(LDSection& pTo, const LDSection& pFrom)
bool GNULDBackend::readRelocation(const llvm::ELF::Elf32_Rel& pRel,
Relocation::Type& pType,
uint32_t& pSymIdx,
- uint32_t& pOffset) const
-{
+ uint32_t& pOffset) const {
uint32_t r_info = 0x0;
if (llvm::sys::IsLittleEndianHost) {
pOffset = pRel.r_offset;
- r_info = pRel.r_info;
- }
- else {
+ r_info = pRel.r_info;
+ } else {
pOffset = mcld::bswap32(pRel.r_offset);
- r_info = mcld::bswap32(pRel.r_info);
+ r_info = mcld::bswap32(pRel.r_info);
}
pType = static_cast<unsigned char>(r_info);
@@ -1713,17 +1641,15 @@ bool GNULDBackend::readRelocation(const llvm::ELF::Elf32_Rela& pRel,
Relocation::Type& pType,
uint32_t& pSymIdx,
uint32_t& pOffset,
- int32_t& pAddend) const
-{
- uint32_t r_info = 0x0;
+ int32_t& pAddend) const {
+ uint32_t r_info = 0x0;
if (llvm::sys::IsLittleEndianHost) {
pOffset = pRel.r_offset;
- r_info = pRel.r_info;
+ r_info = pRel.r_info;
pAddend = pRel.r_addend;
- }
- else {
+ } else {
pOffset = mcld::bswap32(pRel.r_offset);
- r_info = mcld::bswap32(pRel.r_info);
+ r_info = mcld::bswap32(pRel.r_info);
pAddend = mcld::bswap32(pRel.r_addend);
}
@@ -1734,18 +1660,16 @@ bool GNULDBackend::readRelocation(const llvm::ELF::Elf32_Rela& pRel,
/// readRelocation - read ELF64_Rel entry
bool GNULDBackend::readRelocation(const llvm::ELF::Elf64_Rel& pRel,
- Relocation::Type& pType,
- uint32_t& pSymIdx,
- uint64_t& pOffset) const
-{
+ Relocation::Type& pType,
+ uint32_t& pSymIdx,
+ uint64_t& pOffset) const {
uint64_t r_info = 0x0;
if (llvm::sys::IsLittleEndianHost) {
pOffset = pRel.r_offset;
- r_info = pRel.r_info;
- }
- else {
+ r_info = pRel.r_info;
+ } else {
pOffset = mcld::bswap64(pRel.r_offset);
- r_info = mcld::bswap64(pRel.r_info);
+ r_info = mcld::bswap64(pRel.r_info);
}
pType = static_cast<uint32_t>(r_info);
@@ -1755,20 +1679,18 @@ bool GNULDBackend::readRelocation(const llvm::ELF::Elf64_Rel& pRel,
/// readRel - read ELF64_Rela entry
bool GNULDBackend::readRelocation(const llvm::ELF::Elf64_Rela& pRel,
- Relocation::Type& pType,
- uint32_t& pSymIdx,
- uint64_t& pOffset,
- int64_t& pAddend) const
-{
+ Relocation::Type& pType,
+ uint32_t& pSymIdx,
+ uint64_t& pOffset,
+ int64_t& pAddend) const {
uint64_t r_info = 0x0;
if (llvm::sys::IsLittleEndianHost) {
pOffset = pRel.r_offset;
- r_info = pRel.r_info;
+ r_info = pRel.r_info;
pAddend = pRel.r_addend;
- }
- else {
+ } else {
pOffset = mcld::bswap64(pRel.r_offset);
- r_info = mcld::bswap64(pRel.r_info);
+ r_info = mcld::bswap64(pRel.r_info);
pAddend = mcld::bswap64(pRel.r_addend);
}
@@ -1781,8 +1703,7 @@ bool GNULDBackend::readRelocation(const llvm::ELF::Elf64_Rela& pRel,
void GNULDBackend::emitRelocation(llvm::ELF::Elf32_Rel& pRel,
Relocation::Type pType,
uint32_t pSymIdx,
- uint32_t pOffset) const
-{
+ uint32_t pOffset) const {
pRel.r_offset = pOffset;
pRel.setSymbolAndType(pSymIdx, pType);
}
@@ -1792,8 +1713,7 @@ void GNULDBackend::emitRelocation(llvm::ELF::Elf32_Rela& pRel,
Relocation::Type pType,
uint32_t pSymIdx,
uint32_t pOffset,
- int32_t pAddend) const
-{
+ int32_t pAddend) const {
pRel.r_offset = pOffset;
pRel.r_addend = pAddend;
pRel.setSymbolAndType(pSymIdx, pType);
@@ -1803,8 +1723,7 @@ void GNULDBackend::emitRelocation(llvm::ELF::Elf32_Rela& pRel,
void GNULDBackend::emitRelocation(llvm::ELF::Elf64_Rel& pRel,
Relocation::Type pType,
uint32_t pSymIdx,
- uint64_t pOffset) const
-{
+ uint64_t pOffset) const {
pRel.r_offset = pOffset;
pRel.setSymbolAndType(pSymIdx, pType);
}
@@ -1814,17 +1733,15 @@ void GNULDBackend::emitRelocation(llvm::ELF::Elf64_Rela& pRel,
Relocation::Type pType,
uint32_t pSymIdx,
uint64_t pOffset,
- int64_t pAddend) const
-{
+ int64_t pAddend) const {
pRel.r_offset = pOffset;
pRel.r_addend = pAddend;
pRel.setSymbolAndType(pSymIdx, pType);
}
/// createProgramHdrs - base on output sections to create the program headers
-void GNULDBackend::createProgramHdrs(Module& pModule)
-{
- ELFFileFormat *file_format = getOutputFormat();
+void GNULDBackend::createProgramHdrs(Module& pModule) {
+ ELFFileFormat* file_format = getOutputFormat();
// make PT_INTERP
if (file_format->hasInterp()) {
@@ -1839,7 +1756,7 @@ void GNULDBackend::createProgramHdrs(Module& pModule)
ELFSegment* load_seg = NULL;
// make possible PT_LOAD segments
LinkerScript& ldscript = pModule.getScript();
- LinkerScript::AddressMap::iterator addrEnd= ldscript.addressMap().end();
+ LinkerScript::AddressMap::iterator addrEnd = ldscript.addressMap().end();
SectionMap::iterator out, prev, outBegin, outEnd;
outBegin = ldscript.sectionMap().begin();
outEnd = ldscript.sectionMap().end();
@@ -1860,28 +1777,23 @@ void GNULDBackend::createProgramHdrs(Module& pModule)
if (LDFileFormat::Null == sect->kind()) {
// 1. create text segment
createPT_LOAD = true;
- }
- else if (!config().options().omagic() &&
- (prev_flag & llvm::ELF::PF_W) ^ (cur_flag & llvm::ELF::PF_W)) {
+ } else if (!config().options().omagic() &&
+ (prev_flag & llvm::ELF::PF_W) ^ (cur_flag & llvm::ELF::PF_W)) {
// 2. create data segment if w/o omagic set
createPT_LOAD = true;
- }
- else if (sect->kind() == LDFileFormat::BSS &&
- load_seg->isDataSegment() &&
- addrEnd != ldscript.addressMap().find(".bss")) {
+ } else if (sect->kind() == LDFileFormat::BSS && load_seg->isDataSegment() &&
+ addrEnd != ldscript.addressMap().find(".bss")) {
// 3. create bss segment if w/ -Tbss and there is a data segment
createPT_LOAD = true;
- }
- else if ((sect != &(file_format->getText())) &&
- (sect != &(file_format->getData())) &&
- (sect != &(file_format->getBSS())) &&
- (addrEnd != ldscript.addressMap().find(sect->name()))) {
+ } else if ((sect != &(file_format->getText())) &&
+ (sect != &(file_format->getData())) &&
+ (sect != &(file_format->getBSS())) &&
+ (addrEnd != ldscript.addressMap().find(sect->name()))) {
// 4. create PT_LOAD for sections in address map except for text, data,
// and bss
createPT_LOAD = true;
- }
- else if (LDFileFormat::Null == (*prev)->getSection()->kind() &&
- !config().options().getScriptList().empty()) {
+ } else if (LDFileFormat::Null == (*prev)->getSection()->kind() &&
+ !config().options().getScriptList().empty()) {
// 5. create PT_LOAD to hold NULL section if there is a default ldscript
createPT_LOAD = true;
}
@@ -1893,7 +1805,7 @@ void GNULDBackend::createProgramHdrs(Module& pModule)
load_seg->setAlign(abiPageSize());
}
- assert(NULL != load_seg);
+ assert(load_seg != NULL);
load_seg->append(sect);
if (cur_flag != prev_flag)
load_seg->updateFlag(cur_flag);
@@ -1903,9 +1815,8 @@ void GNULDBackend::createProgramHdrs(Module& pModule)
// make PT_DYNAMIC
if (file_format->hasDynamic()) {
- ELFSegment* dyn_seg = elfSegmentTable().produce(llvm::ELF::PT_DYNAMIC,
- llvm::ELF::PF_R |
- llvm::ELF::PF_W);
+ ELFSegment* dyn_seg = elfSegmentTable().produce(
+ llvm::ELF::PT_DYNAMIC, llvm::ELF::PF_R | llvm::ELF::PF_W);
dyn_seg->append(&file_format->getDynamic());
}
@@ -1913,15 +1824,17 @@ void GNULDBackend::createProgramHdrs(Module& pModule)
// make PT_GNU_RELRO
ELFSegment* relro_seg = elfSegmentTable().produce(llvm::ELF::PT_GNU_RELRO);
for (ELFSegmentFactory::iterator seg = elfSegmentTable().begin(),
- segEnd = elfSegmentTable().end(); seg != segEnd; ++seg) {
+ segEnd = elfSegmentTable().end();
+ seg != segEnd;
+ ++seg) {
if (llvm::ELF::PT_LOAD != (*seg)->type())
continue;
- for (ELFSegment::iterator sect = (*seg)->begin(),
- sectEnd = (*seg)->end(); sect != sectEnd; ++sect) {
+ for (ELFSegment::iterator sect = (*seg)->begin(), sectEnd = (*seg)->end();
+ sect != sectEnd;
+ ++sect) {
unsigned int order = getSectionOrder(**sect);
- if (SHO_RELRO_LOCAL == order ||
- SHO_RELRO == order ||
+ if (SHO_RELRO_LOCAL == order || SHO_RELRO == order ||
SHO_RELRO_LAST == order) {
relro_seg->append(*sect);
}
@@ -1946,14 +1859,13 @@ void GNULDBackend::createProgramHdrs(Module& pModule)
// make PT_GNU_STACK
if (file_format->hasStackNote()) {
+ uint32_t flag = getSegmentFlag(file_format->getStackNote().flag());
elfSegmentTable().produce(llvm::ELF::PT_GNU_STACK,
- llvm::ELF::PF_R |
- llvm::ELF::PF_W |
- getSegmentFlag(file_format->getStackNote().flag()));
+ llvm::ELF::PF_R | llvm::ELF::PF_W | flag);
}
// make PT_NOTE
- ELFSegment *note_seg = NULL;
+ ELFSegment* note_seg = NULL;
prev_flag = 0x0;
Module::iterator sect, sectBegin, sectEnd;
sectBegin = pModule.begin();
@@ -1979,21 +1891,20 @@ void GNULDBackend::createProgramHdrs(Module& pModule)
}
/// setupProgramHdrs - set up the attributes of segments
-void GNULDBackend::setupProgramHdrs(const LinkerScript& pScript)
-{
+void GNULDBackend::setupProgramHdrs(const LinkerScript& pScript) {
// update segment info
for (ELFSegmentFactory::iterator seg = elfSegmentTable().begin(),
- segEnd = elfSegmentTable().end(); seg != segEnd; ++seg) {
-
+ segEnd = elfSegmentTable().end();
+ seg != segEnd;
+ ++seg) {
// bypass if there is no section in this segment (e.g., PT_GNU_STACK)
if ((*seg)->size() == 0)
continue;
// bypass the PT_LOAD that only has NULL section now
if ((*seg)->type() == llvm::ELF::PT_LOAD &&
- (*seg)->front()->kind() == LDFileFormat::Null &&
- (*seg)->size() == 1)
- continue;
+ (*seg)->front()->kind() == LDFileFormat::Null && (*seg)->size() == 1)
+ continue;
(*seg)->setOffset((*seg)->front()->offset());
if ((*seg)->type() == llvm::ELF::PT_LOAD &&
@@ -2012,22 +1923,19 @@ void GNULDBackend::setupProgramHdrs(const LinkerScript& pScript)
break;
}
if (sect != sectREnd) {
- (*seg)->setFilesz((*sect)->offset() +
- (*sect)->size() -
- (*seg)->offset());
+ (*seg)->setFilesz((*sect)->offset() + (*sect)->size() - (*seg)->offset());
} else {
(*seg)->setFilesz(0x0);
}
- (*seg)->setMemsz((*seg)->back()->addr() +
- (*seg)->back()->size() -
+ (*seg)->setMemsz((*seg)->back()->addr() + (*seg)->back()->size() -
(*seg)->vaddr());
- } // end of for
+ } // end of for
// handle the case if text segment only has NULL section
LDSection* null_sect = &getOutputFormat()->getNULLSection();
ELFSegmentFactory::iterator null_seg =
- elfSegmentTable().find(llvm::ELF::PT_LOAD, null_sect);
+ elfSegmentTable().find(llvm::ELF::PT_LOAD, null_sect);
if ((*null_seg)->size() == 1) {
// find 2nd PT_LOAD
@@ -2053,20 +1961,17 @@ void GNULDBackend::setupProgramHdrs(const LinkerScript& pScript)
}
}
if (sect == sectEnd) {
- (*seg)->setFilesz((*seg)->back()->offset() +
- (*seg)->back()->size() -
+ (*seg)->setFilesz((*seg)->back()->offset() + (*seg)->back()->size() -
(*seg)->offset());
} else if (*sect != (*seg)->front()) {
--sect;
- (*seg)->setFilesz((*sect)->offset() +
- (*sect)->size() -
+ (*seg)->setFilesz((*sect)->offset() + (*sect)->size() -
(*seg)->offset());
} else {
(*seg)->setFilesz(0x0);
}
- (*seg)->setMemsz((*seg)->back()->addr() +
- (*seg)->back()->size() -
+ (*seg)->setMemsz((*seg)->back()->addr() + (*seg)->back()->size() -
(*seg)->vaddr());
(*seg)->insert((*seg)->begin(), null_sect);
@@ -2087,11 +1992,11 @@ void GNULDBackend::setupProgramHdrs(const LinkerScript& pScript)
// set up PT_PHDR
ELFSegmentFactory::iterator phdr =
- elfSegmentTable().find(llvm::ELF::PT_PHDR, llvm::ELF::PF_R, 0x0);
+ elfSegmentTable().find(llvm::ELF::PT_PHDR, llvm::ELF::PF_R, 0x0);
if (phdr != elfSegmentTable().end()) {
ELFSegmentFactory::iterator null_seg =
- elfSegmentTable().find(llvm::ELF::PT_LOAD, null_sect);
+ elfSegmentTable().find(llvm::ELF::PT_LOAD, null_sect);
if (null_seg != elfSegmentTable().end()) {
uint64_t offset = 0x0, phdr_size = 0x0;
if (config().targets().is32Bits()) {
@@ -2115,8 +2020,7 @@ void GNULDBackend::setupProgramHdrs(const LinkerScript& pScript)
/// getSegmentFlag - give a section flag and return the corresponding segment
/// flag
-uint32_t GNULDBackend::getSegmentFlag(const uint32_t pSectionFlag)
-{
+uint32_t GNULDBackend::getSegmentFlag(const uint32_t pSectionFlag) {
uint32_t flag = 0x0;
if ((pSectionFlag & llvm::ELF::SHF_ALLOC) != 0x0)
flag |= llvm::ELF::PF_R;
@@ -2128,16 +2032,13 @@ uint32_t GNULDBackend::getSegmentFlag(const uint32_t pSectionFlag)
}
/// setupGNUStackInfo - setup the section flag of .note.GNU-stack in output
-/// @ref gold linker: layout.cc:2608
-void GNULDBackend::setupGNUStackInfo(Module& pModule)
-{
+void GNULDBackend::setupGNUStackInfo(Module& pModule) {
uint32_t flag = 0x0;
if (config().options().hasStackSet()) {
// 1. check the command line option (-z execstack or -z noexecstack)
if (config().options().hasExecStack())
flag = llvm::ELF::SHF_EXECINSTR;
- }
- else {
+ } else {
// 2. check the stack info from the input objects
// FIXME: since we alway emit .note.GNU-stack in output now, we may be able
// to check this from the output .note.GNU-stack directly after section
@@ -2147,7 +2048,7 @@ void GNULDBackend::setupGNUStackInfo(Module& pModule)
for (obj = pModule.obj_begin(); obj != objEnd; ++obj) {
++object_count;
const LDSection* sect = (*obj)->context()->getSection(".note.GNU-stack");
- if (NULL != sect) {
+ if (sect != NULL) {
++stack_note_count;
// 2.1 found a stack note that is set as executable
if (0 != (llvm::ELF::SHF_EXECINSTR & sect->flag())) {
@@ -2174,8 +2075,7 @@ void GNULDBackend::setupGNUStackInfo(Module& pModule)
}
/// setOutputSectionOffset - helper function to set output sections' offset.
-void GNULDBackend::setOutputSectionOffset(Module& pModule)
-{
+void GNULDBackend::setOutputSectionOffset(Module& pModule) {
LinkerScript& script = pModule.getScript();
uint64_t offset = 0x0;
LDSection* cur = NULL;
@@ -2191,15 +2091,15 @@ void GNULDBackend::setOutputSectionOffset(Module& pModule)
}
switch (prev->kind()) {
- case LDFileFormat::Null:
- offset = sectionStartOffset();
- break;
- case LDFileFormat::BSS:
- offset = prev->offset();
- break;
- default:
- offset = prev->offset() + prev->size();
- break;
+ case LDFileFormat::Null:
+ offset = sectionStartOffset();
+ break;
+ case LDFileFormat::BSS:
+ offset = prev->offset();
+ break;
+ default:
+ offset = prev->offset() + prev->size();
+ break;
}
alignAddress(offset, cur->align());
cur->setOffset(offset);
@@ -2207,8 +2107,7 @@ void GNULDBackend::setOutputSectionOffset(Module& pModule)
}
/// setOutputSectionAddress - helper function to set output sections' address.
-void GNULDBackend::setOutputSectionAddress(Module& pModule)
-{
+void GNULDBackend::setOutputSectionAddress(Module& pModule) {
RpnEvaluator evaluator(pModule, *this);
LinkerScript& script = pModule.getScript();
uint64_t vma = 0x0, offset = 0x0;
@@ -2230,7 +2129,9 @@ void GNULDBackend::setOutputSectionAddress(Module& pModule)
// process dot assignments between 2 output sections
for (SectionMap::Output::dot_iterator it = (*out)->dot_begin(),
- ie = (*out)->dot_end(); it != ie; ++it) {
+ ie = (*out)->dot_end();
+ it != ie;
+ ++it) {
(*it).assign(evaluator);
}
@@ -2292,8 +2193,7 @@ void GNULDBackend::setOutputSectionAddress(Module& pModule)
// check if current is the first non-relro section
SectionMap::iterator relro_last = out - 1;
- if (relro_last != outEnd &&
- (*relro_last)->order() <= SHO_RELRO_LAST &&
+ if (relro_last != outEnd && (*relro_last)->order() <= SHO_RELRO_LAST &&
(*out)->order() > SHO_RELRO_LAST) {
// align the first non-relro section to page boundary
alignAddress(vma, abiPageSize());
@@ -2311,20 +2211,20 @@ void GNULDBackend::setOutputSectionAddress(Module& pModule)
got.setOffset(got.offset() + diff);
}
}
- } // end of if - for relro processing
+ } // end of if - for relro processing
cur->setAddr(vma);
switch (prev->kind()) {
- case LDFileFormat::Null:
- offset = sectionStartOffset();
- break;
- case LDFileFormat::BSS:
- offset = prev->offset();
- break;
- default:
- offset = prev->offset() + prev->size();
- break;
+ case LDFileFormat::Null:
+ offset = sectionStartOffset();
+ break;
+ case LDFileFormat::BSS:
+ offset = prev->offset();
+ break;
+ default:
+ offset = prev->offset() + prev->size();
+ break;
}
alignAddress(offset, cur->align());
// in p75, http://www.sco.com/developers/devspecs/gabi41.pdf
@@ -2336,8 +2236,7 @@ void GNULDBackend::setOutputSectionAddress(Module& pModule)
// output!
if ((cur->flag() & llvm::ELF::SHF_ALLOC) != 0 &&
(vma & (abiPageSize() - 1)) != (offset & (abiPageSize() - 1))) {
- uint64_t padding = abiPageSize() +
- (vma & (abiPageSize() - 1)) -
+ uint64_t padding = abiPageSize() + (vma & (abiPageSize() - 1)) -
(offset & (abiPageSize() - 1));
offset += padding;
}
@@ -2348,8 +2247,9 @@ void GNULDBackend::setOutputSectionAddress(Module& pModule)
bool changed = false;
Fragment* invalid = NULL;
for (SectionMap::Output::iterator in = (*out)->begin(),
- inEnd = (*out)->end(); in != inEnd; ++in) {
-
+ inEnd = (*out)->end();
+ in != inEnd;
+ ++in) {
if (invalid != NULL && !(*in)->dotAssignments().empty()) {
while (invalid != (*in)->dotAssignments().front().first) {
Fragment* prev = invalid->getPrevNode();
@@ -2360,7 +2260,9 @@ void GNULDBackend::setOutputSectionAddress(Module& pModule)
}
for (SectionMap::Input::dot_iterator it = (*in)->dot_begin(),
- ie = (*in)->dot_end(); it != ie; ++it) {
+ ie = (*in)->dot_end();
+ it != ie;
+ ++it) {
(*it).second.assign(evaluator);
if ((*it).first != NULL) {
uint64_t new_offset = (*it).second.symbol().value() - vma;
@@ -2370,8 +2272,8 @@ void GNULDBackend::setOutputSectionAddress(Module& pModule)
changed = true;
}
}
- } // for each dot assignment
- } // for each input description
+ } // for each dot assignment
+ } // for each input description
if (changed) {
while (invalid != NULL) {
@@ -2383,73 +2285,72 @@ void GNULDBackend::setOutputSectionAddress(Module& pModule)
cur->setSize(cur->getSectionData()->back().getOffset() +
cur->getSectionData()->back().size());
}
-
- } // for each output section description
+ } // for each output section description
}
/// placeOutputSections - place output sections based on SectionMap
-void GNULDBackend::placeOutputSections(Module& pModule)
-{
+void GNULDBackend::placeOutputSections(Module& pModule) {
typedef std::vector<LDSection*> Orphans;
Orphans orphans;
SectionMap& sectionMap = pModule.getScript().sectionMap();
for (Module::iterator it = pModule.begin(), ie = pModule.end(); it != ie;
- ++it) {
+ ++it) {
bool wanted = false;
switch ((*it)->kind()) {
- // take NULL and StackNote directly
- case LDFileFormat::Null:
- case LDFileFormat::StackNote:
- wanted = true;
- break;
- // ignore if section size is 0
- case LDFileFormat::EhFrame:
- if (((*it)->size() != 0) ||
- ((*it)->hasEhFrame() &&
- config().codeGenType() == LinkerConfig::Object))
- wanted = true;
- break;
- case LDFileFormat::Relocation:
- if (((*it)->size() != 0) ||
- ((*it)->hasRelocData() &&
- config().codeGenType() == LinkerConfig::Object))
- wanted = true;
- break;
- case LDFileFormat::TEXT:
- case LDFileFormat::DATA:
- case LDFileFormat::Target:
- case LDFileFormat::MetaData:
- case LDFileFormat::BSS:
- case LDFileFormat::Debug:
- case LDFileFormat::GCCExceptTable:
- case LDFileFormat::Note:
- case LDFileFormat::NamePool:
- case LDFileFormat::EhFrameHdr:
- if (((*it)->size() != 0) ||
- ((*it)->hasSectionData() &&
- config().codeGenType() == LinkerConfig::Object))
+ // take NULL and StackNote directly
+ case LDFileFormat::Null:
+ case LDFileFormat::StackNote:
wanted = true;
- break;
- case LDFileFormat::Group:
- if (LinkerConfig::Object == config().codeGenType()) {
- //TODO: support incremental linking
- ;
- }
- break;
- case LDFileFormat::Version:
- if ((*it)->size() != 0) {
- wanted = true;
- warning(diag::warn_unsupported_symbolic_versioning) << (*it)->name();
- }
- break;
- default:
- if ((*it)->size() != 0) {
- error(diag::err_unsupported_section) << (*it)->name() << (*it)->kind();
- }
- break;
- } // end of switch
+ break;
+ // ignore if section size is 0
+ case LDFileFormat::EhFrame:
+ if (((*it)->size() != 0) ||
+ ((*it)->hasEhFrame() &&
+ config().codeGenType() == LinkerConfig::Object))
+ wanted = true;
+ break;
+ case LDFileFormat::Relocation:
+ if (((*it)->size() != 0) ||
+ ((*it)->hasRelocData() &&
+ config().codeGenType() == LinkerConfig::Object))
+ wanted = true;
+ break;
+ case LDFileFormat::TEXT:
+ case LDFileFormat::DATA:
+ case LDFileFormat::Target:
+ case LDFileFormat::MetaData:
+ case LDFileFormat::BSS:
+ case LDFileFormat::Debug:
+ case LDFileFormat::DebugString:
+ case LDFileFormat::GCCExceptTable:
+ case LDFileFormat::Note:
+ case LDFileFormat::NamePool:
+ case LDFileFormat::EhFrameHdr:
+ if (((*it)->size() != 0) ||
+ ((*it)->hasSectionData() &&
+ config().codeGenType() == LinkerConfig::Object))
+ wanted = true;
+ break;
+ case LDFileFormat::Group:
+ if (LinkerConfig::Object == config().codeGenType()) {
+ // TODO: support incremental linking
+ }
+ break;
+ case LDFileFormat::Version:
+ if ((*it)->size() != 0) {
+ wanted = true;
+ warning(diag::warn_unsupported_symbolic_versioning) << (*it)->name();
+ }
+ break;
+ default:
+ if ((*it)->size() != 0) {
+ error(diag::err_unsupported_section) << (*it)->name()
+ << (*it)->kind();
+ }
+ break;
+ } // end of switch
if (wanted) {
SectionMap::iterator out, outBegin, outEnd;
@@ -2459,21 +2360,21 @@ void GNULDBackend::placeOutputSections(Module& pModule)
bool matched = false;
if ((*it)->name().compare((*out)->name()) == 0) {
switch ((*out)->prolog().constraint()) {
- case OutputSectDesc::NO_CONSTRAINT:
- matched = true;
- break;
- case OutputSectDesc::ONLY_IF_RO:
- matched = ((*it)->flag() & llvm::ELF::SHF_WRITE) == 0;
- break;
- case OutputSectDesc::ONLY_IF_RW:
- matched = ((*it)->flag() & llvm::ELF::SHF_WRITE) != 0;
- break;
- } // end of switch
+ case OutputSectDesc::NO_CONSTRAINT:
+ matched = true;
+ break;
+ case OutputSectDesc::ONLY_IF_RO:
+ matched = ((*it)->flag() & llvm::ELF::SHF_WRITE) == 0;
+ break;
+ case OutputSectDesc::ONLY_IF_RW:
+ matched = ((*it)->flag() & llvm::ELF::SHF_WRITE) != 0;
+ break;
+ } // end of switch
if (matched)
break;
}
- } // for each output section description
+ } // for each output section description
if (out != outEnd) {
// set up the section
@@ -2483,14 +2384,16 @@ void GNULDBackend::placeOutputSections(Module& pModule)
orphans.push_back(*it);
}
}
- } // for each section in Module
+ } // for each section in Module
// set up sections in SectionMap but do not exist at all.
uint32_t flag = 0x0;
unsigned int order = SHO_UNDEFINED;
OutputSectDesc::Type type = OutputSectDesc::LOAD;
for (SectionMap::reverse_iterator out = sectionMap.rbegin(),
- outEnd = sectionMap.rend(); out != outEnd; ++out) {
+ outEnd = sectionMap.rend();
+ out != outEnd;
+ ++out) {
if ((*out)->hasContent() ||
(*out)->getSection()->kind() == LDFileFormat::Null ||
(*out)->getSection()->kind() == LDFileFormat::StackNote) {
@@ -2502,11 +2405,11 @@ void GNULDBackend::placeOutputSections(Module& pModule)
(*out)->setOrder(order);
(*out)->prolog().setType(type);
}
- } // for each output section description
+ } // for each output section description
// place orphan sections
for (Orphans::iterator it = orphans.begin(), ie = orphans.end(); it != ie;
- ++it) {
+ ++it) {
size_t order = getSectionOrder(**it);
SectionMap::iterator out, outBegin, outEnd;
outBegin = sectionMap.begin();
@@ -2522,13 +2425,12 @@ void GNULDBackend::placeOutputSections(Module& pModule)
out = sectionMap.insert(out, *it);
}
(*out)->setOrder(order);
- } // for each orphan section
+ } // for each orphan section
// sort output section orders if there is no default ldscript
if (config().options().getScriptList().empty()) {
- std::stable_sort(sectionMap.begin(),
- sectionMap.end(),
- SectionMap::SHOCompare());
+ std::stable_sort(
+ sectionMap.begin(), sectionMap.end(), SectionMap::SHOCompare());
}
// when section ordering is fixed, now we can make sure dot assignments are
@@ -2537,8 +2439,7 @@ void GNULDBackend::placeOutputSections(Module& pModule)
}
/// layout - layout method
-void GNULDBackend::layout(Module& pModule)
-{
+void GNULDBackend::layout(Module& pModule) {
// 1. place output sections based on SectionMap from SECTIONS command
placeOutputSections(pModule);
@@ -2546,7 +2447,8 @@ void GNULDBackend::layout(Module& pModule)
SectionMap& sectionMap = pModule.getScript().sectionMap();
pModule.getSectionTable().clear();
for (SectionMap::iterator out = sectionMap.begin(), outEnd = sectionMap.end();
- out != outEnd; ++out) {
+ out != outEnd;
+ ++out) {
if ((*out)->hasContent() ||
(*out)->getSection()->kind() == LDFileFormat::Null ||
(*out)->getSection()->kind() == LDFileFormat::StackNote ||
@@ -2554,7 +2456,7 @@ void GNULDBackend::layout(Module& pModule)
(*out)->getSection()->setIndex(pModule.size());
pModule.getSectionTable().push_back((*out)->getSection());
}
- } // for each output section description
+ } // for each output section description
// 3. update the size of .shstrtab
sizeShstrtab(pModule);
@@ -2571,42 +2473,38 @@ void GNULDBackend::layout(Module& pModule)
setOutputSectionOffset(pModule);
}
-void GNULDBackend::createAndSizeEhFrameHdr(Module& pModule)
-{
+void GNULDBackend::createAndSizeEhFrameHdr(Module& pModule) {
if (LinkerConfig::Object != config().codeGenType() &&
config().options().hasEhFrameHdr() && getOutputFormat()->hasEhFrame()) {
// init EhFrameHdr and size the output section
ELFFileFormat* format = getOutputFormat();
- m_pEhFrameHdr = new EhFrameHdr(format->getEhFrameHdr(),
- format->getEhFrame());
+ m_pEhFrameHdr =
+ new EhFrameHdr(format->getEhFrameHdr(), format->getEhFrame());
m_pEhFrameHdr->sizeOutput();
}
}
/// mayHaveUnsafeFunctionPointerAccess - check if the section may have unsafe
/// function pointer access
-bool GNULDBackend::mayHaveUnsafeFunctionPointerAccess(const LDSection& pSection)
- const
-{
+bool GNULDBackend::mayHaveUnsafeFunctionPointerAccess(
+ const LDSection& pSection) const {
llvm::StringRef name(pSection.name());
return !name.startswith(".rodata._ZTV") &&
!name.startswith(".data.rel.ro._ZTV") &&
!name.startswith(".rodata._ZTC") &&
- !name.startswith(".data.rel.ro._ZTC") &&
- !name.startswith(".eh_frame");
+ !name.startswith(".data.rel.ro._ZTC") && !name.startswith(".eh_frame");
}
/// preLayout - Backend can do any needed modification before layout
-void GNULDBackend::preLayout(Module& pModule, IRBuilder& pBuilder)
-{
+void GNULDBackend::preLayout(Module& pModule, IRBuilder& pBuilder) {
// prelayout target first
doPreLayout(pBuilder);
// change .tbss and .tdata section symbol from Local to LocalDyn category
- if (NULL != f_pTDATA)
+ if (f_pTDATA != NULL)
pModule.getSymbolTable().changeToDynamic(*f_pTDATA);
- if (NULL != f_pTBSS)
+ if (f_pTBSS != NULL)
pModule.getSymbolTable().changeToDynamic(*f_pTBSS);
// To merge input's relocation sections into output's relocation sections.
@@ -2618,14 +2516,11 @@ void GNULDBackend::preLayout(Module& pModule, IRBuilder& pBuilder)
for (input = pModule.obj_begin(); input != inEnd; ++input) {
LDContext::sect_iterator rs, rsEnd = (*input)->context()->relocSectEnd();
for (rs = (*input)->context()->relocSectBegin(); rs != rsEnd; ++rs) {
-
// get the output relocation LDSection with identical name.
LDSection* output_sect = pModule.getSection((*rs)->name());
- if (NULL == output_sect) {
- output_sect = LDSection::Create((*rs)->name(),
- (*rs)->kind(),
- (*rs)->type(),
- (*rs)->flag());
+ if (output_sect == NULL) {
+ output_sect = LDSection::Create(
+ (*rs)->name(), (*rs)->kind(), (*rs)->type(), (*rs)->flag());
output_sect->setAlign((*rs)->align());
pModule.getSectionTable().push_back(output_sect);
@@ -2633,11 +2528,11 @@ void GNULDBackend::preLayout(Module& pModule, IRBuilder& pBuilder)
// set output relocation section link
const LDSection* input_link = (*rs)->getLink();
- assert(NULL != input_link && "Illegal input relocation section.");
+ assert(input_link != NULL && "Illegal input relocation section.");
// get the linked output section
LDSection* output_link = pModule.getSection(input_link->name());
- assert(NULL != output_link);
+ assert(output_link != NULL);
output_sect->setLink(output_link);
@@ -2649,9 +2544,9 @@ void GNULDBackend::preLayout(Module& pModule, IRBuilder& pBuilder)
// move relocations from input's to output's RelcoationData
RelocData::RelocationListType& out_list =
- out_reloc_data->getRelocationList();
+ out_reloc_data->getRelocationList();
RelocData::RelocationListType& in_list =
- (*rs)->getRelocData()->getRelocationList();
+ (*rs)->getRelocData()->getRelocationList();
out_list.splice(out_list.end(), in_list);
// size output
@@ -2663,17 +2558,16 @@ void GNULDBackend::preLayout(Module& pModule, IRBuilder& pBuilder)
fatal(diag::unknown_reloc_section_type) << output_sect->type()
<< output_sect->name();
}
- } // end of for each relocation section
- } // end of for each input
- } // end of if
+ } // end of for each relocation section
+ } // end of for each input
+ } // end of if
// set up the section flag of .note.GNU-stack section
setupGNUStackInfo(pModule);
}
/// postLayout - Backend can do any needed modification after layout
-void GNULDBackend::postLayout(Module& pModule, IRBuilder& pBuilder)
-{
+void GNULDBackend::postLayout(Module& pModule, IRBuilder& pBuilder) {
if (LinkerConfig::Object != config().codeGenType()) {
// do relaxation
relax(pModule, pBuilder);
@@ -2684,8 +2578,7 @@ void GNULDBackend::postLayout(Module& pModule, IRBuilder& pBuilder)
doPostLayout(pModule, pBuilder);
}
-void GNULDBackend::postProcessing(FileOutputBuffer& pOutput)
-{
+void GNULDBackend::postProcessing(FileOutputBuffer& pOutput) {
if (LinkerConfig::Object != config().codeGenType() &&
config().options().hasEhFrameHdr() && getOutputFormat()->hasEhFrame()) {
// emit eh_frame_hdr
@@ -2694,15 +2587,11 @@ void GNULDBackend::postProcessing(FileOutputBuffer& pOutput)
}
/// getHashBucketCount - calculate hash bucket count.
-/// @ref Google gold linker, dynobj.cc:791
unsigned GNULDBackend::getHashBucketCount(unsigned pNumOfSymbols,
- bool pIsGNUStyle)
-{
- // @ref Google gold, dynobj.cc:loc 791
- static const unsigned int buckets[] =
- {
- 1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209,
- 16411, 32771, 65537, 131101, 262147
+ bool pIsGNUStyle) {
+ static const unsigned int buckets[] = {
+ 1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209, 16411,
+ 32771, 65537, 131101, 262147
};
const unsigned buckets_count = sizeof buckets / sizeof buckets[0];
@@ -2720,11 +2609,9 @@ unsigned GNULDBackend::getHashBucketCount(unsigned pNumOfSymbols,
}
/// getGNUHashMaskbitslog2 - calculate the number of mask bits in log2
-/// @ref binutils gold, dynobj.cc:1165
-unsigned GNULDBackend::getGNUHashMaskbitslog2(unsigned pNumOfSymbols) const
-{
+unsigned GNULDBackend::getGNUHashMaskbitslog2(unsigned pNumOfSymbols) const {
uint32_t maskbitslog2 = 1;
- for (uint32_t x = pNumOfSymbols >> 1; x != 0; x >>=1)
+ for (uint32_t x = pNumOfSymbols >> 1; x != 0; x >>= 1)
++maskbitslog2;
if (maskbitslog2 < 3)
@@ -2741,9 +2628,7 @@ unsigned GNULDBackend::getGNUHashMaskbitslog2(unsigned pNumOfSymbols) const
}
/// isDynamicSymbol
-/// @ref Google gold linker: symtab.cc:311
-bool GNULDBackend::isDynamicSymbol(const LDSymbol& pSymbol) const
-{
+bool GNULDBackend::isDynamicSymbol(const LDSymbol& pSymbol) const {
// If a local symbol is in the LDContext's symbol table, it's a real local
// symbol. We should not add it
if (pSymbol.binding() == ResolveInfo::Local)
@@ -2752,7 +2637,7 @@ bool GNULDBackend::isDynamicSymbol(const LDSymbol& pSymbol) const
// If we are building shared object, and the visibility is external, we
// need to add it.
if (LinkerConfig::DynObj == config().codeGenType() ||
- LinkerConfig::Exec == config().codeGenType() ||
+ LinkerConfig::Exec == config().codeGenType() ||
LinkerConfig::Binary == config().codeGenType()) {
if (pSymbol.resolveInfo()->visibility() == ResolveInfo::Default ||
pSymbol.resolveInfo()->visibility() == ResolveInfo::Protected)
@@ -2762,9 +2647,7 @@ bool GNULDBackend::isDynamicSymbol(const LDSymbol& pSymbol) const
}
/// isDynamicSymbol
-/// @ref Google gold linker: symtab.cc:311
-bool GNULDBackend::isDynamicSymbol(const ResolveInfo& pResolveInfo) const
-{
+bool GNULDBackend::isDynamicSymbol(const ResolveInfo& pResolveInfo) const {
// If a local symbol is in the LDContext's symbol table, it's a real local
// symbol. We should not add it
if (pResolveInfo.binding() == ResolveInfo::Local)
@@ -2773,7 +2656,7 @@ bool GNULDBackend::isDynamicSymbol(const ResolveInfo& pResolveInfo) const
// If we are building shared object, and the visibility is external, we
// need to add it.
if (LinkerConfig::DynObj == config().codeGenType() ||
- LinkerConfig::Exec == config().codeGenType() ||
+ LinkerConfig::Exec == config().codeGenType() ||
LinkerConfig::Binary == config().codeGenType()) {
if (pResolveInfo.visibility() == ResolveInfo::Default ||
pResolveInfo.visibility() == ResolveInfo::Protected)
@@ -2783,23 +2666,19 @@ bool GNULDBackend::isDynamicSymbol(const ResolveInfo& pResolveInfo) const
}
/// elfSegmentTable - return the reference of the elf segment table
-ELFSegmentFactory& GNULDBackend::elfSegmentTable()
-{
+ELFSegmentFactory& GNULDBackend::elfSegmentTable() {
assert(m_pELFSegmentTable != NULL && "Do not create ELFSegmentTable!");
return *m_pELFSegmentTable;
}
/// elfSegmentTable - return the reference of the elf segment table
-const ELFSegmentFactory& GNULDBackend::elfSegmentTable() const
-{
+const ELFSegmentFactory& GNULDBackend::elfSegmentTable() const {
assert(m_pELFSegmentTable != NULL && "Do not create ELFSegmentTable!");
return *m_pELFSegmentTable;
}
/// commonPageSize - the common page size of the target machine.
-/// @ref gold linker: target.h:135
-uint64_t GNULDBackend::commonPageSize() const
-{
+uint64_t GNULDBackend::commonPageSize() const {
if (config().options().commPageSize() > 0)
return std::min(config().options().commPageSize(), abiPageSize());
else
@@ -2807,9 +2686,7 @@ uint64_t GNULDBackend::commonPageSize() const
}
/// abiPageSize - the abi page size of the target machine.
-/// @ref gold linker: target.h:125
-uint64_t GNULDBackend::abiPageSize() const
-{
+uint64_t GNULDBackend::abiPageSize() const {
if (config().options().maxPageSize() > 0)
return config().options().maxPageSize();
else
@@ -2818,9 +2695,7 @@ uint64_t GNULDBackend::abiPageSize() const
/// isSymbolPreemtible - whether the symbol can be preemted by other
/// link unit
-/// @ref Google gold linker, symtab.h:551
-bool GNULDBackend::isSymbolPreemptible(const ResolveInfo& pSym) const
-{
+bool GNULDBackend::isSymbolPreemptible(const ResolveInfo& pSym) const {
if (pSym.other() != ResolveInfo::Default)
return false;
@@ -2846,16 +2721,13 @@ bool GNULDBackend::isSymbolPreemptible(const ResolveInfo& pSym) const
}
/// symbolNeedsDynRel - return whether the symbol needs a dynamic relocation
-/// @ref Google gold linker, symtab.h:645
bool GNULDBackend::symbolNeedsDynRel(const ResolveInfo& pSym,
bool pSymHasPLT,
- bool isAbsReloc) const
-{
+ bool isAbsReloc) const {
// an undefined reference in the executables should be statically
// resolved to 0 and no need a dynamic relocation
- if (pSym.isUndef() &&
- !pSym.isDyn() &&
- (LinkerConfig::Exec == config().codeGenType() ||
+ if (pSym.isUndef() && !pSym.isDyn() &&
+ (LinkerConfig::Exec == config().codeGenType() ||
LinkerConfig::Binary == config().codeGenType()))
return false;
@@ -2871,19 +2743,15 @@ bool GNULDBackend::symbolNeedsDynRel(const ResolveInfo& pSym,
return false;
if (!config().isCodeIndep() && pSymHasPLT)
return false;
- if (pSym.isDyn() || pSym.isUndef() ||
- isSymbolPreemptible(pSym))
+ if (pSym.isDyn() || pSym.isUndef() || isSymbolPreemptible(pSym))
return true;
return false;
}
/// symbolNeedsPLT - return whether the symbol needs a PLT entry
-/// @ref Google gold linker, symtab.h:596
-bool GNULDBackend::symbolNeedsPLT(const ResolveInfo& pSym) const
-{
- if (pSym.isUndef() &&
- !pSym.isDyn() &&
+bool GNULDBackend::symbolNeedsPLT(const ResolveInfo& pSym) const {
+ if (pSym.isUndef() && !pSym.isDyn() &&
LinkerConfig::DynObj != config().codeGenType())
return false;
@@ -2900,16 +2768,12 @@ bool GNULDBackend::symbolNeedsPLT(const ResolveInfo& pSym) const
if (config().options().isPIE())
return false;
- return (pSym.isDyn() ||
- pSym.isUndef() ||
- isSymbolPreemptible(pSym));
+ return (pSym.isDyn() || pSym.isUndef() || isSymbolPreemptible(pSym));
}
/// symbolHasFinalValue - return true if the symbol's value can be decided at
/// link time
-/// @ref Google gold linker, Symbol::final_value_is_known
-bool GNULDBackend::symbolFinalValueIsKnown(const ResolveInfo& pSym) const
-{
+bool GNULDBackend::symbolFinalValueIsKnown(const ResolveInfo& pSym) const {
// if the output is pic code or if not executables, symbols' value may change
// at runtime
// FIXME: CodeIndep() || LinkerConfig::Relocatable == CodeGenType
@@ -2935,14 +2799,11 @@ bool GNULDBackend::symbolFinalValueIsKnown(const ResolveInfo& pSym) const
/// symbolNeedsCopyReloc - return whether the symbol needs a copy relocation
bool GNULDBackend::symbolNeedsCopyReloc(const Relocation& pReloc,
- const ResolveInfo& pSym) const
-{
+ const ResolveInfo& pSym) const {
// only the reference from dynamic executable to non-function symbol in
// the dynamic objects may need copy relocation
- if (config().isCodeIndep() ||
- !pSym.isDyn() ||
- pSym.type() == ResolveInfo::Function ||
- pSym.size() == 0)
+ if (config().isCodeIndep() || !pSym.isDyn() ||
+ pSym.type() == ResolveInfo::Function || pSym.size() == 0)
return false;
// check if the option -z nocopyreloc is given
@@ -2958,40 +2819,34 @@ bool GNULDBackend::symbolNeedsCopyReloc(const Relocation& pReloc,
return false;
}
-LDSymbol& GNULDBackend::getTDATASymbol()
-{
- assert(NULL != f_pTDATA);
+LDSymbol& GNULDBackend::getTDATASymbol() {
+ assert(f_pTDATA != NULL);
return *f_pTDATA;
}
-const LDSymbol& GNULDBackend::getTDATASymbol() const
-{
- assert(NULL != f_pTDATA);
+const LDSymbol& GNULDBackend::getTDATASymbol() const {
+ assert(f_pTDATA != NULL);
return *f_pTDATA;
}
-LDSymbol& GNULDBackend::getTBSSSymbol()
-{
- assert(NULL != f_pTBSS);
+LDSymbol& GNULDBackend::getTBSSSymbol() {
+ assert(f_pTBSS != NULL);
return *f_pTBSS;
}
-const LDSymbol& GNULDBackend::getTBSSSymbol() const
-{
- assert(NULL != f_pTBSS);
+const LDSymbol& GNULDBackend::getTBSSSymbol() const {
+ assert(f_pTBSS != NULL);
return *f_pTBSS;
}
-llvm::StringRef GNULDBackend::getEntry(const Module& pModule) const
-{
+llvm::StringRef GNULDBackend::getEntry(const Module& pModule) const {
if (pModule.getScript().hasEntry())
return pModule.getScript().entry();
else
return getInfo().entry();
}
-void GNULDBackend::checkAndSetHasTextRel(const LDSection& pSection)
-{
+void GNULDBackend::checkAndSetHasTextRel(const LDSection& pSection) {
if (m_bHasTextRel)
return;
@@ -3006,47 +2861,43 @@ void GNULDBackend::checkAndSetHasTextRel(const LDSection& pSection)
/// sortRelocation - sort the dynamic relocations to let dynamic linker
/// process relocations more efficiently
-void GNULDBackend::sortRelocation(LDSection& pSection)
-{
+void GNULDBackend::sortRelocation(LDSection& pSection) {
if (!config().options().hasCombReloc())
return;
assert(pSection.kind() == LDFileFormat::Relocation);
switch (config().codeGenType()) {
- case LinkerConfig::DynObj:
- case LinkerConfig::Exec:
- if (&pSection == &getOutputFormat()->getRelDyn() ||
- &pSection == &getOutputFormat()->getRelaDyn()) {
- if (pSection.hasRelocData())
- pSection.getRelocData()->sort(RelocCompare(*this));
- }
- default:
- return;
+ case LinkerConfig::DynObj:
+ case LinkerConfig::Exec:
+ if (&pSection == &getOutputFormat()->getRelDyn() ||
+ &pSection == &getOutputFormat()->getRelaDyn()) {
+ if (pSection.hasRelocData())
+ pSection.getRelocData()->sort(RelocCompare(*this));
+ }
+ default:
+ return;
}
}
/// initBRIslandFactory - initialize the branch island factory for relaxation
-bool GNULDBackend::initBRIslandFactory()
-{
- if (NULL == m_pBRIslandFactory) {
- m_pBRIslandFactory = new BranchIslandFactory(maxFwdBranchOffset(),
- maxBwdBranchOffset());
+bool GNULDBackend::initBRIslandFactory() {
+ if (m_pBRIslandFactory == NULL) {
+ m_pBRIslandFactory =
+ new BranchIslandFactory(maxFwdBranchOffset(), maxBwdBranchOffset());
}
return true;
}
/// initStubFactory - initialize the stub factory for relaxation
-bool GNULDBackend::initStubFactory()
-{
- if (NULL == m_pStubFactory) {
+bool GNULDBackend::initStubFactory() {
+ if (m_pStubFactory == NULL) {
m_pStubFactory = new StubFactory();
}
return true;
}
-bool GNULDBackend::relax(Module& pModule, IRBuilder& pBuilder)
-{
+bool GNULDBackend::relax(Module& pModule, IRBuilder& pBuilder) {
if (!mayRelax())
return true;
@@ -3062,8 +2913,7 @@ bool GNULDBackend::relax(Module& pModule, IRBuilder& pBuilder)
return true;
}
-bool GNULDBackend::DynsymCompare::needGNUHash(const LDSymbol& X) const
-{
+bool GNULDBackend::DynsymCompare::needGNUHash(const LDSymbol& X) const {
// FIXME: in bfd and gold linker, an undefined symbol might be hashed
// when the ouput is not PIC, if the symbol is referred by a non pc-relative
// reloc, and its value is set to the addr of the plt entry.
@@ -3071,14 +2921,12 @@ bool GNULDBackend::DynsymCompare::needGNUHash(const LDSymbol& X) const
}
bool GNULDBackend::DynsymCompare::operator()(const LDSymbol* X,
- const LDSymbol* Y) const
-{
+ const LDSymbol* Y) const {
return !needGNUHash(*X) && needGNUHash(*Y);
}
bool GNULDBackend::RelocCompare::operator()(const Relocation* X,
- const Relocation* Y) const
-{
+ const Relocation* Y) const {
// 1. compare if relocation is relative
if (X->symInfo() == NULL) {
if (Y->symInfo() != NULL)
@@ -3115,3 +2963,5 @@ bool GNULDBackend::RelocCompare::operator()(const Relocation* X,
return false;
}
+
+} // namespace mcld
diff --git a/lib/Target/GOT.cpp b/lib/Target/GOT.cpp
index a441775..0e08c8b 100644
--- a/lib/Target/GOT.cpp
+++ b/lib/Target/GOT.cpp
@@ -6,32 +6,29 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <llvm/Support/Casting.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/GOT.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/Target/GOT.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/IRBuilder.h>
+#include <llvm/Support/Casting.h>
#include <cstring>
#include <cstdlib>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// GOT
//===----------------------------------------------------------------------===//
-GOT::GOT(LDSection& pSection)
- : m_Section(pSection) {
+GOT::GOT(LDSection& pSection) : m_Section(pSection) {
m_SectionData = IRBuilder::CreateSectionData(pSection);
}
-GOT::~GOT()
-{
+GOT::~GOT() {
}
-void GOT::finalizeSectionSize()
-{
+void GOT::finalizeSectionSize() {
uint32_t offset = 0;
SectionData::iterator frag, fragEnd = m_SectionData->end();
for (frag = m_SectionData->begin(); frag != fragEnd; ++frag) {
@@ -42,3 +39,4 @@ void GOT::finalizeSectionSize()
m_Section.setSize(offset);
}
+} // namespace mcld
diff --git a/lib/Target/Hexagon/Hexagon.h b/lib/Target/Hexagon/Hexagon.h
index 437a839..78e333a 100644
--- a/lib/Target/Hexagon/Hexagon.h
+++ b/lib/Target/Hexagon/Hexagon.h
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGON_H
-#define TARGET_HEXAGON_HEXAGON_H
+#ifndef TARGET_HEXAGON_HEXAGON_H_
+#define TARGET_HEXAGON_HEXAGON_H_
#include <string>
namespace llvm {
class Target;
-} // namespace of llvm
+} // namespace llvm
namespace mcld {
@@ -21,10 +21,9 @@ class TargetLDBackend;
extern mcld::Target TheHexagonTarget;
-TargetLDBackend*
-createHexagonLDBackend(const llvm::Target&, const std::string&);
+TargetLDBackend* createHexagonLDBackend(const llvm::Target&,
+ const std::string&);
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_HEXAGON_HEXAGON_H_
diff --git a/lib/Target/Hexagon/HexagonAbsoluteStub.cpp b/lib/Target/Hexagon/HexagonAbsoluteStub.cpp
index 38c1a3c..3ddf08b 100644
--- a/lib/Target/Hexagon/HexagonAbsoluteStub.cpp
+++ b/lib/Target/Hexagon/HexagonAbsoluteStub.cpp
@@ -1,4 +1,4 @@
-//===- HexagonAbsoluteStub.cpp ---------------------------------------------------===//
+//===- HexagonAbsoluteStub.cpp --------------------------------------------===//
//
// The MCLinker Project
//
@@ -10,34 +10,34 @@
#include "HexagonAbsoluteStub.h"
#include "HexagonLDBackend.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/Fragment/Relocation.h"
+
#include <llvm/Support/ELF.h>
#include <llvm/Support/MathExtras.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Fragment/Relocation.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// HexagonAbsoluteStub
//===----------------------------------------------------------------------===//
const uint32_t HexagonAbsoluteStub::TEMPLATE[] = {
- 0xbffd7f1d, /* { sp = add (sp, #-8) */
- 0xa79dfcfe, /* memw (sp + #-8) = r28 } */
- 0x723cc000, /* r28.h = #HI (foo) */
- 0x713cc000, /* r28.l = #LO (foo) */
- 0xb01d411d, /* { sp = add (sp, #8) */
- 0x529c4000, /* jumpr r28 */
- 0x919dc01c /* r28 = memw (sp) } */
+ 0xbffd7f1d, /* { sp = add (sp, #-8) */
+ 0xa79dfcfe, /* memw (sp + #-8) = r28 } */
+ 0x723cc000, /* r28.h = #HI (foo) */
+ 0x713cc000, /* r28.l = #LO (foo) */
+ 0xb01d411d, /* { sp = add (sp, #8) */
+ 0x529c4000, /* jumpr r28 */
+ 0x919dc01c /* r28 = memw (sp) } */
};
#define FITS_IN_NBITS(D, B) \
- ( llvm::abs64(D) < (~(~(int64_t) 0 << ((B) - 1)) & -(4 * 4)))
+ (llvm::abs64(D) < (~(~(int64_t)0 << ((B)-1)) & -(4 * 4)))
HexagonAbsoluteStub::HexagonAbsoluteStub(bool pIsOutputPIC)
- : Stub(), m_Name("HexagonTrampoline"), m_pData(NULL), m_Size(0x0)
-{
+ : Stub(), m_Name("HexagonTrampoline"), m_pData(NULL), m_Size(0x0) {
m_pData = TEMPLATE;
m_Size = sizeof(TEMPLATE);
addFixup(8u, 0x0, llvm::ELF::R_HEX_HI16);
@@ -49,20 +49,17 @@ HexagonAbsoluteStub::HexagonAbsoluteStub(const uint32_t* pData,
size_t pSize,
const_fixup_iterator pBegin,
const_fixup_iterator pEnd)
- : Stub(), m_Name("AbsVeneer"), m_pData(pData), m_Size(pSize)
-{
+ : Stub(), m_Name("AbsVeneer"), m_pData(pData), m_Size(pSize) {
for (const_fixup_iterator it = pBegin, ie = pEnd; it != ie; ++it)
addFixup(**it);
}
-HexagonAbsoluteStub::~HexagonAbsoluteStub()
-{
+HexagonAbsoluteStub::~HexagonAbsoluteStub() {
}
bool HexagonAbsoluteStub::isMyDuty(const class Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue) const
-{
+ uint64_t pTargetSymValue) const {
int nbits = 0;
switch (pReloc.type()) {
case llvm::ELF::R_HEX_B22_PCREL:
@@ -92,27 +89,24 @@ bool HexagonAbsoluteStub::isMyDuty(const class Relocation& pReloc,
return true;
}
-const std::string& HexagonAbsoluteStub::name() const
-{
+const std::string& HexagonAbsoluteStub::name() const {
return m_Name;
}
-const uint8_t* HexagonAbsoluteStub::getContent() const
-{
+const uint8_t* HexagonAbsoluteStub::getContent() const {
return reinterpret_cast<const uint8_t*>(m_pData);
}
-size_t HexagonAbsoluteStub::size() const
-{
+size_t HexagonAbsoluteStub::size() const {
return m_Size;
}
-size_t HexagonAbsoluteStub::alignment() const
-{
+size_t HexagonAbsoluteStub::alignment() const {
return 4u;
}
-Stub* HexagonAbsoluteStub::doClone()
-{
+Stub* HexagonAbsoluteStub::doClone() {
return new HexagonAbsoluteStub(m_pData, m_Size, fixup_begin(), fixup_end());
}
+
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonAbsoluteStub.h b/lib/Target/Hexagon/HexagonAbsoluteStub.h
index f3ba2e5..c7d8267 100644
--- a/lib/Target/Hexagon/HexagonAbsoluteStub.h
+++ b/lib/Target/Hexagon/HexagonAbsoluteStub.h
@@ -1,4 +1,4 @@
-//===- HexagonAbsoluteStub.h -----------------------------------------------===//
+//===- HexagonAbsoluteStub.h ----------------------------------------------===//
//
// The MCLinker Project
//
@@ -6,17 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_HEXAGON_HEXAGONABSOLUTESTUB_H_
+#define TARGET_HEXAGON_HEXAGONABSOLUTESTUB_H_
-#ifndef TARGET_HEXAGON_HEXAGONABSOLUTESTUB_H
-#define TARGET_HEXAGON_HEXAGONABSOLUTESTUB_H
-
+#include "mcld/Fragment/Stub.h"
#include <llvm/Support/DataTypes.h>
-#include <mcld/Fragment/Stub.h>
#include <string>
#include <vector>
-namespace mcld
-{
+namespace mcld {
class Relocation;
class ResolveInfo;
@@ -25,10 +23,9 @@ class ResolveInfo;
* \brief Hexagon stub for abs long call from source to target
*
*/
-class HexagonAbsoluteStub : public Stub
-{
-public:
- HexagonAbsoluteStub(bool pIsOutputPIC);
+class HexagonAbsoluteStub : public Stub {
+ public:
+ explicit HexagonAbsoluteStub(bool pIsOutputPIC);
~HexagonAbsoluteStub();
@@ -46,27 +43,27 @@ public:
size_t alignment() const;
-private:
+ private:
HexagonAbsoluteStub(const HexagonAbsoluteStub&);
HexagonAbsoluteStub& operator=(const HexagonAbsoluteStub&);
/// for doClone
HexagonAbsoluteStub(const uint32_t* pData,
- size_t pSize,
- const_fixup_iterator pBegin,
- const_fixup_iterator pEnd);
+ size_t pSize,
+ const_fixup_iterator pBegin,
+ const_fixup_iterator pEnd);
/// doClone
Stub* doClone();
-private:
+ private:
std::string m_Name;
static const uint32_t TEMPLATE[];
const uint32_t* m_pData;
size_t m_Size;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_HEXAGON_HEXAGONABSOLUTESTUB_H_
diff --git a/lib/Target/Hexagon/HexagonDiagnostic.cpp b/lib/Target/Hexagon/HexagonDiagnostic.cpp
index 7fd58c0..4122daa 100644
--- a/lib/Target/Hexagon/HexagonDiagnostic.cpp
+++ b/lib/Target/Hexagon/HexagonDiagnostic.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/DWARFLineInfo.h>
+#include "mcld/LD/DWARFLineInfo.h"
+#include "mcld/Support/TargetRegistry.h"
#include "Hexagon.h"
namespace mcld {
@@ -16,22 +16,18 @@ namespace mcld {
// createHexagonDiagnostic - the help function to create corresponding
// HexagonDiagnostic
//===----------------------------------------------------------------------===//
-DiagnosticLineInfo*
-createHexagonDiagLineInfo(const Target& pTarget, const std::string &pTriple)
-{
+DiagnosticLineInfo* createHexagonDiagLineInfo(const Target& pTarget,
+ const std::string& pTriple) {
return new DWARFLineInfo();
}
-} // namespace of mcld
-
-using namespace mcld;
+} // namespace mcld
//===----------------------------------------------------------------------===//
// InitializeHexagonDiagnostic
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeHexagonDiagnosticLineInfo() {
// Register the linker frontend
- mcld::TargetRegistry::RegisterDiagnosticLineInfo(TheHexagonTarget,
- createHexagonDiagLineInfo);
+ mcld::TargetRegistry::RegisterDiagnosticLineInfo(
+ mcld::TheHexagonTarget, mcld::createHexagonDiagLineInfo);
}
-
diff --git a/lib/Target/Hexagon/HexagonELFDynamic.cpp b/lib/Target/Hexagon/HexagonELFDynamic.cpp
index 96534cc..8fe17d9 100644
--- a/lib/Target/Hexagon/HexagonELFDynamic.cpp
+++ b/lib/Target/Hexagon/HexagonELFDynamic.cpp
@@ -8,30 +8,28 @@
//===----------------------------------------------------------------------===//
#include "HexagonELFDynamic.h"
-#include <mcld/LD/ELFFileFormat.h>
+#include "mcld/LD/ELFFileFormat.h"
-using namespace mcld;
+namespace mcld {
HexagonELFDynamic::HexagonELFDynamic(const GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : ELFDynamic(pParent, pConfig) {
+ : ELFDynamic(pParent, pConfig) {
}
-HexagonELFDynamic::~HexagonELFDynamic()
-{
+HexagonELFDynamic::~HexagonELFDynamic() {
}
-void HexagonELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat)
-{
+void HexagonELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat) {
// reservePLTGOT
if (pFormat.hasGOTPLT())
reserveOne(llvm::ELF::DT_PLTGOT);
}
-void HexagonELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat)
-{
+void HexagonELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat) {
// applyPLTGOT
if (pFormat.hasGOTPLT())
applyOne(llvm::ELF::DT_PLTGOT, pFormat.getGOTPLT().addr());
}
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonELFDynamic.h b/lib/Target/Hexagon/HexagonELFDynamic.h
index d1d43dc..97c826a 100644
--- a/lib/Target/Hexagon/HexagonELFDynamic.h
+++ b/lib/Target/Hexagon/HexagonELFDynamic.h
@@ -6,24 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONELFDYNAMIC_H
-#define TARGET_HEXAGON_HEXAGONELFDYNAMIC_H
+#ifndef TARGET_HEXAGON_HEXAGONELFDYNAMIC_H_
+#define TARGET_HEXAGON_HEXAGONELFDYNAMIC_H_
-#include <mcld/Target/ELFDynamic.h>
+#include "mcld/Target/ELFDynamic.h"
namespace mcld {
-class HexagonELFDynamic : public ELFDynamic
-{
-public:
+class HexagonELFDynamic : public ELFDynamic {
+ public:
HexagonELFDynamic(const GNULDBackend& pParent, const LinkerConfig& pConfig);
~HexagonELFDynamic();
-private:
+ private:
void reserveTargetEntries(const ELFFileFormat& pFormat);
void applyTargetEntries(const ELFFileFormat& pFormat);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_HEXAGON_HEXAGONELFDYNAMIC_H_
diff --git a/lib/Target/Hexagon/HexagonELFMCLinker.cpp b/lib/Target/Hexagon/HexagonELFMCLinker.cpp
deleted file mode 100644
index bf5f7d7..0000000
--- a/lib/Target/Hexagon/HexagonELFMCLinker.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-//===- HexagonELFMCLinker.cpp ---------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "HexagonELFMCLinker.h"
-
-using namespace mcld;
-
-HexagonELFMCLinker::HexagonELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
- : ELFMCLinker(pConfig, pModule, pFileHandle) {
-}
-
-HexagonELFMCLinker::~HexagonELFMCLinker()
-{
-}
-
diff --git a/lib/Target/Hexagon/HexagonELFMCLinker.h b/lib/Target/Hexagon/HexagonELFMCLinker.h
deleted file mode 100644
index 777420d..0000000
--- a/lib/Target/Hexagon/HexagonELFMCLinker.h
+++ /dev/null
@@ -1,35 +0,0 @@
-//===- HexagonELFMCLinker.h -----------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONELFMCLINKER_H
-#define TARGET_HEXAGON_HEXAGONELFMCLINKER_H
-#include <mcld/Target/ELFMCLinker.h>
-
-namespace mcld {
-
-class Module;
-class FileHandle;
-
-/** \class HexagonELFMCLinker
- * \brief HexagonELFMCLinker sets up the environment for linking.
- *
- * \see
- */
-class HexagonELFMCLinker : public ELFMCLinker
-{
-public:
- HexagonELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle);
-
- ~HexagonELFMCLinker();
-};
-
-} // namespace of mcld
-
-#endif
diff --git a/lib/Target/Hexagon/HexagonEmulation.cpp b/lib/Target/Hexagon/HexagonEmulation.cpp
index 8a77cf7..d14c082 100644
--- a/lib/Target/Hexagon/HexagonEmulation.cpp
+++ b/lib/Target/Hexagon/HexagonEmulation.cpp
@@ -7,15 +7,15 @@
//
//===----------------------------------------------------------------------===//
#include "Hexagon.h"
-#include <mcld/LinkerScript.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Target/ELFEmulation.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/LinkerScript.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/ELFEmulation.h"
namespace mcld {
-static bool MCLDEmulateHexagonELF(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+static bool MCLDEmulateHexagonELF(LinkerScript& pScript,
+ LinkerConfig& pConfig) {
if (!MCLDEmulateELF(pScript, pConfig))
return false;
@@ -38,8 +38,7 @@ static bool MCLDEmulateHexagonELF(LinkerScript& pScript, LinkerConfig& pConfig)
//===----------------------------------------------------------------------===//
// emulateHexagonLD - the help function to emulate Hexagon ld
//===----------------------------------------------------------------------===//
-bool emulateHexagonLD(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+bool emulateHexagonLD(LinkerScript& pScript, LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker has not supported yet");
return false;
@@ -52,7 +51,7 @@ bool emulateHexagonLD(LinkerScript& pScript, LinkerConfig& pConfig)
return MCLDEmulateHexagonELF(pScript, pConfig);
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// HexagonEmulation
@@ -62,4 +61,3 @@ extern "C" void MCLDInitializeHexagonEmulation() {
mcld::TargetRegistry::RegisterEmulation(mcld::TheHexagonTarget,
mcld::emulateHexagonLD);
}
-
diff --git a/lib/Target/Hexagon/HexagonEncodings.h b/lib/Target/Hexagon/HexagonEncodings.h
index 2a2e9db..a9d056d 100644
--- a/lib/Target/Hexagon/HexagonEncodings.h
+++ b/lib/Target/Hexagon/HexagonEncodings.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONENCODINGS_H
-#define TARGET_HEXAGON_HEXAGONENCODINGS_H
+#ifndef TARGET_HEXAGON_HEXAGONENCODINGS_H_
+#define TARGET_HEXAGON_HEXAGONENCODINGS_H_
Instruction insn_encodings[] = {
{ "if (Pv4) memb(Rs32+#u6:0)=Rt32",
@@ -3558,4 +3558,4 @@ Instruction insn_encodings[] = {
},
};
-#endif
+#endif // TARGET_HEXAGON_HEXAGONENCODINGS_H_
diff --git a/lib/Target/Hexagon/HexagonGNUInfo.cpp b/lib/Target/Hexagon/HexagonGNUInfo.cpp
index ad4cd34..05eb0cc 100644
--- a/lib/Target/Hexagon/HexagonGNUInfo.cpp
+++ b/lib/Target/Hexagon/HexagonGNUInfo.cpp
@@ -11,21 +11,21 @@
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/StringSwitch.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// HexagonGNUInfo
//===----------------------------------------------------------------------===//
HexagonGNUInfo::HexagonGNUInfo(const TargetOptions& pTargetOptions)
- : GNUInfo(pTargetOptions.triple()), m_Options(pTargetOptions) {
+ : GNUInfo(pTargetOptions.triple()), m_Options(pTargetOptions) {
}
/// flags - the value of ElfXX_Ehdr::e_flags
-uint64_t HexagonGNUInfo::flags() const
-{
+uint64_t HexagonGNUInfo::flags() const {
return llvm::StringSwitch<uint64_t>(m_Options.getTargetCPU())
- .Case("hexagonv4", V4)
- .Case("hexagonv5", V5)
- .Default(V4);
+ .Case("hexagonv4", V4)
+ .Case("hexagonv5", V5)
+ .Default(V4);
}
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonGNUInfo.h b/lib/Target/Hexagon/HexagonGNUInfo.h
index 0173e65..d43d95c 100644
--- a/lib/Target/Hexagon/HexagonGNUInfo.h
+++ b/lib/Target/Hexagon/HexagonGNUInfo.h
@@ -6,26 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONGNUINFO_H
-#define TARGET_HEXAGON_HEXAGONGNUINFO_H
-#include <mcld/Target/GNUInfo.h>
-#include <mcld/TargetOptions.h>
+#ifndef TARGET_HEXAGON_HEXAGONGNUINFO_H_
+#define TARGET_HEXAGON_HEXAGONGNUINFO_H_
+#include "mcld/Target/GNUInfo.h"
+#include "mcld/TargetOptions.h"
#include <llvm/Support/ELF.h>
namespace mcld {
-class HexagonGNUInfo : public GNUInfo
-{
-public:
- enum CPUType {
- V3 = 0x2,
- V4 = 0x3,
- V5
- };
+class HexagonGNUInfo : public GNUInfo {
+ public:
+ enum CPUType { V3 = 0x2, V4 = 0x3, V5 };
-public:
- HexagonGNUInfo(const TargetOptions& pTargetOptions);
+ public:
+ explicit HexagonGNUInfo(const TargetOptions& pTargetOptions);
uint32_t machine() const { return llvm::ELF::EM_HEXAGON; }
@@ -34,11 +29,10 @@ public:
/// flags - the value of ElfXX_Ehdr::e_flags
uint64_t flags() const;
-private:
+ private:
const TargetOptions& m_Options;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_HEXAGON_HEXAGONGNUINFO_H_
diff --git a/lib/Target/Hexagon/HexagonGOT.cpp b/lib/Target/Hexagon/HexagonGOT.cpp
index eaa2669..bcfc468 100644
--- a/lib/Target/Hexagon/HexagonGOT.cpp
+++ b/lib/Target/Hexagon/HexagonGOT.cpp
@@ -8,27 +8,24 @@
//===----------------------------------------------------------------------===//
#include "HexagonGOT.h"
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/LD/SectionData.h>
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/LD/SectionData.h"
#include <llvm/Support/Casting.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// HexagonGOT
//===----------------------------------------------------------------------===//
-HexagonGOT::HexagonGOT(LDSection& pSection)
- : GOT(pSection)
-{
+HexagonGOT::HexagonGOT(LDSection& pSection) : GOT(pSection) {
}
-HexagonGOT::~HexagonGOT()
-{
+HexagonGOT::~HexagonGOT() {
}
-HexagonGOTEntry* HexagonGOT::create()
-{
+HexagonGOTEntry* HexagonGOT::create() {
return new HexagonGOTEntry(0, m_SectionData);
}
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonGOT.h b/lib/Target/Hexagon/HexagonGOT.h
index ac94c11..6fa9fab 100644
--- a/lib/Target/Hexagon/HexagonGOT.h
+++ b/lib/Target/Hexagon/HexagonGOT.h
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONGOT_H
-#define TARGET_HEXAGON_HEXAGONGOT_H
+#ifndef TARGET_HEXAGON_HEXAGONGOT_H_
+#define TARGET_HEXAGON_HEXAGONGOT_H_
-#include <mcld/Target/GOT.h>
+#include "mcld/Target/GOT.h"
namespace mcld {
@@ -19,29 +19,25 @@ class SectionData;
/** \class HexagonGOTEntry
* \brief GOT Entry with size of 4 bytes
*/
-class HexagonGOTEntry : public GOT::Entry<4>
-{
-public:
+class HexagonGOTEntry : public GOT::Entry<4> {
+ public:
HexagonGOTEntry(uint64_t pContent, SectionData* pParent)
- : GOT::Entry<4>(pContent, pParent)
- {}
+ : GOT::Entry<4>(pContent, pParent) {}
};
/** \class HexagonGOT
* \brief Hexagon Global Offset Table.
*/
-class HexagonGOT : public GOT
-{
-public:
- HexagonGOT(LDSection& pSection);
+class HexagonGOT : public GOT {
+ public:
+ explicit HexagonGOT(LDSection& pSection);
~HexagonGOT();
HexagonGOTEntry* create();
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_HEXAGON_HEXAGONGOT_H_
diff --git a/lib/Target/Hexagon/HexagonGOTPLT.cpp b/lib/Target/Hexagon/HexagonGOTPLT.cpp
index cfceff5..0601a70 100644
--- a/lib/Target/Hexagon/HexagonGOTPLT.cpp
+++ b/lib/Target/Hexagon/HexagonGOTPLT.cpp
@@ -1,4 +1,4 @@
-//===- HexagonGOTPLT.cpp ------------------------------------------------------===//
+//===- HexagonGOTPLT.cpp --------------------------------------------------===//
//
// The MCLinker Project
//
@@ -9,20 +9,18 @@
#include "HexagonGOTPLT.h"
#include "HexagonPLT.h"
-#include <llvm/Support/Casting.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/Support/MsgHandling.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/Support/MsgHandling.h>
+#include <llvm/Support/Casting.h>
namespace mcld {
//===----------------------------------------------------------------------===//
// HexagonGOTPLT
//===----------------------------------------------------------------------===//
-HexagonGOTPLT::HexagonGOTPLT(LDSection& pSection)
- : HexagonGOT(pSection)
-{
+HexagonGOTPLT::HexagonGOTPLT(LDSection& pSection) : HexagonGOT(pSection) {
// Skip GOT0 entries
for (size_t i = 0; i < HexagonGOTPLT0Num; ++i) {
create();
@@ -30,24 +28,20 @@ HexagonGOTPLT::HexagonGOTPLT(LDSection& pSection)
pSection.setAlign(8);
}
-HexagonGOTPLT::~HexagonGOTPLT()
-{
+HexagonGOTPLT::~HexagonGOTPLT() {
}
// Check if we really have GOT PLT entries ?
-bool HexagonGOTPLT::hasGOT1() const
-{
+bool HexagonGOTPLT::hasGOT1() const {
return (m_SectionData->size() > HexagonGOTPLT0Num);
}
-void HexagonGOTPLT::applyGOT0(uint64_t pAddress)
-{
- llvm::cast<HexagonGOTEntry>
- (*(m_SectionData->getFragmentList().begin())).setValue(pAddress);
+void HexagonGOTPLT::applyGOT0(uint64_t pAddress) {
+ llvm::cast<HexagonGOTEntry>(*(m_SectionData->getFragmentList().begin()))
+ .setValue(pAddress);
}
-void HexagonGOTPLT::applyAllGOTPLT(const HexagonPLT& pPLT)
-{
+void HexagonGOTPLT::applyAllGOTPLT(const HexagonPLT& pPLT) {
iterator it = begin();
// skip GOT0
for (size_t i = 0; i < HexagonGOTPLT0Num; ++i)
@@ -55,9 +49,9 @@ void HexagonGOTPLT::applyAllGOTPLT(const HexagonPLT& pPLT)
// Set the initial value of the GOT entry to the address
// of PLT0, the stub calculates the index of the caller directly from
// the address where the call arised
- for (; it != end() ; ++it) {
+ for (; it != end(); ++it) {
llvm::cast<HexagonGOTEntry>(*it).setValue(pPLT.addr());
}
}
-}
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonGOTPLT.h b/lib/Target/Hexagon/HexagonGOTPLT.h
index fa68bff..e692cd9 100644
--- a/lib/Target/Hexagon/HexagonGOTPLT.h
+++ b/lib/Target/Hexagon/HexagonGOTPLT.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONGOTPLT_H
-#define TARGET_HEXAGON_HEXAGONGOTPLT_H
+#ifndef TARGET_HEXAGON_HEXAGONGOTPLT_H_
+#define TARGET_HEXAGON_HEXAGONGOTPLT_H_
-#include <llvm/ADT/DenseMap.h>
#include "HexagonGOT.h"
+#include <llvm/ADT/DenseMap.h>
namespace mcld {
@@ -23,10 +23,9 @@ const unsigned int HexagonGOTPLT0Num = 4;
/** \class HexagonGOTPLT
* \brief Hexagon .got.plt section.
*/
-class HexagonGOTPLT : public HexagonGOT
-{
-public:
- HexagonGOTPLT(LDSection &pSection);
+class HexagonGOTPLT : public HexagonGOT {
+ public:
+ explicit HexagonGOTPLT(LDSection& pSection);
~HexagonGOTPLT();
@@ -38,6 +37,6 @@ public:
void applyAllGOTPLT(const HexagonPLT& pPLT);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_HEXAGON_HEXAGONGOTPLT_H_
diff --git a/lib/Target/Hexagon/HexagonLDBackend.cpp b/lib/Target/Hexagon/HexagonLDBackend.cpp
index eb3458b..5d4d4dc 100644
--- a/lib/Target/Hexagon/HexagonLDBackend.cpp
+++ b/lib/Target/Hexagon/HexagonLDBackend.cpp
@@ -13,49 +13,48 @@
#include "HexagonGNUInfo.h"
#include "HexagonAbsoluteStub.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Fragment/AlignFragment.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Fragment/Stub.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/StubFactory.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/TargetRegistry.h"
+
#include <llvm/ADT/Triple.h>
#include <llvm/Support/Casting.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/Fragment/AlignFragment.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/Fragment/Stub.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/LD/StubFactory.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/ELFSegment.h>
-
#include <cstring>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// HexagonLDBackend
//===----------------------------------------------------------------------===//
HexagonLDBackend::HexagonLDBackend(const LinkerConfig& pConfig,
HexagonGNUInfo* pInfo)
- : GNULDBackend(pConfig, pInfo),
- m_pRelocator(NULL),
- m_pGOT(NULL),
- m_pGOTPLT(NULL),
- m_pPLT(NULL),
- m_pRelaDyn(NULL),
- m_pRelaPLT(NULL),
- m_pDynamic(NULL),
- m_pGOTSymbol(NULL),
- m_CopyRel(llvm::ELF::R_HEX_COPY) {
+ : GNULDBackend(pConfig, pInfo),
+ m_pRelocator(NULL),
+ m_pGOT(NULL),
+ m_pGOTPLT(NULL),
+ m_pPLT(NULL),
+ m_pRelaDyn(NULL),
+ m_pRelaPLT(NULL),
+ m_pDynamic(NULL),
+ m_pGOTSymbol(NULL),
+ m_CopyRel(llvm::ELF::R_HEX_COPY) {
}
-HexagonLDBackend::~HexagonLDBackend()
-{
+HexagonLDBackend::~HexagonLDBackend() {
delete m_pRelocator;
delete m_pGOT;
delete m_pPLT;
@@ -64,30 +63,26 @@ HexagonLDBackend::~HexagonLDBackend()
delete m_pDynamic;
}
-bool HexagonLDBackend::initRelocator()
-{
- if (NULL == m_pRelocator) {
+bool HexagonLDBackend::initRelocator() {
+ if (m_pRelocator == NULL) {
m_pRelocator = new HexagonRelocator(*this, config());
}
return true;
}
-const Relocator* HexagonLDBackend::getRelocator() const
-{
- assert(NULL != m_pRelocator);
+const Relocator* HexagonLDBackend::getRelocator() const {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-Relocator* HexagonLDBackend::getRelocator()
-{
- assert(NULL != m_pRelocator);
+Relocator* HexagonLDBackend::getRelocator() {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-void HexagonLDBackend::doPreLayout(IRBuilder& pBuilder)
-{
+void HexagonLDBackend::doPreLayout(IRBuilder& pBuilder) {
// initialize .dynamic data
- if (!config().isCodeStatic() && NULL == m_pDynamic)
+ if (!config().isCodeStatic() && m_pDynamic == NULL)
m_pDynamic = new HexagonELFDynamic(*this, config());
// set .got.plt and .got sizes
@@ -102,14 +97,16 @@ void HexagonLDBackend::doPreLayout(IRBuilder& pBuilder)
// set .rela.dyn size
if (!m_pRelaDyn->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
setRelaDynSize();
}
// set .rela.plt size
if (!m_pRelaPLT->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
setRelaPLTSize();
}
}
@@ -118,29 +115,25 @@ void HexagonLDBackend::doPreLayout(IRBuilder& pBuilder)
SetSDataSection();
}
-void HexagonLDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder)
-{
+void HexagonLDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder) {
}
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-HexagonELFDynamic& HexagonLDBackend::dynamic()
-{
- assert(NULL != m_pDynamic);
+HexagonELFDynamic& HexagonLDBackend::dynamic() {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-const HexagonELFDynamic& HexagonLDBackend::dynamic() const
-{
- assert(NULL != m_pDynamic);
+const HexagonELFDynamic& HexagonLDBackend::dynamic() const {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
uint64_t HexagonLDBackend::emitSectionData(const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
if (!pRegion.size())
return 0;
@@ -151,7 +144,6 @@ uint64_t HexagonLDBackend::emitSectionData(const LDSection& pSection,
if ((LinkerConfig::Object != config().codeGenType()) &&
(!config().isCodeStatic())) {
if (FileFormat->hasPLT() && (&pSection == &(FileFormat->getPLT()))) {
-
unsigned char* buffer = pRegion.begin();
m_pPLT->applyPLT0();
@@ -173,13 +165,11 @@ uint64_t HexagonLDBackend::emitSectionData(const LDSection& pSection,
++it;
}
return RegionSize;
- }
- else if (FileFormat->hasGOT() && (&pSection == &(FileFormat->getGOT()))) {
+ } else if (FileFormat->hasGOT() && (&pSection == &(FileFormat->getGOT()))) {
RegionSize += emitGOTSectionData(pRegion);
return RegionSize;
- }
- else if (FileFormat->hasGOTPLT() &&
- (&pSection == &(FileFormat->getGOTPLT()))) {
+ } else if (FileFormat->hasGOTPLT() &&
+ (&pSection == &(FileFormat->getGOTPLT()))) {
RegionSize += emitGOTPLTSectionData(pRegion, FileFormat);
return RegionSize;
}
@@ -190,11 +180,10 @@ uint64_t HexagonLDBackend::emitSectionData(const LDSection& pSection,
uint8_t* out_offset = pRegion.begin();
for (frag_iter = sect_data->begin(); frag_iter != frag_end; ++frag_iter) {
size_t size = frag_iter->size();
- switch(frag_iter->getKind()) {
+ switch (frag_iter->getKind()) {
case Fragment::Fillment: {
- const FillFragment& fill_frag =
- llvm::cast<FillFragment>(*frag_iter);
- if (0 == fill_frag.getValueSize()) {
+ const FillFragment& fill_frag = llvm::cast<FillFragment>(*frag_iter);
+ if (fill_frag.getValueSize() == 0) {
// virtual fillment, ignore it.
break;
}
@@ -203,7 +192,7 @@ uint64_t HexagonLDBackend::emitSectionData(const LDSection& pSection,
}
case Fragment::Region: {
const RegionFragment& region_frag =
- llvm::cast<RegionFragment>(*frag_iter);
+ llvm::cast<RegionFragment>(*frag_iter);
const char* start = region_frag.getRegion().begin();
memcpy(out_offset, start, size);
break;
@@ -217,9 +206,9 @@ uint64_t HexagonLDBackend::emitSectionData(const LDSection& pSection,
break;
default:
llvm::report_fatal_error(
- "unsupported value size for align fragment emission yet.\n");
+ "unsupported value size for align fragment emission yet.\n");
break;
- } // end switch
+ } // end switch
break;
}
case Fragment::Null: {
@@ -229,93 +218,79 @@ uint64_t HexagonLDBackend::emitSectionData(const LDSection& pSection,
default:
llvm::report_fatal_error("unsupported fragment type.\n");
break;
- } // end switch
+ } // end switch
out_offset += size;
- } // end for
+ } // end for
return pRegion.size();
}
-HexagonGOT& HexagonLDBackend::getGOT()
-{
- assert(NULL != m_pGOT);
+HexagonGOT& HexagonLDBackend::getGOT() {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-const HexagonGOT& HexagonLDBackend::getGOT() const
-{
- assert(NULL != m_pGOT);
+const HexagonGOT& HexagonLDBackend::getGOT() const {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-HexagonPLT& HexagonLDBackend::getPLT()
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+HexagonPLT& HexagonLDBackend::getPLT() {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-const HexagonPLT& HexagonLDBackend::getPLT() const
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+const HexagonPLT& HexagonLDBackend::getPLT() const {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-OutputRelocSection& HexagonLDBackend::getRelaDyn()
-{
- assert(NULL != m_pRelaDyn && ".rela.dyn section not exist");
+OutputRelocSection& HexagonLDBackend::getRelaDyn() {
+ assert(m_pRelaDyn != NULL && ".rela.dyn section not exist");
return *m_pRelaDyn;
}
-const OutputRelocSection& HexagonLDBackend::getRelaDyn() const
-{
- assert(NULL != m_pRelaDyn && ".rela.dyn section not exist");
+const OutputRelocSection& HexagonLDBackend::getRelaDyn() const {
+ assert(m_pRelaDyn != NULL && ".rela.dyn section not exist");
return *m_pRelaDyn;
}
-OutputRelocSection& HexagonLDBackend::getRelaPLT()
-{
- assert(NULL != m_pRelaPLT && ".rela.plt section not exist");
+OutputRelocSection& HexagonLDBackend::getRelaPLT() {
+ assert(m_pRelaPLT != NULL && ".rela.plt section not exist");
return *m_pRelaPLT;
}
-const OutputRelocSection& HexagonLDBackend::getRelaPLT() const
-{
- assert(NULL != m_pRelaPLT && ".rela.plt section not exist");
+const OutputRelocSection& HexagonLDBackend::getRelaPLT() const {
+ assert(m_pRelaPLT != NULL && ".rela.plt section not exist");
return *m_pRelaPLT;
}
-HexagonGOTPLT& HexagonLDBackend::getGOTPLT()
-{
- assert(NULL != m_pGOTPLT);
+HexagonGOTPLT& HexagonLDBackend::getGOTPLT() {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-const HexagonGOTPLT& HexagonLDBackend::getGOTPLT() const
-{
- assert(NULL != m_pGOTPLT);
+const HexagonGOTPLT& HexagonLDBackend::getGOTPLT() const {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-void HexagonLDBackend::setRelaDynSize()
-{
+void HexagonLDBackend::setRelaDynSize() {
ELFFileFormat* file_format = getOutputFormat();
- file_format->getRelaDyn().setSize
- (m_pRelaDyn->numOfRelocs() * getRelaEntrySize());
+ file_format->getRelaDyn().setSize(m_pRelaDyn->numOfRelocs() *
+ getRelaEntrySize());
}
-void HexagonLDBackend::setRelaPLTSize()
-{
+void HexagonLDBackend::setRelaPLTSize() {
ELFFileFormat* file_format = getOutputFormat();
- file_format->getRelaPlt().setSize
- (m_pRelaPLT->numOfRelocs() * getRelaEntrySize());
+ file_format->getRelaPlt().setSize(m_pRelaPLT->numOfRelocs() *
+ getRelaEntrySize());
}
-void HexagonLDBackend::setGOTSectionSize(IRBuilder& pBuilder)
-{
+void HexagonLDBackend::setGOTSectionSize(IRBuilder& pBuilder) {
// set .got.plt size
- if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOTPLT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ if (LinkerConfig::DynObj == config().codeGenType() || m_pGOTPLT->hasGOT1() ||
+ m_pGOTSymbol != NULL) {
m_pGOTPLT->finalizeSectionSize();
defineGOTSymbol(pBuilder, *(m_pGOTPLT->begin()));
}
@@ -325,9 +300,7 @@ void HexagonLDBackend::setGOTSectionSize(IRBuilder& pBuilder)
m_pGOT->finalizeSectionSize();
}
-uint64_t
-HexagonLDBackend::emitGOTSectionData(MemoryRegion& pRegion) const
-{
+uint64_t HexagonLDBackend::emitGOTSectionData(MemoryRegion& pRegion) const {
assert(m_pGOT && "emitGOTSectionData failed, m_pGOT is NULL!");
uint32_t* buffer = reinterpret_cast<uint32_t*>(pRegion.begin());
@@ -336,8 +309,8 @@ HexagonLDBackend::emitGOTSectionData(MemoryRegion& pRegion) const
unsigned int EntrySize = HexagonGOTEntry::EntrySize;
uint64_t RegionSize = 0;
- for (HexagonGOT::iterator it = m_pGOT->begin(),
- ie = m_pGOT->end(); it != ie; ++it, ++buffer) {
+ for (HexagonGOT::iterator it = m_pGOT->begin(), ie = m_pGOT->end(); it != ie;
+ ++it, ++buffer) {
got = &(llvm::cast<HexagonGOTEntry>((*it)));
*buffer = static_cast<uint32_t>(got->getValue());
RegionSize += EntrySize;
@@ -346,38 +319,36 @@ HexagonLDBackend::emitGOTSectionData(MemoryRegion& pRegion) const
return RegionSize;
}
-void HexagonLDBackend::defineGOTSymbol(IRBuilder& pBuilder,
- Fragment& pFrag)
-{
+void HexagonLDBackend::defineGOTSymbol(IRBuilder& pBuilder, Fragment& pFrag) {
// define symbol _GLOBAL_OFFSET_TABLE_
if (m_pGOTSymbol != NULL) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(pFrag, 0x0),
- ResolveInfo::Hidden);
- }
- else {
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(pFrag, 0x0),
+ ResolveInfo::Hidden);
+ } else {
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(pFrag, 0x0),
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(pFrag, 0x0),
+ ResolveInfo::Hidden);
}
}
-uint64_t HexagonLDBackend::emitGOTPLTSectionData(MemoryRegion& pRegion,
- const ELFFileFormat* FileFormat) const
-{
- assert(m_pGOTPLT && "emitGOTPLTSectionData failed, m_pGOTPLT is NULL!");
+uint64_t HexagonLDBackend::emitGOTPLTSectionData(
+ MemoryRegion& pRegion,
+ const ELFFileFormat* FileFormat) const {
+ assert(m_pGOTPLT != NULL &&
+ "emitGOTPLTSectionData failed, m_pGOTPLT is NULL!");
m_pGOTPLT->applyGOT0(FileFormat->getDynamic().addr());
m_pGOTPLT->applyAllGOTPLT(*m_pPLT);
@@ -387,8 +358,9 @@ uint64_t HexagonLDBackend::emitGOTPLTSectionData(MemoryRegion& pRegion,
unsigned int EntrySize = HexagonGOTEntry::EntrySize;
uint64_t RegionSize = 0;
- for (HexagonGOTPLT::iterator it = m_pGOTPLT->begin(),
- ie = m_pGOTPLT->end(); it != ie; ++it, ++buffer) {
+ for (HexagonGOTPLT::iterator it = m_pGOTPLT->begin(), ie = m_pGOTPLT->end();
+ it != ie;
+ ++it, ++buffer) {
got = &(llvm::cast<HexagonGOTEntry>((*it)));
*buffer = static_cast<uint32_t>(got->getValue());
RegionSize += EntrySize;
@@ -397,9 +369,8 @@ uint64_t HexagonLDBackend::emitGOTPLTSectionData(MemoryRegion& pRegion,
return RegionSize;
}
-unsigned int
-HexagonLDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
-{
+unsigned int HexagonLDBackend::getTargetSectionOrder(
+ const LDSection& pSectHdr) const {
const ELFFileFormat* file_format = getOutputFormat();
if (LinkerConfig::Object != config().codeGenType()) {
@@ -429,9 +400,7 @@ HexagonLDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
}
void HexagonLDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
-
+ ObjectBuilder& pBuilder) {
if ((LinkerConfig::Object != config().codeGenType()) &&
(!config().isCodeStatic())) {
ELFFileFormat* file_format = getOutputFormat();
@@ -445,9 +414,7 @@ void HexagonLDBackend::initTargetSections(Module& pModule,
// initialize .plt
LDSection& plt = file_format->getPLT();
- m_pPLT = new HexagonPLT(plt,
- *m_pGOTPLT,
- config());
+ m_pPLT = new HexagonPLT(plt, *m_pGOTPLT, config());
// initialize .rela.plt
LDSection& relaplt = file_format->getRelaPlt();
@@ -457,39 +424,42 @@ void HexagonLDBackend::initTargetSections(Module& pModule,
// initialize .rela.dyn
LDSection& reladyn = file_format->getRelaDyn();
m_pRelaDyn = new OutputRelocSection(pModule, reladyn);
-
}
m_psdata = pBuilder.CreateSection(".sdata",
LDFileFormat::Target,
llvm::ELF::SHT_PROGBITS,
llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 4*1024);
- m_pscommon_1 = pBuilder.CreateSection(".scommon.1",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 1);
+ 4 * 1024);
+ m_pscommon_1 =
+ pBuilder.CreateSection(".scommon.1",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 1);
IRBuilder::CreateSectionData(*m_pscommon_1);
- m_pscommon_2 = pBuilder.CreateSection(".scommon.2",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 2);
+ m_pscommon_2 =
+ pBuilder.CreateSection(".scommon.2",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 2);
IRBuilder::CreateSectionData(*m_pscommon_2);
- m_pscommon_4 = pBuilder.CreateSection(".scommon.4",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 4);
+ m_pscommon_4 =
+ pBuilder.CreateSection(".scommon.4",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 4);
IRBuilder::CreateSectionData(*m_pscommon_4);
- m_pscommon_8 = pBuilder.CreateSection(".scommon.8",
- LDFileFormat::Target,
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 8);
+ m_pscommon_8 =
+ pBuilder.CreateSection(".scommon.8",
+ LDFileFormat::Target,
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 8);
IRBuilder::CreateSectionData(*m_pscommon_8);
m_pstart = pBuilder.CreateSection(".start",
@@ -500,84 +470,81 @@ void HexagonLDBackend::initTargetSections(Module& pModule,
IRBuilder::CreateSectionData(*m_pstart);
}
-void HexagonLDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule)
-{
+void HexagonLDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule) {
if (config().codeGenType() == LinkerConfig::Object)
return;
// Define the symbol _GLOBAL_OFFSET_TABLE_ if there is a symbol with the
// same name in input
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Hidden);
- m_psdabase =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_SDA_BASE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Hidden);
+
+ m_psdabase = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_SDA_BASE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Hidden);
+
pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__sbss_start",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Hidden);
+ "__sbss_start",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Hidden);
+
pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "__sbss_end",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(),
- ResolveInfo::Hidden);
+ "__sbss_end",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(),
+ ResolveInfo::Hidden);
}
-bool HexagonLDBackend::initTargetStubs()
-{
- if (NULL != getStubFactory()) {
- getStubFactory()->addPrototype
- (new HexagonAbsoluteStub(config().isCodeIndep()));
+bool HexagonLDBackend::initTargetStubs() {
+ if (getStubFactory() != NULL) {
+ getStubFactory()->addPrototype(
+ new HexagonAbsoluteStub(config().isCodeIndep()));
return true;
}
return false;
}
-bool HexagonLDBackend::initBRIslandFactory()
-{
- if (NULL == m_pBRIslandFactory) {
- m_pBRIslandFactory = new BranchIslandFactory(maxFwdBranchOffset(),
- maxBwdBranchOffset(),
- 0);
+bool HexagonLDBackend::initBRIslandFactory() {
+ if (m_pBRIslandFactory == NULL) {
+ m_pBRIslandFactory =
+ new BranchIslandFactory(maxFwdBranchOffset(), maxBwdBranchOffset(), 0);
}
return true;
}
-bool HexagonLDBackend::initStubFactory()
-{
- if (NULL == m_pStubFactory) {
+bool HexagonLDBackend::initStubFactory() {
+ if (m_pStubFactory == NULL) {
m_pStubFactory = new StubFactory();
}
return true;
}
-bool HexagonLDBackend::doRelax(Module& pModule, IRBuilder& pBuilder,
- bool& pFinished)
-{
- assert(NULL != getStubFactory() && NULL != getBRIslandFactory());
+bool HexagonLDBackend::doRelax(Module& pModule,
+ IRBuilder& pBuilder,
+ bool& pFinished) {
+ assert(getStubFactory() != NULL && getBRIslandFactory() != NULL);
bool isRelaxed = false;
ELFFileFormat* file_format = getOutputFormat();
// check branch relocs and create the related stubs if needed
@@ -601,15 +568,15 @@ bool HexagonLDBackend::doRelax(Module& pModule, IRBuilder& pBuilder,
if (symbol->hasFragRef()) {
uint64_t value = symbol->fragRef()->getOutputOffset();
uint64_t addr =
- symbol->fragRef()->frag()->getParent()->getSection().addr();
+ symbol->fragRef()->frag()->getParent()->getSection().addr();
sym_value = addr + value;
}
- Stub* stub = getStubFactory()->create(*relocation, // relocation
- sym_value, //symbol value
+ Stub* stub = getStubFactory()->create(*relocation, // relocation
+ sym_value, // symbol value
pBuilder,
*getBRIslandFactory());
- if (NULL != stub) {
- assert(NULL != stub->symInfo());
+ if (stub != NULL) {
+ assert(stub->symInfo() != NULL);
// increase the size of .symtab and .strtab
LDSection& symtab = file_format->getSymTab();
LDSection& strtab = file_format->getStrTab();
@@ -617,8 +584,7 @@ bool HexagonLDBackend::doRelax(Module& pModule, IRBuilder& pBuilder,
strtab.setSize(strtab.size() + stub->symInfo()->nameSize() + 1);
isRelaxed = true;
}
- }
- break;
+ } break;
default:
break;
@@ -631,8 +597,9 @@ bool HexagonLDBackend::doRelax(Module& pModule, IRBuilder& pBuilder,
Fragment* invalid = NULL;
pFinished = true;
for (BranchIslandFactory::iterator island = getBRIslandFactory()->begin(),
- island_end = getBRIslandFactory()->end(); island != island_end; ++island)
- {
+ island_end = getBRIslandFactory()->end();
+ island != island_end;
+ ++island) {
if ((*island).end() == file_format->getText().getSectionData()->end())
break;
@@ -645,7 +612,7 @@ bool HexagonLDBackend::doRelax(Module& pModule, IRBuilder& pBuilder,
}
// reset the offset of invalid fragments
- while (NULL != invalid) {
+ while (invalid != NULL) {
invalid->setOffset(invalid->getPrevNode()->getOffset() +
invalid->getPrevNode()->size());
invalid = invalid->getNextNode();
@@ -654,42 +621,37 @@ bool HexagonLDBackend::doRelax(Module& pModule, IRBuilder& pBuilder,
// reset the size of .text
if (isRelaxed) {
file_format->getText().setSize(
- file_format->getText().getSectionData()->back().getOffset() +
- file_format->getText().getSectionData()->back().size());
+ file_format->getText().getSectionData()->back().getOffset() +
+ file_format->getText().getSectionData()->back().size());
}
return isRelaxed;
}
/// finalizeSymbol - finalize the symbol value
-bool HexagonLDBackend::finalizeTargetSymbols()
-{
+bool HexagonLDBackend::finalizeTargetSymbols() {
if (config().codeGenType() == LinkerConfig::Object)
return true;
if (m_psdabase)
m_psdabase->setValue(m_psdata->addr());
- ELFSegmentFactory::const_iterator edata =
- elfSegmentTable().find(llvm::ELF::PT_LOAD,
- llvm::ELF::PF_W,
- llvm::ELF::PF_X);
+ ELFSegmentFactory::const_iterator edata = elfSegmentTable().find(
+ llvm::ELF::PT_LOAD, llvm::ELF::PF_W, llvm::ELF::PF_X);
if (elfSegmentTable().end() != edata) {
- if (NULL != f_pEData && ResolveInfo::ThreadLocal != f_pEData->type()) {
+ if (f_pEData != NULL && ResolveInfo::ThreadLocal != f_pEData->type()) {
f_pEData->setValue((*edata)->vaddr() + (*edata)->filesz());
}
- if (NULL != f_p_EData && ResolveInfo::ThreadLocal != f_p_EData->type()) {
+ if (f_p_EData != NULL && ResolveInfo::ThreadLocal != f_p_EData->type()) {
f_p_EData->setValue((*edata)->vaddr() + (*edata)->filesz());
}
- if (NULL != f_pBSSStart &&
+ if (f_pBSSStart != NULL &&
ResolveInfo::ThreadLocal != f_pBSSStart->type()) {
f_pBSSStart->setValue((*edata)->vaddr() + (*edata)->filesz());
}
- if (NULL != f_pEnd && ResolveInfo::ThreadLocal != f_pEnd->type()) {
- f_pEnd->setValue((((*edata)->vaddr() +
- (*edata)->memsz()) + 7) & ~7);
+ if (f_pEnd != NULL && ResolveInfo::ThreadLocal != f_pEnd->type()) {
+ f_pEnd->setValue((((*edata)->vaddr() + (*edata)->memsz()) + 7) & ~7);
}
- if (NULL != f_p_End && ResolveInfo::ThreadLocal != f_p_End->type()) {
- f_p_End->setValue((((*edata)->vaddr() +
- (*edata)->memsz()) + 7) & ~7);
+ if (f_p_End != NULL && ResolveInfo::ThreadLocal != f_p_End->type()) {
+ f_p_End->setValue((((*edata)->vaddr() + (*edata)->memsz()) + 7) & ~7);
}
}
return true;
@@ -698,20 +660,18 @@ bool HexagonLDBackend::finalizeTargetSymbols()
/// merge Input Sections
bool HexagonLDBackend::mergeSection(Module& pModule,
const Input& pInputFile,
- LDSection& pInputSection)
-{
+ LDSection& pInputSection) {
if ((pInputSection.flag() & llvm::ELF::SHF_HEX_GPREL) ||
(pInputSection.kind() == LDFileFormat::LinkOnce) ||
(pInputSection.kind() == LDFileFormat::Target)) {
- SectionData *sd = NULL;
+ SectionData* sd = NULL;
if (!m_psdata->hasSectionData()) {
sd = IRBuilder::CreateSectionData(*m_psdata);
m_psdata->setSectionData(sd);
}
sd = m_psdata->getSectionData();
MoveSectionDataAndSort(*pInputSection.getSectionData(), *sd);
- }
- else {
+ } else {
ObjectBuilder builder(pModule);
builder.MergeSection(pInputFile, pInputSection);
}
@@ -719,7 +679,7 @@ bool HexagonLDBackend::mergeSection(Module& pModule,
}
bool HexagonLDBackend::SetSDataSection() {
- SectionData *pTo = (m_psdata->getSectionData());
+ SectionData* pTo = (m_psdata->getSectionData());
if (pTo) {
MoveCommonData(*m_pscommon_1->getSectionData(), *pTo);
@@ -741,7 +701,8 @@ bool HexagonLDBackend::SetSDataSection() {
SectionData::FragmentListType& newlist = pTo->getFragmentList();
for (fragTo = newlist.begin(), fragToEnd = newlist.end();
- fragTo != fragToEnd; ++fragTo) {
+ fragTo != fragToEnd;
+ ++fragTo) {
fragTo->setParent(pTo);
}
}
@@ -751,9 +712,7 @@ bool HexagonLDBackend::SetSDataSection() {
/// allocateCommonSymbols - allocate common symbols in the corresponding
/// sections. This is called at pre-layout stage.
-/// @refer Google gold linker: common.cc: 214
-bool HexagonLDBackend::allocateCommonSymbols(Module& pModule)
-{
+bool HexagonLDBackend::allocateCommonSymbols(Module& pModule) {
SymbolCategory& symbol_list = pModule.getSymbolTable();
if (symbol_list.emptyCommons() && symbol_list.emptyLocals()) {
@@ -784,7 +743,7 @@ bool HexagonLDBackend::allocateCommonSymbols(Module& pModule)
tbss_sect_data = IRBuilder::CreateSectionData(tbss_sect);
// remember original BSS size
- uint64_t bss_offset = bss_sect.size();
+ uint64_t bss_offset = bss_sect.size();
uint64_t tbss_offset = tbss_sect.size();
// allocate all local common symbols
@@ -800,55 +759,48 @@ bool HexagonLDBackend::allocateCommonSymbols(Module& pModule)
(*com_sym)->resolveInfo()->setDesc(ResolveInfo::Define);
Fragment* frag = new FillFragment(0x0, 1, (*com_sym)->size());
- switch((*com_sym)->size()) {
- case 1:
- if (maxGPSize <= 0)
- break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_1->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- case 2:
- if (maxGPSize <= 1)
- break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_2->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- case 4:
- if (maxGPSize <= 3)
- break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_4->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- case 8:
- if (maxGPSize <= 7)
+ switch ((*com_sym)->size()) {
+ case 1:
+ if (maxGPSize <= 0)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_1->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ case 2:
+ if (maxGPSize <= 1)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_2->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ case 4:
+ if (maxGPSize <= 3)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_4->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ case 8:
+ if (maxGPSize <= 7)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_8->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ default:
break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_8->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- default:
- break;
}
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
- tbss_offset += ObjectBuilder::AppendFragment(*frag,
- *tbss_sect_data,
- (*com_sym)->value());
+ tbss_offset += ObjectBuilder::AppendFragment(
+ *frag, *tbss_sect_data, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- }
- // FIXME: how to identify small and large common symbols?
- else {
- bss_offset += ObjectBuilder::AppendFragment(*frag,
- *bss_sect_data,
- (*com_sym)->value());
+ } else {
+ // FIXME: how to identify small and large common symbols?
+ bss_offset += ObjectBuilder::AppendFragment(
+ *frag, *bss_sect_data, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
}
}
@@ -865,55 +817,48 @@ bool HexagonLDBackend::allocateCommonSymbols(Module& pModule)
(*com_sym)->resolveInfo()->setDesc(ResolveInfo::Define);
Fragment* frag = new FillFragment(0x0, 1, (*com_sym)->size());
- switch((*com_sym)->size()) {
- case 1:
- if (maxGPSize <= 0)
- break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_1->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- case 2:
- if (maxGPSize <= 1)
- break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_2->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- case 4:
- if (maxGPSize <= 3)
- break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_4->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- case 8:
- if (maxGPSize <= 7)
+ switch ((*com_sym)->size()) {
+ case 1:
+ if (maxGPSize <= 0)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_1->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ case 2:
+ if (maxGPSize <= 1)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_2->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ case 4:
+ if (maxGPSize <= 3)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_4->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ case 8:
+ if (maxGPSize <= 7)
+ break;
+ ObjectBuilder::AppendFragment(
+ *frag, *(m_pscommon_8->getSectionData()), (*com_sym)->value());
+ (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
+ continue;
+ default:
break;
- ObjectBuilder::AppendFragment(*frag,
- *(m_pscommon_8->getSectionData()),
- (*com_sym)->value());
- (*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- continue;
- default:
- break;
}
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
- tbss_offset += ObjectBuilder::AppendFragment(*frag,
- *tbss_sect_data,
- (*com_sym)->value());
+ tbss_offset += ObjectBuilder::AppendFragment(
+ *frag, *tbss_sect_data, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- }
- // FIXME: how to identify small and large common symbols?
- else {
- bss_offset += ObjectBuilder::AppendFragment(*frag,
- *bss_sect_data,
- (*com_sym)->value());
+ } else {
+ // FIXME: how to identify small and large common symbols?
+ bss_offset += ObjectBuilder::AppendFragment(
+ *frag, *bss_sect_data, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
}
}
@@ -925,8 +870,7 @@ bool HexagonLDBackend::allocateCommonSymbols(Module& pModule)
return true;
}
-bool HexagonLDBackend::MoveCommonData(SectionData &pFrom, SectionData &pTo)
-{
+bool HexagonLDBackend::MoveCommonData(SectionData& pFrom, SectionData& pTo) {
SectionData::FragmentListType& to_list = pTo.getFragmentList();
SectionData::FragmentListType::iterator frag, fragEnd = to_list.end();
@@ -953,11 +897,11 @@ bool HexagonLDBackend::MoveCommonData(SectionData &pFrom, SectionData &pTo)
AlignFragment* align = NULL;
if (pFrom.getSection().align() > 1) {
// if the align constraint is larger than 1, append an alignment
- align = new AlignFragment(pFrom.getSection().align(), // alignment
- 0x0, // the filled value
- 1u, // the size of filled value
- pFrom.getSection().align() - 1 // max bytes to emit
- );
+ unsigned int alignment = pFrom.getSection().align();
+ align = new AlignFragment(/*alignment*/alignment,
+ /*the filled value*/0x0,
+ /*the size of filled value*/1u,
+ /*max bytes to emit*/alignment - 1);
pFrom.getFragmentList().push_front(align);
}
if (found)
@@ -968,23 +912,20 @@ bool HexagonLDBackend::MoveCommonData(SectionData &pFrom, SectionData &pTo)
return true;
}
-bool HexagonLDBackend::readSection(Input& pInput, SectionData& pSD)
-{
+bool HexagonLDBackend::readSection(Input& pInput, SectionData& pSD) {
Fragment* frag = NULL;
uint32_t offset = pInput.fileOffset() + pSD.getSection().offset();
uint32_t size = pSD.getSection().size();
if (pSD.getSection().type() == llvm::ELF::SHT_NOBITS) {
frag = new FillFragment(0x0, 1, size);
- }
- else {
+ } else {
llvm::StringRef region = pInput.memArea()->request(offset, size);
if (region.size() == 0) {
// If the input section's size is zero, we got a NULL region.
// use a virtual fill fragment
frag = new FillFragment(0x0, 0, 0);
- }
- else {
+ } else {
frag = new RegionFragment(region);
}
}
@@ -994,8 +935,8 @@ bool HexagonLDBackend::readSection(Input& pInput, SectionData& pSD)
}
/// MoveSectionData - move the fragments of pTO section data to pTo
-bool HexagonLDBackend::MoveSectionDataAndSort(SectionData& pFrom, SectionData& pTo)
-{
+bool HexagonLDBackend::MoveSectionDataAndSort(SectionData& pFrom,
+ SectionData& pTo) {
assert(&pFrom != &pTo && "Cannot move section data to itself!");
SectionData::FragmentListType& to_list = pTo.getFragmentList();
SectionData::FragmentListType::iterator frag, fragEnd = to_list.end();
@@ -1023,11 +964,11 @@ bool HexagonLDBackend::MoveSectionDataAndSort(SectionData& pFrom, SectionData& p
AlignFragment* align = NULL;
if (pFrom.getSection().align() > 1) {
// if the align constraint is larger than 1, append an alignment
- align = new AlignFragment(pFrom.getSection().align(), // alignment
- 0x0, // the filled value
- 1u, // the size of filled value
- pFrom.getSection().align() - 1 // max bytes to emit
- );
+ unsigned int alignment = pFrom.getSection().align();
+ align = new AlignFragment(/*alignment*/alignment,
+ /*the filled value*/0x0,
+ /*the size of filled value*/1u,
+ /*max bytes to emit*/alignment - 1);
pFrom.getFragmentList().push_front(align);
}
if (found)
@@ -1054,18 +995,14 @@ bool HexagonLDBackend::MoveSectionDataAndSort(SectionData& pFrom, SectionData& p
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
-void HexagonLDBackend::doCreateProgramHdrs(Module& pModule)
-{
+void HexagonLDBackend::doCreateProgramHdrs(Module& pModule) {
// TODO
}
-namespace mcld {
-
//===----------------------------------------------------------------------===//
/// createHexagonLDBackend - the help funtion to create corresponding
/// HexagonLDBackend
-TargetLDBackend* createHexagonLDBackend(const LinkerConfig& pConfig)
-{
+TargetLDBackend* createHexagonLDBackend(const LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker is not supported yet");
/**
@@ -1085,13 +1022,13 @@ TargetLDBackend* createHexagonLDBackend(const LinkerConfig& pConfig)
return new HexagonLDBackend(pConfig, new HexagonGNUInfo(pConfig.targets()));
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// Force static initialization.
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeHexagonLDBackend() {
// Register the linker backend
- mcld::TargetRegistry::RegisterTargetLDBackend(TheHexagonTarget,
- createHexagonLDBackend);
+ mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheHexagonTarget,
+ mcld::createHexagonLDBackend);
}
diff --git a/lib/Target/Hexagon/HexagonLDBackend.h b/lib/Target/Hexagon/HexagonLDBackend.h
index 0fc909c..89aea83 100644
--- a/lib/Target/Hexagon/HexagonLDBackend.h
+++ b/lib/Target/Hexagon/HexagonLDBackend.h
@@ -6,31 +6,30 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONLDBACKEND_H
-#define TARGET_HEXAGON_HEXAGONLDBACKEND_H
+#ifndef TARGET_HEXAGON_HEXAGONLDBACKEND_H_
+#define TARGET_HEXAGON_HEXAGONLDBACKEND_H_
#include "HexagonELFDynamic.h"
#include "HexagonGOT.h"
#include "HexagonPLT.h"
#include "HexagonGOTPLT.h"
-#include <mcld/IRBuilder.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Target/OutputRelocSection.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Target/GNULDBackend.h"
+#include "mcld/Target/OutputRelocSection.h"
namespace mcld {
-class LinkerConfig;
class HexagonGNUInfo;
+class LinkerConfig;
//===----------------------------------------------------------------------===//
/// HexagonLDBackend - linker backend of Hexagon target of GNU ELF format
///
-class HexagonLDBackend : public GNULDBackend
-{
-public:
+class HexagonLDBackend : public GNULDBackend {
+ public:
HexagonLDBackend(const LinkerConfig& pConfig, HexagonGNUInfo* pInfo);
~HexagonLDBackend();
@@ -86,8 +85,7 @@ public:
const Relocator* getRelocator() const;
Relocator* getRelocator();
- ResolveInfo::Desc getSymDesc(uint16_t shndx) const
- {
+ ResolveInfo::Desc getSymDesc(uint16_t shndx) const {
if (shndx >= llvm::ELF::SHN_HEXAGON_SCOMMON &&
shndx <= llvm::ELF::SHN_HEXAGON_SCOMMON_8)
return ResolveInfo::Common;
@@ -132,7 +130,7 @@ public:
/// readSection - read target dependent sections
bool readSection(Input& pInput, SectionData& pSD);
- bool MoveCommonData(SectionData &pFrom, SectionData &pTo);
+ bool MoveCommonData(SectionData& pFrom, SectionData& pTo);
bool MoveSectionDataAndSort(SectionData& pFrom, SectionData& pTo);
@@ -140,24 +138,19 @@ public:
uint32_t getGP() { return m_psdata->addr(); }
- Relocation::Type getCopyRelType() const { return m_CopyRel; }
-
- virtual uint32_t getGOTSymbolAddr() {
- return m_pGOTSymbol->value();
- }
+ Relocation::Type getCopyRelType() const { return m_CopyRel; }
+ virtual uint32_t getGOTSymbolAddr() { return m_pGOTSymbol->value(); }
-protected:
+ protected:
void defineGOTSymbol(IRBuilder& pBuilder, Fragment&);
-private:
+ private:
/// getRelEntrySize - the size in BYTE of rela type relocation
- size_t getRelEntrySize()
- { return 0; }
+ size_t getRelEntrySize() { return 0; }
/// getRelaEntrySize - the size in BYTE of rela type relocation
- size_t getRelaEntrySize()
- { return 12; }
+ size_t getRelaEntrySize() { return 12; }
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
@@ -176,7 +169,7 @@ private:
virtual void setRelaDynSize();
virtual void setRelaPLTSize();
-private:
+ private:
Relocator* m_pRelocator;
HexagonGOT* m_pGOT;
HexagonGOTPLT* m_pGOTPLT;
@@ -200,7 +193,7 @@ private:
LDSymbol* m_pBSSEnd;
Relocation::Type m_CopyRel;
};
-} // namespace of mcld
-#endif
+} // namespace mcld
+#endif // TARGET_HEXAGON_HEXAGONLDBACKEND_H_
diff --git a/lib/Target/Hexagon/HexagonMCLinker.cpp b/lib/Target/Hexagon/HexagonMCLinker.cpp
deleted file mode 100644
index 770ae94..0000000
--- a/lib/Target/Hexagon/HexagonMCLinker.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-//===- HexagonMCLinker.cpp ------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "Hexagon.h"
-#include "HexagonELFMCLinker.h"
-#include <mcld/Module.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <llvm/ADT/Triple.h>
-
-using namespace mcld;
-
-namespace mcld {
-
-/// createHexagonMCLinker - the help funtion to create corresponding
-/// HexagonMCLinker
-MCLinker* createHexagonMCLinker(const std::string &pTriple,
- LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
-{
- llvm::Triple theTriple(pTriple);
- if (theTriple.isOSDarwin()) {
- assert(0 && "MachO linker has not supported yet");
- return NULL;
- }
- if (theTriple.isOSWindows()) {
- assert(0 && "COFF linker has not supported yet");
- return NULL;
- }
-
- if (theTriple.isArch32Bit())
- return new HexagonELFMCLinker(pConfig, pModule, pFileHandle);
-
- assert(0 && "Hexagon_64 has not supported yet");
- return NULL;
-}
-
-} // namespace of mcld
-
-//===----------------------------------------------------------------------===//
-// HexagonMCLinker
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeHexagonMCLinker() {
- // Register the linker frontend
- mcld::TargetRegistry::RegisterMCLinker(TheHexagonTarget,
- createHexagonMCLinker);
-}
-
diff --git a/lib/Target/Hexagon/HexagonPLT.cpp b/lib/Target/Hexagon/HexagonPLT.cpp
index 3d692fd..ca9352a 100644
--- a/lib/Target/Hexagon/HexagonPLT.cpp
+++ b/lib/Target/Hexagon/HexagonPLT.cpp
@@ -9,55 +9,48 @@
#include "HexagonPLT.h"
#include "HexagonRelocationFunctions.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <llvm/Support/ELF.h>
#include <llvm/Support/Casting.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Support/MsgHandling.h>
-
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// PLT entry data
//===----------------------------------------------------------------------===//
HexagonPLT0::HexagonPLT0(SectionData& pParent)
- : PLT::Entry<sizeof(hexagon_plt0)>(pParent)
-{
+ : PLT::Entry<sizeof(hexagon_plt0)>(pParent) {
}
HexagonPLT1::HexagonPLT1(SectionData& pParent)
- : PLT::Entry<sizeof(hexagon_plt1)>(pParent)
-{
+ : PLT::Entry<sizeof(hexagon_plt1)>(pParent) {
}
//===----------------------------------------------------------------------===//
// HexagonPLT
//===----------------------------------------------------------------------===//
HexagonPLT::HexagonPLT(LDSection& pSection,
- HexagonGOTPLT &pGOTPLT,
- const LinkerConfig& pConfig)
- : PLT(pSection),
- m_GOTPLT(pGOTPLT),
- m_Config(pConfig)
-{
+ HexagonGOTPLT& pGOTPLT,
+ const LinkerConfig& pConfig)
+ : PLT(pSection), m_GOTPLT(pGOTPLT), m_Config(pConfig) {
assert(LinkerConfig::DynObj == m_Config.codeGenType() ||
- LinkerConfig::Exec == m_Config.codeGenType() ||
+ LinkerConfig::Exec == m_Config.codeGenType() ||
LinkerConfig::Binary == m_Config.codeGenType());
m_PLT0 = hexagon_plt0;
- m_PLT0Size = sizeof (hexagon_plt0);
+ m_PLT0Size = sizeof(hexagon_plt0);
// create PLT0
new HexagonPLT0(*m_pSectionData);
pSection.setAlign(16);
}
-HexagonPLT::~HexagonPLT()
-{
+HexagonPLT::~HexagonPLT() {
}
-PLTEntryBase* HexagonPLT::getPLT0() const
-{
+PLTEntryBase* HexagonPLT::getPLT0() const {
iterator first = m_pSectionData->getFragmentList().begin();
assert(first != m_pSectionData->getFragmentList().end() &&
@@ -68,8 +61,7 @@ PLTEntryBase* HexagonPLT::getPLT0() const
return plt0;
}
-void HexagonPLT::finalizeSectionSize()
-{
+void HexagonPLT::finalizeSectionSize() {
uint64_t size = 0;
// plt0 size
size = getPLT0()->size();
@@ -92,18 +84,15 @@ void HexagonPLT::finalizeSectionSize()
}
}
-bool HexagonPLT::hasPLT1() const
-{
+bool HexagonPLT::hasPLT1() const {
return (m_pSectionData->size() > 1);
}
-HexagonPLT1* HexagonPLT::create()
-{
+HexagonPLT1* HexagonPLT::create() {
return new HexagonPLT1(*m_pSectionData);
}
-void HexagonPLT::applyPLT0()
-{
+void HexagonPLT::applyPLT0() {
PLTEntryBase* plt0 = getPLT0();
uint64_t pltBase = m_Section.addr();
@@ -116,8 +105,8 @@ void HexagonPLT::applyPLT0()
memcpy(data, m_PLT0, plt0->size());
uint32_t gotpltAddr = m_GOTPLT.addr();
- int32_t *dest = (int32_t *)data;
- int32_t result = ((gotpltAddr - pltBase ) >> 6);
+ int32_t* dest = reinterpret_cast<int32_t*>(data);
+ int32_t result = ((gotpltAddr - pltBase) >> 6);
*dest |= ApplyMask<int32_t>(0xfff3fff, result);
dest = dest + 1;
// Already calculated using pltBase
@@ -128,7 +117,6 @@ void HexagonPLT::applyPLT0()
}
void HexagonPLT::applyPLT1() {
-
uint64_t plt_base = m_Section.addr();
assert(plt_base && ".plt base address is NULL!");
@@ -140,13 +128,12 @@ void HexagonPLT::applyPLT1() {
assert(it != ie && "FragmentList is empty, applyPLT1 failed!");
uint32_t GOTEntrySize = HexagonGOTEntry::EntrySize;
- uint32_t GOTEntryAddress =
- got_base + GOTEntrySize * 4;
+ uint32_t GOTEntryAddress = got_base + GOTEntrySize * 4;
uint64_t PLTEntryAddress =
- plt_base + HexagonPLT0::EntrySize; //Offset of PLT0
+ plt_base + HexagonPLT0::EntrySize; // Offset of PLT0
- ++it; //skip PLT0
+ ++it; // skip PLT0
uint64_t PLT1EntrySize = HexagonPLT1::EntrySize;
HexagonPLT1* plt1 = NULL;
@@ -160,8 +147,8 @@ void HexagonPLT::applyPLT1() {
memcpy(Out, hexagon_plt1, plt1->size());
- int32_t *dest = (int32_t *)Out;
- int32_t result = ((GOTEntryAddress - PLTEntryAddress ) >> 6);
+ int32_t* dest = reinterpret_cast<int32_t*>(Out);
+ int32_t result = ((GOTEntryAddress - PLTEntryAddress) >> 6);
*dest |= ApplyMask<int32_t>(0xfff3fff, result);
dest = dest + 1;
result = (GOTEntryAddress - PLTEntryAddress);
@@ -178,13 +165,14 @@ void HexagonPLT::applyPLT1() {
}
}
-uint64_t HexagonPLT::emit(MemoryRegion& pRegion)
-{
+uint64_t HexagonPLT::emit(MemoryRegion& pRegion) {
uint64_t result = 0x0;
iterator it = begin();
unsigned char* buffer = pRegion.begin();
- memcpy(buffer, llvm::cast<HexagonPLT0>((*it)).getValue(), HexagonPLT0::EntrySize);
+ memcpy(buffer,
+ llvm::cast<HexagonPLT0>((*it)).getValue(),
+ HexagonPLT0::EntrySize);
result += HexagonPLT0::EntrySize;
++it;
@@ -199,3 +187,4 @@ uint64_t HexagonPLT::emit(MemoryRegion& pRegion)
return result;
}
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonPLT.h b/lib/Target/Hexagon/HexagonPLT.h
index 4acce49..22f580e 100644
--- a/lib/Target/Hexagon/HexagonPLT.h
+++ b/lib/Target/Hexagon/HexagonPLT.h
@@ -6,53 +6,48 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONPLT_H
-#define TARGET_HEXAGON_HEXAGONPLT_H
+#ifndef TARGET_HEXAGON_HEXAGONPLT_H_
+#define TARGET_HEXAGON_HEXAGONPLT_H_
#include "HexagonGOT.h"
#include "HexagonGOTPLT.h"
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/PLT.h>
-#include <mcld/Support/MemoryRegion.h>
-
-namespace {
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/PLT.h"
+#include "mcld/Support/MemoryRegion.h"
const uint8_t hexagon_plt0[] = {
- 0x00, 0x40, 0x00, 0x00, // { immext (#0)
- 0x1c, 0xc0, 0x49, 0x6a, // r28 = add (pc, ##GOT0@PCREL) } # address of GOT0
- 0x0e, 0x42, 0x9c, 0xe2, // { r14 -= add (r28, #16) # offset of GOTn from GOTa
- 0x4f, 0x40, 0x9c, 0x91, // r15 = memw (r28 + #8) # object ID at GOT2
- 0x3c, 0xc0, 0x9c, 0x91, // r28 = memw (r28 + #4) }# dynamic link at GOT1
- 0x0e, 0x42, 0x0e, 0x8c, // { r14 = asr (r14, #2) # index of PLTn
- 0x00, 0xc0, 0x9c, 0x52, // jumpr r28 } # call dynamic linker
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
+ 0x00, 0x40, 0x00, 0x00, // { immext (#0)
+ 0x1c, 0xc0, 0x49, 0x6a, // r28 = add (pc, ##GOT0@PCREL) } # address of GOT0 // NOLINT
+ 0x0e, 0x42, 0x9c, 0xe2, // { r14 -= add (r28, #16) # offset of GOTn from GOTa // NOLINT
+ 0x4f, 0x40, 0x9c, 0x91, // r15 = memw (r28 + #8) # object ID at GOT2
+ 0x3c, 0xc0, 0x9c, 0x91, // r28 = memw (r28 + #4) } # dynamic link at GOT1
+ 0x0e, 0x42, 0x0e, 0x8c, // { r14 = asr (r14, #2) # index of PLTn
+ 0x00, 0xc0, 0x9c, 0x52, // jumpr r28 } # call dynamic linker
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00
};
const uint8_t hexagon_plt1[] = {
- 0x00, 0x40, 0x00, 0x00, // { immext (#0)
- 0x0e, 0xc0, 0x49, 0x6a, // r14 = add (pc, ##GOTn@PCREL) } # address of GOTn
- 0x1c, 0xc0, 0x8e, 0x91, // r28 = memw (r14) # contents of GOTn
- 0x00, 0xc0, 0x9c, 0x52 // jumpr r28 # call it
+ 0x00, 0x40, 0x00, 0x00, // { immext (#0)
+ 0x0e, 0xc0, 0x49, 0x6a, // r14 = add (pc, ##GOTn@PCREL) } # address of GOTn // NOLINT
+ 0x1c, 0xc0, 0x8e, 0x91, // r28 = memw (r14) # contents of GOTn // NOLINT
+ 0x00, 0xc0, 0x9c, 0x52 // jumpr r28 # call it
};
-} // anonymous namespace
-
namespace mcld {
class GOTEntry;
-class LinkerConfig;
class HexagonPLT1;
+class LinkerConfig;
//===----------------------------------------------------------------------===//
// HexagonPLT Entry
//===----------------------------------------------------------------------===//
-class HexagonPLT0 : public PLT::Entry<sizeof(hexagon_plt0)>
-{
-public:
+class HexagonPLT0 : public PLT::Entry<sizeof(hexagon_plt0)> {
+ public:
HexagonPLT0(SectionData& pParent);
};
@@ -62,9 +57,8 @@ public:
/** \class HexagonPLT
* \brief Hexagon Procedure Linkage Table
*/
-class HexagonPLT : public PLT
-{
-public:
+class HexagonPLT : public PLT {
+ public:
HexagonPLT(LDSection& pSection,
HexagonGOTPLT& pGOTPLT,
const LinkerConfig& pConfig);
@@ -86,22 +80,20 @@ public:
PLTEntryBase* getPLT0() const;
-private:
+ private:
HexagonGOTPLT& m_GOTPLT;
- const uint8_t *m_PLT0;
+ const uint8_t* m_PLT0;
unsigned int m_PLT0Size;
const LinkerConfig& m_Config;
};
-class HexagonPLT1 : public PLT::Entry<sizeof(hexagon_plt1)>
-{
-public:
+class HexagonPLT1 : public PLT::Entry<sizeof(hexagon_plt1)> {
+ public:
HexagonPLT1(SectionData& pParent);
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_HEXAGON_HEXAGONPLT_H_
diff --git a/lib/Target/Hexagon/HexagonRelocationFunctions.h b/lib/Target/Hexagon/HexagonRelocationFunctions.h
index 6c60954..7b6783d 100644
--- a/lib/Target/Hexagon/HexagonRelocationFunctions.h
+++ b/lib/Target/Hexagon/HexagonRelocationFunctions.h
@@ -6,8 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_HEXAGON_HEXAGONRELOCATIONFUNCTIONS_H_
+#define TARGET_HEXAGON_HEXAGONRELOCATIONFUNCTIONS_H_
+
typedef struct {
- const char *insnSyntax;
+ const char* insnSyntax;
uint32_t insnMask;
uint32_t insnCmpMask;
uint32_t insnBitMask;
@@ -33,104 +36,106 @@ T1 ApplyMask(T2 pMask, T1 pData) {
return result;
}
-#define DECL_HEXAGON_APPLY_RELOC_FUNC(Name) \
-static HexagonRelocator::Result Name (Relocation& pEntry, \
- HexagonRelocator& pParent);
+#define DECL_HEXAGON_APPLY_RELOC_FUNC(Name) \
+ static HexagonRelocator::Result Name(Relocation& pEntry, \
+ HexagonRelocator& pParent);
+
+#define DECL_HEXAGON_APPLY_RELOC_FUNCS \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(none) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(relocPCREL) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(relocGPREL) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(relocAbs) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(relocPLTB22PCREL) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(relocGOTREL) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(relocGOT) \
+ DECL_HEXAGON_APPLY_RELOC_FUNC(unsupported)
-#define DECL_HEXAGON_APPLY_RELOC_FUNCS \
-DECL_HEXAGON_APPLY_RELOC_FUNC(none) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(relocPCREL) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(relocGPREL) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(relocAbs) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(relocPLTB22PCREL) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(relocGOTREL) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(relocGOT) \
-DECL_HEXAGON_APPLY_RELOC_FUNC(unsupport)
+#define DECL_HEXAGON_APPLY_RELOC_FUNC_PTRS \
+ { &none, 0, "R_HEX_NONE" }, \
+ { &relocPCREL, 1, "R_HEX_B22_PCREL" }, \
+ { &relocPCREL, 2, "R_HEX_B15_PCREL" }, \
+ { &relocPCREL, 3, "R_HEX_B7_PCREL" }, \
+ { &relocAbs, 4, "R_HEX_LO16" }, \
+ { &relocAbs, 5, "R_HEX_HI16" }, \
+ { &relocAbs, 6, "R_HEX_32" }, \
+ { &relocAbs, 7, "R_HEX_16" }, \
+ { &relocAbs, 8, "R_HEX_8" }, \
+ { &relocGPREL, 9, "R_HEX_GPREL16_0" }, \
+ { &relocGPREL, 10, "R_HEX_GPREL16_1" }, \
+ { &relocGPREL, 11, "R_HEX_GPREL16_2" }, \
+ { &relocGPREL, 12, "R_HEX_GPREL16_3" }, \
+ { &unsupported, 13, "R_HEX_HL16" }, \
+ { &relocPCREL, 14, "R_HEX_B13_PCREL" }, \
+ { &relocPCREL, 15, "R_HEX_B9_PCREL" }, \
+ { &relocPCREL, 16, "R_HEX_B32_PCREL_X" }, \
+ { &relocAbs, 17, "R_HEX_32_6_X" }, \
+ { &relocPCREL, 18, "R_HEX_B22_PCREL_X" }, \
+ { &relocPCREL, 19, "R_HEX_B15_PCREL_X" }, \
+ { &relocPCREL, 20, "R_HEX_B13_PCREL_X" }, \
+ { &relocPCREL, 21, "R_HEX_B9_PCREL_X" }, \
+ { &relocPCREL, 22, "R_HEX_B7_PCREL_X" }, \
+ { &relocAbs, 23, "R_HEX_16_X" }, \
+ { &relocAbs, 24, "R_HEX_12_X" }, \
+ { &relocAbs, 25, "R_HEX_11_X" }, \
+ { &relocAbs, 26, "R_HEX_10_X" }, \
+ { &relocAbs, 27, "R_HEX_9_X" }, \
+ { &relocAbs, 28, "R_HEX_8_X" }, \
+ { &relocAbs, 29, "R_HEX_7_X" }, \
+ { &relocAbs, 30, "R_HEX_6_X" }, \
+ { &relocPCREL, 31, "R_HEX_32_PCREL" }, \
+ { &none, 32, "R_HEX_COPY" }, \
+ { &none, 33, "R_HEX_GLOB_DAT" }, \
+ { &none, 34, "R_HEX_JMP_SLOT" }, \
+ { &none, 35, "R_HEX_RELATIVE" }, \
+ { &relocPLTB22PCREL, 36, "R_HEX_PLT_B22_PCREL" }, \
+ { &relocGOTREL, 37, "R_HEX_GOTREL_LO16" }, \
+ { &relocGOTREL, 38, "R_HEX_GOTREL_HI16" }, \
+ { &relocGOTREL, 39, "R_HEX_GOTREL_32" }, \
+ { &relocGOT, 40, "R_HEX_GOT_LO16" }, \
+ { &relocGOT, 41, "R_HEX_GOT_HI16" }, \
+ { &relocGOT, 42, "R_HEX_GOT_32" }, \
+ { &relocGOT, 43, "R_HEX_GOT_16" }, \
+ { &unsupported, 44, "R_HEX_DTPMOD_32" }, \
+ { &unsupported, 45, "R_HEX_DTPREL_LO16" }, \
+ { &unsupported, 46, "R_HEX_DTPREL_HI16" }, \
+ { &unsupported, 47, "R_HEX_DTPREL_32" }, \
+ { &unsupported, 48, "R_HEX_DTPREL_16" }, \
+ { &unsupported, 49, "R_HEX_GD_PLT_B22_PCREL" }, \
+ { &unsupported, 50, "R_HEX_GD_GOT_LO16" }, \
+ { &unsupported, 51, "R_HEX_GD_GOT_HI16" }, \
+ { &unsupported, 52, "R_HEX_GD_GOT_32" }, \
+ { &unsupported, 53, "R_HEX_GD_GOT_16" }, \
+ { &unsupported, 54, "R_HEX_IE_LO16" }, \
+ { &unsupported, 55, "R_HEX_IE_HI16" }, \
+ { &unsupported, 56, "R_HEX_IE_32" }, \
+ { &unsupported, 57, "R_HEX_IE_GOT_LO16" }, \
+ { &unsupported, 58, "R_HEX_IE_GOT_HI16" }, \
+ { &unsupported, 59, "R_HEX_IE_GOT_32" }, \
+ { &unsupported, 60, "R_HEX_IE_GOT_16" }, \
+ { &unsupported, 61, "R_HEX_TPREL_LO16" }, \
+ { &unsupported, 62, "R_HEX_TPREL_HI16" }, \
+ { &unsupported, 63, "R_HEX_TPREL_32" }, \
+ { &unsupported, 64, "R_HEX_TPREL_16" }, \
+ { &relocPCREL, 65, "R_HEX_6_PCREL_X" }, \
+ { &relocGOTREL, 66, "R_HEX_GOTREL_32_6_X" }, \
+ { &relocGOTREL, 67, "R_HEX_GOTREL_16_X" }, \
+ { &relocGOTREL, 68, "R_HEX_GOTREL_11_X" }, \
+ { &relocGOT, 69, "R_HEX_GOT_32_6_X" }, \
+ { &relocGOT, 70, "R_HEX_GOT_16_X" }, \
+ { &relocGOT, 71, "R_HEX_GOT_11_X" }, \
+ { &unsupported, 72, "R_HEX_DTPREL_32_6_X" }, \
+ { &unsupported, 73, "R_HEX_DTPREL_16_X" }, \
+ { &unsupported, 74, "R_HEX_DTPREL_11_X" }, \
+ { &unsupported, 75, "R_HEX_GD_GOT_32_6_X" }, \
+ { &unsupported, 76, "R_HEX_GD_GOT_16_X" }, \
+ { &unsupported, 77, "R_HEX_GD_GOT_11_X" }, \
+ { &unsupported, 78, "R_HEX_IE_32_6_X" }, \
+ { &unsupported, 79, "R_HEX_IE_16_X" }, \
+ { &unsupported, 80, "R_HEX_IE_GOT_32_6_X" }, \
+ { &unsupported, 81, "R_HEX_IE_GOT_16_X" }, \
+ { &unsupported, 82, "R_HEX_IE_GOT_11_X" }, \
+ { &unsupported, 83, "R_HEX_TPREL_32_6_X" }, \
+ { &unsupported, 84, "R_HEX_TPREL_16_X" }, \
+ { &unsupported, 85, "R_HEX_TPREL_11_X" }
-#define DECL_HEXAGON_APPLY_RELOC_FUNC_PTRS \
- { &none, 0, "R_HEX_NONE" }, \
- { &relocPCREL, 1, "R_HEX_B22_PCREL" }, \
- { &relocPCREL, 2, "R_HEX_B15_PCREL" }, \
- { &relocPCREL, 3, "R_HEX_B7_PCREL" }, \
- { &relocAbs, 4, "R_HEX_LO16" }, \
- { &relocAbs, 5, "R_HEX_HI16" }, \
- { &relocAbs, 6, "R_HEX_32" }, \
- { &relocAbs, 7, "R_HEX_16" }, \
- { &relocAbs, 8, "R_HEX_8" }, \
- { &relocGPREL, 9, "R_HEX_GPREL16_0" }, \
- { &relocGPREL, 10, "R_HEX_GPREL16_1" }, \
- { &relocGPREL, 11, "R_HEX_GPREL16_2" }, \
- { &relocGPREL, 12, "R_HEX_GPREL16_3" }, \
- { &unsupport, 13, "R_HEX_HL16" }, \
- { &relocPCREL, 14, "R_HEX_B13_PCREL" }, \
- { &relocPCREL, 15, "R_HEX_B9_PCREL" }, \
- { &relocPCREL, 16, "R_HEX_B32_PCREL_X" }, \
- { &relocAbs, 17, "R_HEX_32_6_X" }, \
- { &relocPCREL, 18, "R_HEX_B22_PCREL_X" }, \
- { &relocPCREL, 19, "R_HEX_B15_PCREL_X" }, \
- { &relocPCREL, 20, "R_HEX_B13_PCREL_X" }, \
- { &relocPCREL, 21, "R_HEX_B9_PCREL_X" }, \
- { &relocPCREL, 22, "R_HEX_B7_PCREL_X" }, \
- { &relocAbs, 23, "R_HEX_16_X" }, \
- { &relocAbs, 24, "R_HEX_12_X" }, \
- { &relocAbs, 25, "R_HEX_11_X" }, \
- { &relocAbs, 26, "R_HEX_10_X" }, \
- { &relocAbs, 27, "R_HEX_9_X" }, \
- { &relocAbs, 28, "R_HEX_8_X" }, \
- { &relocAbs, 29, "R_HEX_7_X" }, \
- { &relocAbs, 30, "R_HEX_6_X" }, \
- { &relocPCREL, 31, "R_HEX_32_PCREL" }, \
- { &none, 32, "R_HEX_COPY" }, \
- { &none, 33, "R_HEX_GLOB_DAT" }, \
- { &none, 34, "R_HEX_JMP_SLOT" }, \
- { &none, 35, "R_HEX_RELATIVE" }, \
- { &relocPLTB22PCREL, 36, "R_HEX_PLT_B22_PCREL" }, \
- { &relocGOTREL, 37, "R_HEX_GOTREL_LO16" }, \
- { &relocGOTREL, 38, "R_HEX_GOTREL_HI16" }, \
- { &relocGOTREL, 39, "R_HEX_GOTREL_32" }, \
- { &relocGOT, 40, "R_HEX_GOT_LO16" }, \
- { &relocGOT, 41, "R_HEX_GOT_HI16" }, \
- { &relocGOT, 42, "R_HEX_GOT_32" }, \
- { &relocGOT, 43, "R_HEX_GOT_16" }, \
- { &unsupport, 44, "R_HEX_DTPMOD_32" }, \
- { &unsupport, 45, "R_HEX_DTPREL_LO16" }, \
- { &unsupport, 46, "R_HEX_DTPREL_HI16" }, \
- { &unsupport, 47, "R_HEX_DTPREL_32" }, \
- { &unsupport, 48, "R_HEX_DTPREL_16" }, \
- { &unsupport, 49, "R_HEX_GD_PLT_B22_PCREL" }, \
- { &unsupport, 50, "R_HEX_GD_GOT_LO16" }, \
- { &unsupport, 51, "R_HEX_GD_GOT_HI16" }, \
- { &unsupport, 52, "R_HEX_GD_GOT_32" }, \
- { &unsupport, 53, "R_HEX_GD_GOT_16" }, \
- { &unsupport, 54, "R_HEX_IE_LO16" }, \
- { &unsupport, 55, "R_HEX_IE_HI16" }, \
- { &unsupport, 56, "R_HEX_IE_32" }, \
- { &unsupport, 57, "R_HEX_IE_GOT_LO16" }, \
- { &unsupport, 58, "R_HEX_IE_GOT_HI16" }, \
- { &unsupport, 59, "R_HEX_IE_GOT_32" }, \
- { &unsupport, 60, "R_HEX_IE_GOT_16" }, \
- { &unsupport, 61, "R_HEX_TPREL_LO16" }, \
- { &unsupport, 62, "R_HEX_TPREL_HI16" }, \
- { &unsupport, 63, "R_HEX_TPREL_32" }, \
- { &unsupport, 64, "R_HEX_TPREL_16" }, \
- { &relocPCREL, 65, "R_HEX_6_PCREL_X" }, \
- { &relocGOTREL, 66, "R_HEX_GOTREL_32_6_X" }, \
- { &relocGOTREL, 67, "R_HEX_GOTREL_16_X" }, \
- { &relocGOTREL, 68, "R_HEX_GOTREL_11_X" }, \
- { &relocGOT, 69, "R_HEX_GOT_32_6_X" }, \
- { &relocGOT, 70, "R_HEX_GOT_16_X" }, \
- { &relocGOT, 71, "R_HEX_GOT_11_X" }, \
- { &unsupport, 72, "R_HEX_DTPREL_32_6_X" }, \
- { &unsupport, 73, "R_HEX_DTPREL_16_X" }, \
- { &unsupport, 74, "R_HEX_DTPREL_11_X" }, \
- { &unsupport, 75, "R_HEX_GD_GOT_32_6_X" }, \
- { &unsupport, 76, "R_HEX_GD_GOT_16_X" }, \
- { &unsupport, 77, "R_HEX_GD_GOT_11_X" }, \
- { &unsupport, 78, "R_HEX_IE_32_6_X" }, \
- { &unsupport, 79, "R_HEX_IE_16_X" }, \
- { &unsupport, 80, "R_HEX_IE_GOT_32_6_X" }, \
- { &unsupport, 81, "R_HEX_IE_GOT_16_X" }, \
- { &unsupport, 82, "R_HEX_IE_GOT_11_X" }, \
- { &unsupport, 83, "R_HEX_TPREL_32_6_X" }, \
- { &unsupport, 84, "R_HEX_TPREL_16_X" }, \
- { &unsupport, 85, "R_HEX_TPREL_11_X" }
+#endif // TARGET_HEXAGON_HEXAGONRELOCATIONFUNCTIONS_H_
diff --git a/lib/Target/Hexagon/HexagonRelocator.cpp b/lib/Target/Hexagon/HexagonRelocator.cpp
index d02b640..c05d76f 100644
--- a/lib/Target/Hexagon/HexagonRelocator.cpp
+++ b/lib/Target/Hexagon/HexagonRelocator.cpp
@@ -9,30 +9,31 @@
#include "HexagonRelocator.h"
#include "HexagonRelocationFunctions.h"
#include "HexagonEncodings.h"
+
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <llvm/ADT/Twine.h>
#include <llvm/Support/DataTypes.h>
#include <llvm/Support/ELF.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/Support/MsgHandling.h>
-
-using namespace mcld;
+namespace mcld {
//===--------------------------------------------------------------------===//
// Relocation Helper Functions
//===--------------------------------------------------------------------===//
/// helper_DynRel - Get an relocation entry in .rela.dyn
-static Relocation &helper_DynRel_init(ResolveInfo *pSym,
- Fragment &pFrag,
+static Relocation& helper_DynRel_init(ResolveInfo* pSym,
+ Fragment& pFrag,
uint64_t pOffset,
Relocator::Type pType,
- HexagonRelocator &pParent) {
- HexagonLDBackend &ld_backend = pParent.getTarget();
- Relocation &rela_entry = *ld_backend.getRelaDyn().create();
+ HexagonRelocator& pParent) {
+ HexagonLDBackend& ld_backend = pParent.getTarget();
+ Relocation& rela_entry = *ld_backend.getRelaDyn().create();
rela_entry.setType(pType);
rela_entry.targetRef().assign(pFrag, pOffset);
- if (pType == llvm::ELF::R_HEX_RELATIVE || NULL == pSym)
+ if (pType == llvm::ELF::R_HEX_RELATIVE || pSym == NULL)
rela_entry.setSymInfo(0);
else
rela_entry.setSymInfo(pSym);
@@ -42,8 +43,8 @@ static Relocation &helper_DynRel_init(ResolveInfo *pSym,
/// helper_use_relative_reloc - Check if symbol can use relocation
/// R_HEX_RELATIVE
-static bool helper_use_relative_reloc(const ResolveInfo &pSym,
- const HexagonRelocator &pFactory) {
+static bool helper_use_relative_reloc(const ResolveInfo& pSym,
+ const HexagonRelocator& pFactory) {
// if symbol is dynamic or undefine or preemptible
if (pSym.isDyn() || pSym.isUndef() ||
pFactory.getTarget().isSymbolPreemptible(pSym))
@@ -51,60 +52,58 @@ static bool helper_use_relative_reloc(const ResolveInfo &pSym,
return true;
}
-static HexagonGOTEntry &helper_GOT_init(Relocation &pReloc,
+static HexagonGOTEntry& helper_GOT_init(Relocation& pReloc,
bool pHasRel,
- HexagonRelocator &pParent) {
+ HexagonRelocator& pParent) {
// rsym - The relocation target symbol
- ResolveInfo *rsym = pReloc.symInfo();
- HexagonLDBackend &ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymGOTMap().lookUp(*rsym));
+ ResolveInfo* rsym = pReloc.symInfo();
+ HexagonLDBackend& ld_backend = pParent.getTarget();
+ assert(pParent.getSymGOTMap().lookUp(*rsym) == NULL);
- HexagonGOTEntry *got_entry = ld_backend.getGOT().create();
+ HexagonGOTEntry* got_entry = ld_backend.getGOT().create();
pParent.getSymGOTMap().record(*rsym, *got_entry);
if (!pHasRel) {
// No corresponding dynamic relocation, initialize to the symbol value.
got_entry->setValue(HexagonRelocator::SymVal);
- }
- else {
+ } else {
// Initialize got_entry content and the corresponding dynamic relocation.
if (helper_use_relative_reloc(*rsym, pParent)) {
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_HEX_RELATIVE,
- pParent);
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_HEX_RELATIVE, pParent);
got_entry->setValue(HexagonRelocator::SymVal);
- }
- else {
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_HEX_GLOB_DAT,
- pParent);
+ } else {
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_HEX_GLOB_DAT, pParent);
got_entry->setValue(0);
}
}
return *got_entry;
}
-static Relocator::Address helper_get_GOT_address(ResolveInfo &pSym,
- HexagonRelocator &pParent) {
- HexagonGOTEntry *got_entry = pParent.getSymGOTMap().lookUp(pSym);
- assert(NULL != got_entry);
+static Relocator::Address helper_get_GOT_address(ResolveInfo& pSym,
+ HexagonRelocator& pParent) {
+ HexagonGOTEntry* got_entry = pParent.getSymGOTMap().lookUp(pSym);
+ assert(got_entry != NULL);
return pParent.getTarget().getGOT().addr() + got_entry->getOffset();
}
-static PLTEntryBase &helper_PLT_init(Relocation &pReloc,
- HexagonRelocator &pParent) {
+static PLTEntryBase& helper_PLT_init(Relocation& pReloc,
+ HexagonRelocator& pParent) {
// rsym - The relocation target symbol
- ResolveInfo *rsym = pReloc.symInfo();
- HexagonLDBackend &ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymPLTMap().lookUp(*rsym));
+ ResolveInfo* rsym = pReloc.symInfo();
+ HexagonLDBackend& ld_backend = pParent.getTarget();
+ assert(pParent.getSymPLTMap().lookUp(*rsym) == NULL);
- PLTEntryBase *plt_entry = ld_backend.getPLT().create();
+ PLTEntryBase* plt_entry = ld_backend.getPLT().create();
pParent.getSymPLTMap().record(*rsym, *plt_entry);
- assert(NULL == pParent.getSymGOTPLTMap().lookUp(*rsym) &&
+ assert(pParent.getSymGOTPLTMap().lookUp(*rsym) == NULL &&
"PLT entry not exist, but DynRel entry exist!");
- HexagonGOTEntry *gotplt_entry = ld_backend.getGOTPLT().create();
+ HexagonGOTEntry* gotplt_entry = ld_backend.getGOTPLT().create();
pParent.getSymGOTPLTMap().record(*rsym, *gotplt_entry);
// init the corresponding rel entry in .rela.plt
- Relocation &rela_entry = *ld_backend.getRelaPLT().create();
+ Relocation& rela_entry = *ld_backend.getRelaPLT().create();
rela_entry.setType(llvm::ELF::R_HEX_JMP_SLOT);
rela_entry.targetRef().assign(*gotplt_entry);
rela_entry.setSymInfo(rsym);
@@ -113,9 +112,9 @@ static PLTEntryBase &helper_PLT_init(Relocation &pReloc,
}
static Relocator::Address helper_get_PLT_address(ResolveInfo& pSym,
- HexagonRelocator &pParent) {
- PLTEntryBase *plt_entry = pParent.getSymPLTMap().lookUp(pSym);
- assert(NULL != plt_entry);
+ HexagonRelocator& pParent) {
+ PLTEntryBase* plt_entry = pParent.getSymPLTMap().lookUp(pSym);
+ assert(plt_entry != NULL);
return pParent.getTarget().getPLT().addr() + plt_entry->getOffset();
}
@@ -125,24 +124,24 @@ static Relocator::Address helper_get_PLT_address(ResolveInfo& pSym,
DECL_HEXAGON_APPLY_RELOC_FUNCS
/// the prototype of applying function
-typedef Relocator::Result (*ApplyFunctionType)(Relocation &pReloc,
- HexagonRelocator &pParent);
+typedef Relocator::Result (*ApplyFunctionType)(Relocation& pReloc,
+ HexagonRelocator& pParent);
// the table entry of applying functions
struct ApplyFunctionTriple {
ApplyFunctionType func;
unsigned int type;
- const char *name;
+ const char* name;
};
// declare the table of applying functions
static const ApplyFunctionTriple ApplyFunctions[] = {
- DECL_HEXAGON_APPLY_RELOC_FUNC_PTRS
-};
+ DECL_HEXAGON_APPLY_RELOC_FUNC_PTRS};
-static uint32_t findBitMask(uint32_t insn, Instruction *encodings,
+static uint32_t findBitMask(uint32_t insn,
+ Instruction* encodings,
int32_t numInsns) {
- for (int32_t i = 0; i < numInsns; i++) {
+ for (int32_t i = 0; i < numInsns; ++i) {
if (((insn & 0xc000) == 0) && !(encodings[i].isDuplex))
continue;
@@ -158,23 +157,26 @@ static uint32_t findBitMask(uint32_t insn, Instruction *encodings,
return -1;
}
-#define FINDBITMASK(INSN) \
- findBitMask((uint32_t) INSN, insn_encodings, \
+#define FINDBITMASK(INSN) \
+ findBitMask((uint32_t)INSN, \
+ insn_encodings, \
sizeof(insn_encodings) / sizeof(Instruction))
//===--------------------------------------------------------------------===//
// HexagonRelocator
//===--------------------------------------------------------------------===//
-HexagonRelocator::HexagonRelocator(HexagonLDBackend &pParent,
- const LinkerConfig &pConfig)
- : Relocator(pConfig), m_Target(pParent) {}
+HexagonRelocator::HexagonRelocator(HexagonLDBackend& pParent,
+ const LinkerConfig& pConfig)
+ : Relocator(pConfig), m_Target(pParent) {
+}
-HexagonRelocator::~HexagonRelocator() {}
+HexagonRelocator::~HexagonRelocator() {
+}
-Relocator::Result HexagonRelocator::applyRelocation(Relocation &pRelocation) {
+Relocator::Result HexagonRelocator::applyRelocation(Relocation& pRelocation) {
Relocation::Type type = pRelocation.type();
- if (type > 85) { // 86-255 relocs do not exists for Hexagon
+ if (type > 85) { // 86-255 relocs do not exists for Hexagon
return Relocator::Unknown;
}
@@ -182,7 +184,7 @@ Relocator::Result HexagonRelocator::applyRelocation(Relocation &pRelocation) {
return ApplyFunctions[type].func(pRelocation, *this);
}
-const char *HexagonRelocator::getName(Relocation::Type pType) const {
+const char* HexagonRelocator::getName(Relocation::Type pType) const {
return ApplyFunctions[pType].name;
}
@@ -190,26 +192,29 @@ Relocator::Size HexagonRelocator::getSize(Relocation::Type pType) const {
return 32;
}
-void HexagonRelocator::scanRelocation(Relocation &pReloc, IRBuilder &pLinker,
- Module &pModule, LDSection &pSection, Input &pInput) {
+void HexagonRelocator::scanRelocation(Relocation& pReloc,
+ IRBuilder& pLinker,
+ Module& pModule,
+ LDSection& pSection,
+ Input& pInput) {
if (LinkerConfig::Object == config().codeGenType())
return;
// rsym - The relocation target symbol
- ResolveInfo *rsym = pReloc.symInfo();
- assert(NULL != rsym &&
+ ResolveInfo* rsym = pReloc.symInfo();
+ assert(rsym != NULL &&
"ResolveInfo of relocation not set while scanRelocation");
if (config().isCodeStatic())
return;
- assert(NULL != pSection.getLink());
- if (0 == (pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC))
+ assert(pSection.getLink() != NULL);
+ if ((pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC) == 0)
return;
- if (rsym->isLocal()) // rsym is local
+ if (rsym->isLocal()) // rsym is local
scanLocalReloc(pReloc, pLinker, pModule, pSection);
- else // rsym is external
+ else // rsym is external
scanGlobalReloc(pReloc, pLinker, pModule, pSection);
// check if we should issue undefined reference for the relocation target
@@ -218,176 +223,179 @@ void HexagonRelocator::scanRelocation(Relocation &pReloc, IRBuilder &pLinker,
issueUndefRef(pReloc, pSection, pInput);
}
-void HexagonRelocator::addCopyReloc(ResolveInfo &pSym,
- HexagonLDBackend &pTarget) {
- Relocation &rel_entry = *pTarget.getRelaDyn().create();
+void HexagonRelocator::addCopyReloc(ResolveInfo& pSym,
+ HexagonLDBackend& pTarget) {
+ Relocation& rel_entry = *pTarget.getRelaDyn().create();
rel_entry.setType(pTarget.getCopyRelType());
assert(pSym.outSymbol()->hasFragRef());
rel_entry.targetRef().assign(*pSym.outSymbol()->fragRef());
rel_entry.setSymInfo(&pSym);
}
-void HexagonRelocator::scanLocalReloc(Relocation &pReloc, IRBuilder &pBuilder,
- Module &pModule, LDSection &pSection) {
+void HexagonRelocator::scanLocalReloc(Relocation& pReloc,
+ IRBuilder& pBuilder,
+ Module& pModule,
+ LDSection& pSection) {
// rsym - The relocation target symbol
- ResolveInfo *rsym = pReloc.symInfo();
+ ResolveInfo* rsym = pReloc.symInfo();
switch (pReloc.type()) {
+ case llvm::ELF::R_HEX_LO16:
+ case llvm::ELF::R_HEX_HI16:
+ case llvm::ELF::R_HEX_16:
+ case llvm::ELF::R_HEX_8:
+ case llvm::ELF::R_HEX_32_6_X:
+ case llvm::ELF::R_HEX_16_X:
+ case llvm::ELF::R_HEX_12_X:
+ case llvm::ELF::R_HEX_11_X:
+ case llvm::ELF::R_HEX_10_X:
+ case llvm::ELF::R_HEX_9_X:
+ case llvm::ELF::R_HEX_8_X:
+ case llvm::ELF::R_HEX_7_X:
+ case llvm::ELF::R_HEX_6_X:
+ assert(!(rsym->reserved() & ReserveRel) &&
+ "Cannot apply this relocation for read only section");
+ return;
- case llvm::ELF::R_HEX_LO16:
- case llvm::ELF::R_HEX_HI16:
- case llvm::ELF::R_HEX_16:
- case llvm::ELF::R_HEX_8:
- case llvm::ELF::R_HEX_32_6_X:
- case llvm::ELF::R_HEX_16_X:
- case llvm::ELF::R_HEX_12_X:
- case llvm::ELF::R_HEX_11_X:
- case llvm::ELF::R_HEX_10_X:
- case llvm::ELF::R_HEX_9_X:
- case llvm::ELF::R_HEX_8_X:
- case llvm::ELF::R_HEX_7_X:
- case llvm::ELF::R_HEX_6_X:
- assert(!(rsym->reserved() & ReserveRel) &&
- "Cannot apply this relocation for read only section");
- return;
+ case llvm::ELF::R_HEX_32:
+ // If buiding PIC object (shared library or PIC executable),
+ // a dynamic relocations with RELATIVE type to this location is needed.
+ // Reserve an entry in .rel.dyn
+ if (config().isCodeIndep()) {
+ Relocation& reloc = helper_DynRel_init(rsym,
+ *pReloc.targetRef().frag(),
+ pReloc.targetRef().offset(),
+ llvm::ELF::R_HEX_RELATIVE,
+ *this);
+ // we need to set up the relocation addend at apply relocation, record
+ // the
+ // relocation
+ getRelRelMap().record(pReloc, reloc);
- case llvm::ELF::R_HEX_32:
- // If buiding PIC object (shared library or PIC executable),
- // a dynamic relocations with RELATIVE type to this location is needed.
- // Reserve an entry in .rel.dyn
- if (config().isCodeIndep()) {
- Relocation &reloc = helper_DynRel_init(rsym,
- *pReloc.targetRef().frag(),
- pReloc.targetRef().offset(),
- llvm::ELF::R_HEX_RELATIVE,
- *this);
- // we need to set up the relocation addend at apply relocation, record the
- // relocation
- getRelRelMap().record(pReloc, reloc);
-
- // set Rel bit
- rsym->setReserved(rsym->reserved() | ReserveRel);
- getTarget().checkAndSetHasTextRel(*pSection.getLink());
- }
- return;
+ // set Rel bit
+ rsym->setReserved(rsym->reserved() | ReserveRel);
+ getTarget().checkAndSetHasTextRel(*pSection.getLink());
+ }
+ return;
- default:
- return;
+ default:
+ return;
}
}
-void HexagonRelocator::scanGlobalReloc(Relocation &pReloc, IRBuilder &pBuilder,
- Module &pModule, LDSection &pSection) {
+void HexagonRelocator::scanGlobalReloc(Relocation& pReloc,
+ IRBuilder& pBuilder,
+ Module& pModule,
+ LDSection& pSection) {
// rsym - The relocation target symbol
- ResolveInfo *rsym = pReloc.symInfo();
- HexagonLDBackend &ld_backend = getTarget();
+ ResolveInfo* rsym = pReloc.symInfo();
+ HexagonLDBackend& ld_backend = getTarget();
switch (pReloc.type()) {
- case llvm::ELF::R_HEX_LO16:
- case llvm::ELF::R_HEX_HI16:
- case llvm::ELF::R_HEX_16:
- case llvm::ELF::R_HEX_8:
- case llvm::ELF::R_HEX_32_6_X:
- case llvm::ELF::R_HEX_16_X:
- case llvm::ELF::R_HEX_12_X:
- case llvm::ELF::R_HEX_11_X:
- case llvm::ELF::R_HEX_10_X:
- case llvm::ELF::R_HEX_9_X:
- case llvm::ELF::R_HEX_8_X:
- case llvm::ELF::R_HEX_7_X:
- case llvm::ELF::R_HEX_6_X:
- assert(!(rsym->reserved() & ReserveRel) &&
- "Cannot apply this relocation for read only section");
- return;
+ case llvm::ELF::R_HEX_LO16:
+ case llvm::ELF::R_HEX_HI16:
+ case llvm::ELF::R_HEX_16:
+ case llvm::ELF::R_HEX_8:
+ case llvm::ELF::R_HEX_32_6_X:
+ case llvm::ELF::R_HEX_16_X:
+ case llvm::ELF::R_HEX_12_X:
+ case llvm::ELF::R_HEX_11_X:
+ case llvm::ELF::R_HEX_10_X:
+ case llvm::ELF::R_HEX_9_X:
+ case llvm::ELF::R_HEX_8_X:
+ case llvm::ELF::R_HEX_7_X:
+ case llvm::ELF::R_HEX_6_X:
+ assert(!(rsym->reserved() & ReserveRel) &&
+ "Cannot apply this relocation for read only section");
+ return;
- case llvm::ELF::R_HEX_32:
- if (ld_backend.symbolNeedsPLT(*rsym)) {
- //create PLT for this symbol if it does not have.
- if (!(rsym->reserved() & ReservePLT)) {
- helper_PLT_init(pReloc, *this);
- rsym->setReserved(rsym->reserved() | ReservePLT);
+ case llvm::ELF::R_HEX_32:
+ if (ld_backend.symbolNeedsPLT(*rsym)) {
+ // create PLT for this symbol if it does not have.
+ if (!(rsym->reserved() & ReservePLT)) {
+ helper_PLT_init(pReloc, *this);
+ rsym->setReserved(rsym->reserved() | ReservePLT);
+ }
}
- }
- if (ld_backend.symbolNeedsDynRel(*rsym, (rsym->reserved() & ReservePLT),
- true)) {
- if (ld_backend.symbolNeedsCopyReloc(pReloc, *rsym)) {
- LDSymbol &cpy_sym =
- defineSymbolforCopyReloc(pBuilder, *rsym, ld_backend);
- addCopyReloc(*cpy_sym.resolveInfo(), ld_backend);
+ if (ld_backend.symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), true)) {
+ if (ld_backend.symbolNeedsCopyReloc(pReloc, *rsym)) {
+ LDSymbol& cpy_sym =
+ defineSymbolforCopyReloc(pBuilder, *rsym, ld_backend);
+ addCopyReloc(*cpy_sym.resolveInfo(), ld_backend);
+ } else {
+ Relocation& reloc = helper_DynRel_init(rsym,
+ *pReloc.targetRef().frag(),
+ pReloc.targetRef().offset(),
+ llvm::ELF::R_HEX_RELATIVE,
+ *this);
+ // we need to set up the relocation addend at apply relocation, record
+ // the
+ // relocation
+ getRelRelMap().record(pReloc, reloc);
+ rsym->setReserved(rsym->reserved() | ReserveRel);
+ ld_backend.checkAndSetHasTextRel(*pSection.getLink());
+ }
}
- else {
- Relocation &reloc = helper_DynRel_init(rsym,
- *pReloc.targetRef().frag(),
- pReloc.targetRef().offset(),
- llvm::ELF::R_HEX_RELATIVE,
- *this);
- // we need to set up the relocation addend at apply relocation, record the
- // relocation
- getRelRelMap().record(pReloc, reloc);
- rsym->setReserved(rsym->reserved() | ReserveRel);
- ld_backend.checkAndSetHasTextRel(*pSection.getLink());
- }
- }
- return;
-
- case llvm::ELF::R_HEX_GOTREL_LO16:
- case llvm::ELF::R_HEX_GOTREL_HI16:
- case llvm::ELF::R_HEX_GOTREL_32:
- case llvm::ELF::R_HEX_GOTREL_32_6_X:
- case llvm::ELF::R_HEX_GOTREL_16_X:
- case llvm::ELF::R_HEX_GOTREL_11_X:
- // This assumes that GOT exists
- return;
+ return;
- case llvm::ELF::R_HEX_GOT_LO16:
- case llvm::ELF::R_HEX_GOT_HI16:
- case llvm::ELF::R_HEX_GOT_32:
- case llvm::ELF::R_HEX_GOT_16:
- case llvm::ELF::R_HEX_GOT_32_6_X:
- case llvm::ELF::R_HEX_GOT_16_X:
- case llvm::ELF::R_HEX_GOT_11_X:
- // Symbol needs GOT entry, reserve entry in .got
- // return if we already create GOT for this symbol
- if (rsym->reserved() & ReserveGOT)
+ case llvm::ELF::R_HEX_GOTREL_LO16:
+ case llvm::ELF::R_HEX_GOTREL_HI16:
+ case llvm::ELF::R_HEX_GOTREL_32:
+ case llvm::ELF::R_HEX_GOTREL_32_6_X:
+ case llvm::ELF::R_HEX_GOTREL_16_X:
+ case llvm::ELF::R_HEX_GOTREL_11_X:
+ // This assumes that GOT exists
return;
- // If the GOT is used in statically linked binaries,
- // the GOT entry is enough and no relocation is needed.
- if (config().isCodeStatic())
- helper_GOT_init(pReloc, false, *this);
- else
- helper_GOT_init(pReloc, true, *this);
- // set GOT bit
- rsym->setReserved(rsym->reserved() | ReserveGOT);
- return;
- case llvm::ELF::R_HEX_B22_PCREL:
- case llvm::ELF::R_HEX_B15_PCREL:
- case llvm::ELF::R_HEX_B7_PCREL:
- case llvm::ELF::R_HEX_B13_PCREL:
- case llvm::ELF::R_HEX_B9_PCREL:
- case llvm::ELF::R_HEX_B32_PCREL_X:
- case llvm::ELF::R_HEX_B22_PCREL_X:
- case llvm::ELF::R_HEX_B15_PCREL_X:
- case llvm::ELF::R_HEX_B13_PCREL_X:
- case llvm::ELF::R_HEX_B9_PCREL_X:
- case llvm::ELF::R_HEX_B7_PCREL_X:
- case llvm::ELF::R_HEX_32_PCREL:
- case llvm::ELF::R_HEX_6_PCREL_X:
- case llvm::ELF::R_HEX_PLT_B22_PCREL:
- if (rsym->reserved() & ReservePLT)
+ case llvm::ELF::R_HEX_GOT_LO16:
+ case llvm::ELF::R_HEX_GOT_HI16:
+ case llvm::ELF::R_HEX_GOT_32:
+ case llvm::ELF::R_HEX_GOT_16:
+ case llvm::ELF::R_HEX_GOT_32_6_X:
+ case llvm::ELF::R_HEX_GOT_16_X:
+ case llvm::ELF::R_HEX_GOT_11_X:
+ // Symbol needs GOT entry, reserve entry in .got
+ // return if we already create GOT for this symbol
+ if (rsym->reserved() & ReserveGOT)
+ return;
+ // If the GOT is used in statically linked binaries,
+ // the GOT entry is enough and no relocation is needed.
+ if (config().isCodeStatic())
+ helper_GOT_init(pReloc, false, *this);
+ else
+ helper_GOT_init(pReloc, true, *this);
+ // set GOT bit
+ rsym->setReserved(rsym->reserved() | ReserveGOT);
return;
- if (ld_backend.symbolNeedsPLT(*rsym) ||
- pReloc.type() == llvm::ELF::R_HEX_PLT_B22_PCREL) {
- helper_PLT_init(pReloc, *this);
- rsym->setReserved(rsym->reserved() | ReservePLT);
- }
- return;
- default:
- break;
+ case llvm::ELF::R_HEX_B22_PCREL:
+ case llvm::ELF::R_HEX_B15_PCREL:
+ case llvm::ELF::R_HEX_B7_PCREL:
+ case llvm::ELF::R_HEX_B13_PCREL:
+ case llvm::ELF::R_HEX_B9_PCREL:
+ case llvm::ELF::R_HEX_B32_PCREL_X:
+ case llvm::ELF::R_HEX_B22_PCREL_X:
+ case llvm::ELF::R_HEX_B15_PCREL_X:
+ case llvm::ELF::R_HEX_B13_PCREL_X:
+ case llvm::ELF::R_HEX_B9_PCREL_X:
+ case llvm::ELF::R_HEX_B7_PCREL_X:
+ case llvm::ELF::R_HEX_32_PCREL:
+ case llvm::ELF::R_HEX_6_PCREL_X:
+ case llvm::ELF::R_HEX_PLT_B22_PCREL:
+ if (rsym->reserved() & ReservePLT)
+ return;
+ if (ld_backend.symbolNeedsPLT(*rsym) ||
+ pReloc.type() == llvm::ELF::R_HEX_PLT_B22_PCREL) {
+ helper_PLT_init(pReloc, *this);
+ rsym->setReserved(rsym->reserved() | ReservePLT);
+ }
+ return;
- } // end of switch
+ default:
+ break;
+ } // end of switch
}
/// defineSymbolforCopyReloc
@@ -395,19 +403,21 @@ void HexagonRelocator::scanGlobalReloc(Relocation &pReloc, IRBuilder &pBuilder,
/// section and all other reference to this symbol should refer to this
/// copy.
/// @note This is executed at `scan relocation' stage.
-LDSymbol &HexagonRelocator::defineSymbolforCopyReloc(
- IRBuilder &pBuilder, const ResolveInfo &pSym, HexagonLDBackend &pTarget) {
+LDSymbol& HexagonRelocator::defineSymbolforCopyReloc(
+ IRBuilder& pBuilder,
+ const ResolveInfo& pSym,
+ HexagonLDBackend& pTarget) {
// get or create corresponding BSS LDSection
- LDSection *bss_sect_hdr = NULL;
- ELFFileFormat *file_format = pTarget.getOutputFormat();
+ LDSection* bss_sect_hdr = NULL;
+ ELFFileFormat* file_format = pTarget.getOutputFormat();
if (ResolveInfo::ThreadLocal == pSym.type())
bss_sect_hdr = &file_format->getTBSS();
else
bss_sect_hdr = &file_format->getBSS();
// get or create corresponding BSS SectionData
- assert(NULL != bss_sect_hdr);
- SectionData *bss_section = NULL;
+ assert(bss_sect_hdr != NULL);
+ SectionData* bss_section = NULL;
if (bss_sect_hdr->hasSectionData())
bss_section = bss_sect_hdr->getSectionData();
else
@@ -418,36 +428,43 @@ LDSymbol &HexagonRelocator::defineSymbolforCopyReloc(
uint32_t addralign = config().targets().bitclass() / 8;
// allocate space in BSS for the copy symbol
- Fragment *frag = new FillFragment(0x0, 1, pSym.size());
+ Fragment* frag = new FillFragment(0x0, 1, pSym.size());
uint64_t size = ObjectBuilder::AppendFragment(*frag, *bss_section, addralign);
bss_sect_hdr->setSize(bss_sect_hdr->size() + size);
// change symbol binding to Global if it's a weak symbol
- ResolveInfo::Binding binding = (ResolveInfo::Binding) pSym.binding();
+ ResolveInfo::Binding binding = (ResolveInfo::Binding)pSym.binding();
if (binding == ResolveInfo::Weak)
binding = ResolveInfo::Global;
// Define the copy symbol in the bss section and resolve it
- LDSymbol *cpy_sym = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- pSym.name(), (ResolveInfo::Type) pSym.type(), ResolveInfo::Define,
- binding, pSym.size(), // size
- 0x0, // value
- FragmentRef::Create(*frag, 0x0), (ResolveInfo::Visibility) pSym.other());
+ LDSymbol* cpy_sym = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
+ pSym.name(),
+ (ResolveInfo::Type)pSym.type(),
+ ResolveInfo::Define,
+ binding,
+ pSym.size(), // size
+ 0x0, // value
+ FragmentRef::Create(*frag, 0x0),
+ (ResolveInfo::Visibility)pSym.other());
// output all other alias symbols if any
- Module &pModule = pBuilder.getModule();
- Module::AliasList *alias_list = pModule.getAliasList(pSym);
- if (NULL != alias_list) {
+ Module& pModule = pBuilder.getModule();
+ Module::AliasList* alias_list = pModule.getAliasList(pSym);
+ if (alias_list != NULL) {
Module::alias_iterator it, it_e = alias_list->end();
for (it = alias_list->begin(); it != it_e; ++it) {
- const ResolveInfo *alias = *it;
+ const ResolveInfo* alias = *it;
if (alias != &pSym && alias->isDyn()) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- alias->name(), (ResolveInfo::Type) alias->type(),
- ResolveInfo::Define, binding, alias->size(), // size
- 0x0, // value
+ alias->name(),
+ (ResolveInfo::Type)alias->type(),
+ ResolveInfo::Define,
+ binding,
+ alias->size(), // size
+ 0x0, // value
FragmentRef::Create(*frag, 0x0),
- (ResolveInfo::Visibility) alias->other());
+ (ResolveInfo::Visibility)alias->other());
}
}
}
@@ -455,20 +472,19 @@ LDSymbol &HexagonRelocator::defineSymbolforCopyReloc(
return *cpy_sym;
}
-void HexagonRelocator::partialScanRelocation(Relocation &pReloc,
- Module &pModule,
- const LDSection &pSection) {
+void HexagonRelocator::partialScanRelocation(Relocation& pReloc,
+ Module& pModule) {
pReloc.updateAddend();
// if we meet a section symbol
if (pReloc.symInfo()->type() == ResolveInfo::Section) {
- LDSymbol *input_sym = pReloc.symInfo()->outSymbol();
+ LDSymbol* input_sym = pReloc.symInfo()->outSymbol();
// 1. update the relocation target offset
assert(input_sym->hasFragRef());
// 2. get the output LDSection which the symbol defined in
- const LDSection &out_sect =
+ const LDSection& out_sect =
input_sym->fragRef()->frag()->getParent()->getSection();
- ResolveInfo *sym_info =
+ ResolveInfo* sym_info =
pModule.getSectionSymbolSet().get(out_sect)->resolveInfo();
// set relocation target symbol to the output section symbol's resolveInfo
pReloc.setSymInfo(sym_info);
@@ -480,14 +496,14 @@ void HexagonRelocator::partialScanRelocation(Relocation &pReloc,
//=========================================//
// R_HEX_NONE
-Relocator::Result none(Relocation &pReloc, HexagonRelocator &pParent) {
+Relocator::Result none(Relocation& pReloc, HexagonRelocator& pParent) {
return Relocator::OK;
}
-//R_HEX_32 and its class of relocations use only addend and symbol value
+// R_HEX_32 and its class of relocations use only addend and symbol value
// S + A : result is unsigned truncate.
// Exception: R_HEX_32_6_X : unsigned verify
-Relocator::Result applyAbs(Relocation &pReloc) {
+Relocator::Result applyAbs(Relocation& pReloc) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord A = pReloc.addend();
uint32_t result = (uint32_t)(S + A);
@@ -497,54 +513,53 @@ Relocator::Result applyAbs(Relocation &pReloc) {
uint32_t shift = 0;
switch (pReloc.type()) {
- case llvm::ELF::R_HEX_LO16:
- bitMask = 0x00c03fff;
- break;
-
- case llvm::ELF::R_HEX_HI16:
- shift = 16;
- bitMask = 0x00c03fff;
- break;
-
- case llvm::ELF::R_HEX_32:
- bitMask = 0xffffffff;
- break;
-
- case llvm::ELF::R_HEX_16:
- bitMask = 0x0000ffff;
- alignment = 2;
- break;
-
- case llvm::ELF::R_HEX_8:
- bitMask = 0x000000ff;
- alignment = 1;
- break;
-
- case llvm::ELF::R_HEX_12_X:
- bitMask = 0x000007e0;
- break;
-
- case llvm::ELF::R_HEX_32_6_X:
- bitMask = 0xfff3fff;
- shift = 6;
- effectiveBits = 26;
- break;
-
- case llvm::ELF::R_HEX_16_X:
- case llvm::ELF::R_HEX_11_X:
- case llvm::ELF::R_HEX_10_X:
- case llvm::ELF::R_HEX_9_X:
- case llvm::ELF::R_HEX_8_X:
- case llvm::ELF::R_HEX_7_X:
- case llvm::ELF::R_HEX_6_X:
- bitMask = FINDBITMASK(pReloc.target());
- break;
-
- default:
- // show proper error
- fatal(diag::unsupported_relocation) << (int)
- pReloc.type() << "mclinker@googlegroups.com";
-
+ case llvm::ELF::R_HEX_LO16:
+ bitMask = 0x00c03fff;
+ break;
+
+ case llvm::ELF::R_HEX_HI16:
+ shift = 16;
+ bitMask = 0x00c03fff;
+ break;
+
+ case llvm::ELF::R_HEX_32:
+ bitMask = 0xffffffff;
+ break;
+
+ case llvm::ELF::R_HEX_16:
+ bitMask = 0x0000ffff;
+ alignment = 2;
+ break;
+
+ case llvm::ELF::R_HEX_8:
+ bitMask = 0x000000ff;
+ alignment = 1;
+ break;
+
+ case llvm::ELF::R_HEX_12_X:
+ bitMask = 0x000007e0;
+ break;
+
+ case llvm::ELF::R_HEX_32_6_X:
+ bitMask = 0xfff3fff;
+ shift = 6;
+ effectiveBits = 26;
+ break;
+
+ case llvm::ELF::R_HEX_16_X:
+ case llvm::ELF::R_HEX_11_X:
+ case llvm::ELF::R_HEX_10_X:
+ case llvm::ELF::R_HEX_9_X:
+ case llvm::ELF::R_HEX_8_X:
+ case llvm::ELF::R_HEX_7_X:
+ case llvm::ELF::R_HEX_6_X:
+ bitMask = FINDBITMASK(pReloc.target());
+ break;
+
+ default:
+ // show proper error
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
+ << "mclinker@googlegroups.com";
}
if ((shift != 0) && (result % alignment != 0))
@@ -562,11 +577,11 @@ Relocator::Result applyAbs(Relocation &pReloc) {
return Relocator::OK;
}
-//R_HEX_B22_PCREL and its class of relocations, use
+// R_HEX_B22_PCREL and its class of relocations, use
// S + A - P : result is signed verify.
// Exception: R_HEX_B32_PCREL_X : signed truncate
// Another Exception: R_HEX_6_PCREL_X is unsigned truncate
-Relocator::Result applyRel(Relocation &pReloc, int64_t pResult) {
+Relocator::Result applyRel(Relocation& pReloc, int64_t pResult) {
uint32_t bitMask = 0;
uint32_t effectiveBits = 0;
uint32_t alignment = 1;
@@ -574,92 +589,92 @@ Relocator::Result applyRel(Relocation &pReloc, int64_t pResult) {
uint32_t shift = 0;
switch (pReloc.type()) {
- case llvm::ELF::R_HEX_B22_PCREL:
- bitMask = 0x01ff3ffe;
- effectiveBits = 22;
- alignment = 4;
- shift = 2;
- break;
-
- case llvm::ELF::R_HEX_B15_PCREL:
- bitMask = 0x00df20fe;
- effectiveBits = 15;
- alignment = 4;
- shift = 2;
- break;
-
- case llvm::ELF::R_HEX_B7_PCREL:
- bitMask = 0x00001f18;
- effectiveBits = 7;
- alignment = 4;
- shift = 2;
- break;
-
- case llvm::ELF::R_HEX_B13_PCREL:
- bitMask = 0x00202ffe;
- effectiveBits = 13;
- alignment = 4;
- shift = 2;
- break;
-
- case llvm::ELF::R_HEX_B9_PCREL:
- bitMask = 0x003000fe;
- effectiveBits = 9;
- alignment = 4;
- shift = 2;
- break;
-
- case llvm::ELF::R_HEX_B32_PCREL_X:
- bitMask = 0xfff3fff;
- shift = 6;
- break;
-
- case llvm::ELF::R_HEX_B22_PCREL_X:
- bitMask = 0x01ff3ffe;
- effectiveBits = 22;
- pResult &= 0x3f;
- break;
-
- case llvm::ELF::R_HEX_B15_PCREL_X:
- bitMask = 0x00df20fe;
- effectiveBits = 15;
- pResult &= 0x3f;
- break;
-
- case llvm::ELF::R_HEX_B13_PCREL_X:
- bitMask = 0x00202ffe;
- effectiveBits = 13;
- pResult &= 0x3f;
- break;
-
- case llvm::ELF::R_HEX_B9_PCREL_X:
- bitMask = 0x003000fe;
- effectiveBits = 9;
- pResult &= 0x3f;
- break;
-
- case llvm::ELF::R_HEX_B7_PCREL_X:
- bitMask = 0x00001f18;
- effectiveBits = 7;
- pResult &= 0x3f;
- break;
-
- case llvm::ELF::R_HEX_32_PCREL:
- bitMask = 0xffffffff;
- effectiveBits = 32;
- break;
-
- case llvm::ELF::R_HEX_6_PCREL_X:
- // This is unique since it has a unsigned operand and its truncated
- bitMask = FINDBITMASK(pReloc.target());
- result = pReloc.addend() + pReloc.symValue() - pReloc.place();
- pReloc.target() |= ApplyMask<uint32_t>(bitMask, result);
- return Relocator::OK;
+ case llvm::ELF::R_HEX_B22_PCREL:
+ bitMask = 0x01ff3ffe;
+ effectiveBits = 22;
+ alignment = 4;
+ shift = 2;
+ break;
+
+ case llvm::ELF::R_HEX_B15_PCREL:
+ bitMask = 0x00df20fe;
+ effectiveBits = 15;
+ alignment = 4;
+ shift = 2;
+ break;
+
+ case llvm::ELF::R_HEX_B7_PCREL:
+ bitMask = 0x00001f18;
+ effectiveBits = 7;
+ alignment = 4;
+ shift = 2;
+ break;
+
+ case llvm::ELF::R_HEX_B13_PCREL:
+ bitMask = 0x00202ffe;
+ effectiveBits = 13;
+ alignment = 4;
+ shift = 2;
+ break;
+
+ case llvm::ELF::R_HEX_B9_PCREL:
+ bitMask = 0x003000fe;
+ effectiveBits = 9;
+ alignment = 4;
+ shift = 2;
+ break;
+
+ case llvm::ELF::R_HEX_B32_PCREL_X:
+ bitMask = 0xfff3fff;
+ shift = 6;
+ break;
+
+ case llvm::ELF::R_HEX_B22_PCREL_X:
+ bitMask = 0x01ff3ffe;
+ effectiveBits = 22;
+ pResult &= 0x3f;
+ break;
+
+ case llvm::ELF::R_HEX_B15_PCREL_X:
+ bitMask = 0x00df20fe;
+ effectiveBits = 15;
+ pResult &= 0x3f;
+ break;
+
+ case llvm::ELF::R_HEX_B13_PCREL_X:
+ bitMask = 0x00202ffe;
+ effectiveBits = 13;
+ pResult &= 0x3f;
+ break;
+
+ case llvm::ELF::R_HEX_B9_PCREL_X:
+ bitMask = 0x003000fe;
+ effectiveBits = 9;
+ pResult &= 0x3f;
+ break;
+
+ case llvm::ELF::R_HEX_B7_PCREL_X:
+ bitMask = 0x00001f18;
+ effectiveBits = 7;
+ pResult &= 0x3f;
+ break;
+
+ case llvm::ELF::R_HEX_32_PCREL:
+ bitMask = 0xffffffff;
+ effectiveBits = 32;
+ break;
+
+ case llvm::ELF::R_HEX_6_PCREL_X:
+ // This is unique since it has a unsigned operand and its truncated
+ bitMask = FINDBITMASK(pReloc.target());
+ result = pReloc.addend() + pReloc.symValue() - pReloc.place();
+ pReloc.target() |= ApplyMask<uint32_t>(bitMask, result);
+ return Relocator::OK;
- default:
- // show proper error
- fatal(diag::unsupported_relocation) << (int)
- pReloc.type() << "mclinker@googlegroups.com";
+ default:
+ // show proper error
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
+ << "mclinker@googlegroups.com";
}
if ((shift != 0) && (pResult % alignment != 0))
@@ -673,17 +688,17 @@ Relocator::Result applyRel(Relocation &pReloc, int64_t pResult) {
return Relocator::Overflow;
}
- pReloc.target() |= (uint32_t) ApplyMask<int32_t>(bitMask, pResult);
+ pReloc.target() |= (uint32_t)ApplyMask<int32_t>(bitMask, pResult);
return Relocator::OK;
}
-Relocator::Result relocAbs(Relocation &pReloc, HexagonRelocator &pParent) {
- ResolveInfo *rsym = pReloc.symInfo();
+Relocator::Result relocAbs(Relocation& pReloc, HexagonRelocator& pParent) {
+ ResolveInfo* rsym = pReloc.symInfo();
Relocator::Address S = pReloc.symValue();
Relocator::DWord A = pReloc.addend();
Relocation* rel_entry = pParent.getRelRelMap().lookUp(pReloc);
- bool has_dyn_rel = (NULL != rel_entry);
+ bool has_dyn_rel = (rel_entry != NULL);
// if the flag of target section is not ALLOC, we eprform only static
// relocation.
@@ -717,22 +732,22 @@ Relocator::Result relocAbs(Relocation &pReloc, HexagonRelocator &pParent) {
return applyAbs(pReloc);
}
-Relocator::Result relocPCREL(Relocation &pReloc, HexagonRelocator &pParent) {
- ResolveInfo *rsym = pReloc.symInfo();
+Relocator::Result relocPCREL(Relocation& pReloc, HexagonRelocator& pParent) {
+ ResolveInfo* rsym = pReloc.symInfo();
int64_t result;
Relocator::Address S = pReloc.symValue();
Relocator::DWord A = pReloc.addend();
Relocator::DWord P = pReloc.place();
- FragmentRef &target_fragref = pReloc.targetRef();
- Fragment *target_frag = target_fragref.frag();
- LDSection &target_sect = target_frag->getParent()->getSection();
+ FragmentRef& target_fragref = pReloc.targetRef();
+ Fragment* target_frag = target_fragref.frag();
+ LDSection& target_sect = target_frag->getParent()->getSection();
result = (int64_t)(S + A - P);
// for relocs inside non ALLOC, just apply
- if (0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) == 0) {
return applyRel(pReloc, result);
}
@@ -749,7 +764,7 @@ Relocator::Result relocPCREL(Relocation &pReloc, HexagonRelocator &pParent) {
}
// R_HEX_GPREL16_0 and its class : Unsigned Verify
-Relocator::Result relocGPREL(Relocation &pReloc, HexagonRelocator &pParent) {
+Relocator::Result relocGPREL(Relocation& pReloc, HexagonRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord A = pReloc.addend();
Relocator::DWord GP = pParent.getTarget().getGP();
@@ -759,28 +774,28 @@ Relocator::Result relocGPREL(Relocation &pReloc, HexagonRelocator &pParent) {
uint32_t alignment = 1;
switch (pReloc.type()) {
- case llvm::ELF::R_HEX_GPREL16_0:
- break;
-
- case llvm::ELF::R_HEX_GPREL16_1:
- shift = 1;
- alignment = 2;
- break;
-
- case llvm::ELF::R_HEX_GPREL16_2:
- shift = 2;
- alignment = 4;
- break;
-
- case llvm::ELF::R_HEX_GPREL16_3:
- shift = 3;
- alignment = 8;
- break;
-
- default:
- // show proper error
- fatal(diag::unsupported_relocation) << (int)
- pReloc.type() << "mclinker@googlegroups.com";
+ case llvm::ELF::R_HEX_GPREL16_0:
+ break;
+
+ case llvm::ELF::R_HEX_GPREL16_1:
+ shift = 1;
+ alignment = 2;
+ break;
+
+ case llvm::ELF::R_HEX_GPREL16_2:
+ shift = 2;
+ alignment = 4;
+ break;
+
+ case llvm::ELF::R_HEX_GPREL16_3:
+ shift = 3;
+ alignment = 8;
+ break;
+
+ default:
+ // show proper error
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
+ << "mclinker@googlegroups.com";
}
uint32_t range = 1 << 16;
@@ -799,8 +814,8 @@ Relocator::Result relocGPREL(Relocation &pReloc, HexagonRelocator &pParent) {
}
// R_HEX_PLT_B22_PCREL: PLT(S) + A - P
-Relocator::Result relocPLTB22PCREL(Relocation &pReloc,
- HexagonRelocator &pParent) {
+Relocator::Result relocPLTB22PCREL(Relocation& pReloc,
+ HexagonRelocator& pParent) {
// PLT_S depends on if there is a PLT entry.
Relocator::Address PLT_S;
if ((pReloc.symInfo()->reserved() & HexagonRelocator::ReservePLT))
@@ -814,22 +829,21 @@ Relocator::Result relocPLTB22PCREL(Relocation &pReloc,
return Relocator::OK;
}
-//R_HEX_GOT_LO16 and its class : (G) Signed Truncate
-//Exception: R_HEX_GOT_16(_X): signed verify
+// R_HEX_GOT_LO16 and its class : (G) Signed Truncate
+// Exception: R_HEX_GOT_16(_X): signed verify
// Exception: R_HEX_GOT_11_X : unsigned truncate
-Relocator::Result relocGOT(Relocation &pReloc, HexagonRelocator &pParent) {
+Relocator::Result relocGOT(Relocation& pReloc, HexagonRelocator& pParent) {
if (!(pReloc.symInfo()->reserved() & HexagonRelocator::ReserveGOT)) {
return Relocator::BadReloc;
}
// set got entry value if needed
- HexagonGOTEntry *got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- assert(NULL != got_entry);
+ HexagonGOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
+ assert(got_entry != NULL);
if (HexagonRelocator::SymVal == got_entry->getValue())
got_entry->setValue(pReloc.symValue());
- Relocator::Address GOT_S =
- helper_get_GOT_address(*pReloc.symInfo(), pParent);
+ Relocator::Address GOT_S = helper_get_GOT_address(*pReloc.symInfo(), pParent);
Relocator::Address GOT = pParent.getTarget().getGOTSymbolAddr();
int32_t result = (int32_t)(GOT_S - GOT);
uint32_t effectiveBits = 0;
@@ -839,45 +853,45 @@ Relocator::Result relocGOT(Relocation &pReloc, HexagonRelocator &pParent) {
uint32_t shift = 0;
switch (pReloc.type()) {
- case llvm::ELF::R_HEX_GOT_LO16:
- bitMask = 0x00c03fff;
- break;
-
- case llvm::ELF::R_HEX_GOT_HI16:
- bitMask = 0x00c03fff;
- shift = 16;
- alignment = 4;
- break;
-
- case llvm::ELF::R_HEX_GOT_32:
- bitMask = 0xffffffff;
- break;
-
- case llvm::ELF::R_HEX_GOT_16:
- bitMask = FINDBITMASK(pReloc.target());
- effectiveBits = 16;
- break;
-
- case llvm::ELF::R_HEX_GOT_32_6_X:
- bitMask = 0xfff3fff;
- shift = 6;
- break;
-
- case llvm::ELF::R_HEX_GOT_16_X:
- bitMask = FINDBITMASK(pReloc.target());
- effectiveBits = 6;
- break;
-
- case llvm::ELF::R_HEX_GOT_11_X:
- bitMask = FINDBITMASK(pReloc.target());
- result_u = GOT_S - GOT;
- pReloc.target() |= ApplyMask<uint32_t>(bitMask, result_u);
- return Relocator::OK;
+ case llvm::ELF::R_HEX_GOT_LO16:
+ bitMask = 0x00c03fff;
+ break;
+
+ case llvm::ELF::R_HEX_GOT_HI16:
+ bitMask = 0x00c03fff;
+ shift = 16;
+ alignment = 4;
+ break;
+
+ case llvm::ELF::R_HEX_GOT_32:
+ bitMask = 0xffffffff;
+ break;
+
+ case llvm::ELF::R_HEX_GOT_16:
+ bitMask = FINDBITMASK(pReloc.target());
+ effectiveBits = 16;
+ break;
+
+ case llvm::ELF::R_HEX_GOT_32_6_X:
+ bitMask = 0xfff3fff;
+ shift = 6;
+ break;
+
+ case llvm::ELF::R_HEX_GOT_16_X:
+ bitMask = FINDBITMASK(pReloc.target());
+ effectiveBits = 6;
+ break;
+
+ case llvm::ELF::R_HEX_GOT_11_X:
+ bitMask = FINDBITMASK(pReloc.target());
+ result_u = GOT_S - GOT;
+ pReloc.target() |= ApplyMask<uint32_t>(bitMask, result_u);
+ return Relocator::OK;
- default:
- // show proper error
- fatal(diag::unsupported_relocation) << (int)
- pReloc.type() << "mclinker@googlegroups.com";
+ default:
+ // show proper error
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
+ << "mclinker@googlegroups.com";
}
if ((shift != 0) && (result % alignment != 0))
@@ -896,7 +910,7 @@ Relocator::Result relocGOT(Relocation &pReloc, HexagonRelocator &pParent) {
// R_HEX_GOTREL_LO16: and its class of relocs
// (S + A - GOT) : Signed Truncate
-Relocator::Result relocGOTREL(Relocation &pReloc, HexagonRelocator &pParent) {
+Relocator::Result relocGOTREL(Relocation& pReloc, HexagonRelocator& pParent) {
Relocator::Address S = pReloc.symValue();
Relocator::DWord A = pReloc.addend();
Relocator::Address GOT = pParent.getTarget().getGOTSymbolAddr();
@@ -908,34 +922,34 @@ Relocator::Result relocGOTREL(Relocation &pReloc, HexagonRelocator &pParent) {
uint32_t result = (uint32_t)(S + A - GOT);
switch (pReloc.type()) {
- case llvm::ELF::R_HEX_GOTREL_LO16:
- bitMask = 0x00c03fff;
- break;
-
- case llvm::ELF::R_HEX_GOTREL_HI16:
- bitMask = 0x00c03fff;
- shift = 16;
- alignment = 4;
- break;
-
- case llvm::ELF::R_HEX_GOTREL_32:
- bitMask = 0xffffffff;
- break;
-
- case llvm::ELF::R_HEX_GOTREL_32_6_X:
- bitMask = 0x0fff3fff;
- shift = 6;
- break;
-
- case llvm::ELF::R_HEX_GOTREL_16_X:
- case llvm::ELF::R_HEX_GOTREL_11_X:
- bitMask = FINDBITMASK(pReloc.target());
- break;
-
- default:
- // show proper error
- fatal(diag::unsupported_relocation) << (int)
- pReloc.type() << "mclinker@googlegroups.com";
+ case llvm::ELF::R_HEX_GOTREL_LO16:
+ bitMask = 0x00c03fff;
+ break;
+
+ case llvm::ELF::R_HEX_GOTREL_HI16:
+ bitMask = 0x00c03fff;
+ shift = 16;
+ alignment = 4;
+ break;
+
+ case llvm::ELF::R_HEX_GOTREL_32:
+ bitMask = 0xffffffff;
+ break;
+
+ case llvm::ELF::R_HEX_GOTREL_32_6_X:
+ bitMask = 0x0fff3fff;
+ shift = 6;
+ break;
+
+ case llvm::ELF::R_HEX_GOTREL_16_X:
+ case llvm::ELF::R_HEX_GOTREL_11_X:
+ bitMask = FINDBITMASK(pReloc.target());
+ break;
+
+ default:
+ // show proper error
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
+ << "mclinker@googlegroups.com";
}
if (result % alignment != 0)
@@ -947,6 +961,8 @@ Relocator::Result relocGOTREL(Relocation &pReloc, HexagonRelocator &pParent) {
return Relocator::OK;
}
-Relocator::Result unsupport(Relocation &pReloc, HexagonRelocator &pParent) {
- return Relocator::Unsupport;
+Relocator::Result unsupported(Relocation& pReloc, HexagonRelocator& pParent) {
+ return Relocator::Unsupported;
}
+
+} // namespace mcld
diff --git a/lib/Target/Hexagon/HexagonRelocator.h b/lib/Target/Hexagon/HexagonRelocator.h
index 7f50f31..2a7ee54 100644
--- a/lib/Target/Hexagon/HexagonRelocator.h
+++ b/lib/Target/Hexagon/HexagonRelocator.h
@@ -6,33 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONRELOCATOR_H
-#define TARGET_HEXAGON_HEXAGONRELOCATOR_H
+#ifndef TARGET_HEXAGON_HEXAGONRELOCATOR_H_
+#define TARGET_HEXAGON_HEXAGONRELOCATOR_H_
-#include <mcld/LD/Relocator.h>
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/PLT.h>
-#include <mcld/Target/KeyEntryMap.h>
+#include "mcld/LD/Relocator.h"
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/PLT.h"
+#include "mcld/Target/KeyEntryMap.h"
#include "HexagonLDBackend.h"
namespace mcld {
-class ResolveInfo;
class LinkerConfig;
+class ResolveInfo;
/** \class HexagonRelocator
* \brief HexagonRelocator creates and destroys the Hexagon relocations.
*
*/
-class HexagonRelocator : public Relocator
-{
-public:
+class HexagonRelocator : public Relocator {
+ public:
typedef KeyEntryMap<ResolveInfo, PLTEntryBase> SymPLTMap;
typedef KeyEntryMap<ResolveInfo, HexagonGOTEntry> SymGOTMap;
typedef KeyEntryMap<ResolveInfo, HexagonGOTEntry> SymGOTPLTMap;
typedef KeyEntryMap<Relocation, Relocation> RelRelMap;
-public:
+ public:
/** \enum ReservedEntryType
* \brief The reserved entry type of reserved space in ResolveInfo.
*
@@ -52,10 +51,10 @@ public:
*
*/
enum ReservedEntryType {
- None = 0,
- ReserveRel = 1,
- ReserveGOT = 2,
- ReservePLT = 4,
+ None = 0,
+ ReserveRel = 1,
+ ReserveGOT = 2,
+ ReservePLT = 4,
};
/** \enum EntryValue
@@ -63,10 +62,7 @@ public:
* layout, so we mark the entry during scanRelocation and fill up the actual
* value when applying relocations.
*/
- enum EntryValue {
- Default = 0,
- SymVal = 1
- };
+ enum EntryValue { Default = 0, SymVal = 1 };
HexagonRelocator(HexagonLDBackend& pParent, const LinkerConfig& pConfig);
~HexagonRelocator();
@@ -87,32 +83,37 @@ public:
// Handle partial linking
void partialScanRelocation(Relocation& pReloc,
- Module& pModule,
- const LDSection& pSection);
+ Module& pModule);
- HexagonLDBackend& getTarget()
- { return m_Target; }
+ HexagonLDBackend& getTarget() { return m_Target; }
- const HexagonLDBackend& getTarget() const
- { return m_Target; }
+ const HexagonLDBackend& getTarget() const { return m_Target; }
const char* getName(Relocation::Type pType) const;
Size getSize(Relocation::Type pType) const;
const SymPLTMap& getSymPLTMap() const { return m_SymPLTMap; }
- SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
+ SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
const SymGOTMap& getSymGOTMap() const { return m_SymGOTMap; }
- SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
+ SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
const SymGOTPLTMap& getSymGOTPLTMap() const { return m_SymGOTPLTMap; }
- SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
+ SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
const RelRelMap& getRelRelMap() const { return m_RelRelMap; }
- RelRelMap& getRelRelMap() { return m_RelRelMap; }
+ RelRelMap& getRelRelMap() { return m_RelRelMap; }
-protected:
+ /// getDebugStringOffset - get the offset from the relocation target. This is
+ /// used to get the debug string offset.
+ uint32_t getDebugStringOffset(Relocation& pReloc) const { return 0; }
+
+ /// applyDebugStringOffset - apply the relocation target to specific offset.
+ /// This is used to set the debug string offset.
+ void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset) {}
+
+ protected:
/// addCopyReloc - add a copy relocation into .rela.dyn for pSym
/// @param pSym - A resolved copy symbol that defined in BSS section
void addCopyReloc(ResolveInfo& pSym, HexagonLDBackend& pTarget);
@@ -124,7 +125,7 @@ protected:
const ResolveInfo& pSym,
HexagonLDBackend& pTarget);
-private:
+ private:
virtual void scanLocalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
@@ -142,7 +143,6 @@ private:
RelRelMap m_RelRelMap;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_HEXAGON_HEXAGONRELOCATOR_H_
diff --git a/lib/Target/Hexagon/HexagonTargetMachine.cpp b/lib/Target/Hexagon/HexagonTargetMachine.cpp
deleted file mode 100644
index 33067b9..0000000
--- a/lib/Target/Hexagon/HexagonTargetMachine.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-//===- HexagonTargetMachine.cpp -------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "HexagonTargetMachine.h"
-#include "Hexagon.h"
-#include <mcld/Support/TargetRegistry.h>
-
-extern "C" void MCLDInitializeHexagonLDTarget() {
- // Register createTargetMachine function pointer to mcld::Target
- mcld::RegisterTargetMachine<mcld::HexagonTargetMachine>
- X(mcld::TheHexagonTarget);
-}
-
-using namespace mcld;
-
-//===----------------------------------------------------------------------===//
-// HexagonTargetMachine
-//===----------------------------------------------------------------------===//
-HexagonTargetMachine::HexagonTargetMachine(llvm::TargetMachine& pPM,
- const llvm::Target& pLLVMTarget,
- const mcld::Target& pMCLDTarget,
- const std::string& pTriple)
- : MCLDTargetMachine(pPM, pLLVMTarget, pMCLDTarget, pTriple) {
-}
diff --git a/lib/Target/Hexagon/HexagonTargetMachine.h b/lib/Target/Hexagon/HexagonTargetMachine.h
deleted file mode 100644
index 5ebf434..0000000
--- a/lib/Target/Hexagon/HexagonTargetMachine.h
+++ /dev/null
@@ -1,27 +0,0 @@
-//===- HexagonTargetMachine.h ---------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_HEXAGON_HEXAGONTARGETMACHINE_H
-#define TARGET_HEXAGON_HEXAGONTARGETMACHINE_H
-#include "Hexagon.h"
-#include <mcld/CodeGen/TargetMachine.h>
-
-namespace mcld {
-
-class HexagonTargetMachine : public MCLDTargetMachine
-{
-public:
- HexagonTargetMachine(llvm::TargetMachine &pTM,
- const llvm::Target &pLLVMTarget,
- const mcld::Target &pMCLDTarget,
- const std::string &pTriple);
-};
-
-} // namespace of mcld
-
-#endif
diff --git a/lib/Target/Hexagon/TargetInfo/HexagonTargetInfo.cpp b/lib/Target/Hexagon/TargetInfo/HexagonTargetInfo.cpp
index e0d660b..ef63225 100644
--- a/lib/Target/Hexagon/TargetInfo/HexagonTargetInfo.cpp
+++ b/lib/Target/Hexagon/TargetInfo/HexagonTargetInfo.cpp
@@ -1,4 +1,4 @@
-//===- HexagonTargetInfo.cpp -----------------------------------------------===//
+//===- HexagonTargetInfo.cpp ----------------------------------------------===//
//
// The MCLinker Project
//
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Target.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/Support/Target.h"
+#include "mcld/Support/TargetRegistry.h"
namespace mcld {
@@ -18,5 +18,4 @@ extern "C" void MCLDInitializeHexagonLDTargetInfo() {
mcld::RegisterTarget<llvm::Triple::hexagon> X(TheHexagonTarget, "hexagon");
}
-} // namespace of mcld
-
+} // namespace mcld
diff --git a/lib/Target/Mips/Android.mk b/lib/Target/Mips/Android.mk
index 541f5bb..0bb2d40 100644
--- a/lib/Target/Mips/Android.mk
+++ b/lib/Target/Mips/Android.mk
@@ -3,17 +3,14 @@ LOCAL_PATH:= $(call my-dir)
mcld_mips_target_SRC_FILES := \
MipsDiagnostic.cpp \
MipsELFDynamic.cpp \
- MipsELFMCLinker.cpp \
MipsEmulation.cpp \
MipsGNUInfo.cpp \
MipsGOT.cpp \
MipsGOTPLT.cpp \
MipsLA25Stub.cpp \
MipsLDBackend.cpp \
- MipsMCLinker.cpp \
MipsPLT.cpp \
- MipsRelocator.cpp \
- MipsTargetMachine.cpp
+ MipsRelocator.cpp
# For the host
# =====================================================
diff --git a/lib/Target/Mips/Mips.h b/lib/Target/Mips/Mips.h
index c3fe7a2..9841655 100644
--- a/lib/Target/Mips/Mips.h
+++ b/lib/Target/Mips/Mips.h
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPS_H
-#define TARGET_MIPS_MIPS_H
+#ifndef TARGET_MIPS_MIPS_H_
+#define TARGET_MIPS_MIPS_H_
namespace mcld {
@@ -16,6 +16,6 @@ class Target;
extern Target TheMipselTarget;
extern Target TheMips64elTarget;
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPS_H_
diff --git a/lib/Target/Mips/MipsDiagnostic.cpp b/lib/Target/Mips/MipsDiagnostic.cpp
index e03ea3c..e4534f8 100644
--- a/lib/Target/Mips/MipsDiagnostic.cpp
+++ b/lib/Target/Mips/MipsDiagnostic.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/DWARFLineInfo.h>
+#include "mcld/LD/DWARFLineInfo.h"
+#include "mcld/Support/TargetRegistry.h"
#include "Mips.h"
namespace {
@@ -17,12 +17,11 @@ namespace {
// MipsDiagnostic
//===----------------------------------------------------------------------===//
mcld::DiagnosticLineInfo* createMipsDiagLineInfo(const mcld::Target& pTarget,
- const std::string &pTriple)
-{
+ const std::string& pTriple) {
return new mcld::DWARFLineInfo();
}
-} // namespace of mcld
+} // anonymous namespace
//===----------------------------------------------------------------------===//
// InitializeMipsDiagnostic
diff --git a/lib/Target/Mips/MipsELFDynamic.cpp b/lib/Target/Mips/MipsELFDynamic.cpp
index b532b03..c732f36 100644
--- a/lib/Target/Mips/MipsELFDynamic.cpp
+++ b/lib/Target/Mips/MipsELFDynamic.cpp
@@ -6,27 +6,24 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <llvm/Support/ELF.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/Target/GNULDBackend.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/Target/GNULDBackend.h"
#include "MipsELFDynamic.h"
#include "MipsLDBackend.h"
-using namespace mcld;
+#include <llvm/Support/ELF.h>
+
+namespace mcld {
MipsELFDynamic::MipsELFDynamic(const MipsGNULDBackend& pParent,
const LinkerConfig& pConfig)
- : ELFDynamic(pParent, pConfig),
- m_pParent(pParent),
- m_pConfig(pConfig)
-{
+ : ELFDynamic(pParent, pConfig), m_pParent(pParent), m_pConfig(pConfig) {
}
-void MipsELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat)
-{
+void MipsELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat) {
if (pFormat.hasGOT())
reserveOne(llvm::ELF::DT_PLTGOT);
@@ -41,8 +38,7 @@ void MipsELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat)
reserveOne(llvm::ELF::DT_MIPS_PLTGOT);
}
-void MipsELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat)
-{
+void MipsELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat) {
if (pFormat.hasGOT())
applyOne(llvm::ELF::DT_PLTGOT, pFormat.getGOT().addr());
@@ -57,8 +53,7 @@ void MipsELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat)
applyOne(llvm::ELF::DT_MIPS_PLTGOT, pFormat.getGOTPLT().addr());
}
-size_t MipsELFDynamic::getSymTabNum(const ELFFileFormat& pFormat) const
-{
+size_t MipsELFDynamic::getSymTabNum(const ELFFileFormat& pFormat) const {
if (!pFormat.hasDynSymTab())
return 0;
@@ -66,29 +61,28 @@ size_t MipsELFDynamic::getSymTabNum(const ELFFileFormat& pFormat) const
return dynsym.size() / symbolSize();
}
-size_t MipsELFDynamic::getGotSym(const ELFFileFormat& pFormat) const
-{
+size_t MipsELFDynamic::getGotSym(const ELFFileFormat& pFormat) const {
if (!pFormat.hasGOT())
return 0;
return getSymTabNum(pFormat) - m_pParent.getGOT().getGlobalNum();
}
-size_t MipsELFDynamic::getLocalGotNum(const ELFFileFormat& pFormat) const
-{
+size_t MipsELFDynamic::getLocalGotNum(const ELFFileFormat& pFormat) const {
if (!pFormat.hasGOT())
return 0;
return m_pParent.getGOT().getLocalNum();
}
-uint64_t MipsELFDynamic::getBaseAddress()
-{
+uint64_t MipsELFDynamic::getBaseAddress() {
if (LinkerConfig::Exec != m_pConfig.codeGenType())
return 0;
ELFSegmentFactory::const_iterator baseSeg =
- m_pParent.elfSegmentTable().find(llvm::ELF::PT_LOAD, 0x0, 0x0);
+ m_pParent.elfSegmentTable().find(llvm::ELF::PT_LOAD, 0x0, 0x0);
return m_pParent.elfSegmentTable().end() == baseSeg ? 0 : (*baseSeg)->vaddr();
}
+
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsELFDynamic.h b/lib/Target/Mips/MipsELFDynamic.h
index ff0666e..f51d6bc 100644
--- a/lib/Target/Mips/MipsELFDynamic.h
+++ b/lib/Target/Mips/MipsELFDynamic.h
@@ -6,25 +6,24 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSELFDYNAMIC_H
-#define TARGET_MIPS_MIPSELFDYNAMIC_H
+#ifndef TARGET_MIPS_MIPSELFDYNAMIC_H_
+#define TARGET_MIPS_MIPSELFDYNAMIC_H_
-#include <mcld/Target/ELFDynamic.h>
+#include "mcld/Target/ELFDynamic.h"
namespace mcld {
class MipsGNULDBackend;
-class MipsELFDynamic : public ELFDynamic
-{
-public:
+class MipsELFDynamic : public ELFDynamic {
+ public:
MipsELFDynamic(const MipsGNULDBackend& pParent, const LinkerConfig& pConfig);
-private:
+ private:
const MipsGNULDBackend& m_pParent;
const LinkerConfig& m_pConfig;
-private:
+ private:
void reserveTargetEntries(const ELFFileFormat& pFormat);
void applyTargetEntries(const ELFFileFormat& pFormat);
@@ -34,6 +33,6 @@ private:
uint64_t getBaseAddress();
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSELFDYNAMIC_H_
diff --git a/lib/Target/Mips/MipsELFMCLinker.cpp b/lib/Target/Mips/MipsELFMCLinker.cpp
deleted file mode 100644
index 077177a..0000000
--- a/lib/Target/Mips/MipsELFMCLinker.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-//===- MipsELFMCLinker.cpp ------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "MipsELFMCLinker.h"
-
-using namespace mcld;
-
-MipsELFMCLinker::MipsELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
- : ELFMCLinker(pConfig, pModule, pFileHandle) {
-}
-
-MipsELFMCLinker::~MipsELFMCLinker()
-{
-}
-
diff --git a/lib/Target/Mips/MipsELFMCLinker.h b/lib/Target/Mips/MipsELFMCLinker.h
deleted file mode 100644
index c0a2dfa..0000000
--- a/lib/Target/Mips/MipsELFMCLinker.h
+++ /dev/null
@@ -1,34 +0,0 @@
-//===- MipsELFMCLinker.h --------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSELFMCLINKER_H
-#define TARGET_MIPS_MIPSELFMCLINKER_H
-#include <mcld/Target/ELFMCLinker.h>
-
-namespace mcld {
-
-class Module;
-class FileHandle;
-
-/** \class MipsELFMCLinker
- * \brief MipsELFMCLinker sets up the environment for linking.
- */
-class MipsELFMCLinker : public ELFMCLinker
-{
-public:
- MipsELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle);
-
- ~MipsELFMCLinker();
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/lib/Target/Mips/MipsEmulation.cpp b/lib/Target/Mips/MipsEmulation.cpp
index 5e5d192..416e3d7 100644
--- a/lib/Target/Mips/MipsEmulation.cpp
+++ b/lib/Target/Mips/MipsEmulation.cpp
@@ -7,15 +7,14 @@
//
//===----------------------------------------------------------------------===//
#include "Mips.h"
-#include <mcld/LinkerScript.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Target/ELFEmulation.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/LinkerScript.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/ELFEmulation.h"
namespace mcld {
-static bool MCLDEmulateMipsELF(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+static bool MCLDEmulateMipsELF(LinkerScript& pScript, LinkerConfig& pConfig) {
if (!MCLDEmulateELF(pScript, pConfig))
return false;
@@ -42,8 +41,7 @@ static bool MCLDEmulateMipsELF(LinkerScript& pScript, LinkerConfig& pConfig)
//===----------------------------------------------------------------------===//
// emulateMipsLD - the help function to emulate Mips ld
//===----------------------------------------------------------------------===//
-bool emulateMipsLD(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+bool emulateMipsLD(LinkerScript& pScript, LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker has not supported yet");
return false;
@@ -56,7 +54,7 @@ bool emulateMipsLD(LinkerScript& pScript, LinkerConfig& pConfig)
return MCLDEmulateMipsELF(pScript, pConfig);
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// MipsEmulation
diff --git a/lib/Target/Mips/MipsGNUInfo.cpp b/lib/Target/Mips/MipsGNUInfo.cpp
index 521a800..132e9c3 100644
--- a/lib/Target/Mips/MipsGNUInfo.cpp
+++ b/lib/Target/Mips/MipsGNUInfo.cpp
@@ -14,41 +14,33 @@ namespace mcld {
// MipsGNUInfo
//===----------------------------------------------------------------------===//
MipsGNUInfo::MipsGNUInfo(const llvm::Triple& pTriple)
- : GNUInfo(pTriple),
- m_ABIVersion(0),
- m_PICFlags(0)
-{}
+ : GNUInfo(pTriple), m_ABIVersion(0), m_PICFlags(0) {
+}
-void MipsGNUInfo::setABIVersion(uint8_t ver)
-{
+void MipsGNUInfo::setABIVersion(uint8_t ver) {
m_ABIVersion = ver;
}
-void MipsGNUInfo::setPICFlags(uint64_t flags)
-{
+void MipsGNUInfo::setPICFlags(uint64_t flags) {
m_PICFlags = flags;
}
-uint32_t MipsGNUInfo::machine() const
-{
+uint32_t MipsGNUInfo::machine() const {
return llvm::ELF::EM_MIPS;
}
-uint8_t MipsGNUInfo::ABIVersion() const
-{
+uint8_t MipsGNUInfo::ABIVersion() const {
return m_ABIVersion;
}
-uint64_t MipsGNUInfo::defaultTextSegmentAddr() const
-{
+uint64_t MipsGNUInfo::defaultTextSegmentAddr() const {
if (m_Triple.isArch32Bit())
return 0x400000;
else
return 0x120000000ull;
}
-uint64_t MipsGNUInfo::flags() const
-{
+uint64_t MipsGNUInfo::flags() const {
uint64_t val = llvm::ELF::EF_MIPS_NOREORDER | m_PICFlags;
if (m_Triple.isArch32Bit())
@@ -59,19 +51,16 @@ uint64_t MipsGNUInfo::flags() const
return val;
}
-const char* MipsGNUInfo::entry() const
-{
+const char* MipsGNUInfo::entry() const {
return "__start";
}
-const char* MipsGNUInfo::dyld() const
-{
+const char* MipsGNUInfo::dyld() const {
return m_Triple.isArch32Bit() ? "/lib/ld.so.1" : "/lib64/ld.so.1";
}
-uint64_t MipsGNUInfo::abiPageSize() const
-{
+uint64_t MipsGNUInfo::abiPageSize() const {
return 0x10000;
}
-} // end mcld namespace
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsGNUInfo.h b/lib/Target/Mips/MipsGNUInfo.h
index 8b5d9b6..673c39a 100644
--- a/lib/Target/Mips/MipsGNUInfo.h
+++ b/lib/Target/Mips/MipsGNUInfo.h
@@ -6,17 +6,16 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSGNUINFO_H
-#define TARGET_MIPS_MIPSGNUINFO_H
-#include <llvm/Support/ELF.h>
-#include <mcld/Target/GNUInfo.h>
+#ifndef TARGET_MIPS_MIPSGNUINFO_H_
+#define TARGET_MIPS_MIPSGNUINFO_H_
+#include "mcld/Target/GNUInfo.h"
+#include <llvm/Support/ELF.h>
namespace mcld {
-class MipsGNUInfo : public GNUInfo
-{
-public:
- MipsGNUInfo(const llvm::Triple& pTriple);
+class MipsGNUInfo : public GNUInfo {
+ public:
+ explicit MipsGNUInfo(const llvm::Triple& pTriple);
void setABIVersion(uint8_t ver);
void setPICFlags(uint64_t flags);
@@ -30,11 +29,11 @@ public:
const char* dyld() const;
uint64_t abiPageSize() const;
-private:
+ private:
uint8_t m_ABIVersion;
uint64_t m_PICFlags;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSGNUINFO_H_
diff --git a/lib/Target/Mips/MipsGOT.cpp b/lib/Target/Mips/MipsGOT.cpp
index dddf12b..85d89c7 100644
--- a/lib/Target/Mips/MipsGOT.cpp
+++ b/lib/Target/Mips/MipsGOT.cpp
@@ -7,55 +7,49 @@
//
//===----------------------------------------------------------------------===//
-#include <llvm/Support/Casting.h>
-#include <llvm/Support/ELF.h>
-
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Target/OutputRelocSection.h>
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/OutputRelocSection.h"
#include "MipsGOT.h"
#include "MipsRelocator.h"
+#include <llvm/Support/Casting.h>
+#include <llvm/Support/ELF.h>
+
namespace {
- const uint32_t Mips32ModulePtr = 1 << 31;
- const uint64_t Mips64ModulePtr = 1ull << 63;
- const size_t MipsGOT0Num = 2;
- const size_t MipsGOTGpOffset = 0x7FF0;
- const size_t MipsGOTSize = MipsGOTGpOffset + 0x7FFF;
+const uint32_t Mips32ModulePtr = 1 << 31;
+const uint64_t Mips64ModulePtr = 1ull << 63;
+const size_t MipsGOT0Num = 2;
+const size_t MipsGOTGpOffset = 0x7FF0;
+const size_t MipsGOTSize = MipsGOTGpOffset + 0x7FFF;
}
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// MipsGOT::GOTMultipart
//===----------------------------------------------------------------------===//
MipsGOT::GOTMultipart::GOTMultipart(size_t local, size_t global)
- : m_LocalNum(local),
- m_GlobalNum(global),
- m_ConsumedLocal(0),
- m_ConsumedGlobal(0),
- m_pLastLocal(NULL),
- m_pLastGlobal(NULL)
-{
+ : m_LocalNum(local),
+ m_GlobalNum(global),
+ m_ConsumedLocal(0),
+ m_ConsumedGlobal(0),
+ m_pLastLocal(NULL),
+ m_pLastGlobal(NULL) {
}
-bool MipsGOT::GOTMultipart::isConsumed() const
-{
- return m_LocalNum == m_ConsumedLocal &&
- m_GlobalNum == m_ConsumedGlobal;
+bool MipsGOT::GOTMultipart::isConsumed() const {
+ return m_LocalNum == m_ConsumedLocal && m_GlobalNum == m_ConsumedGlobal;
}
-void MipsGOT::GOTMultipart::consumeLocal()
-{
- assert(m_ConsumedLocal < m_LocalNum &&
- "Consumed too many local GOT entries");
+void MipsGOT::GOTMultipart::consumeLocal() {
+ assert(m_ConsumedLocal < m_LocalNum && "Consumed too many local GOT entries");
++m_ConsumedLocal;
m_pLastLocal = m_pLastLocal->getNextNode();
}
-void MipsGOT::GOTMultipart::consumeGlobal()
-{
+void MipsGOT::GOTMultipart::consumeGlobal() {
assert(m_ConsumedGlobal < m_GlobalNum &&
"Consumed too many global GOT entries");
++m_ConsumedGlobal;
@@ -66,15 +60,12 @@ void MipsGOT::GOTMultipart::consumeGlobal()
// MipsGOT::LocalEntry
//===----------------------------------------------------------------------===//
MipsGOT::LocalEntry::LocalEntry(const ResolveInfo* pInfo,
- Relocation::DWord addend, bool isGot16)
- : m_pInfo(pInfo),
- m_Addend(addend),
- m_IsGot16(isGot16)
-{
+ Relocation::DWord addend,
+ bool isGot16)
+ : m_pInfo(pInfo), m_Addend(addend), m_IsGot16(isGot16) {
}
-bool MipsGOT::LocalEntry::operator<(const LocalEntry &O) const
-{
+bool MipsGOT::LocalEntry::operator<(const LocalEntry& O) const {
if (m_pInfo != O.m_pInfo)
return m_pInfo < O.m_pInfo;
@@ -88,49 +79,42 @@ bool MipsGOT::LocalEntry::operator<(const LocalEntry &O) const
// MipsGOT
//===----------------------------------------------------------------------===//
MipsGOT::MipsGOT(LDSection& pSection)
- : GOT(pSection),
- m_pInput(NULL),
- m_CurrentGOTPart(0)
-{
+ : GOT(pSection), m_pInput(NULL), m_CurrentGOTPart(0) {
}
-uint64_t MipsGOT::getGPDispAddress() const
-{
+uint64_t MipsGOT::getGPDispAddress() const {
return addr() + MipsGOTGpOffset;
}
-void MipsGOT::reserve(size_t pNum)
-{
- for (size_t i = 0; i < pNum; i++)
+void MipsGOT::reserve(size_t pNum) {
+ for (size_t i = 0; i < pNum; ++i)
createEntry(0, m_SectionData);
}
-bool MipsGOT::hasGOT1() const
-{
+bool MipsGOT::hasGOT1() const {
return !m_MultipartList.empty();
}
-bool MipsGOT::hasMultipleGOT() const
-{
+bool MipsGOT::hasMultipleGOT() const {
return m_MultipartList.size() > 1;
}
-void MipsGOT::finalizeScanning(OutputRelocSection& pRelDyn)
-{
+void MipsGOT::finalizeScanning(OutputRelocSection& pRelDyn) {
for (MultipartListType::iterator it = m_MultipartList.begin();
- it != m_MultipartList.end(); ++it) {
+ it != m_MultipartList.end();
+ ++it) {
reserveHeader();
it->m_pLastLocal = &m_SectionData->back();
reserve(it->m_LocalNum);
it->m_pLastGlobal = &m_SectionData->back();
reserve(it->m_GlobalNum);
- if (it == m_MultipartList.begin())
+ if (it == m_MultipartList.begin()) {
// Reserve entries in the second part of the primary GOT.
// These entries correspond to the global symbols in all
// non-primary GOTs.
reserve(getGlobalNum() - it->m_GlobalNum);
- else {
+ } else {
// Reserve reldyn entries for R_MIPS_REL32 relocations
// for all global entries of secondary GOTs.
// FIXME: (simon) Do not count local entries for non-pic.
@@ -141,8 +125,7 @@ void MipsGOT::finalizeScanning(OutputRelocSection& pRelDyn)
}
}
-bool MipsGOT::dynSymOrderCompare(const LDSymbol* pX, const LDSymbol* pY) const
-{
+bool MipsGOT::dynSymOrderCompare(const LDSymbol* pX, const LDSymbol* pY) const {
SymbolOrderMapType::const_iterator itX = m_SymbolOrderMap.find(pX);
SymbolOrderMapType::const_iterator itY = m_SymbolOrderMap.find(pY);
@@ -152,8 +135,7 @@ bool MipsGOT::dynSymOrderCompare(const LDSymbol* pX, const LDSymbol* pY) const
return itX == m_SymbolOrderMap.end() && itY != m_SymbolOrderMap.end();
}
-void MipsGOT::initGOTList()
-{
+void MipsGOT::initGOTList() {
m_SymbolOrderMap.clear();
m_MultipartList.clear();
@@ -167,29 +149,28 @@ void MipsGOT::initGOTList()
m_InputLocalSymbols.clear();
}
-void MipsGOT::changeInput()
-{
+void MipsGOT::changeInput() {
m_MultipartList.back().m_Inputs.insert(m_pInput);
for (LocalSymbolSetType::iterator it = m_InputLocalSymbols.begin(),
end = m_InputLocalSymbols.end();
- it != end; ++it)
+ it != end;
+ ++it)
m_MergedLocalSymbols.insert(*it);
m_InputLocalSymbols.clear();
for (SymbolUniqueMapType::iterator it = m_InputGlobalSymbols.begin(),
end = m_InputGlobalSymbols.end();
- it != end; ++it)
+ it != end;
+ ++it)
m_MergedGlobalSymbols.insert(it->first);
m_InputGlobalSymbols.clear();
}
-bool MipsGOT::isGOTFull() const
-{
- uint64_t gotCount = MipsGOT0Num +
- m_MultipartList.back().m_LocalNum +
+bool MipsGOT::isGOTFull() const {
+ uint64_t gotCount = MipsGOT0Num + m_MultipartList.back().m_LocalNum +
m_MultipartList.back().m_GlobalNum;
gotCount += 1;
@@ -197,15 +178,15 @@ bool MipsGOT::isGOTFull() const
return gotCount * getEntrySize() > MipsGOTSize;
}
-void MipsGOT::split()
-{
+void MipsGOT::split() {
m_MergedLocalSymbols.clear();
m_MergedGlobalSymbols.clear();
size_t uniqueCount = 0;
for (SymbolUniqueMapType::const_iterator it = m_InputGlobalSymbols.begin(),
end = m_InputGlobalSymbols.end();
- it != end; ++it) {
+ it != end;
+ ++it) {
if (it->second)
++uniqueCount;
}
@@ -214,30 +195,27 @@ void MipsGOT::split()
m_MultipartList.back().m_GlobalNum -= uniqueCount;
m_MultipartList.back().m_Inputs.erase(m_pInput);
- m_MultipartList.push_back(GOTMultipart(m_InputLocalSymbols.size(),
- m_InputGlobalSymbols.size()));
+ m_MultipartList.push_back(
+ GOTMultipart(m_InputLocalSymbols.size(), m_InputGlobalSymbols.size()));
m_MultipartList.back().m_Inputs.insert(m_pInput);
}
-void MipsGOT::initializeScan(const Input& pInput)
-{
+void MipsGOT::initializeScan(const Input& pInput) {
if (m_pInput == NULL) {
m_pInput = &pInput;
initGOTList();
- }
- else {
+ } else {
m_pInput = &pInput;
changeInput();
}
}
-void MipsGOT::finalizeScan(const Input& pInput)
-{
+void MipsGOT::finalizeScan(const Input& pInput) {
}
-bool MipsGOT::reserveLocalEntry(ResolveInfo& pInfo, int reloc,
- Relocation::DWord pAddend)
-{
+bool MipsGOT::reserveLocalEntry(ResolveInfo& pInfo,
+ int reloc,
+ Relocation::DWord pAddend) {
LocalEntry entry(&pInfo, pAddend, reloc == llvm::ELF::R_MIPS_GOT16);
if (m_InputLocalSymbols.count(entry))
@@ -261,8 +239,7 @@ bool MipsGOT::reserveLocalEntry(ResolveInfo& pInfo, int reloc,
return true;
}
-bool MipsGOT::reserveGlobalEntry(ResolveInfo& pInfo)
-{
+bool MipsGOT::reserveGlobalEntry(ResolveInfo& pInfo) {
if (m_InputGlobalSymbols.count(&pInfo))
return false;
@@ -285,14 +262,13 @@ bool MipsGOT::reserveGlobalEntry(ResolveInfo& pInfo)
return true;
}
-bool MipsGOT::isPrimaryGOTConsumed()
-{
+bool MipsGOT::isPrimaryGOTConsumed() {
return m_CurrentGOTPart > 0;
}
-Fragment* MipsGOT::consumeLocal()
-{
- assert(m_CurrentGOTPart < m_MultipartList.size() && "GOT number is out of range!");
+Fragment* MipsGOT::consumeLocal() {
+ assert(m_CurrentGOTPart < m_MultipartList.size() &&
+ "GOT number is out of range!");
if (m_MultipartList[m_CurrentGOTPart].isConsumed())
++m_CurrentGOTPart;
@@ -302,9 +278,9 @@ Fragment* MipsGOT::consumeLocal()
return m_MultipartList[m_CurrentGOTPart].m_pLastLocal;
}
-Fragment* MipsGOT::consumeGlobal()
-{
- assert(m_CurrentGOTPart < m_MultipartList.size() && "GOT number is out of range!");
+Fragment* MipsGOT::consumeGlobal() {
+ assert(m_CurrentGOTPart < m_MultipartList.size() &&
+ "GOT number is out of range!");
if (m_MultipartList[m_CurrentGOTPart].isConsumed())
++m_CurrentGOTPart;
@@ -314,11 +290,12 @@ Fragment* MipsGOT::consumeGlobal()
return m_MultipartList[m_CurrentGOTPart].m_pLastGlobal;
}
-uint64_t MipsGOT::getGPAddr(const Input& pInput) const
-{
+uint64_t MipsGOT::getGPAddr(const Input& pInput) const {
uint64_t gotSize = 0;
- for (MultipartListType::const_iterator it = m_MultipartList.begin();
- it != m_MultipartList.end(); ++it) {
+ for (MultipartListType::const_iterator it = m_MultipartList.begin(),
+ ie = m_MultipartList.end();
+ it != ie;
+ ++it) {
if (it->m_Inputs.count(&pInput))
break;
@@ -331,13 +308,11 @@ uint64_t MipsGOT::getGPAddr(const Input& pInput) const
}
uint64_t MipsGOT::getGPRelOffset(const Input& pInput,
- const Fragment& pEntry) const
-{
+ const Fragment& pEntry) const {
return addr() + pEntry.getOffset() - getGPAddr(pInput);
}
-void MipsGOT::recordGlobalEntry(const ResolveInfo* pInfo, Fragment* pEntry)
-{
+void MipsGOT::recordGlobalEntry(const ResolveInfo* pInfo, Fragment* pEntry) {
GotEntryKey key;
key.m_GOTPage = m_CurrentGOTPart;
key.m_pInfo = pInfo;
@@ -345,10 +320,9 @@ void MipsGOT::recordGlobalEntry(const ResolveInfo* pInfo, Fragment* pEntry)
m_GotGlobalEntriesMap[key] = pEntry;
}
-Fragment* MipsGOT::lookupGlobalEntry(const ResolveInfo* pInfo)
-{
+Fragment* MipsGOT::lookupGlobalEntry(const ResolveInfo* pInfo) {
GotEntryKey key;
- key.m_GOTPage= m_CurrentGOTPart;
+ key.m_GOTPage = m_CurrentGOTPart;
key.m_pInfo = pInfo;
key.m_Addend = 0;
GotEntryMapType::iterator it = m_GotGlobalEntriesMap.find(key);
@@ -361,8 +335,7 @@ Fragment* MipsGOT::lookupGlobalEntry(const ResolveInfo* pInfo)
void MipsGOT::recordLocalEntry(const ResolveInfo* pInfo,
Relocation::DWord pAddend,
- Fragment* pEntry)
-{
+ Fragment* pEntry) {
GotEntryKey key;
key.m_GOTPage = m_CurrentGOTPart;
key.m_pInfo = pInfo;
@@ -371,10 +344,9 @@ void MipsGOT::recordLocalEntry(const ResolveInfo* pInfo,
}
Fragment* MipsGOT::lookupLocalEntry(const ResolveInfo* pInfo,
- Relocation::DWord pAddend)
-{
+ Relocation::DWord pAddend) {
GotEntryKey key;
- key.m_GOTPage= m_CurrentGOTPart;
+ key.m_GOTPage = m_CurrentGOTPart;
key.m_pInfo = pInfo;
key.m_Addend = pAddend;
GotEntryMapType::iterator it = m_GotLocalEntriesMap.find(key);
@@ -385,31 +357,26 @@ Fragment* MipsGOT::lookupLocalEntry(const ResolveInfo* pInfo,
return it->second;
}
-size_t MipsGOT::getLocalNum() const
-{
+size_t MipsGOT::getLocalNum() const {
assert(!m_MultipartList.empty() && "GOT is empty!");
return m_MultipartList[0].m_LocalNum + MipsGOT0Num;
}
-size_t MipsGOT::getGlobalNum() const
-{
+size_t MipsGOT::getGlobalNum() const {
return m_SymbolOrderMap.size();
}
//===----------------------------------------------------------------------===//
// Mips32GOT
//===----------------------------------------------------------------------===//
-Mips32GOT::Mips32GOT(LDSection& pSection)
- : MipsGOT(pSection)
-{}
+Mips32GOT::Mips32GOT(LDSection& pSection) : MipsGOT(pSection) {
+}
-void Mips32GOT::setEntryValue(Fragment* entry, uint64_t pValue)
-{
+void Mips32GOT::setEntryValue(Fragment* entry, uint64_t pValue) {
llvm::cast<Mips32GOTEntry>(entry)->setValue(pValue);
}
-uint64_t Mips32GOT::emit(MemoryRegion& pRegion)
-{
+uint64_t Mips32GOT::emit(MemoryRegion& pRegion) {
uint32_t* buffer = reinterpret_cast<uint32_t*>(pRegion.begin());
uint64_t result = 0;
@@ -421,18 +388,15 @@ uint64_t Mips32GOT::emit(MemoryRegion& pRegion)
return result;
}
-Fragment* Mips32GOT::createEntry(uint64_t pValue, SectionData* pParent)
-{
+Fragment* Mips32GOT::createEntry(uint64_t pValue, SectionData* pParent) {
return new Mips32GOTEntry(pValue, pParent);
}
-size_t Mips32GOT::getEntrySize() const
-{
+size_t Mips32GOT::getEntrySize() const {
return Mips32GOTEntry::EntrySize;
}
-void Mips32GOT::reserveHeader()
-{
+void Mips32GOT::reserveHeader() {
createEntry(0, m_SectionData);
createEntry(Mips32ModulePtr, m_SectionData);
}
@@ -440,17 +404,14 @@ void Mips32GOT::reserveHeader()
//===----------------------------------------------------------------------===//
// Mips64GOT
//===----------------------------------------------------------------------===//
-Mips64GOT::Mips64GOT(LDSection& pSection)
- : MipsGOT(pSection)
-{}
+Mips64GOT::Mips64GOT(LDSection& pSection) : MipsGOT(pSection) {
+}
-void Mips64GOT::setEntryValue(Fragment* entry, uint64_t pValue)
-{
+void Mips64GOT::setEntryValue(Fragment* entry, uint64_t pValue) {
llvm::cast<Mips64GOTEntry>(entry)->setValue(pValue);
}
-uint64_t Mips64GOT::emit(MemoryRegion& pRegion)
-{
+uint64_t Mips64GOT::emit(MemoryRegion& pRegion) {
uint64_t* buffer = reinterpret_cast<uint64_t*>(pRegion.begin());
uint64_t result = 0;
@@ -462,18 +423,17 @@ uint64_t Mips64GOT::emit(MemoryRegion& pRegion)
return result;
}
-Fragment* Mips64GOT::createEntry(uint64_t pValue, SectionData* pParent)
-{
+Fragment* Mips64GOT::createEntry(uint64_t pValue, SectionData* pParent) {
return new Mips64GOTEntry(pValue, pParent);
}
-size_t Mips64GOT::getEntrySize() const
-{
+size_t Mips64GOT::getEntrySize() const {
return Mips64GOTEntry::EntrySize;
}
-void Mips64GOT::reserveHeader()
-{
+void Mips64GOT::reserveHeader() {
createEntry(0, m_SectionData);
createEntry(Mips64ModulePtr, m_SectionData);
}
+
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsGOT.h b/lib/Target/Mips/MipsGOT.h
index f5b213c..409347b 100644
--- a/lib/Target/Mips/MipsGOT.h
+++ b/lib/Target/Mips/MipsGOT.h
@@ -6,19 +6,19 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSGOT_H
-#define TARGET_MIPS_MIPSGOT_H
-#include <map>
-#include <vector>
+#ifndef TARGET_MIPS_MIPSGOT_H_
+#define TARGET_MIPS_MIPSGOT_H_
+#include "mcld/ADT/SizeTraits.h"
+#include "mcld/Fragment/Relocation.h"
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Target/GOT.h"
-
-#include <mcld/ADT/SizeTraits.h>
-#include <mcld/Target/GOT.h>
-#include <mcld/Fragment/Relocation.h>
-#include <mcld/Support/MemoryRegion.h>
#include <llvm/ADT/DenseMap.h>
#include <llvm/ADT/DenseSet.h>
+
+#include <map>
#include <set>
+#include <vector>
namespace mcld {
@@ -30,10 +30,9 @@ class OutputRelocSection;
/** \class MipsGOT
* \brief Mips Global Offset Table.
*/
-class MipsGOT : public GOT
-{
-public:
- MipsGOT(LDSection& pSection);
+class MipsGOT : public GOT {
+ public:
+ explicit MipsGOT(LDSection& pSection);
/// Assign value to the GOT entry.
virtual void setEntryValue(Fragment* entry, uint64_t pValue) = 0;
@@ -47,7 +46,8 @@ public:
void initializeScan(const Input& pInput);
void finalizeScan(const Input& pInput);
- bool reserveLocalEntry(ResolveInfo& pInfo, int reloc,
+ bool reserveLocalEntry(ResolveInfo& pInfo,
+ int reloc,
Relocation::DWord pAddend);
bool reserveGlobalEntry(ResolveInfo& pInfo);
@@ -82,7 +82,7 @@ public:
/// Compare two symbols to define order in the .dynsym.
bool dynSymOrderCompare(const LDSymbol* pX, const LDSymbol* pY) const;
-protected:
+ protected:
/// Create GOT entry.
virtual Fragment* createEntry(uint64_t pValue, SectionData* pParent) = 0;
@@ -92,21 +92,20 @@ protected:
/// Reserve GOT header entries.
virtual void reserveHeader() = 0;
-private:
+ private:
/** \class GOTMultipart
* \brief GOTMultipart counts local and global entries in the GOT.
*/
- struct GOTMultipart
- {
- GOTMultipart(size_t local = 0, size_t global = 0);
+ struct GOTMultipart {
+ explicit GOTMultipart(size_t local = 0, size_t global = 0);
typedef llvm::DenseSet<const Input*> InputSetType;
- size_t m_LocalNum; ///< number of reserved local entries
- size_t m_GlobalNum; ///< number of reserved global entries
+ size_t m_LocalNum; ///< number of reserved local entries
+ size_t m_GlobalNum; ///< number of reserved global entries
- size_t m_ConsumedLocal; ///< consumed local entries
- size_t m_ConsumedGlobal; ///< consumed global entries
+ size_t m_ConsumedLocal; ///< consumed local entries
+ size_t m_ConsumedGlobal; ///< consumed global entries
Fragment* m_pLastLocal; ///< the last consumed local entry
Fragment* m_pLastGlobal; ///< the last consumed global entry
@@ -122,16 +121,16 @@ private:
/** \class LocalEntry
* \brief LocalEntry local GOT entry descriptor.
*/
- struct LocalEntry
- {
+ struct LocalEntry {
const ResolveInfo* m_pInfo;
- Relocation::DWord m_Addend;
- bool m_IsGot16;
+ Relocation::DWord m_Addend;
+ bool m_IsGot16;
LocalEntry(const ResolveInfo* pInfo,
- Relocation::DWord addend, bool isGot16);
+ Relocation::DWord addend,
+ bool isGot16);
- bool operator<(const LocalEntry &O) const;
+ bool operator<(const LocalEntry& O) const;
};
typedef std::vector<GOTMultipart> MultipartListType;
@@ -172,15 +171,13 @@ private:
void split();
void reserve(size_t pNum);
-private:
- struct GotEntryKey
- {
+ private:
+ struct GotEntryKey {
size_t m_GOTPage;
const ResolveInfo* m_pInfo;
Relocation::DWord m_Addend;
- bool operator<(const GotEntryKey& key) const
- {
+ bool operator<(const GotEntryKey& key) const {
if (m_GOTPage != key.m_GOTPage)
return m_GOTPage < key.m_GOTPage;
@@ -199,12 +196,11 @@ private:
/** \class Mips32GOT
* \brief Mips 32-bit Global Offset Table.
*/
-class Mips32GOT : public MipsGOT
-{
-public:
- Mips32GOT(LDSection& pSection);
+class Mips32GOT : public MipsGOT {
+ public:
+ explicit Mips32GOT(LDSection& pSection);
-private:
+ private:
typedef GOT::Entry<4> Mips32GOTEntry;
// MipsGOT
@@ -218,12 +214,11 @@ private:
/** \class Mips64GOT
* \brief Mips 64-bit Global Offset Table.
*/
-class Mips64GOT : public MipsGOT
-{
-public:
- Mips64GOT(LDSection& pSection);
+class Mips64GOT : public MipsGOT {
+ public:
+ explicit Mips64GOT(LDSection& pSection);
-private:
+ private:
typedef GOT::Entry<8> Mips64GOTEntry;
// MipsGOT
@@ -234,7 +229,6 @@ private:
virtual void reserveHeader();
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_MIPS_MIPSGOT_H_
diff --git a/lib/Target/Mips/MipsGOTPLT.cpp b/lib/Target/Mips/MipsGOTPLT.cpp
index 1f65490..745b258 100644
--- a/lib/Target/Mips/MipsGOTPLT.cpp
+++ b/lib/Target/Mips/MipsGOTPLT.cpp
@@ -6,13 +6,14 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <llvm/Support/Casting.h>
#include "MipsGOTPLT.h"
+#include <llvm/Support/Casting.h>
+
namespace {
- typedef mcld::GOT::Entry<4> GOTPLTEntry;
+typedef mcld::GOT::Entry<4> GOTPLTEntry;
- const size_t MipsGOTPLT0Num = 2;
+const size_t MipsGOTPLT0Num = 2;
}
namespace mcld {
@@ -20,23 +21,19 @@ namespace mcld {
//===----------------------------------------------------------------------===//
// MipsGOTPLT
//===----------------------------------------------------------------------===//
-MipsGOTPLT::MipsGOTPLT(LDSection& pSection)
- : GOT(pSection)
-{
+MipsGOTPLT::MipsGOTPLT(LDSection& pSection) : GOT(pSection) {
// Create header's entries.
new GOTPLTEntry(0, m_SectionData);
new GOTPLTEntry(0, m_SectionData);
m_Last = ++m_SectionData->begin();
}
-void MipsGOTPLT::reserve(size_t pNum)
-{
- for (size_t i = 0; i < pNum; i++)
+void MipsGOTPLT::reserve(size_t pNum) {
+ for (size_t i = 0; i < pNum; ++i)
new GOTPLTEntry(0, m_SectionData);
}
-uint64_t MipsGOTPLT::emit(MemoryRegion& pRegion)
-{
+uint64_t MipsGOTPLT::emit(MemoryRegion& pRegion) {
uint32_t* buffer = reinterpret_cast<uint32_t*>(pRegion.begin());
uint64_t result = 0;
@@ -48,32 +45,28 @@ uint64_t MipsGOTPLT::emit(MemoryRegion& pRegion)
return result;
}
-Fragment* MipsGOTPLT::consume()
-{
+Fragment* MipsGOTPLT::consume() {
++m_Last;
assert(m_Last != m_SectionData->end() &&
"There is no reserved GOTPLT entries");
return &(*m_Last);
}
-bool MipsGOTPLT::hasGOT1() const
-{
+bool MipsGOTPLT::hasGOT1() const {
return m_SectionData->size() > MipsGOTPLT0Num;
}
-uint64_t MipsGOTPLT::getEntryAddr(size_t num) const
-{
+uint64_t MipsGOTPLT::getEntryAddr(size_t num) const {
return addr() + (MipsGOTPLT0Num + num) * GOTPLTEntry::EntrySize;
}
-void MipsGOTPLT::applyAllGOTPLT(uint64_t pltAddr)
-{
+void MipsGOTPLT::applyAllGOTPLT(uint64_t pltAddr) {
iterator it = begin();
- llvm::cast<GOTPLTEntry>(*it++).setValue(0); // PLT lazy resolver
- llvm::cast<GOTPLTEntry>(*it++).setValue(0); // Module pointer
+ llvm::cast<GOTPLTEntry>(*it++).setValue(0); // PLT lazy resolver
+ llvm::cast<GOTPLTEntry>(*it++).setValue(0); // Module pointer
for (; it != end(); ++it)
llvm::cast<GOTPLTEntry>(*it).setValue(pltAddr);
}
-} //end mcld namespace
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsGOTPLT.h b/lib/Target/Mips/MipsGOTPLT.h
index 94067fe..f5cd909 100644
--- a/lib/Target/Mips/MipsGOTPLT.h
+++ b/lib/Target/Mips/MipsGOTPLT.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSGOTPLT_H
-#define TARGET_MIPS_MIPSGOTPLT_H
+#ifndef TARGET_MIPS_MIPSGOTPLT_H_
+#define TARGET_MIPS_MIPSGOTPLT_H_
-#include <mcld/Target/GOT.h>
-#include <mcld/Support/MemoryRegion.h>
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Target/GOT.h"
#include <llvm/ADT/DenseMap.h>
namespace mcld {
@@ -20,10 +20,9 @@ class LDSection;
/** \class MipsGOTPLT
* \brief Mips .got.plt section.
*/
-class MipsGOTPLT : public GOT
-{
-public:
- MipsGOTPLT(LDSection &pSection);
+class MipsGOTPLT : public GOT {
+ public:
+ explicit MipsGOTPLT(LDSection& pSection);
// hasGOT1 - return if this section has any GOT1 entry
bool hasGOT1() const;
@@ -36,15 +35,15 @@ public:
void applyAllGOTPLT(uint64_t pltAddr);
-public:
+ public:
// GOT
void reserve(size_t pNum = 1);
-private:
+ private:
// the last consumed entry.
SectionData::iterator m_Last;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSGOTPLT_H_
diff --git a/lib/Target/Mips/MipsLA25Stub.cpp b/lib/Target/Mips/MipsLA25Stub.cpp
index fcbc011..3127b37 100644
--- a/lib/Target/Mips/MipsLA25Stub.cpp
+++ b/lib/Target/Mips/MipsLA25Stub.cpp
@@ -6,27 +6,27 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ResolveInfo.h>
+#include "mcld/LD/ResolveInfo.h"
#include "MipsLA25Stub.h"
#include "MipsLDBackend.h"
namespace {
const uint32_t STUB[] = {
- 0x3c190000, // lui $25,%hi(func)
- 0x08000000, // j func
- 0x27390000, // add $25,$25,%lo(func)
- 0x00000000 // nop
+ 0x3c190000, // lui $25,%hi(func)
+ 0x08000000, // j func
+ 0x27390000, // add $25,$25,%lo(func)
+ 0x00000000 // nop
};
enum {
// Fake relocations for patching LA25 stubs.
R_MIPS_LA25_LUI = 200,
- R_MIPS_LA25_J = 201,
+ R_MIPS_LA25_J = 201,
R_MIPS_LA25_ADD = 202
};
-}
+} // anonymous namespace
namespace mcld {
@@ -35,11 +35,10 @@ namespace mcld {
//===----------------------------------------------------------------------===//
MipsLA25Stub::MipsLA25Stub(const MipsGNULDBackend& pTarget)
- : m_Target(pTarget),
- m_Name("MipsLA25_Prototype"),
- m_pData(STUB),
- m_Size(sizeof(STUB))
-{
+ : m_Target(pTarget),
+ m_Name("MipsLA25_Prototype"),
+ m_pData(STUB),
+ m_Size(sizeof(STUB)) {
addFixup(0, 0x0, R_MIPS_LA25_LUI);
addFixup(4, 0x0, R_MIPS_LA25_J);
addFixup(8, 0x0, R_MIPS_LA25_ADD);
@@ -50,19 +49,14 @@ MipsLA25Stub::MipsLA25Stub(const MipsGNULDBackend& pTarget,
size_t pSize,
const_fixup_iterator pBegin,
const_fixup_iterator pEnd)
- : m_Target(pTarget),
- m_Name("pic"),
- m_pData(pData),
- m_Size(pSize)
-{
+ : m_Target(pTarget), m_Name("pic"), m_pData(pData), m_Size(pSize) {
for (const_fixup_iterator it = pBegin, ie = pEnd; it != ie; ++it)
addFixup(**it);
}
bool MipsLA25Stub::isMyDuty(const Relocation& pReloc,
uint64_t pSource,
- uint64_t pTargetSymValue) const
-{
+ uint64_t pTargetSymValue) const {
if (llvm::ELF::R_MIPS_26 != pReloc.type())
return false;
@@ -80,30 +74,25 @@ bool MipsLA25Stub::isMyDuty(const Relocation& pReloc,
return true;
}
-const std::string& MipsLA25Stub::name() const
-{
+const std::string& MipsLA25Stub::name() const {
return m_Name;
}
-const uint8_t* MipsLA25Stub::getContent() const
-{
+const uint8_t* MipsLA25Stub::getContent() const {
return reinterpret_cast<const uint8_t*>(m_pData);
}
-size_t MipsLA25Stub::size() const
-{
+size_t MipsLA25Stub::size() const {
return m_Size;
}
-size_t MipsLA25Stub::alignment() const
-{
+size_t MipsLA25Stub::alignment() const {
return 4;
}
-Stub* MipsLA25Stub::doClone()
-{
- return new MipsLA25Stub(m_Target, m_pData, m_Size,
- fixup_begin(), fixup_end());
+Stub* MipsLA25Stub::doClone() {
+ return new MipsLA25Stub(
+ m_Target, m_pData, m_Size, fixup_begin(), fixup_end());
}
-} //end mcld namespace
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsLA25Stub.h b/lib/Target/Mips/MipsLA25Stub.h
index c74cd0d..0d43b87 100644
--- a/lib/Target/Mips/MipsLA25Stub.h
+++ b/lib/Target/Mips/MipsLA25Stub.h
@@ -6,13 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSLA25STUB_H
-#define TARGET_MIPS_MIPSLA25STUB_H
+#ifndef TARGET_MIPS_MIPSLA25STUB_H_
+#define TARGET_MIPS_MIPSLA25STUB_H_
-#include <mcld/Fragment/Stub.h>
+#include "mcld/Fragment/Stub.h"
-namespace mcld
-{
+namespace mcld {
class MipsGNULDBackend;
class Relocation;
@@ -23,12 +22,11 @@ class Relocation;
/** \class MipsLA25Stub
* \brief Mips stub for a non-PIC interface to a PIC function.
*/
-class MipsLA25Stub : public Stub
-{
-public:
- MipsLA25Stub(const MipsGNULDBackend& pTarget);
+class MipsLA25Stub : public Stub {
+ public:
+ explicit MipsLA25Stub(const MipsGNULDBackend& pTarget);
-private:
+ private:
// Stub
Stub* doClone();
bool isMyDuty(const Relocation& pReloc,
@@ -39,7 +37,7 @@ private:
size_t size() const;
size_t alignment() const;
-private:
+ private:
MipsLA25Stub(const MipsLA25Stub&);
MipsLA25Stub& operator=(const MipsLA25Stub&);
@@ -49,13 +47,13 @@ private:
const_fixup_iterator pBegin,
const_fixup_iterator pEnd);
-private:
+ private:
const MipsGNULDBackend& m_Target;
const std::string m_Name;
const uint32_t* m_pData;
const size_t m_Size;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSLA25STUB_H_
diff --git a/lib/Target/Mips/MipsLDBackend.cpp b/lib/Target/Mips/MipsLDBackend.cpp
index 9714e91..44156af 100644
--- a/lib/Target/Mips/MipsLDBackend.cpp
+++ b/lib/Target/Mips/MipsLDBackend.cpp
@@ -13,51 +13,49 @@
#include "MipsLDBackend.h"
#include "MipsRelocator.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Module.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/LD/BranchIslandFactory.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/LD/StubFactory.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/MC/Attribute.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Support/MemoryArea.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/OutputRelocSection.h"
+
#include <llvm/ADT/Triple.h>
#include <llvm/Support/Casting.h>
#include <llvm/Support/ELF.h>
#include <llvm/Support/Host.h>
-#include <mcld/Module.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/LD/BranchIslandFactory.h>
-#include <mcld/LD/LDContext.h>
-#include <mcld/LD/StubFactory.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/MC/Attribute.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/Support/MemoryRegion.h>
-#include <mcld/Support/MemoryArea.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Target/OutputRelocSection.h>
-#include <mcld/Object/ObjectBuilder.h>
-
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// MipsGNULDBackend
//===----------------------------------------------------------------------===//
MipsGNULDBackend::MipsGNULDBackend(const LinkerConfig& pConfig,
MipsGNUInfo* pInfo)
- : GNULDBackend(pConfig, pInfo),
- m_pRelocator(NULL),
- m_pGOT(NULL),
- m_pPLT(NULL),
- m_pGOTPLT(NULL),
- m_pInfo(*pInfo),
- m_pRelPlt(NULL),
- m_pRelDyn(NULL),
- m_pDynamic(NULL),
- m_pGOTSymbol(NULL),
- m_pPLTSymbol(NULL),
- m_pGpDispSymbol(NULL)
-{
-}
-
-MipsGNULDBackend::~MipsGNULDBackend()
-{
+ : GNULDBackend(pConfig, pInfo),
+ m_pRelocator(NULL),
+ m_pGOT(NULL),
+ m_pPLT(NULL),
+ m_pGOTPLT(NULL),
+ m_pInfo(*pInfo),
+ m_pRelPlt(NULL),
+ m_pRelDyn(NULL),
+ m_pDynamic(NULL),
+ m_pGOTSymbol(NULL),
+ m_pPLTSymbol(NULL),
+ m_pGpDispSymbol(NULL) {
+}
+
+MipsGNULDBackend::~MipsGNULDBackend() {
delete m_pRelocator;
delete m_pPLT;
delete m_pRelPlt;
@@ -66,8 +64,7 @@ MipsGNULDBackend::~MipsGNULDBackend()
}
bool MipsGNULDBackend::needsLA25Stub(Relocation::Type pType,
- const mcld::ResolveInfo* pSym)
-{
+ const mcld::ResolveInfo* pSym) {
if (config().isCodeIndep())
return false;
@@ -80,19 +77,16 @@ bool MipsGNULDBackend::needsLA25Stub(Relocation::Type pType,
return true;
}
-void MipsGNULDBackend::addNonPICBranchSym(ResolveInfo* rsym)
-{
+void MipsGNULDBackend::addNonPICBranchSym(ResolveInfo* rsym) {
m_HasNonPICBranchSyms.insert(rsym);
}
-bool MipsGNULDBackend::hasNonPICBranch(const ResolveInfo* rsym) const
-{
+bool MipsGNULDBackend::hasNonPICBranch(const ResolveInfo* rsym) const {
return m_HasNonPICBranchSyms.count(rsym);
}
void MipsGNULDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
+ ObjectBuilder& pBuilder) {
if (LinkerConfig::Object == config().codeGenType())
return;
@@ -107,77 +101,73 @@ void MipsGNULDBackend::initTargetSections(Module& pModule,
m_pRelDyn = new OutputRelocSection(pModule, reldyn);
}
-void MipsGNULDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule)
-{
+void MipsGNULDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule) {
// Define the symbol _GLOBAL_OFFSET_TABLE_ if there is a symbol with the
// same name in input
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Hidden);
// Define the symbol _PROCEDURE_LINKAGE_TABLE_ if there is a symbol with the
// same name in input
- m_pPLTSymbol =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_PROCEDURE_LINKAGE_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Hidden);
-
- m_pGpDispSymbol = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_gp_disp",
- ResolveInfo::Section,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>(
- "_gp",
- ResolveInfo::NoType,
- ResolveInfo::Define,
- ResolveInfo::Absolute,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Default);
-}
+ m_pPLTSymbol = pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_PROCEDURE_LINKAGE_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Hidden);
+
+ m_pGpDispSymbol =
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_gp_disp",
+ ResolveInfo::Section,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
-const Relocator* MipsGNULDBackend::getRelocator() const
-{
- assert(NULL != m_pRelocator);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Unresolve>(
+ "_gp",
+ ResolveInfo::NoType,
+ ResolveInfo::Define,
+ ResolveInfo::Absolute,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Default);
+}
+
+const Relocator* MipsGNULDBackend::getRelocator() const {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-Relocator* MipsGNULDBackend::getRelocator()
-{
- assert(NULL != m_pRelocator);
+Relocator* MipsGNULDBackend::getRelocator() {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-void MipsGNULDBackend::doPreLayout(IRBuilder& pBuilder)
-{
+void MipsGNULDBackend::doPreLayout(IRBuilder& pBuilder) {
// initialize .dynamic data
- if (!config().isCodeStatic() && NULL == m_pDynamic)
+ if (!config().isCodeStatic() && m_pDynamic == NULL)
m_pDynamic = new MipsELFDynamic(*this, config());
// set .got size
// when building shared object, the .got section is must.
if (LinkerConfig::Object != config().codeGenType()) {
- if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ if (LinkerConfig::DynObj == config().codeGenType() || m_pGOT->hasGOT1() ||
+ m_pGOTSymbol != NULL) {
m_pGOT->finalizeScanning(*m_pRelDyn);
m_pGOT->finalizeSectionSize();
@@ -197,33 +187,34 @@ void MipsGNULDBackend::doPreLayout(IRBuilder& pBuilder)
// set .rel.plt size
if (!m_pRelPlt->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
- file_format->getRelPlt().setSize(
- m_pRelPlt->numOfRelocs() * getRelEntrySize());
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
+ file_format->getRelPlt().setSize(m_pRelPlt->numOfRelocs() *
+ getRelEntrySize());
}
// set .rel.dyn size
if (!m_pRelDyn->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
- file_format->getRelDyn().setSize(
- m_pRelDyn->numOfRelocs() * getRelEntrySize());
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
+ file_format->getRelDyn().setSize(m_pRelDyn->numOfRelocs() *
+ getRelEntrySize());
}
}
}
-void MipsGNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder)
-{
- const ELFFileFormat *format = getOutputFormat();
+void MipsGNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder) {
+ const ELFFileFormat* format = getOutputFormat();
if (format->hasGOTPLT()) {
- assert(m_pGOTPLT && "doPostLayout failed, m_pGOTPLT is NULL!");
+ assert(m_pGOTPLT != NULL && "doPostLayout failed, m_pGOTPLT is NULL!");
m_pGOTPLT->applyAllGOTPLT(m_pPLT->addr());
}
if (format->hasPLT()) {
- assert(m_pPLT && "doPostLayout failed, m_pPLT is NULL!");
+ assert(m_pPLT != NULL && "doPostLayout failed, m_pPLT is NULL!");
m_pPLT->applyAllPLT(*m_pGOTPLT);
}
@@ -234,8 +225,7 @@ void MipsGNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder)
uint64_t picFlags = llvm::ELF::EF_MIPS_CPIC;
if (config().targets().triple().isArch64Bit()) {
picFlags |= llvm::ELF::EF_MIPS_PIC;
- }
- else {
+ } else {
if (LinkerConfig::DynObj == config().codeGenType())
picFlags |= llvm::ELF::EF_MIPS_PIC;
}
@@ -245,23 +235,20 @@ void MipsGNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder)
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-MipsELFDynamic& MipsGNULDBackend::dynamic()
-{
- assert(NULL != m_pDynamic);
+MipsELFDynamic& MipsGNULDBackend::dynamic() {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-const MipsELFDynamic& MipsGNULDBackend::dynamic() const
-{
- assert(NULL != m_pDynamic);
+const MipsELFDynamic& MipsGNULDBackend::dynamic() const {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
uint64_t MipsGNULDBackend::emitSectionData(const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
assert(pRegion.size() && "Size of MemoryRegion is zero!");
const ELFFileFormat* file_format = getOutputFormat();
@@ -278,38 +265,29 @@ uint64_t MipsGNULDBackend::emitSectionData(const LDSection& pSection,
return m_pGOTPLT->emit(pRegion);
}
- fatal(diag::unrecognized_output_sectoin)
- << pSection.name()
- << "mclinker@googlegroups.com";
+ fatal(diag::unrecognized_output_sectoin) << pSection.name()
+ << "mclinker@googlegroups.com";
return 0;
}
-bool MipsGNULDBackend::hasEntryInStrTab(const LDSymbol& pSym) const
-{
- return ResolveInfo::Section != pSym.type() ||
- m_pGpDispSymbol == &pSym;
+bool MipsGNULDBackend::hasEntryInStrTab(const LDSymbol& pSym) const {
+ return ResolveInfo::Section != pSym.type() || m_pGpDispSymbol == &pSym;
}
namespace {
- struct DynsymGOTCompare
- {
- const MipsGOT& m_pGOT;
+struct DynsymGOTCompare {
+ const MipsGOT& m_pGOT;
- DynsymGOTCompare(const MipsGOT& pGOT)
- : m_pGOT(pGOT)
- {
- }
+ explicit DynsymGOTCompare(const MipsGOT& pGOT) : m_pGOT(pGOT) {}
- bool operator()(const LDSymbol* X, const LDSymbol* Y) const
- {
- return m_pGOT.dynSymOrderCompare(X, Y);
- }
- };
-}
+ bool operator()(const LDSymbol* X, const LDSymbol* Y) const {
+ return m_pGOT.dynSymOrderCompare(X, Y);
+ }
+};
+} // anonymous namespace
-void MipsGNULDBackend::orderSymbolTable(Module& pModule)
-{
- if (GeneralOptions::GNU == config().options().getHashStyle() ||
+void MipsGNULDBackend::orderSymbolTable(Module& pModule) {
+ if (GeneralOptions::GNU == config().options().getHashStyle() ||
GeneralOptions::Both == config().options().getHashStyle()) {
// The MIPS ABI and .gnu.hash require .dynsym to be sorted
// in different ways. The MIPS ABI requires a mapping between
@@ -320,57 +298,60 @@ void MipsGNULDBackend::orderSymbolTable(Module& pModule)
Module::SymbolTable& symbols = pModule.getSymbolTable();
- std::stable_sort(symbols.dynamicBegin(), symbols.dynamicEnd(),
- DynsymGOTCompare(*m_pGOT));
+ std::stable_sort(
+ symbols.dynamicBegin(), symbols.dynamicEnd(), DynsymGOTCompare(*m_pGOT));
}
+} // namespace mcld
+
namespace llvm {
namespace ELF {
// SHT_MIPS_OPTIONS section's block descriptor.
struct Elf_Options {
- unsigned char kind; // Determines interpretation of variable
- // part of descriptor. See ODK_xxx enumeration.
- unsigned char size; // Byte size of descriptor, including this header.
- Elf64_Half section; // Section header index of section affected,
- // or 0 for global options.
- Elf64_Word info; // Kind-specific information.
+ unsigned char kind; // Determines interpretation of variable
+ // part of descriptor. See ODK_xxx enumeration.
+ unsigned char size; // Byte size of descriptor, including this header.
+ Elf64_Half section; // Section header index of section affected,
+ // or 0 for global options.
+ Elf64_Word info; // Kind-specific information.
};
// Type of SHT_MIPS_OPTIONS section's block.
enum {
- ODK_NULL = 0, // Undefined.
- ODK_REGINFO = 1, // Register usage and GP value.
- ODK_EXCEPTIONS = 2, // Exception processing information.
- ODK_PAD = 3, // Section padding information.
- ODK_HWPATCH = 4, // Hardware workarounds performed.
- ODK_FILL = 5, // Fill value used by the linker.
- ODK_TAGS = 6, // Reserved space for desktop tools.
- ODK_HWAND = 7, // Hardware workarounds, AND bits when merging.
- ODK_HWOR = 8, // Hardware workarounds, OR bits when merging.
- ODK_GP_GROUP = 9, // GP group to use for text/data sections.
- ODK_IDENT = 10 // ID information.
+ ODK_NULL = 0, // Undefined.
+ ODK_REGINFO = 1, // Register usage and GP value.
+ ODK_EXCEPTIONS = 2, // Exception processing information.
+ ODK_PAD = 3, // Section padding information.
+ ODK_HWPATCH = 4, // Hardware workarounds performed.
+ ODK_FILL = 5, // Fill value used by the linker.
+ ODK_TAGS = 6, // Reserved space for desktop tools.
+ ODK_HWAND = 7, // Hardware workarounds, AND bits when merging.
+ ODK_HWOR = 8, // Hardware workarounds, OR bits when merging.
+ ODK_GP_GROUP = 9, // GP group to use for text/data sections.
+ ODK_IDENT = 10 // ID information.
};
// Content of ODK_REGINFO block in SHT_MIPS_OPTIONS section on 32 bit ABI.
struct Elf32_RegInfo {
- Elf32_Word ri_gprmask; // Mask of general purpose registers used.
- Elf32_Word ri_cprmask[4]; // Mask of co-processor registers used.
- Elf32_Addr ri_gp_value; // GP register value for this object file.
+ Elf32_Word ri_gprmask; // Mask of general purpose registers used.
+ Elf32_Word ri_cprmask[4]; // Mask of co-processor registers used.
+ Elf32_Addr ri_gp_value; // GP register value for this object file.
};
// Content of ODK_REGINFO block in SHT_MIPS_OPTIONS section on 64 bit ABI.
struct Elf64_RegInfo {
- Elf32_Word ri_gprmask; // Mask of general purpose registers used.
- Elf32_Word ri_pad; // Padding.
- Elf32_Word ri_cprmask[4]; // Mask of co-processor registers used.
- Elf64_Addr ri_gp_value; // GP register value for this object file.
+ Elf32_Word ri_gprmask; // Mask of general purpose registers used.
+ Elf32_Word ri_pad; // Padding.
+ Elf32_Word ri_cprmask[4]; // Mask of co-processor registers used.
+ Elf64_Addr ri_gp_value; // GP register value for this object file.
};
-}
-}
+} // namespace ELF
+} // namespace llvm
+
+namespace mcld {
-bool MipsGNULDBackend::readSection(Input& pInput, SectionData& pSD)
-{
+bool MipsGNULDBackend::readSection(Input& pInput, SectionData& pSD) {
llvm::StringRef name(pSD.getSection().name());
if (name.startswith(".sdata")) {
@@ -389,11 +370,13 @@ bool MipsGNULDBackend::readSection(Input& pInput, SectionData& pSD)
llvm::StringRef region = pInput.memArea()->request(offset, size);
if (region.size() > 0) {
const llvm::ELF::Elf_Options* optb =
- reinterpret_cast<const llvm::ELF::Elf_Options*>(region.begin());
+ reinterpret_cast<const llvm::ELF::Elf_Options*>(region.begin());
const llvm::ELF::Elf_Options* opte =
- reinterpret_cast<const llvm::ELF::Elf_Options*>(region.begin() + size);
+ reinterpret_cast<const llvm::ELF::Elf_Options*>(region.begin() +
+ size);
- for (const llvm::ELF::Elf_Options* opt = optb; opt < opte; opt += opt->size) {
+ for (const llvm::ELF::Elf_Options* opt = optb; opt < opte;
+ opt += opt->size) {
switch (opt->kind) {
default:
// Nothing to do.
@@ -401,12 +384,11 @@ bool MipsGNULDBackend::readSection(Input& pInput, SectionData& pSD)
case llvm::ELF::ODK_REGINFO:
if (config().targets().triple().isArch32Bit()) {
const llvm::ELF::Elf32_RegInfo* reg =
- reinterpret_cast<const llvm::ELF::Elf32_RegInfo*>(opt + 1);
+ reinterpret_cast<const llvm::ELF::Elf32_RegInfo*>(opt + 1);
m_GP0Map[&pInput] = reg->ri_gp_value;
- }
- else {
+ } else {
const llvm::ELF::Elf64_RegInfo* reg =
- reinterpret_cast<const llvm::ELF::Elf64_RegInfo*>(opt + 1);
+ reinterpret_cast<const llvm::ELF::Elf64_RegInfo*>(opt + 1);
m_GP0Map[&pInput] = reg->ri_gp_value;
}
break;
@@ -420,69 +402,58 @@ bool MipsGNULDBackend::readSection(Input& pInput, SectionData& pSD)
return GNULDBackend::readSection(pInput, pSD);
}
-MipsGOT& MipsGNULDBackend::getGOT()
-{
- assert(NULL != m_pGOT);
+MipsGOT& MipsGNULDBackend::getGOT() {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-const MipsGOT& MipsGNULDBackend::getGOT() const
-{
- assert(NULL != m_pGOT);
+const MipsGOT& MipsGNULDBackend::getGOT() const {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-MipsPLT& MipsGNULDBackend::getPLT()
-{
- assert(NULL != m_pPLT);
+MipsPLT& MipsGNULDBackend::getPLT() {
+ assert(m_pPLT != NULL);
return *m_pPLT;
}
-const MipsPLT& MipsGNULDBackend::getPLT() const
-{
- assert(NULL != m_pPLT);
+const MipsPLT& MipsGNULDBackend::getPLT() const {
+ assert(m_pPLT != NULL);
return *m_pPLT;
}
-MipsGOTPLT& MipsGNULDBackend::getGOTPLT()
-{
- assert(NULL != m_pGOTPLT);
+MipsGOTPLT& MipsGNULDBackend::getGOTPLT() {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-const MipsGOTPLT& MipsGNULDBackend::getGOTPLT() const
-{
- assert(NULL != m_pGOTPLT);
+const MipsGOTPLT& MipsGNULDBackend::getGOTPLT() const {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-OutputRelocSection& MipsGNULDBackend::getRelPLT()
-{
- assert(NULL != m_pRelPlt);
+OutputRelocSection& MipsGNULDBackend::getRelPLT() {
+ assert(m_pRelPlt != NULL);
return *m_pRelPlt;
}
-const OutputRelocSection& MipsGNULDBackend::getRelPLT() const
-{
- assert(NULL != m_pRelPlt);
+const OutputRelocSection& MipsGNULDBackend::getRelPLT() const {
+ assert(m_pRelPlt != NULL);
return *m_pRelPlt;
}
-OutputRelocSection& MipsGNULDBackend::getRelDyn()
-{
- assert(NULL != m_pRelDyn);
+OutputRelocSection& MipsGNULDBackend::getRelDyn() {
+ assert(m_pRelDyn != NULL);
return *m_pRelDyn;
}
-const OutputRelocSection& MipsGNULDBackend::getRelDyn() const
-{
- assert(NULL != m_pRelDyn);
+const OutputRelocSection& MipsGNULDBackend::getRelDyn() const {
+ assert(m_pRelDyn != NULL);
return *m_pRelDyn;
}
-unsigned int
-MipsGNULDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
-{
+unsigned int MipsGNULDBackend::getTargetSectionOrder(
+ const LDSection& pSectHdr) const {
const ELFFileFormat* file_format = getOutputFormat();
if (file_format->hasGOT() && (&pSectHdr == &file_format->getGOT()))
@@ -498,9 +469,8 @@ MipsGNULDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
}
/// finalizeSymbol - finalize the symbol value
-bool MipsGNULDBackend::finalizeTargetSymbols()
-{
- if (NULL != m_pGpDispSymbol)
+bool MipsGNULDBackend::finalizeTargetSymbols() {
+ if (m_pGpDispSymbol != NULL)
m_pGpDispSymbol->setValue(m_pGOT->getGPDispAddress());
return true;
@@ -508,10 +478,8 @@ bool MipsGNULDBackend::finalizeTargetSymbols()
/// allocateCommonSymbols - allocate common symbols in the corresponding
/// sections. This is called at pre-layout stage.
-/// @refer Google gold linker: common.cc: 214
/// FIXME: Mips needs to allocate small common symbol
-bool MipsGNULDBackend::allocateCommonSymbols(Module& pModule)
-{
+bool MipsGNULDBackend::allocateCommonSymbols(Module& pModule) {
SymbolCategory& symbol_list = pModule.getSymbolTable();
if (symbol_list.emptyCommons() && symbol_list.emptyFiles() &&
@@ -542,7 +510,7 @@ bool MipsGNULDBackend::allocateCommonSymbols(Module& pModule)
tbss_sect_data = IRBuilder::CreateSectionData(tbss_sect);
// remember original BSS size
- uint64_t bss_offset = bss_sect.size();
+ uint64_t bss_offset = bss_sect.size();
uint64_t tbss_offset = tbss_sect.size();
// allocate all local common symbols
@@ -560,17 +528,14 @@ bool MipsGNULDBackend::allocateCommonSymbols(Module& pModule)
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
- tbss_offset += ObjectBuilder::AppendFragment(*frag,
- *tbss_sect_data,
- (*com_sym)->value());
+ tbss_offset += ObjectBuilder::AppendFragment(
+ *frag, *tbss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(tbss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- }
- // FIXME: how to identify small and large common symbols?
- else {
- bss_offset += ObjectBuilder::AppendFragment(*frag,
- *bss_sect_data,
- (*com_sym)->value());
+ } else {
+ // FIXME: how to identify small and large common symbols?
+ bss_offset += ObjectBuilder::AppendFragment(
+ *frag, *bss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(bss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
}
@@ -590,17 +555,14 @@ bool MipsGNULDBackend::allocateCommonSymbols(Module& pModule)
if (ResolveInfo::ThreadLocal == (*com_sym)->type()) {
// allocate TLS common symbol in tbss section
- tbss_offset += ObjectBuilder::AppendFragment(*frag,
- *tbss_sect_data,
- (*com_sym)->value());
+ tbss_offset += ObjectBuilder::AppendFragment(
+ *frag, *tbss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(tbss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
- }
- // FIXME: how to identify small and large common symbols?
- else {
- bss_offset += ObjectBuilder::AppendFragment(*frag,
- *bss_sect_data,
- (*com_sym)->value());
+ } else {
+ // FIXME: how to identify small and large common symbols?
+ bss_offset += ObjectBuilder::AppendFragment(
+ *frag, *bss_sect_data, (*com_sym)->value());
ObjectBuilder::UpdateSectionAlign(bss_sect, (*com_sym)->value());
(*com_sym)->setFragmentRef(FragmentRef::Create(*frag, 0));
}
@@ -612,79 +574,72 @@ bool MipsGNULDBackend::allocateCommonSymbols(Module& pModule)
return true;
}
-uint64_t MipsGNULDBackend::getGP0(const Input& pInput) const
-{
+uint64_t MipsGNULDBackend::getGP0(const Input& pInput) const {
return m_GP0Map.lookup(&pInput);
}
-void MipsGNULDBackend::defineGOTSymbol(IRBuilder& pBuilder)
-{
+void MipsGNULDBackend::defineGOTSymbol(IRBuilder& pBuilder) {
// If we do not reserve any GOT entries, we do not need to re-define GOT
// symbol.
if (!m_pGOT->hasGOT1())
return;
// define symbol _GLOBAL_OFFSET_TABLE_
- if ( m_pGOTSymbol != NULL ) {
+ if (m_pGOTSymbol != NULL) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pGOT->begin()), 0x0),
- ResolveInfo::Hidden);
- }
- else {
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pGOT->begin()), 0x0),
+ ResolveInfo::Hidden);
+ } else {
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pGOT->begin()), 0x0),
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pGOT->begin()), 0x0),
+ ResolveInfo::Hidden);
}
}
-void MipsGNULDBackend::defineGOTPLTSymbol(IRBuilder& pBuilder)
-{
+void MipsGNULDBackend::defineGOTPLTSymbol(IRBuilder& pBuilder) {
// define symbol _PROCEDURE_LINKAGE_TABLE_
- if ( m_pPLTSymbol != NULL ) {
+ if (m_pPLTSymbol != NULL) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- "_PROCEDURE_LINKAGE_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pPLT->begin()), 0x0),
- ResolveInfo::Hidden);
- }
- else {
+ "_PROCEDURE_LINKAGE_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pPLT->begin()), 0x0),
+ ResolveInfo::Hidden);
+ } else {
m_pPLTSymbol = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_PROCEDURE_LINKAGE_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(*(m_pPLT->begin()), 0x0),
- ResolveInfo::Hidden);
+ "_PROCEDURE_LINKAGE_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(*(m_pPLT->begin()), 0x0),
+ ResolveInfo::Hidden);
}
}
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
-void MipsGNULDBackend::doCreateProgramHdrs(Module& pModule)
-{
+void MipsGNULDBackend::doCreateProgramHdrs(Module& pModule) {
// TODO
}
-bool MipsGNULDBackend::relaxRelocation(IRBuilder& pBuilder, Relocation& pRel)
-{
+bool MipsGNULDBackend::relaxRelocation(IRBuilder& pBuilder, Relocation& pRel) {
uint64_t sym_value = 0x0;
LDSymbol* symbol = pRel.symInfo()->outSymbol();
@@ -694,13 +649,13 @@ bool MipsGNULDBackend::relaxRelocation(IRBuilder& pBuilder, Relocation& pRel)
sym_value = addr + value;
}
- Stub* stub =
- getStubFactory()->create(pRel, sym_value, pBuilder, *getBRIslandFactory());
+ Stub* stub = getStubFactory()->create(
+ pRel, sym_value, pBuilder, *getBRIslandFactory());
- if (NULL == stub)
+ if (stub == NULL)
return false;
- assert(NULL != stub->symInfo());
+ assert(stub->symInfo() != NULL);
// increase the size of .symtab and .strtab
LDSection& symtab = getOutputFormat()->getSymTab();
LDSection& strtab = getOutputFormat()->getStrTab();
@@ -710,26 +665,29 @@ bool MipsGNULDBackend::relaxRelocation(IRBuilder& pBuilder, Relocation& pRel)
return true;
}
-bool MipsGNULDBackend::doRelax(Module& pModule, IRBuilder& pBuilder,
- bool& pFinished)
-{
- assert(NULL != getStubFactory() && NULL != getBRIslandFactory());
+bool MipsGNULDBackend::doRelax(Module& pModule,
+ IRBuilder& pBuilder,
+ bool& pFinished) {
+ assert(getStubFactory() != NULL && getBRIslandFactory() != NULL);
bool isRelaxed = false;
for (Module::obj_iterator input = pModule.obj_begin();
- input != pModule.obj_end(); ++input) {
+ input != pModule.obj_end();
+ ++input) {
LDContext* context = (*input)->context();
for (LDContext::sect_iterator rs = context->relocSectBegin();
- rs != context->relocSectEnd(); ++rs) {
+ rs != context->relocSectEnd();
+ ++rs) {
LDSection* sec = *rs;
if (LDFileFormat::Ignore == sec->kind() || !sec->hasRelocData())
continue;
for (RelocData::iterator reloc = sec->getRelocData()->begin();
- reloc != sec->getRelocData()->end(); ++reloc) {
+ reloc != sec->getRelocData()->end();
+ ++reloc) {
if (llvm::ELF::R_MIPS_26 != reloc->type())
continue;
@@ -746,8 +704,8 @@ bool MipsGNULDBackend::doRelax(Module& pModule, IRBuilder& pBuilder,
pFinished = true;
for (BranchIslandFactory::iterator ii = getBRIslandFactory()->begin(),
ie = getBRIslandFactory()->end();
- ii != ie; ++ii)
- {
+ ii != ie;
+ ++ii) {
BranchIsland& island = *ii;
if (island.end() == textData->end())
break;
@@ -761,7 +719,7 @@ bool MipsGNULDBackend::doRelax(Module& pModule, IRBuilder& pBuilder,
}
// reset the offset of invalid fragments
- while (NULL != invalid) {
+ while (invalid != NULL) {
invalid->setOffset(invalid->getPrevNode()->getOffset() +
invalid->getPrevNode()->size());
invalid = invalid->getNextNode();
@@ -775,9 +733,8 @@ bool MipsGNULDBackend::doRelax(Module& pModule, IRBuilder& pBuilder,
return isRelaxed;
}
-bool MipsGNULDBackend::initTargetStubs()
-{
- if (NULL == getStubFactory())
+bool MipsGNULDBackend::initTargetStubs() {
+ if (getStubFactory() == NULL)
return false;
getStubFactory()->addPrototype(new MipsLA25Stub(*this));
@@ -787,8 +744,7 @@ bool MipsGNULDBackend::initTargetStubs()
bool MipsGNULDBackend::readRelocation(const llvm::ELF::Elf32_Rel& pRel,
Relocation::Type& pType,
uint32_t& pSymIdx,
- uint32_t& pOffset) const
-{
+ uint32_t& pOffset) const {
return GNULDBackend::readRelocation(pRel, pType, pSymIdx, pOffset);
}
@@ -796,24 +752,21 @@ bool MipsGNULDBackend::readRelocation(const llvm::ELF::Elf32_Rela& pRel,
Relocation::Type& pType,
uint32_t& pSymIdx,
uint32_t& pOffset,
- int32_t& pAddend) const
-{
+ int32_t& pAddend) const {
return GNULDBackend::readRelocation(pRel, pType, pSymIdx, pOffset, pAddend);
}
bool MipsGNULDBackend::readRelocation(const llvm::ELF::Elf64_Rel& pRel,
Relocation::Type& pType,
uint32_t& pSymIdx,
- uint64_t& pOffset) const
-{
+ uint64_t& pOffset) const {
uint64_t r_info = 0x0;
if (llvm::sys::IsLittleEndianHost) {
pOffset = pRel.r_offset;
- r_info = pRel.r_info;
- }
- else {
+ r_info = pRel.r_info;
+ } else {
pOffset = mcld::bswap64(pRel.r_offset);
- r_info = mcld::bswap64(pRel.r_info);
+ r_info = mcld::bswap64(pRel.r_info);
}
// MIPS 64 little endian (we do not support big endian now)
@@ -829,17 +782,15 @@ bool MipsGNULDBackend::readRelocation(const llvm::ELF::Elf64_Rela& pRel,
Relocation::Type& pType,
uint32_t& pSymIdx,
uint64_t& pOffset,
- int64_t& pAddend) const
-{
+ int64_t& pAddend) const {
uint64_t r_info = 0x0;
if (llvm::sys::IsLittleEndianHost) {
pOffset = pRel.r_offset;
- r_info = pRel.r_info;
+ r_info = pRel.r_info;
pAddend = pRel.r_addend;
- }
- else {
+ } else {
pOffset = mcld::bswap64(pRel.r_offset);
- r_info = mcld::bswap64(pRel.r_info);
+ r_info = mcld::bswap64(pRel.r_info);
pAddend = mcld::bswap64(pRel.r_addend);
}
@@ -851,8 +802,7 @@ bool MipsGNULDBackend::readRelocation(const llvm::ELF::Elf64_Rela& pRel,
void MipsGNULDBackend::emitRelocation(llvm::ELF::Elf32_Rel& pRel,
Relocation::Type pType,
uint32_t pSymIdx,
- uint32_t pOffset) const
-{
+ uint32_t pOffset) const {
GNULDBackend::emitRelocation(pRel, pType, pSymIdx, pOffset);
}
@@ -860,16 +810,14 @@ void MipsGNULDBackend::emitRelocation(llvm::ELF::Elf32_Rela& pRel,
Relocation::Type pType,
uint32_t pSymIdx,
uint32_t pOffset,
- int32_t pAddend) const
-{
+ int32_t pAddend) const {
GNULDBackend::emitRelocation(pRel, pType, pSymIdx, pOffset, pAddend);
}
void MipsGNULDBackend::emitRelocation(llvm::ELF::Elf64_Rel& pRel,
Relocation::Type pType,
uint32_t pSymIdx,
- uint64_t pOffset) const
-{
+ uint64_t pOffset) const {
uint64_t r_info = mcld::bswap32(pType);
r_info <<= 32;
r_info |= pSymIdx;
@@ -882,8 +830,7 @@ void MipsGNULDBackend::emitRelocation(llvm::ELF::Elf64_Rela& pRel,
Relocation::Type pType,
uint32_t pSymIdx,
uint64_t pOffset,
- int64_t pAddend) const
-{
+ int64_t pAddend) const {
uint64_t r_info = mcld::bswap32(pType);
r_info <<= 32;
r_info |= pSymIdx;
@@ -898,20 +845,18 @@ void MipsGNULDBackend::emitRelocation(llvm::ELF::Elf64_Rela& pRel,
//===----------------------------------------------------------------------===//
Mips32GNULDBackend::Mips32GNULDBackend(const LinkerConfig& pConfig,
MipsGNUInfo* pInfo)
- : MipsGNULDBackend(pConfig, pInfo)
-{}
+ : MipsGNULDBackend(pConfig, pInfo) {
+}
-bool Mips32GNULDBackend::initRelocator()
-{
- if (NULL == m_pRelocator)
+bool Mips32GNULDBackend::initRelocator() {
+ if (m_pRelocator == NULL)
m_pRelocator = new Mips32Relocator(*this, config());
return true;
}
void Mips32GNULDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
+ ObjectBuilder& pBuilder) {
MipsGNULDBackend::initTargetSections(pModule, pBuilder);
if (LinkerConfig::Object == config().codeGenType())
@@ -932,13 +877,11 @@ void Mips32GNULDBackend::initTargetSections(Module& pModule,
m_pPLT = new MipsPLT(plt);
}
-size_t Mips32GNULDBackend::getRelEntrySize()
-{
+size_t Mips32GNULDBackend::getRelEntrySize() {
return 8;
}
-size_t Mips32GNULDBackend::getRelaEntrySize()
-{
+size_t Mips32GNULDBackend::getRelaEntrySize() {
return 12;
}
@@ -947,20 +890,18 @@ size_t Mips32GNULDBackend::getRelaEntrySize()
//===----------------------------------------------------------------------===//
Mips64GNULDBackend::Mips64GNULDBackend(const LinkerConfig& pConfig,
MipsGNUInfo* pInfo)
- : MipsGNULDBackend(pConfig, pInfo)
-{}
+ : MipsGNULDBackend(pConfig, pInfo) {
+}
-bool Mips64GNULDBackend::initRelocator()
-{
- if (NULL == m_pRelocator)
+bool Mips64GNULDBackend::initRelocator() {
+ if (m_pRelocator == NULL)
m_pRelocator = new Mips64Relocator(*this, config());
return true;
}
void Mips64GNULDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
+ ObjectBuilder& pBuilder) {
MipsGNULDBackend::initTargetSections(pModule, pBuilder);
if (LinkerConfig::Object == config().codeGenType())
@@ -981,21 +922,18 @@ void Mips64GNULDBackend::initTargetSections(Module& pModule,
m_pPLT = new MipsPLT(plt);
}
-size_t Mips64GNULDBackend::getRelEntrySize()
-{
+size_t Mips64GNULDBackend::getRelEntrySize() {
return 16;
}
-size_t Mips64GNULDBackend::getRelaEntrySize()
-{
+size_t Mips64GNULDBackend::getRelaEntrySize() {
return 24;
}
//===----------------------------------------------------------------------===//
/// createMipsLDBackend - the help funtion to create corresponding MipsLDBackend
///
-static TargetLDBackend* createMipsLDBackend(const LinkerConfig& pConfig)
-{
+static TargetLDBackend* createMipsLDBackend(const LinkerConfig& pConfig) {
const llvm::Triple& triple = pConfig.targets().triple();
if (triple.isOSDarwin()) {
@@ -1010,16 +948,18 @@ static TargetLDBackend* createMipsLDBackend(const LinkerConfig& pConfig)
if (llvm::Triple::mips64el == arch)
return new Mips64GNULDBackend(pConfig, new MipsGNUInfo(triple));
- assert (arch == llvm::Triple::mipsel);
+ assert(arch == llvm::Triple::mipsel);
return new Mips32GNULDBackend(pConfig, new MipsGNUInfo(triple));
}
+} // namespace mcld
+
//===----------------------------------------------------------------------===//
// Force static initialization.
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeMipsLDBackend() {
mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheMipselTarget,
- createMipsLDBackend);
+ mcld::createMipsLDBackend);
mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheMips64elTarget,
- createMipsLDBackend);
+ mcld::createMipsLDBackend);
}
diff --git a/lib/Target/Mips/MipsLDBackend.h b/lib/Target/Mips/MipsLDBackend.h
index 991b3c4..2dbf8d1 100644
--- a/lib/Target/Mips/MipsLDBackend.h
+++ b/lib/Target/Mips/MipsLDBackend.h
@@ -6,9 +6,9 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSLDBACKEND_H
-#define TARGET_MIPS_MIPSLDBACKEND_H
-#include <mcld/Target/GNULDBackend.h>
+#ifndef TARGET_MIPS_MIPSLDBACKEND_H_
+#define TARGET_MIPS_MIPSLDBACKEND_H_
+#include "mcld/Target/GNULDBackend.h"
#include "MipsELFDynamic.h"
#include "MipsGOT.h"
#include "MipsGOTPLT.h"
@@ -17,20 +17,19 @@
namespace mcld {
class LinkerConfig;
-class OutputRelocSection;
-class SectionMap;
class MemoryArea;
class MipsGNUInfo;
+class OutputRelocSection;
+class SectionMap;
/** \class MipsGNULDBackend
* \brief Base linker backend of Mips target of GNU ELF format.
*/
-class MipsGNULDBackend : public GNULDBackend
-{
-public:
+class MipsGNULDBackend : public GNULDBackend {
+ public:
typedef std::vector<LDSymbol*> SymbolListType;
-public:
+ public:
MipsGNULDBackend(const LinkerConfig& pConfig, MipsGNUInfo* pInfo);
~MipsGNULDBackend();
@@ -39,7 +38,7 @@ public:
void addNonPICBranchSym(ResolveInfo* rsym);
bool hasNonPICBranch(const ResolveInfo* rsym) const;
-public:
+ public:
/// initTargetSections - initialize target dependent sections in output
void initTargetSections(Module& pModule, ObjectBuilder& pBuilder);
@@ -105,13 +104,13 @@ public:
OutputRelocSection& getRelDyn();
const OutputRelocSection& getRelDyn() const;
- LDSymbol* getGOTSymbol() { return m_pGOTSymbol; }
- const LDSymbol* getGOTSymbol() const { return m_pGOTSymbol; }
+ LDSymbol* getGOTSymbol() { return m_pGOTSymbol; }
+ const LDSymbol* getGOTSymbol() const { return m_pGOTSymbol; }
- LDSymbol* getGpDispSymbol() { return m_pGpDispSymbol; }
- const LDSymbol* getGpDispSymbol() const { return m_pGpDispSymbol; }
+ LDSymbol* getGpDispSymbol() { return m_pGpDispSymbol; }
+ const LDSymbol* getGpDispSymbol() const { return m_pGpDispSymbol; }
- SymbolListType& getGlobalGOTSyms() { return m_GlobalGOTSyms; }
+ SymbolListType& getGlobalGOTSyms() { return m_GlobalGOTSyms; }
const SymbolListType& getGlobalGOTSyms() const { return m_GlobalGOTSyms; }
/// getTargetSectionOrder - compute the layout order of ARM target sections
@@ -128,7 +127,7 @@ public:
/// in the specified input.
uint64_t getGP0(const Input& pInput) const;
-private:
+ private:
void defineGOTSymbol(IRBuilder& pBuilder);
void defineGOTPLTSymbol(IRBuilder& pBuilder);
@@ -209,21 +208,21 @@ private:
uint64_t pOffset,
int64_t pAddend) const;
-private:
+ private:
typedef llvm::DenseSet<const ResolveInfo*> ResolveInfoSetType;
typedef llvm::DenseMap<const Input*, llvm::ELF::Elf64_Addr> GP0MapType;
-protected:
+ protected:
Relocator* m_pRelocator;
- MipsGOT* m_pGOT; // .got
- MipsPLT* m_pPLT; // .plt
- MipsGOTPLT* m_pGOTPLT; // .got.plt
+ MipsGOT* m_pGOT; // .got
+ MipsPLT* m_pPLT; // .plt
+ MipsGOTPLT* m_pGOTPLT; // .got.plt
-private:
+ private:
MipsGNUInfo& m_pInfo;
- OutputRelocSection* m_pRelPlt; // .rel.plt
- OutputRelocSection* m_pRelDyn; // .rel.dyn
+ OutputRelocSection* m_pRelPlt; // .rel.plt
+ OutputRelocSection* m_pRelDyn; // .rel.dyn
MipsELFDynamic* m_pDynamic;
LDSymbol* m_pGOTSymbol;
@@ -238,12 +237,11 @@ private:
/** \class Mips32GNULDBackend
* \brief Base linker backend of Mips 32-bit target of GNU ELF format.
*/
-class Mips32GNULDBackend : public MipsGNULDBackend
-{
-public:
+class Mips32GNULDBackend : public MipsGNULDBackend {
+ public:
Mips32GNULDBackend(const LinkerConfig& pConfig, MipsGNUInfo* pInfo);
-private:
+ private:
// MipsGNULDBackend
bool initRelocator();
@@ -255,12 +253,11 @@ private:
/** \class Mips64GNULDBackend
* \brief Base linker backend of Mips 64-bit target of GNU ELF format.
*/
-class Mips64GNULDBackend : public MipsGNULDBackend
-{
-public:
+class Mips64GNULDBackend : public MipsGNULDBackend {
+ public:
Mips64GNULDBackend(const LinkerConfig& pConfig, MipsGNUInfo* pInfo);
-private:
+ private:
// MipsGNULDBackend
bool initRelocator();
@@ -269,6 +266,6 @@ private:
size_t getRelaEntrySize();
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSLDBACKEND_H_
diff --git a/lib/Target/Mips/MipsMCLinker.cpp b/lib/Target/Mips/MipsMCLinker.cpp
deleted file mode 100644
index 49940b7..0000000
--- a/lib/Target/Mips/MipsMCLinker.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-//===- MipsMCLinker.cpp ---------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "Mips.h"
-#include "MipsELFMCLinker.h"
-#include <llvm/ADT/Triple.h>
-#include <mcld/Module.h>
-#include <mcld/Support/TargetRegistry.h>
-
-namespace {
-
-//===----------------------------------------------------------------------===//
-/// createMipsMCLinker - the help funtion to create corresponding MipsMCLinker
-//===----------------------------------------------------------------------===//
-mcld::MCLinker* createMipsMCLinker(const std::string &pTriple,
- mcld::LinkerConfig& pConfig,
- mcld::Module& pModule,
- mcld::FileHandle& pFileHandle)
-{
- llvm::Triple theTriple(pTriple);
- if (theTriple.isOSDarwin()) {
- assert(0 && "MachO linker has not supported yet");
- return NULL;
- }
- if (theTriple.isOSWindows()) {
- assert(0 && "COFF linker has not supported yet");
- return NULL;
- }
-
- return new mcld::MipsELFMCLinker(pConfig, pModule, pFileHandle);
-}
-
-} // namespace of mcld
-
-//===----------------------------------------------------------------------===//
-// MipsMCLinker
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeMipsMCLinker() {
- mcld::TargetRegistry::RegisterMCLinker(mcld::TheMipselTarget,
- createMipsMCLinker);
- mcld::TargetRegistry::RegisterMCLinker(mcld::TheMips64elTarget,
- createMipsMCLinker);
-}
diff --git a/lib/Target/Mips/MipsPLT.cpp b/lib/Target/Mips/MipsPLT.cpp
index 81c05c0..aef25f9 100644
--- a/lib/Target/Mips/MipsPLT.cpp
+++ b/lib/Target/Mips/MipsPLT.cpp
@@ -8,70 +8,60 @@
//===----------------------------------------------------------------------===//
#include <llvm/Support/Casting.h>
#include <llvm/Support/ELF.h>
-#include <mcld/Support/MsgHandling.h>
+#include "mcld/Support/MsgHandling.h"
#include "MipsGOTPLT.h"
#include "MipsPLT.h"
namespace {
const uint32_t PLT0[] = {
- 0x3c1c0000, // lui $28, %hi(&GOTPLT[0])
- 0x8f990000, // lw $25, %lo(&GOTPLT[0])($28)
- 0x279c0000, // addiu $28, $28, %lo(&GOTPLT[0])
- 0x031cc023, // subu $24, $24, $28
- 0x03e07821, // move $15, $31
- 0x0018c082, // srl $24, $24, 2
- 0x0320f809, // jalr $25
- 0x2718fffe // subu $24, $24, 2
+ 0x3c1c0000, // lui $28, %hi(&GOTPLT[0])
+ 0x8f990000, // lw $25, %lo(&GOTPLT[0])($28)
+ 0x279c0000, // addiu $28, $28, %lo(&GOTPLT[0])
+ 0x031cc023, // subu $24, $24, $28
+ 0x03e07821, // move $15, $31
+ 0x0018c082, // srl $24, $24, 2
+ 0x0320f809, // jalr $25
+ 0x2718fffe // subu $24, $24, 2
};
const uint32_t PLTA[] = {
- 0x3c0f0000, // lui $15, %hi(.got.plt entry)
- 0x8df90000, // l[wd] $25, %lo(.got.plt entry)($15)
- 0x03200008, // jr $25
- 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
+ 0x3c0f0000, // lui $15, %hi(.got.plt entry)
+ 0x8df90000, // l[wd] $25, %lo(.got.plt entry)($15)
+ 0x03200008, // jr $25
+ 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
};
-}
+} // anonymous namespace
namespace mcld {
//===----------------------------------------------------------------------===//
// MipsPLT0 Entry
//===----------------------------------------------------------------------===//
-class MipsPLT0 : public PLT::Entry<sizeof(PLT0)>
-{
-public:
- MipsPLT0(SectionData& pParent)
- : PLT::Entry<sizeof(PLT0)>(pParent)
- {}
+class MipsPLT0 : public PLT::Entry<sizeof(PLT0)> {
+ public:
+ MipsPLT0(SectionData& pParent) : PLT::Entry<sizeof(PLT0)>(pParent) {}
};
//===----------------------------------------------------------------------===//
// MipsPLTA Entry
//===----------------------------------------------------------------------===//
-class MipsPLTA : public PLT::Entry<sizeof(PLTA)>
-{
-public:
- MipsPLTA(SectionData& pParent)
- : PLT::Entry<sizeof(PLTA)>(pParent)
- {}
+class MipsPLTA : public PLT::Entry<sizeof(PLTA)> {
+ public:
+ MipsPLTA(SectionData& pParent) : PLT::Entry<sizeof(PLTA)>(pParent) {}
};
//===----------------------------------------------------------------------===//
// MipsPLT
//===----------------------------------------------------------------------===//
-MipsPLT::MipsPLT(LDSection& pSection)
- : PLT(pSection)
-{
+MipsPLT::MipsPLT(LDSection& pSection) : PLT(pSection) {
new MipsPLT0(*m_pSectionData);
m_Last = m_pSectionData->begin();
}
-void MipsPLT::finalizeSectionSize()
-{
- uint64_t size = sizeof(PLT0) +
- (m_pSectionData->size() - 1) * sizeof(PLTA);
+void MipsPLT::finalizeSectionSize() {
+ uint64_t size = sizeof(PLT0) + (m_pSectionData->size() - 1) * sizeof(PLTA);
m_Section.setSize(size);
uint32_t offset = 0;
@@ -82,13 +72,11 @@ void MipsPLT::finalizeSectionSize()
}
}
-bool MipsPLT::hasPLT1() const
-{
+bool MipsPLT::hasPLT1() const {
return m_pSectionData->size() > 1;
}
-uint64_t MipsPLT::emit(MemoryRegion& pRegion)
-{
+uint64_t MipsPLT::emit(MemoryRegion& pRegion) {
uint64_t result = 0x0;
iterator it = begin();
@@ -106,30 +94,28 @@ uint64_t MipsPLT::emit(MemoryRegion& pRegion)
return result;
}
-void MipsPLT::reserveEntry(size_t pNum)
-{
+void MipsPLT::reserveEntry(size_t pNum) {
for (size_t i = 0; i < pNum; ++i) {
Fragment* entry = new (std::nothrow) MipsPLTA(*m_pSectionData);
- if (NULL == entry)
+ if (entry == NULL)
fatal(diag::fail_allocate_memory_plt);
}
}
-Fragment* MipsPLT::consume()
-{
+Fragment* MipsPLT::consume() {
++m_Last;
assert(m_Last != m_pSectionData->end() &&
"The number of PLT Entries and ResolveInfo doesn't match");
return &(*m_Last);
}
-void MipsPLT::applyAllPLT(MipsGOTPLT& pGOTPLT)
-{
+void MipsPLT::applyAllPLT(MipsGOTPLT& pGOTPLT) {
assert(m_Section.addr() && ".plt base address is NULL!");
size_t count = 0;
- for (iterator it = m_pSectionData->begin(); it != m_pSectionData->end(); ++it) {
+ for (iterator it = m_pSectionData->begin(); it != m_pSectionData->end();
+ ++it) {
PLTEntryBase* plt = &(llvm::cast<PLTEntryBase>(*it));
if (it == m_pSectionData->begin()) {
@@ -166,4 +152,4 @@ void MipsPLT::applyAllPLT(MipsGOTPLT& pGOTPLT)
}
}
-} //end mcld namespace
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsPLT.h b/lib/Target/Mips/MipsPLT.h
index a1d1b4a..7c26b8e 100644
--- a/lib/Target/Mips/MipsPLT.h
+++ b/lib/Target/Mips/MipsPLT.h
@@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSPLT_H
-#define TARGET_MIPS_MIPSPLT_H
+#ifndef TARGET_MIPS_MIPSPLT_H_
+#define TARGET_MIPS_MIPSPLT_H_
-#include <mcld/Target/PLT.h>
-#include <mcld/Support/MemoryRegion.h>
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Target/PLT.h"
namespace mcld {
@@ -22,10 +22,9 @@ class MipsGOTPLT;
/** \class MipsPLT
* \brief Mips Procedure Linkage Table
*/
-class MipsPLT : public PLT
-{
-public:
- MipsPLT(LDSection& pSection);
+class MipsPLT : public PLT {
+ public:
+ explicit MipsPLT(LDSection& pSection);
// hasPLT1 - return if this PLT has any PLTA/PLTB entries
bool hasPLT1() const;
@@ -36,16 +35,16 @@ public:
void applyAllPLT(MipsGOTPLT& pGOTPLT);
-public:
+ public:
// PLT
void reserveEntry(size_t pNum = 1);
void finalizeSectionSize();
-private:
+ private:
// the last consumed entry.
SectionData::iterator m_Last;
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSPLT_H_
diff --git a/lib/Target/Mips/MipsRelocationFunctions.h b/lib/Target/Mips/MipsRelocationFunctions.h
index 3634686..06c9a0e 100644
--- a/lib/Target/Mips/MipsRelocationFunctions.h
+++ b/lib/Target/Mips/MipsRelocationFunctions.h
@@ -6,287 +6,291 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_MIPS_MIPSRELOCATIONFUNCTIONS_H_
+#define TARGET_MIPS_MIPSRELOCATIONFUNCTIONS_H_
-#define DECL_MIPS_APPLY_RELOC_FUNC(Name) \
-static MipsRelocator::Result Name(MipsRelocationInfo& pReloc, \
- MipsRelocator& pParent);
+#define DECL_MIPS_APPLY_RELOC_FUNC(Name) \
+ static MipsRelocator::Result Name(MipsRelocationInfo& pReloc, \
+ MipsRelocator& pParent);
-#define DECL_MIPS_APPLY_RELOC_FUNCS \
-DECL_MIPS_APPLY_RELOC_FUNC(none) \
-DECL_MIPS_APPLY_RELOC_FUNC(abs32) \
-DECL_MIPS_APPLY_RELOC_FUNC(rel26) \
-DECL_MIPS_APPLY_RELOC_FUNC(hi16) \
-DECL_MIPS_APPLY_RELOC_FUNC(lo16) \
-DECL_MIPS_APPLY_RELOC_FUNC(gprel16) \
-DECL_MIPS_APPLY_RELOC_FUNC(got16) \
-DECL_MIPS_APPLY_RELOC_FUNC(call16) \
-DECL_MIPS_APPLY_RELOC_FUNC(gprel32) \
-DECL_MIPS_APPLY_RELOC_FUNC(abs64) \
-DECL_MIPS_APPLY_RELOC_FUNC(gotdisp) \
-DECL_MIPS_APPLY_RELOC_FUNC(gotoff) \
-DECL_MIPS_APPLY_RELOC_FUNC(gothi16) \
-DECL_MIPS_APPLY_RELOC_FUNC(gotlo16) \
-DECL_MIPS_APPLY_RELOC_FUNC(sub) \
-DECL_MIPS_APPLY_RELOC_FUNC(jalr) \
-DECL_MIPS_APPLY_RELOC_FUNC(la25lui) \
-DECL_MIPS_APPLY_RELOC_FUNC(la25j) \
-DECL_MIPS_APPLY_RELOC_FUNC(la25add) \
-DECL_MIPS_APPLY_RELOC_FUNC(pc32) \
-DECL_MIPS_APPLY_RELOC_FUNC(unsupport)
+#define DECL_MIPS_APPLY_RELOC_FUNCS \
+ DECL_MIPS_APPLY_RELOC_FUNC(none) \
+ DECL_MIPS_APPLY_RELOC_FUNC(abs32) \
+ DECL_MIPS_APPLY_RELOC_FUNC(rel26) \
+ DECL_MIPS_APPLY_RELOC_FUNC(hi16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(lo16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(gprel16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(got16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(call16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(gprel32) \
+ DECL_MIPS_APPLY_RELOC_FUNC(abs64) \
+ DECL_MIPS_APPLY_RELOC_FUNC(gotdisp) \
+ DECL_MIPS_APPLY_RELOC_FUNC(gotoff) \
+ DECL_MIPS_APPLY_RELOC_FUNC(gothi16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(gotlo16) \
+ DECL_MIPS_APPLY_RELOC_FUNC(sub) \
+ DECL_MIPS_APPLY_RELOC_FUNC(jalr) \
+ DECL_MIPS_APPLY_RELOC_FUNC(la25lui) \
+ DECL_MIPS_APPLY_RELOC_FUNC(la25j) \
+ DECL_MIPS_APPLY_RELOC_FUNC(la25add) \
+ DECL_MIPS_APPLY_RELOC_FUNC(pc32) \
+ DECL_MIPS_APPLY_RELOC_FUNC(unsupported)
#define DECL_MIPS_APPLY_RELOC_FUNC_PTRS \
- { &none, 0, "R_MIPS_NONE", 0}, \
- { &unsupport, 1, "R_MIPS_16", 16}, \
- { &abs32, 2, "R_MIPS_32", 32}, \
- { &unsupport, 3, "R_MIPS_REL32", 32}, \
- { &rel26, 4, "R_MIPS_26", 26}, \
- { &hi16, 5, "R_MIPS_HI16", 16}, \
- { &lo16, 6, "R_MIPS_LO16", 16}, \
- { &gprel16, 7, "R_MIPS_GPREL16", 16}, \
- { &unsupport, 8, "R_MIPS_LITERAL", 16}, \
- { &got16, 9, "R_MIPS_GOT16", 16}, \
- { &unsupport, 10, "R_MIPS_PC16", 16}, \
- { &call16, 11, "R_MIPS_CALL16", 16}, \
- { &gprel32, 12, "R_MIPS_GPREL32", 32}, \
- { &none, 13, "R_MIPS_UNUSED1", 0}, \
- { &none, 14, "R_MIPS_UNUSED2", 0}, \
- { &none, 15, "R_MIPS_UNUSED3", 0}, \
- { &unsupport, 16, "R_MIPS_SHIFT5", 32}, \
- { &unsupport, 17, "R_MIPS_SHIFT6", 32}, \
- { &abs64, 18, "R_MIPS_64", 64}, \
- { &gotdisp, 19, "R_MIPS_GOT_DISP", 16}, \
- { &gotdisp, 20, "R_MIPS_GOT_PAGE", 16}, \
- { &gotoff, 21, "R_MIPS_GOT_OFST", 16}, \
- { &gothi16, 22, "R_MIPS_GOT_HI16", 16}, \
- { &gotlo16, 23, "R_MIPS_GOT_LO16", 16}, \
- { &sub, 24, "R_MIPS_SUB", 64}, \
- { &unsupport, 25, "R_MIPS_INSERT_A", 0}, \
- { &unsupport, 26, "R_MIPS_INSERT_B", 0}, \
- { &unsupport, 27, "R_MIPS_DELETE", 0}, \
- { &unsupport, 28, "R_MIPS_HIGHER", 16}, \
- { &unsupport, 29, "R_MIPS_HIGHEST", 16}, \
- { &gothi16, 30, "R_MIPS_CALL_HI16", 16}, \
- { &gotlo16, 31, "R_MIPS_CALL_LO16", 16}, \
- { &unsupport, 32, "R_MIPS_SCN_DISP", 32}, \
- { &unsupport, 33, "R_MIPS_REL16", 0}, \
- { &unsupport, 34, "R_MIPS_ADD_IMMEDIATE", 0}, \
- { &unsupport, 35, "R_MIPS_PJUMP", 0}, \
- { &unsupport, 36, "R_MIPS_RELGOT", 0}, \
- { &jalr, 37, "R_MIPS_JALR", 32}, \
- { &unsupport, 38, "R_MIPS_TLS_DTPMOD32", 32}, \
- { &unsupport, 39, "R_MIPS_TLS_DTPREL32", 32}, \
- { &unsupport, 40, "R_MIPS_TLS_DTPMOD64", 0}, \
- { &unsupport, 41, "R_MIPS_TLS_DTPREL64", 0}, \
- { &unsupport, 42, "R_MIPS_TLS_GD", 16}, \
- { &unsupport, 43, "R_MIPS_TLS_LDM", 16}, \
- { &unsupport, 44, "R_MIPS_TLS_DTPREL_HI16", 16}, \
- { &unsupport, 45, "R_MIPS_TLS_DTPREL_LO16", 16}, \
- { &unsupport, 46, "R_MIPS_TLS_GOTTPREL", 16}, \
- { &unsupport, 47, "R_MIPS_TLS_TPREL32", 32}, \
- { &unsupport, 48, "R_MIPS_TLS_TPREL64", 0}, \
- { &unsupport, 49, "R_MIPS_TLS_TPREL_HI16", 16}, \
- { &unsupport, 50, "R_MIPS_TLS_TPREL_LO16", 16}, \
- { &unsupport, 51, "R_MIPS_GLOB_DAT", 0}, \
- { &unsupport, 52, "", 0}, \
- { &unsupport, 53, "", 0}, \
- { &unsupport, 54, "", 0}, \
- { &unsupport, 55, "", 0}, \
- { &unsupport, 56, "", 0}, \
- { &unsupport, 57, "", 0}, \
- { &unsupport, 58, "", 0}, \
- { &unsupport, 59, "", 0}, \
- { &unsupport, 60, "", 0}, \
- { &unsupport, 61, "", 0}, \
- { &unsupport, 62, "", 0}, \
- { &unsupport, 63, "", 0}, \
- { &unsupport, 64, "", 0}, \
- { &unsupport, 65, "", 0}, \
- { &unsupport, 66, "", 0}, \
- { &unsupport, 67, "", 0}, \
- { &unsupport, 68, "", 0}, \
- { &unsupport, 69, "", 0}, \
- { &unsupport, 70, "", 0}, \
- { &unsupport, 71, "", 0}, \
- { &unsupport, 72, "", 0}, \
- { &unsupport, 73, "", 0}, \
- { &unsupport, 74, "", 0}, \
- { &unsupport, 75, "", 0}, \
- { &unsupport, 76, "", 0}, \
- { &unsupport, 77, "", 0}, \
- { &unsupport, 78, "", 0}, \
- { &unsupport, 79, "", 0}, \
- { &unsupport, 80, "", 0}, \
- { &unsupport, 81, "", 0}, \
- { &unsupport, 82, "", 0}, \
- { &unsupport, 83, "", 0}, \
- { &unsupport, 84, "", 0}, \
- { &unsupport, 85, "", 0}, \
- { &unsupport, 86, "", 0}, \
- { &unsupport, 87, "", 0}, \
- { &unsupport, 88, "", 0}, \
- { &unsupport, 89, "", 0}, \
- { &unsupport, 90, "", 0}, \
- { &unsupport, 91, "", 0}, \
- { &unsupport, 92, "", 0}, \
- { &unsupport, 93, "", 0}, \
- { &unsupport, 94, "", 0}, \
- { &unsupport, 95, "", 0}, \
- { &unsupport, 96, "", 0}, \
- { &unsupport, 97, "", 0}, \
- { &unsupport, 98, "", 0}, \
- { &unsupport, 99, "", 0}, \
- { &unsupport, 100, "R_MIPS16_26", 0}, \
- { &unsupport, 101, "R_MIPS16_GPREL", 0}, \
- { &unsupport, 102, "R_MIPS16_GOT16", 0}, \
- { &unsupport, 103, "R_MIPS16_CALL16", 0}, \
- { &unsupport, 104, "R_MIPS16_HI16", 0}, \
- { &unsupport, 105, "R_MIPS16_LO16", 0}, \
- { &unsupport, 106, "R_MIPS16_TLS_GD", 0}, \
- { &unsupport, 107, "R_MIPS16_TLS_LDM", 0}, \
- { &unsupport, 108, "R_MIPS16_TLS_DTPREL_HI16", 0}, \
- { &unsupport, 109, "R_MIPS16_TLS_DTPREL_LO16", 0}, \
- { &unsupport, 110, "R_MIPS16_TLS_GOTTPREL", 0}, \
- { &unsupport, 111, "R_MIPS16_TLS_TPREL_HI16", 0}, \
- { &unsupport, 112, "R_MIPS16_TLS_TPREL_LO16", 0}, \
- { &unsupport, 113, "", 0}, \
- { &unsupport, 114, "", 0}, \
- { &unsupport, 115, "", 0}, \
- { &unsupport, 116, "", 0}, \
- { &unsupport, 117, "", 0}, \
- { &unsupport, 118, "", 0}, \
- { &unsupport, 119, "", 0}, \
- { &unsupport, 120, "", 0}, \
- { &unsupport, 121, "", 0}, \
- { &unsupport, 122, "", 0}, \
- { &unsupport, 123, "", 0}, \
- { &unsupport, 124, "", 0}, \
- { &unsupport, 125, "", 0}, \
- { &unsupport, 126, "R_MIPS_COPY", 0}, \
- { &unsupport, 127, "R_MIPS_JUMP_SLOT", 0}, \
- { &unsupport, 128, "", 0}, \
- { &unsupport, 129, "", 0}, \
- { &unsupport, 130, "", 0}, \
- { &unsupport, 131, "", 0}, \
- { &unsupport, 132, "", 0}, \
- { &unsupport, 133, "R_MICROMIPS_26_S1", 0}, \
- { &unsupport, 134, "R_MICROMIPS_HI16", 0}, \
- { &unsupport, 135, "R_MICROMIPS_LO16", 0}, \
- { &unsupport, 136, "R_MICROMIPS_GPREL16", 0}, \
- { &unsupport, 137, "R_MICROMIPS_LITERAL", 0}, \
- { &unsupport, 138, "R_MICROMIPS_GOT16", 0}, \
- { &unsupport, 139, "R_MICROMIPS_PC7_S1", 0}, \
- { &unsupport, 140, "R_MICROMIPS_PC10_S1", 0}, \
- { &unsupport, 141, "R_MICROMIPS_PC16_S1", 0}, \
- { &unsupport, 142, "R_MICROMIPS_CALL16", 0}, \
- { &unsupport, 143, "R_MICROMIPS_GOT_DISP", 0}, \
- { &unsupport, 144, "R_MICROMIPS_GOT_PAGE", 0}, \
- { &unsupport, 145, "R_MICROMIPS_GOT_OFST", 0}, \
- { &unsupport, 146, "R_MICROMIPS_GOT_HI16", 0}, \
- { &unsupport, 147, "R_MICROMIPS_GOT_LO16", 0}, \
- { &unsupport, 148, "R_MICROMIPS_SUB", 0}, \
- { &unsupport, 149, "R_MICROMIPS_HIGHER", 0}, \
- { &unsupport, 150, "R_MICROMIPS_HIGHEST", 0}, \
- { &unsupport, 151, "R_MICROMIPS_CALL_HI16", 0}, \
- { &unsupport, 152, "R_MICROMIPS_CALL_LO16", 0}, \
- { &unsupport, 153, "R_MICROMIPS_SCN_DISP", 0}, \
- { &unsupport, 154, "R_MICROMIPS_JALR", 0}, \
- { &unsupport, 155, "R_MICROMIPS_HI0_LO16", 0}, \
- { &unsupport, 156, "", 0}, \
- { &unsupport, 157, "", 0}, \
- { &unsupport, 158, "", 0}, \
- { &unsupport, 159, "", 0}, \
- { &unsupport, 160, "", 0}, \
- { &unsupport, 161, "", 0}, \
- { &unsupport, 162, "R_MICROMIPS_TLS_GD", 0}, \
- { &unsupport, 163, "R_MICROMIPS_TLS_LDM", 0}, \
- { &unsupport, 164, "R_MICROMIPS_TLS_DTPREL_HI16", 0}, \
- { &unsupport, 165, "R_MICROMIPS_TLS_DTPREL_LO16", 0}, \
- { &unsupport, 166, "R_MICROMIPS_TLS_GOTTPREL", 0}, \
- { &unsupport, 167, "", 0}, \
- { &unsupport, 168, "", 0}, \
- { &unsupport, 169, "R_MICROMIPS_TLS_TPREL_HI16", 0}, \
- { &unsupport, 170, "R_MICROMIPS_TLS_TPREL_LO16", 0}, \
- { &unsupport, 171, "", 0}, \
- { &unsupport, 172, "R_MICROMIPS_GPREL7_S2", 0}, \
- { &unsupport, 173, "R_MICROMIPS_PC23_S2", 0}, \
- { &unsupport, 174, "", 0}, \
- { &unsupport, 175, "", 0}, \
- { &unsupport, 176, "", 0}, \
- { &unsupport, 177, "", 0}, \
- { &unsupport, 178, "", 0}, \
- { &unsupport, 179, "", 0}, \
- { &unsupport, 180, "", 0}, \
- { &unsupport, 181, "", 0}, \
- { &unsupport, 182, "", 0}, \
- { &unsupport, 183, "", 0}, \
- { &unsupport, 184, "", 0}, \
- { &unsupport, 185, "", 0}, \
- { &unsupport, 186, "", 0}, \
- { &unsupport, 187, "", 0}, \
- { &unsupport, 188, "", 0}, \
- { &unsupport, 189, "", 0}, \
- { &unsupport, 190, "", 0}, \
- { &unsupport, 191, "", 0}, \
- { &unsupport, 192, "", 0}, \
- { &unsupport, 193, "", 0}, \
- { &unsupport, 194, "", 0}, \
- { &unsupport, 195, "", 0}, \
- { &unsupport, 196, "", 0}, \
- { &unsupport, 197, "", 0}, \
- { &unsupport, 198, "", 0}, \
- { &unsupport, 199, "", 0}, \
- { &la25lui, 200, "R_MIPS_LA25_LUI", 16}, \
- { &la25j, 201, "R_MIPS_LA25_J", 26}, \
- { &la25add, 202, "R_MIPS_LA25_ADD", 16}, \
- { &unsupport, 203, "", 0}, \
- { &unsupport, 204, "", 0}, \
- { &unsupport, 205, "", 0}, \
- { &unsupport, 206, "", 0}, \
- { &unsupport, 207, "", 0}, \
- { &unsupport, 208, "", 0}, \
- { &unsupport, 209, "", 0}, \
- { &unsupport, 210, "", 0}, \
- { &unsupport, 211, "", 0}, \
- { &unsupport, 212, "", 0}, \
- { &unsupport, 213, "", 0}, \
- { &unsupport, 214, "", 0}, \
- { &unsupport, 215, "", 0}, \
- { &unsupport, 216, "", 0}, \
- { &unsupport, 217, "", 0}, \
- { &unsupport, 218, "", 0}, \
- { &unsupport, 219, "", 0}, \
- { &unsupport, 220, "", 0}, \
- { &unsupport, 221, "", 0}, \
- { &unsupport, 222, "", 0}, \
- { &unsupport, 223, "", 0}, \
- { &unsupport, 224, "", 0}, \
- { &unsupport, 225, "", 0}, \
- { &unsupport, 226, "", 0}, \
- { &unsupport, 227, "", 0}, \
- { &unsupport, 228, "", 0}, \
- { &unsupport, 229, "", 0}, \
- { &unsupport, 230, "", 0}, \
- { &unsupport, 231, "", 0}, \
- { &unsupport, 232, "", 0}, \
- { &unsupport, 233, "", 0}, \
- { &unsupport, 234, "", 0}, \
- { &unsupport, 235, "", 0}, \
- { &unsupport, 236, "", 0}, \
- { &unsupport, 237, "", 0}, \
- { &unsupport, 238, "", 0}, \
- { &unsupport, 239, "", 0}, \
- { &unsupport, 240, "", 0}, \
- { &unsupport, 241, "", 0}, \
- { &unsupport, 242, "", 0}, \
- { &unsupport, 243, "", 0}, \
- { &unsupport, 244, "", 0}, \
- { &unsupport, 245, "", 0}, \
- { &unsupport, 246, "", 0}, \
- { &unsupport, 247, "", 0}, \
- { &pc32, 248, "R_MIPS_PC32", 0}, \
- { &unsupport, 249, "", 0}, \
- { &unsupport, 250, "R_MIPS_GNU_REL16_S2", 0}, \
- { &unsupport, 251, "", 0}, \
- { &unsupport, 252, "", 0}, \
- { &unsupport, 253, "R_MIPS_GNU_VTINHERIT", 0}, \
- { &unsupport, 254, "R_MIPS_GNU_VTENTRY", 0}
+ { &none, 0, "R_MIPS_NONE", 0}, \
+ { &unsupported, 1, "R_MIPS_16", 16}, \
+ { &abs32, 2, "R_MIPS_32", 32}, \
+ { &unsupported, 3, "R_MIPS_REL32", 32}, \
+ { &rel26, 4, "R_MIPS_26", 26}, \
+ { &hi16, 5, "R_MIPS_HI16", 16}, \
+ { &lo16, 6, "R_MIPS_LO16", 16}, \
+ { &gprel16, 7, "R_MIPS_GPREL16", 16}, \
+ { &unsupported, 8, "R_MIPS_LITERAL", 16}, \
+ { &got16, 9, "R_MIPS_GOT16", 16}, \
+ { &unsupported, 10, "R_MIPS_PC16", 16}, \
+ { &call16, 11, "R_MIPS_CALL16", 16}, \
+ { &gprel32, 12, "R_MIPS_GPREL32", 32}, \
+ { &none, 13, "R_MIPS_UNUSED1", 0}, \
+ { &none, 14, "R_MIPS_UNUSED2", 0}, \
+ { &none, 15, "R_MIPS_UNUSED3", 0}, \
+ { &unsupported, 16, "R_MIPS_SHIFT5", 32}, \
+ { &unsupported, 17, "R_MIPS_SHIFT6", 32}, \
+ { &abs64, 18, "R_MIPS_64", 64}, \
+ { &gotdisp, 19, "R_MIPS_GOT_DISP", 16}, \
+ { &gotdisp, 20, "R_MIPS_GOT_PAGE", 16}, \
+ { &gotoff, 21, "R_MIPS_GOT_OFST", 16}, \
+ { &gothi16, 22, "R_MIPS_GOT_HI16", 16}, \
+ { &gotlo16, 23, "R_MIPS_GOT_LO16", 16}, \
+ { &sub, 24, "R_MIPS_SUB", 64}, \
+ { &unsupported, 25, "R_MIPS_INSERT_A", 0}, \
+ { &unsupported, 26, "R_MIPS_INSERT_B", 0}, \
+ { &unsupported, 27, "R_MIPS_DELETE", 0}, \
+ { &unsupported, 28, "R_MIPS_HIGHER", 16}, \
+ { &unsupported, 29, "R_MIPS_HIGHEST", 16}, \
+ { &gothi16, 30, "R_MIPS_CALL_HI16", 16}, \
+ { &gotlo16, 31, "R_MIPS_CALL_LO16", 16}, \
+ { &unsupported, 32, "R_MIPS_SCN_DISP", 32}, \
+ { &unsupported, 33, "R_MIPS_REL16", 0}, \
+ { &unsupported, 34, "R_MIPS_ADD_IMMEDIATE", 0}, \
+ { &unsupported, 35, "R_MIPS_PJUMP", 0}, \
+ { &unsupported, 36, "R_MIPS_RELGOT", 0}, \
+ { &jalr, 37, "R_MIPS_JALR", 32}, \
+ { &unsupported, 38, "R_MIPS_TLS_DTPMOD32", 32}, \
+ { &unsupported, 39, "R_MIPS_TLS_DTPREL32", 32}, \
+ { &unsupported, 40, "R_MIPS_TLS_DTPMOD64", 0}, \
+ { &unsupported, 41, "R_MIPS_TLS_DTPREL64", 0}, \
+ { &unsupported, 42, "R_MIPS_TLS_GD", 16}, \
+ { &unsupported, 43, "R_MIPS_TLS_LDM", 16}, \
+ { &unsupported, 44, "R_MIPS_TLS_DTPREL_HI16", 16}, \
+ { &unsupported, 45, "R_MIPS_TLS_DTPREL_LO16", 16}, \
+ { &unsupported, 46, "R_MIPS_TLS_GOTTPREL", 16}, \
+ { &unsupported, 47, "R_MIPS_TLS_TPREL32", 32}, \
+ { &unsupported, 48, "R_MIPS_TLS_TPREL64", 0}, \
+ { &unsupported, 49, "R_MIPS_TLS_TPREL_HI16", 16}, \
+ { &unsupported, 50, "R_MIPS_TLS_TPREL_LO16", 16}, \
+ { &unsupported, 51, "R_MIPS_GLOB_DAT", 0}, \
+ { &unsupported, 52, "", 0}, \
+ { &unsupported, 53, "", 0}, \
+ { &unsupported, 54, "", 0}, \
+ { &unsupported, 55, "", 0}, \
+ { &unsupported, 56, "", 0}, \
+ { &unsupported, 57, "", 0}, \
+ { &unsupported, 58, "", 0}, \
+ { &unsupported, 59, "", 0}, \
+ { &unsupported, 60, "", 0}, \
+ { &unsupported, 61, "", 0}, \
+ { &unsupported, 62, "", 0}, \
+ { &unsupported, 63, "", 0}, \
+ { &unsupported, 64, "", 0}, \
+ { &unsupported, 65, "", 0}, \
+ { &unsupported, 66, "", 0}, \
+ { &unsupported, 67, "", 0}, \
+ { &unsupported, 68, "", 0}, \
+ { &unsupported, 69, "", 0}, \
+ { &unsupported, 70, "", 0}, \
+ { &unsupported, 71, "", 0}, \
+ { &unsupported, 72, "", 0}, \
+ { &unsupported, 73, "", 0}, \
+ { &unsupported, 74, "", 0}, \
+ { &unsupported, 75, "", 0}, \
+ { &unsupported, 76, "", 0}, \
+ { &unsupported, 77, "", 0}, \
+ { &unsupported, 78, "", 0}, \
+ { &unsupported, 79, "", 0}, \
+ { &unsupported, 80, "", 0}, \
+ { &unsupported, 81, "", 0}, \
+ { &unsupported, 82, "", 0}, \
+ { &unsupported, 83, "", 0}, \
+ { &unsupported, 84, "", 0}, \
+ { &unsupported, 85, "", 0}, \
+ { &unsupported, 86, "", 0}, \
+ { &unsupported, 87, "", 0}, \
+ { &unsupported, 88, "", 0}, \
+ { &unsupported, 89, "", 0}, \
+ { &unsupported, 90, "", 0}, \
+ { &unsupported, 91, "", 0}, \
+ { &unsupported, 92, "", 0}, \
+ { &unsupported, 93, "", 0}, \
+ { &unsupported, 94, "", 0}, \
+ { &unsupported, 95, "", 0}, \
+ { &unsupported, 96, "", 0}, \
+ { &unsupported, 97, "", 0}, \
+ { &unsupported, 98, "", 0}, \
+ { &unsupported, 99, "", 0}, \
+ { &unsupported, 100, "R_MIPS16_26", 0}, \
+ { &unsupported, 101, "R_MIPS16_GPREL", 0}, \
+ { &unsupported, 102, "R_MIPS16_GOT16", 0}, \
+ { &unsupported, 103, "R_MIPS16_CALL16", 0}, \
+ { &unsupported, 104, "R_MIPS16_HI16", 0}, \
+ { &unsupported, 105, "R_MIPS16_LO16", 0}, \
+ { &unsupported, 106, "R_MIPS16_TLS_GD", 0}, \
+ { &unsupported, 107, "R_MIPS16_TLS_LDM", 0}, \
+ { &unsupported, 108, "R_MIPS16_TLS_DTPREL_HI16", 0}, \
+ { &unsupported, 109, "R_MIPS16_TLS_DTPREL_LO16", 0}, \
+ { &unsupported, 110, "R_MIPS16_TLS_GOTTPREL", 0}, \
+ { &unsupported, 111, "R_MIPS16_TLS_TPREL_HI16", 0}, \
+ { &unsupported, 112, "R_MIPS16_TLS_TPREL_LO16", 0}, \
+ { &unsupported, 113, "", 0}, \
+ { &unsupported, 114, "", 0}, \
+ { &unsupported, 115, "", 0}, \
+ { &unsupported, 116, "", 0}, \
+ { &unsupported, 117, "", 0}, \
+ { &unsupported, 118, "", 0}, \
+ { &unsupported, 119, "", 0}, \
+ { &unsupported, 120, "", 0}, \
+ { &unsupported, 121, "", 0}, \
+ { &unsupported, 122, "", 0}, \
+ { &unsupported, 123, "", 0}, \
+ { &unsupported, 124, "", 0}, \
+ { &unsupported, 125, "", 0}, \
+ { &unsupported, 126, "R_MIPS_COPY", 0}, \
+ { &unsupported, 127, "R_MIPS_JUMP_SLOT", 0}, \
+ { &unsupported, 128, "", 0}, \
+ { &unsupported, 129, "", 0}, \
+ { &unsupported, 130, "", 0}, \
+ { &unsupported, 131, "", 0}, \
+ { &unsupported, 132, "", 0}, \
+ { &unsupported, 133, "R_MICROMIPS_26_S1", 0}, \
+ { &unsupported, 134, "R_MICROMIPS_HI16", 0}, \
+ { &unsupported, 135, "R_MICROMIPS_LO16", 0}, \
+ { &unsupported, 136, "R_MICROMIPS_GPREL16", 0}, \
+ { &unsupported, 137, "R_MICROMIPS_LITERAL", 0}, \
+ { &unsupported, 138, "R_MICROMIPS_GOT16", 0}, \
+ { &unsupported, 139, "R_MICROMIPS_PC7_S1", 0}, \
+ { &unsupported, 140, "R_MICROMIPS_PC10_S1", 0}, \
+ { &unsupported, 141, "R_MICROMIPS_PC16_S1", 0}, \
+ { &unsupported, 142, "R_MICROMIPS_CALL16", 0}, \
+ { &unsupported, 143, "R_MICROMIPS_GOT_DISP", 0}, \
+ { &unsupported, 144, "R_MICROMIPS_GOT_PAGE", 0}, \
+ { &unsupported, 145, "R_MICROMIPS_GOT_OFST", 0}, \
+ { &unsupported, 146, "R_MICROMIPS_GOT_HI16", 0}, \
+ { &unsupported, 147, "R_MICROMIPS_GOT_LO16", 0}, \
+ { &unsupported, 148, "R_MICROMIPS_SUB", 0}, \
+ { &unsupported, 149, "R_MICROMIPS_HIGHER", 0}, \
+ { &unsupported, 150, "R_MICROMIPS_HIGHEST", 0}, \
+ { &unsupported, 151, "R_MICROMIPS_CALL_HI16", 0}, \
+ { &unsupported, 152, "R_MICROMIPS_CALL_LO16", 0}, \
+ { &unsupported, 153, "R_MICROMIPS_SCN_DISP", 0}, \
+ { &unsupported, 154, "R_MICROMIPS_JALR", 0}, \
+ { &unsupported, 155, "R_MICROMIPS_HI0_LO16", 0}, \
+ { &unsupported, 156, "", 0}, \
+ { &unsupported, 157, "", 0}, \
+ { &unsupported, 158, "", 0}, \
+ { &unsupported, 159, "", 0}, \
+ { &unsupported, 160, "", 0}, \
+ { &unsupported, 161, "", 0}, \
+ { &unsupported, 162, "R_MICROMIPS_TLS_GD", 0}, \
+ { &unsupported, 163, "R_MICROMIPS_TLS_LDM", 0}, \
+ { &unsupported, 164, "R_MICROMIPS_TLS_DTPREL_HI16", 0}, \
+ { &unsupported, 165, "R_MICROMIPS_TLS_DTPREL_LO16", 0}, \
+ { &unsupported, 166, "R_MICROMIPS_TLS_GOTTPREL", 0}, \
+ { &unsupported, 167, "", 0}, \
+ { &unsupported, 168, "", 0}, \
+ { &unsupported, 169, "R_MICROMIPS_TLS_TPREL_HI16", 0}, \
+ { &unsupported, 170, "R_MICROMIPS_TLS_TPREL_LO16", 0}, \
+ { &unsupported, 171, "", 0}, \
+ { &unsupported, 172, "R_MICROMIPS_GPREL7_S2", 0}, \
+ { &unsupported, 173, "R_MICROMIPS_PC23_S2", 0}, \
+ { &unsupported, 174, "", 0}, \
+ { &unsupported, 175, "", 0}, \
+ { &unsupported, 176, "", 0}, \
+ { &unsupported, 177, "", 0}, \
+ { &unsupported, 178, "", 0}, \
+ { &unsupported, 179, "", 0}, \
+ { &unsupported, 180, "", 0}, \
+ { &unsupported, 181, "", 0}, \
+ { &unsupported, 182, "", 0}, \
+ { &unsupported, 183, "", 0}, \
+ { &unsupported, 184, "", 0}, \
+ { &unsupported, 185, "", 0}, \
+ { &unsupported, 186, "", 0}, \
+ { &unsupported, 187, "", 0}, \
+ { &unsupported, 188, "", 0}, \
+ { &unsupported, 189, "", 0}, \
+ { &unsupported, 190, "", 0}, \
+ { &unsupported, 191, "", 0}, \
+ { &unsupported, 192, "", 0}, \
+ { &unsupported, 193, "", 0}, \
+ { &unsupported, 194, "", 0}, \
+ { &unsupported, 195, "", 0}, \
+ { &unsupported, 196, "", 0}, \
+ { &unsupported, 197, "", 0}, \
+ { &unsupported, 198, "", 0}, \
+ { &unsupported, 199, "", 0}, \
+ { &la25lui, 200, "R_MIPS_LA25_LUI", 16}, \
+ { &la25j, 201, "R_MIPS_LA25_J", 26}, \
+ { &la25add, 202, "R_MIPS_LA25_ADD", 16}, \
+ { &unsupported, 203, "", 0}, \
+ { &unsupported, 204, "", 0}, \
+ { &unsupported, 205, "", 0}, \
+ { &unsupported, 206, "", 0}, \
+ { &unsupported, 207, "", 0}, \
+ { &unsupported, 208, "", 0}, \
+ { &unsupported, 209, "", 0}, \
+ { &unsupported, 210, "", 0}, \
+ { &unsupported, 211, "", 0}, \
+ { &unsupported, 212, "", 0}, \
+ { &unsupported, 213, "", 0}, \
+ { &unsupported, 214, "", 0}, \
+ { &unsupported, 215, "", 0}, \
+ { &unsupported, 216, "", 0}, \
+ { &unsupported, 217, "", 0}, \
+ { &unsupported, 218, "", 0}, \
+ { &unsupported, 219, "", 0}, \
+ { &unsupported, 220, "", 0}, \
+ { &unsupported, 221, "", 0}, \
+ { &unsupported, 222, "", 0}, \
+ { &unsupported, 223, "", 0}, \
+ { &unsupported, 224, "", 0}, \
+ { &unsupported, 225, "", 0}, \
+ { &unsupported, 226, "", 0}, \
+ { &unsupported, 227, "", 0}, \
+ { &unsupported, 228, "", 0}, \
+ { &unsupported, 229, "", 0}, \
+ { &unsupported, 230, "", 0}, \
+ { &unsupported, 231, "", 0}, \
+ { &unsupported, 232, "", 0}, \
+ { &unsupported, 233, "", 0}, \
+ { &unsupported, 234, "", 0}, \
+ { &unsupported, 235, "", 0}, \
+ { &unsupported, 236, "", 0}, \
+ { &unsupported, 237, "", 0}, \
+ { &unsupported, 238, "", 0}, \
+ { &unsupported, 239, "", 0}, \
+ { &unsupported, 240, "", 0}, \
+ { &unsupported, 241, "", 0}, \
+ { &unsupported, 242, "", 0}, \
+ { &unsupported, 243, "", 0}, \
+ { &unsupported, 244, "", 0}, \
+ { &unsupported, 245, "", 0}, \
+ { &unsupported, 246, "", 0}, \
+ { &unsupported, 247, "", 0}, \
+ { &pc32, 248, "R_MIPS_PC32", 0}, \
+ { &unsupported, 249, "", 0}, \
+ { &unsupported, 250, "R_MIPS_GNU_REL16_S2", 0}, \
+ { &unsupported, 251, "", 0}, \
+ { &unsupported, 252, "", 0}, \
+ { &unsupported, 253, "R_MIPS_GNU_VTINHERIT", 0}, \
+ { &unsupported, 254, "R_MIPS_GNU_VTENTRY", 0}
+
+#endif // TARGET_MIPS_MIPSRELOCATIONFUNCTIONS_H_
diff --git a/lib/Target/Mips/MipsRelocator.cpp b/lib/Target/Mips/MipsRelocator.cpp
index 7da4dfd..d8039b7 100644
--- a/lib/Target/Mips/MipsRelocator.cpp
+++ b/lib/Target/Mips/MipsRelocator.cpp
@@ -9,12 +9,12 @@
#include "MipsRelocator.h"
#include "MipsRelocationFunctions.h"
-#include <mcld/IRBuilder.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Object/ObjectBuilder.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Target/OutputRelocSection.h>
-#include <mcld/LD/ELFFileFormat.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Target/OutputRelocSection.h"
+#include "mcld/LD/ELFFileFormat.h"
#include <llvm/ADT/Twine.h>
#include <llvm/Support/ELF.h>
@@ -25,28 +25,27 @@ namespace ELF {
// FIXME: Consider upstream these relocation types to LLVM.
enum {
R_MIPS_LA25_LUI = 200,
- R_MIPS_LA25_J = 201,
+ R_MIPS_LA25_J = 201,
R_MIPS_LA25_ADD = 202,
};
-} // end namespace ELF
-} // end namespace llvm
+} // namespace ELF
+} // namespace llvm
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// MipsRelocationInfo
//===----------------------------------------------------------------------===//
-class mcld::MipsRelocationInfo
-{
-public:
- static bool HasSubType(const Relocation& pParent, Relocation::Type pType)
- {
+class MipsRelocationInfo {
+ public:
+ static bool HasSubType(const Relocation& pParent, Relocation::Type pType) {
if (llvm::ELF::R_MIPS_NONE == pType)
return true;
for (Relocation::Type type = pParent.type();
- llvm::ELF::R_MIPS_NONE != (type & 0xff); type >>= 8) {
+ llvm::ELF::R_MIPS_NONE != (type & 0xff);
+ type >>= 8) {
if ((type & 0xff) == pType)
return true;
}
@@ -55,12 +54,11 @@ public:
}
MipsRelocationInfo(Relocation& pParent, bool pIsRel)
- : m_Parent(&pParent),
- m_Type(pParent.type()),
- m_Addend(0),
- m_Symbol(pParent.symValue()),
- m_Result(pParent.target())
- {
+ : m_Parent(&pParent),
+ m_Type(pParent.type()),
+ m_Addend(0),
+ m_Symbol(pParent.symValue()),
+ m_Result(pParent.target()) {
if (pIsRel && (type() < llvm::ELF::R_MIPS_LA25_LUI ||
type() > llvm::ELF::R_MIPS_LA25_ADD))
m_Addend = pParent.target();
@@ -68,81 +66,49 @@ public:
m_Addend = pParent.addend();
}
- bool isNone() const
- {
- return llvm::ELF::R_MIPS_NONE == type();
- }
+ bool isNone() const { return llvm::ELF::R_MIPS_NONE == type(); }
- bool isLast() const
- {
- return llvm::ELF::R_MIPS_NONE == (m_Type >> 8);
- }
+ bool isLast() const { return llvm::ELF::R_MIPS_NONE == (m_Type >> 8); }
- MipsRelocationInfo next() const
- {
+ MipsRelocationInfo next() const {
return MipsRelocationInfo(*m_Parent, m_Type >> 8, result(), result(), 0);
}
- const Relocation& parent() const
- {
- return *m_Parent;
- }
+ const Relocation& parent() const { return *m_Parent; }
- Relocation& parent()
- {
- return *m_Parent;
- }
+ Relocation& parent() { return *m_Parent; }
- Relocation::Type type() const
- {
- return m_Type & 0xff;
- }
+ Relocation::Type type() const { return m_Type & 0xff; }
- Relocation::DWord A() const
- {
- return m_Addend;
- }
+ Relocation::DWord A() const { return m_Addend; }
- Relocation::DWord S() const
- {
- return m_Symbol;
- }
+ Relocation::DWord S() const { return m_Symbol; }
- Relocation::DWord P() const
- {
- return parent().place();
- }
+ Relocation::DWord P() const { return parent().place(); }
- Relocation::DWord result() const
- {
- return m_Result;
- }
+ Relocation::DWord result() const { return m_Result; }
- Relocation::DWord& result()
- {
- return m_Result;
- }
+ Relocation::DWord& result() { return m_Result; }
-private:
+ private:
Relocation* m_Parent;
Relocation::Type m_Type;
Relocation::DWord m_Addend;
Relocation::DWord m_Symbol;
Relocation::DWord m_Result;
- MipsRelocationInfo(Relocation& pParent, Relocation::Type pType,
+ MipsRelocationInfo(Relocation& pParent,
+ Relocation::Type pType,
Relocation::DWord pResult,
- Relocation::DWord pAddend, Relocation::DWord pSymbol)
- : m_Parent(&pParent),
- m_Type(pType),
- m_Addend(pAddend),
- m_Symbol(pSymbol),
- m_Result(pResult)
- {}
-
- bool isFirst() const {
- return m_Type == parent().type();
- }
+ Relocation::DWord pAddend,
+ Relocation::DWord pSymbol)
+ : m_Parent(&pParent),
+ m_Type(pType),
+ m_Addend(pAddend),
+ m_Symbol(pSymbol),
+ m_Result(pResult) {}
+
+ bool isFirst() const { return m_Type == parent().type(); }
};
//===----------------------------------------------------------------------===//
@@ -154,10 +120,8 @@ DECL_MIPS_APPLY_RELOC_FUNCS
typedef Relocator::Result (*ApplyFunctionType)(MipsRelocationInfo&,
MipsRelocator& pParent);
-
// the table entry of applying functions
-struct ApplyFunctionTriple
-{
+struct ApplyFunctionTriple {
ApplyFunctionType func;
unsigned int type;
const char* name;
@@ -166,38 +130,34 @@ struct ApplyFunctionTriple
// declare the table of applying functions
static const ApplyFunctionTriple ApplyFunctions[] = {
- DECL_MIPS_APPLY_RELOC_FUNC_PTRS
-};
+ DECL_MIPS_APPLY_RELOC_FUNC_PTRS};
//===----------------------------------------------------------------------===//
// MipsRelocator
//===----------------------------------------------------------------------===//
MipsRelocator::MipsRelocator(MipsGNULDBackend& pParent,
const LinkerConfig& pConfig)
- : Relocator(pConfig),
- m_Target(pParent),
- m_pApplyingInput(NULL),
- m_CurrentLo16Reloc(NULL)
-{
+ : Relocator(pConfig),
+ m_Target(pParent),
+ m_pApplyingInput(NULL),
+ m_CurrentLo16Reloc(NULL) {
}
-Relocator::Result
-MipsRelocator::applyRelocation(Relocation& pReloc)
-{
+Relocator::Result MipsRelocator::applyRelocation(Relocation& pReloc) {
// If m_CurrentLo16Reloc is not NULL we are processing
// postponed relocation. Otherwise check relocation type
// and postpone it for later handling.
- if (NULL == m_CurrentLo16Reloc && isPostponed(pReloc)) {
+ if (m_CurrentLo16Reloc == NULL && isPostponed(pReloc)) {
postponeRelocation(pReloc);
return OK;
}
- for (MipsRelocationInfo info(pReloc, isRel());
- !info.isNone(); info = info.next()) {
+ for (MipsRelocationInfo info(pReloc, isRel()); !info.isNone();
+ info = info.next()) {
if (info.type() >= sizeof(ApplyFunctions) / sizeof(ApplyFunctions[0]))
return Unknown;
- const ApplyFunctionTriple & triple = ApplyFunctions[info.type()];
+ const ApplyFunctionTriple& triple = ApplyFunctions[info.type()];
Result res = triple.func(info, *this);
if (OK != res)
@@ -213,13 +173,11 @@ MipsRelocator::applyRelocation(Relocation& pReloc)
return OK;
}
-const char* MipsRelocator::getName(Relocation::Type pType) const
-{
+const char* MipsRelocator::getName(Relocation::Type pType) const {
return ApplyFunctions[pType & 0xff].name;
}
-Relocator::Size MipsRelocator::getSize(Relocation::Type pType) const
-{
+Relocator::Size MipsRelocator::getSize(Relocation::Type pType) const {
return ApplyFunctions[pType & 0xff].size;
}
@@ -227,23 +185,23 @@ void MipsRelocator::scanRelocation(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
LDSection& pSection,
- Input& pInput)
-{
+ Input& pInput) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- assert(NULL != rsym && "ResolveInfo of relocation not set while scanRelocation");
+ assert(rsym != NULL &&
+ "ResolveInfo of relocation not set while scanRelocation");
// Skip relocation against _gp_disp
- if (NULL != getTarget().getGpDispSymbol() &&
+ if (getTarget().getGpDispSymbol() != NULL &&
rsym == getTarget().getGpDispSymbol()->resolveInfo())
return;
- assert(NULL != pSection.getLink());
- if (0 == (pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC))
+ assert(pSection.getLink() != NULL);
+ if ((pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC) == 0)
return;
- for (MipsRelocationInfo info(pReloc, isRel());
- !info.isNone(); info = info.next()) {
+ for (MipsRelocationInfo info(pReloc, isRel()); !info.isNone();
+ info = info.next()) {
// We test isLocal or if pInputSym is not a dynamic symbol
// We assume -Bsymbolic to bind all symbols internaly via !rsym->isDyn()
// Don't put undef symbols into local entries.
@@ -262,39 +220,34 @@ void MipsRelocator::scanRelocation(Relocation& pReloc,
issueUndefRef(pReloc, pSection, pInput);
}
-bool MipsRelocator::initializeScan(Input& pInput)
-{
+bool MipsRelocator::initializeScan(Input& pInput) {
if (LinkerConfig::Object != config().codeGenType())
getTarget().getGOT().initializeScan(pInput);
return true;
}
-bool MipsRelocator::finalizeScan(Input& pInput)
-{
+bool MipsRelocator::finalizeScan(Input& pInput) {
if (LinkerConfig::Object != config().codeGenType())
getTarget().getGOT().finalizeScan(pInput);
return true;
}
-bool MipsRelocator::initializeApply(Input& pInput)
-{
+bool MipsRelocator::initializeApply(Input& pInput) {
m_pApplyingInput = &pInput;
return true;
}
-bool MipsRelocator::finalizeApply(Input& pInput)
-{
+bool MipsRelocator::finalizeApply(Input& pInput) {
m_pApplyingInput = NULL;
return true;
}
void MipsRelocator::scanLocalReloc(MipsRelocationInfo& pReloc,
IRBuilder& pBuilder,
- const LDSection& pSection)
-{
+ const LDSection& pSection) {
ResolveInfo* rsym = pReloc.parent().symInfo();
- switch (pReloc.type()){
+ switch (pReloc.type()) {
case llvm::ELF::R_MIPS_NONE:
case llvm::ELF::R_MIPS_16:
break;
@@ -342,8 +295,9 @@ void MipsRelocator::scanLocalReloc(MipsRelocationInfo& pReloc,
case llvm::ELF::R_MIPS_GOT_DISP:
case llvm::ELF::R_MIPS_GOT_PAGE:
case llvm::ELF::R_MIPS_GOT_OFST:
- if (getTarget().getGOT().reserveLocalEntry(*rsym,
- pReloc.type(), pReloc.A())) {
+ if (getTarget()
+ .getGOT()
+ .reserveLocalEntry(*rsym, pReloc.type(), pReloc.A())) {
if (getTarget().getGOT().hasMultipleGOT())
getTarget().checkAndSetHasTextRel(*pSection.getLink());
}
@@ -369,17 +323,17 @@ void MipsRelocator::scanLocalReloc(MipsRelocationInfo& pReloc,
case llvm::ELF::R_MIPS_PC32:
break;
default:
- fatal(diag::unknown_relocation) << (int)pReloc.type() << rsym->name();
+ fatal(diag::unknown_relocation) << static_cast<int>(pReloc.type())
+ << rsym->name();
}
}
void MipsRelocator::scanGlobalReloc(MipsRelocationInfo& pReloc,
IRBuilder& pBuilder,
- const LDSection& pSection)
-{
+ const LDSection& pSection) {
ResolveInfo* rsym = pReloc.parent().symInfo();
- switch (pReloc.type()){
+ switch (pReloc.type()) {
case llvm::ELF::R_MIPS_NONE:
case llvm::ELF::R_MIPS_INSERT_A:
case llvm::ELF::R_MIPS_INSERT_B:
@@ -401,8 +355,7 @@ void MipsRelocator::scanGlobalReloc(MipsRelocationInfo& pReloc,
if (getTarget().symbolNeedsCopyReloc(pReloc.parent(), *rsym)) {
LDSymbol& cpySym = defineSymbolforCopyReloc(pBuilder, *rsym);
addCopyReloc(*cpySym.resolveInfo());
- }
- else {
+ } else {
// set Rel bit
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
@@ -425,7 +378,7 @@ void MipsRelocator::scanGlobalReloc(MipsRelocationInfo& pReloc,
break;
case llvm::ELF::R_MIPS_LITERAL:
case llvm::ELF::R_MIPS_GPREL32:
- fatal(diag::invalid_global_relocation) << (int)pReloc.type()
+ fatal(diag::invalid_global_relocation) << static_cast<int>(pReloc.type())
<< rsym->name();
break;
case llvm::ELF::R_MIPS_GPREL16:
@@ -467,15 +420,15 @@ void MipsRelocator::scanGlobalReloc(MipsRelocationInfo& pReloc,
case llvm::ELF::R_MIPS_COPY:
case llvm::ELF::R_MIPS_GLOB_DAT:
case llvm::ELF::R_MIPS_JUMP_SLOT:
- fatal(diag::dynamic_relocation) << (int)pReloc.type();
+ fatal(diag::dynamic_relocation) << static_cast<int>(pReloc.type());
break;
default:
- fatal(diag::unknown_relocation) << (int)pReloc.type() << rsym->name();
+ fatal(diag::unknown_relocation) << static_cast<int>(pReloc.type())
+ << rsym->name();
}
}
-bool MipsRelocator::isPostponed(const Relocation& pReloc) const
-{
+bool MipsRelocator::isPostponed(const Relocation& pReloc) const {
if (MipsRelocationInfo::HasSubType(pReloc, llvm::ELF::R_MIPS_HI16))
return true;
@@ -486,8 +439,7 @@ bool MipsRelocator::isPostponed(const Relocation& pReloc) const
return false;
}
-void MipsRelocator::addCopyReloc(ResolveInfo& pSym)
-{
+void MipsRelocator::addCopyReloc(ResolveInfo& pSym) {
Relocation& relEntry = *getTarget().getRelDyn().consumeEntry();
relEntry.setType(llvm::ELF::R_MIPS_COPY);
assert(pSym.outSymbol()->hasFragRef());
@@ -496,18 +448,17 @@ void MipsRelocator::addCopyReloc(ResolveInfo& pSym)
}
LDSymbol& MipsRelocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
- const ResolveInfo& pSym)
-{
+ const ResolveInfo& pSym) {
// Get or create corresponding BSS LDSection
ELFFileFormat* fileFormat = getTarget().getOutputFormat();
- LDSection* bssSectHdr =
- ResolveInfo::ThreadLocal == pSym.type() ? &fileFormat->getTBSS()
- : &fileFormat->getBSS();
+ LDSection* bssSectHdr = ResolveInfo::ThreadLocal == pSym.type()
+ ? &fileFormat->getTBSS()
+ : &fileFormat->getBSS();
// Get or create corresponding BSS SectionData
- SectionData* bssData =
- bssSectHdr->hasSectionData() ? bssSectHdr->getSectionData()
- : IRBuilder::CreateSectionData(*bssSectHdr);
+ SectionData* bssData = bssSectHdr->hasSectionData()
+ ? bssSectHdr->getSectionData()
+ : IRBuilder::CreateSectionData(*bssSectHdr);
// Determine the alignment by the symbol value
// FIXME: here we use the largest alignment
@@ -525,22 +476,23 @@ LDSymbol& MipsRelocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
// Define the copy symbol in the bss section and resolve it
LDSymbol* cpySym = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- pSym.name(),
- (ResolveInfo::Type)pSym.type(),
- ResolveInfo::Define,
- binding,
- pSym.size(), // size
- 0x0, // value
- FragmentRef::Create(*frag, 0x0),
- (ResolveInfo::Visibility)pSym.other());
+ pSym.name(),
+ (ResolveInfo::Type)pSym.type(),
+ ResolveInfo::Define,
+ binding,
+ pSym.size(), // size
+ 0x0, // value
+ FragmentRef::Create(*frag, 0x0),
+ (ResolveInfo::Visibility)pSym.other());
// Output all other alias symbols if any
Module::AliasList* alias_list = pBuilder.getModule().getAliasList(pSym);
- if (NULL == alias_list)
+ if (alias_list == NULL)
return *cpySym;
for (Module::alias_iterator it = alias_list->begin(), ie = alias_list->end();
- it != ie; ++it) {
+ it != ie;
+ ++it) {
const ResolveInfo* alias = *it;
if (alias == &pSym || !alias->isDyn())
continue;
@@ -559,19 +511,17 @@ LDSymbol& MipsRelocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
return *cpySym;
}
-void MipsRelocator::postponeRelocation(Relocation& pReloc)
-{
+void MipsRelocator::postponeRelocation(Relocation& pReloc) {
ResolveInfo* rsym = pReloc.symInfo();
m_PostponedRelocs[rsym].insert(&pReloc);
}
-void MipsRelocator::applyPostponedRelocations(MipsRelocationInfo& pLo16Reloc)
-{
+void MipsRelocator::applyPostponedRelocations(MipsRelocationInfo& pLo16Reloc) {
m_CurrentLo16Reloc = &pLo16Reloc;
ResolveInfo* rsym = pLo16Reloc.parent().symInfo();
- RelocationSet & relocs = m_PostponedRelocs[rsym];
+ RelocationSet& relocs = m_PostponedRelocs[rsym];
for (RelocationSet::iterator it = relocs.begin(); it != relocs.end(); ++it)
(*it)->apply(*this);
@@ -580,39 +530,31 @@ void MipsRelocator::applyPostponedRelocations(MipsRelocationInfo& pLo16Reloc)
m_CurrentLo16Reloc = NULL;
}
-bool MipsRelocator::isGpDisp(const Relocation& pReloc) const
-{
- return 0 == strcmp("_gp_disp", pReloc.symInfo()->name());
+bool MipsRelocator::isGpDisp(const Relocation& pReloc) const {
+ return strcmp("_gp_disp", pReloc.symInfo()->name()) == 0;
}
-bool MipsRelocator::isRel() const
-{
+bool MipsRelocator::isRel() const {
return config().targets().is32Bits();
}
-bool MipsRelocator::isLocalReloc(ResolveInfo& pSym) const
-{
+bool MipsRelocator::isLocalReloc(ResolveInfo& pSym) const {
if (pSym.isUndef())
return false;
- return pSym.isLocal() ||
- !getTarget().isDynamicSymbol(pSym) ||
- !pSym.isDyn();
+ return pSym.isLocal() || !getTarget().isDynamicSymbol(pSym) || !pSym.isDyn();
}
-Relocator::Address MipsRelocator::getGPAddress()
-{
+Relocator::Address MipsRelocator::getGPAddress() {
return getTarget().getGOT().getGPAddr(getApplyingInput());
}
-Relocator::Address MipsRelocator::getGP0()
-{
+Relocator::Address MipsRelocator::getGP0() {
return getTarget().getGP0(getApplyingInput());
}
Fragment& MipsRelocator::getLocalGOTEntry(MipsRelocationInfo& pReloc,
- Relocation::DWord entryValue)
-{
+ Relocation::DWord entryValue) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.parent().symInfo();
MipsGOT& got = getTarget().getGOT();
@@ -623,7 +565,7 @@ Fragment& MipsRelocator::getLocalGOTEntry(MipsRelocationInfo& pReloc,
Fragment* got_entry = got.lookupLocalEntry(rsym, entryValue);
// Found a mapping, then return the mapped entry immediately.
- if (NULL != got_entry)
+ if (got_entry != NULL)
return *got_entry;
// Not found.
@@ -639,8 +581,7 @@ Fragment& MipsRelocator::getLocalGOTEntry(MipsRelocationInfo& pReloc,
return *got_entry;
}
-Fragment& MipsRelocator::getGlobalGOTEntry(MipsRelocationInfo& pReloc)
-{
+Fragment& MipsRelocator::getGlobalGOTEntry(MipsRelocationInfo& pReloc) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.parent().symInfo();
MipsGOT& got = getTarget().getGOT();
@@ -651,7 +592,7 @@ Fragment& MipsRelocator::getGlobalGOTEntry(MipsRelocationInfo& pReloc)
Fragment* got_entry = got.lookupGlobalEntry(rsym);
// Found a mapping, then return the mapped entry immediately.
- if (NULL != got_entry)
+ if (got_entry != NULL)
return *got_entry;
// Not found.
@@ -667,8 +608,7 @@ Fragment& MipsRelocator::getGlobalGOTEntry(MipsRelocationInfo& pReloc)
return *got_entry;
}
-Relocator::Address MipsRelocator::getGOTOffset(MipsRelocationInfo& pReloc)
-{
+Relocator::Address MipsRelocator::getGOTOffset(MipsRelocationInfo& pReloc) {
ResolveInfo* rsym = pReloc.parent().symInfo();
MipsGOT& got = getTarget().getGOT();
@@ -680,14 +620,12 @@ Relocator::Address MipsRelocator::getGOTOffset(MipsRelocationInfo& pReloc)
return got.getGPRelOffset(getApplyingInput(),
getLocalGOTEntry(pReloc, value));
- }
- else {
+ } else {
return got.getGPRelOffset(getApplyingInput(), getGlobalGOTEntry(pReloc));
}
}
-void MipsRelocator::createDynRel(MipsRelocationInfo& pReloc)
-{
+void MipsRelocator::createDynRel(MipsRelocationInfo& pReloc) {
Relocator::DWord A = pReloc.A();
Relocator::DWord S = pReloc.S();
@@ -696,17 +634,15 @@ void MipsRelocator::createDynRel(MipsRelocationInfo& pReloc)
if (isLocalReloc(*rsym)) {
setupRelDynEntry(pReloc.parent().targetRef(), NULL);
pReloc.result() = A + S;
- }
- else {
+ } else {
setupRelDynEntry(pReloc.parent().targetRef(), rsym);
// Don't add symbol value that will be resolved by the dynamic linker.
pReloc.result() = A;
}
}
-uint64_t MipsRelocator::calcAHL(const MipsRelocationInfo& pHiReloc)
-{
- assert(NULL != m_CurrentLo16Reloc &&
+uint64_t MipsRelocator::calcAHL(const MipsRelocationInfo& pHiReloc) {
+ assert(m_CurrentLo16Reloc != NULL &&
"There is no saved R_MIPS_LO16 relocation");
uint64_t AHI = pHiReloc.A() & 0xFFFF;
@@ -716,13 +652,11 @@ uint64_t MipsRelocator::calcAHL(const MipsRelocationInfo& pHiReloc)
return AHL;
}
-bool MipsRelocator::isN64ABI() const
-{
+bool MipsRelocator::isN64ABI() const {
return config().targets().is64Bits();
}
-uint64_t MipsRelocator::getPLTAddress(ResolveInfo& rsym)
-{
+uint64_t MipsRelocator::getPLTAddress(ResolveInfo& rsym) {
assert((rsym.reserved() & MipsRelocator::ReservePLT) &&
"Symbol does not require a PLT entry");
@@ -732,8 +666,7 @@ uint64_t MipsRelocator::getPLTAddress(ResolveInfo& rsym)
if (it != m_SymPLTMap.end()) {
plt = it->second.first;
- }
- else {
+ } else {
plt = getTarget().getPLT().consume();
Fragment* got = getTarget().getGOTPLT().consume();
@@ -749,16 +682,33 @@ uint64_t MipsRelocator::getPLTAddress(ResolveInfo& rsym)
return getTarget().getPLT().addr() + plt->getOffset();
}
+uint32_t MipsRelocator::getDebugStringOffset(Relocation& pReloc) const {
+ if (pReloc.type() != llvm::ELF::R_MIPS_32)
+ error(diag::unsupport_reloc_for_debug_string)
+ << getName(pReloc.type()) << "mclinker@googlegroups.com";
+ if (pReloc.symInfo()->type() == ResolveInfo::Section)
+ return pReloc.target();
+ else
+ return pReloc.symInfo()->outSymbol()->fragRef()->offset() +
+ pReloc.target() + pReloc.addend();
+}
+
+void MipsRelocator::applyDebugStringOffset(Relocation& pReloc,
+ uint32_t pOffset) {
+ pReloc.target() = pOffset;
+}
+
+
//===----------------------------------------------------------------------===//
// Mips32Relocator
//===----------------------------------------------------------------------===//
Mips32Relocator::Mips32Relocator(Mips32GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : MipsRelocator(pParent, pConfig)
-{}
+ : MipsRelocator(pParent, pConfig) {
+}
-void Mips32Relocator::setupRelDynEntry(FragmentRef& pFragRef, ResolveInfo* pSym)
-{
+void Mips32Relocator::setupRelDynEntry(FragmentRef& pFragRef,
+ ResolveInfo* pSym) {
Relocation& relEntry = *getTarget().getRelDyn().consumeEntry();
relEntry.setType(llvm::ELF::R_MIPS_REL32);
relEntry.targetRef() = pFragRef;
@@ -770,13 +720,12 @@ void Mips32Relocator::setupRelDynEntry(FragmentRef& pFragRef, ResolveInfo* pSym)
//===----------------------------------------------------------------------===//
Mips64Relocator::Mips64Relocator(Mips64GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : MipsRelocator(pParent, pConfig)
-{}
+ : MipsRelocator(pParent, pConfig) {
+}
-void Mips64Relocator::setupRelDynEntry(FragmentRef& pFragRef, ResolveInfo* pSym)
-{
- Relocation::Type type = llvm::ELF::R_MIPS_REL32 |
- llvm::ELF::R_MIPS_64 << 8;
+void Mips64Relocator::setupRelDynEntry(FragmentRef& pFragRef,
+ ResolveInfo* pSym) {
+ Relocation::Type type = llvm::ELF::R_MIPS_REL32 | llvm::ELF::R_MIPS_64 << 8;
// FIXME (simon): Fix dynamic relocations.
type = llvm::ELF::R_MIPS_NONE;
@@ -791,27 +740,26 @@ void Mips64Relocator::setupRelDynEntry(FragmentRef& pFragRef, ResolveInfo* pSym)
//=========================================//
// R_MIPS_NONE and those unsupported/deprecated relocation type
-static
-MipsRelocator::Result none(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result none(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
return Relocator::OK;
}
// R_MIPS_32: S + A
-static
-MipsRelocator::Result abs32(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result abs32(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
ResolveInfo* rsym = pReloc.parent().symInfo();
Relocator::DWord A = pReloc.A();
Relocator::DWord S = pReloc.S();
LDSection& target_sect =
- pReloc.parent().targetRef().frag()->getParent()->getSection();
+ pReloc.parent().targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation
// but perform static relocation. (e.g., applying .debug section)
- if (0x0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) == 0x0) {
pReloc.result() = S + A;
return Relocator::OK;
}
@@ -829,12 +777,11 @@ MipsRelocator::Result abs32(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
// R_MIPS_26:
// local : ((A | ((P + 4) & 0x3F000000)) + S) >> 2
// external: (sign–extend(A) + S) >> 2
-static
-MipsRelocator::Result rel26(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result rel26(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
ResolveInfo* rsym = pReloc.parent().symInfo();
- int32_t A = ((pReloc.parent().target() & 0x03FFFFFF) << 2);
+ int32_t A = pParent.isN64ABI() ? pReloc.A() : (pReloc.A() & 0x03FFFFFF) << 2;
int32_t P = pReloc.P();
int32_t S = rsym->reserved() & MipsRelocator::ReservePLT
? pParent.getPLTAddress(*rsym)
@@ -843,7 +790,7 @@ MipsRelocator::Result rel26(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
if (rsym->isLocal())
pReloc.result() = A | ((P + 4) & 0x3F000000);
else
- pReloc.result() = mcld::signExtend<28>(A);
+ pReloc.result() = signExtend<28>(A);
pReloc.result() = (pReloc.result() + S) >> 2;
@@ -853,17 +800,15 @@ MipsRelocator::Result rel26(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
// R_MIPS_HI16:
// local/external: ((AHL + S) - (short)(AHL + S)) >> 16
// _gp_disp : ((AHL + GP - P) - (short)(AHL + GP - P)) >> 16
-static
-MipsRelocator::Result hi16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result hi16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
uint64_t AHL = pParent.calcAHL(pReloc);
if (pParent.isGpDisp(pReloc.parent())) {
int32_t P = pReloc.P();
int32_t GP = pParent.getGPAddress();
pReloc.result() = ((AHL + GP - P) - (int16_t)(AHL + GP - P)) >> 16;
- }
- else {
+ } else {
int32_t S = pReloc.S();
if (pParent.isN64ABI())
pReloc.result() = (pReloc.A() + S + 0x8000ull) >> 16;
@@ -877,9 +822,8 @@ MipsRelocator::Result hi16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
// R_MIPS_LO16:
// local/external: AHL + S
// _gp_disp : AHL + GP - P + 4
-static
-MipsRelocator::Result lo16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result lo16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
// AHL is a combination of HI16 and LO16 addends. But R_MIPS_LO16
// uses low 16 bits of the AHL. That is why we do not need R_MIPS_HI16
// addend here.
@@ -889,8 +833,7 @@ MipsRelocator::Result lo16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
int32_t P = pReloc.P();
int32_t GP = pParent.getGPAddress();
pReloc.result() = AHL + GP - P + 4;
- }
- else {
+ } else {
int32_t S = pReloc.S();
pReloc.result() = AHL + S;
}
@@ -903,9 +846,8 @@ MipsRelocator::Result lo16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
// R_MIPS_GPREL16:
// external: sign–extend(A) + S - GP
// local : sign–extend(A) + S + GP0 – GP
-static
-MipsRelocator::Result gprel16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result gprel16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
// Remember to add the section offset to A.
uint64_t A = pReloc.A();
uint64_t S = pReloc.S();
@@ -924,9 +866,8 @@ MipsRelocator::Result gprel16(MipsRelocationInfo& pReloc, MipsRelocator& pParent
// R_MIPS_GOT16:
// local : G (calculate AHL and put high 16 bit to GOT)
// external: G
-static
-MipsRelocator::Result got16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result got16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
if (pReloc.parent().symInfo()->isLocal()) {
int32_t AHL = pParent.calcAHL(pReloc);
int32_t S = pReloc.S();
@@ -937,8 +878,7 @@ MipsRelocator::Result got16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
Fragment& got_entry = pParent.getLocalGOTEntry(pReloc, res);
pReloc.result() = got.getGPRelOffset(pParent.getApplyingInput(), got_entry);
- }
- else {
+ } else {
pReloc.result() = pParent.getGOTOffset(pReloc);
}
@@ -947,9 +887,8 @@ MipsRelocator::Result got16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
// R_MIPS_GOTHI16:
// external: (G - (short)G) >> 16 + A
-static
-MipsRelocator::Result gothi16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result gothi16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
Relocator::Address G = pParent.getGOTOffset(pReloc);
int32_t A = pReloc.A();
@@ -960,9 +899,8 @@ MipsRelocator::Result gothi16(MipsRelocationInfo& pReloc, MipsRelocator& pParent
// R_MIPS_GOTLO16:
// external: G & 0xffff
-static
-MipsRelocator::Result gotlo16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result gotlo16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
pReloc.result() = pParent.getGOTOffset(pReloc) & 0xffff;
return Relocator::OK;
@@ -970,9 +908,8 @@ MipsRelocator::Result gotlo16(MipsRelocationInfo& pReloc, MipsRelocator& pParent
// R_MIPS_SUB:
// external/local: S - A
-static
-MipsRelocator::Result sub(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result sub(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
uint64_t S = pReloc.S();
uint64_t A = pReloc.A();
@@ -982,18 +919,16 @@ MipsRelocator::Result sub(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
}
// R_MIPS_CALL16: G
-static
-MipsRelocator::Result call16(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result call16(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
pReloc.result() = pParent.getGOTOffset(pReloc);
return Relocator::OK;
}
// R_MIPS_GPREL32: A + S + GP0 - GP
-static
-MipsRelocator::Result gprel32(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result gprel32(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
// Remember to add the section offset to A.
uint64_t A = pReloc.A();
uint64_t S = pReloc.S();
@@ -1006,9 +941,8 @@ MipsRelocator::Result gprel32(MipsRelocationInfo& pReloc, MipsRelocator& pParent
}
// R_MIPS_64: S + A
-static
-MipsRelocator::Result abs64(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result abs64(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
// FIXME (simon): Consider to merge with abs32() or use the same function
// but with another mask size.
ResolveInfo* rsym = pReloc.parent().symInfo();
@@ -1017,9 +951,10 @@ MipsRelocator::Result abs64(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
Relocator::DWord S = pReloc.S();
LDSection& target_sect =
- pReloc.parent().targetRef().frag()->getParent()->getSection();
+ pReloc.parent().targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation
// but perform static relocation. (e.g., applying .debug section)
if (0x0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
pReloc.result() = S + A;
@@ -1037,33 +972,29 @@ MipsRelocator::Result abs64(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
}
// R_MIPS_GOT_DISP / R_MIPS_GOT_PAGE: G
-static
-MipsRelocator::Result gotdisp(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result gotdisp(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
pReloc.result() = pParent.getGOTOffset(pReloc);
return Relocator::OK;
}
// R_MIPS_GOT_OFST:
-static
-MipsRelocator::Result gotoff(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result gotoff(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
// FIXME (simon): Needs to be implemented.
return Relocator::OK;
}
// R_MIPS_JALR:
-static
-MipsRelocator::Result jalr(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result jalr(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
return Relocator::OK;
}
// R_MIPS_LA25_LUI
-static
-MipsRelocator::Result la25lui(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result la25lui(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
int32_t S = pReloc.S();
pReloc.result() = (S + 0x8000) >> 16;
@@ -1072,9 +1003,8 @@ MipsRelocator::Result la25lui(MipsRelocationInfo& pReloc, MipsRelocator& pParent
}
// R_MIPS_LA25_J
-static
-MipsRelocator::Result la25j(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result la25j(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
int32_t S = pReloc.S();
pReloc.result() = S >> 2;
@@ -1083,23 +1013,22 @@ MipsRelocator::Result la25j(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
}
// R_MIPS_LA25_ADD
-static
-MipsRelocator::Result la25add(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result la25add(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
pReloc.result() = pReloc.S();
return Relocator::OK;
}
// R_MIPS_PC32:
-static
-MipsRelocator::Result pc32(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
+static MipsRelocator::Result pc32(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
return Relocator::OK;
}
-static
-MipsRelocator::Result unsupport(MipsRelocationInfo& pReloc, MipsRelocator& pParent)
-{
- return Relocator::Unsupport;
+static MipsRelocator::Result unsupported(MipsRelocationInfo& pReloc,
+ MipsRelocator& pParent) {
+ return Relocator::Unsupported;
}
+
+} // namespace mcld
diff --git a/lib/Target/Mips/MipsRelocator.h b/lib/Target/Mips/MipsRelocator.h
index 5456a9f..27d5896 100644
--- a/lib/Target/Mips/MipsRelocator.h
+++ b/lib/Target/Mips/MipsRelocator.h
@@ -6,14 +6,15 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSRELOCATOR_H
-#define TARGET_MIPS_MIPSRELOCATOR_H
+#ifndef TARGET_MIPS_MIPSRELOCATOR_H_
+#define TARGET_MIPS_MIPSRELOCATOR_H_
-#include <llvm/ADT/DenseMapInfo.h>
-#include <mcld/LD/Relocator.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/LD/Relocator.h"
+#include "mcld/Support/GCFactory.h"
#include "MipsLDBackend.h"
+#include <llvm/ADT/DenseMapInfo.h>
+
namespace mcld {
class MipsRelocationInfo;
@@ -21,17 +22,16 @@ class MipsRelocationInfo;
/** \class MipsRelocator
* \brief MipsRelocator creates and destroys the Mips relocations.
*/
-class MipsRelocator : public Relocator
-{
-public:
+class MipsRelocator : public Relocator {
+ public:
enum ReservedEntryType {
- None = 0, // no reserved entry
- ReserveRel = 1, // reserve a dynamic relocation entry
- ReserveGot = 2, // reserve a GOT entry
- ReservePLT = 4 // reserve a PLT entry
+ None = 0, // no reserved entry
+ ReserveRel = 1, // reserve a dynamic relocation entry
+ ReserveGot = 2, // reserve a GOT entry
+ ReservePLT = 4 // reserve a PLT entry
};
-public:
+ public:
MipsRelocator(MipsGNULDBackend& pParent, const LinkerConfig& pConfig);
/// scanRelocation - determine the empty entries are needed or not and
@@ -61,14 +61,19 @@ public:
Result applyRelocation(Relocation& pReloc);
- const Input& getApplyingInput() const
- { return *m_pApplyingInput; }
+ /// getDebugStringOffset - get the offset from the relocation target. This is
+ /// used to get the debug string offset.
+ uint32_t getDebugStringOffset(Relocation& pReloc) const;
+
+ /// applyDebugStringOffset - apply the relocation target to specific offset.
+ /// This is used to set the debug string offset.
+ void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset);
+
+ const Input& getApplyingInput() const { return *m_pApplyingInput; }
- MipsGNULDBackend& getTarget()
- { return m_Target; }
+ MipsGNULDBackend& getTarget() { return m_Target; }
- const MipsGNULDBackend& getTarget() const
- { return m_Target; }
+ const MipsGNULDBackend& getTarget() const { return m_Target; }
/// postponeRelocation - save R_MIPS_LO16 paired relocations
/// like R_MISP_HI16 and R_MIPS_GOT16 for a future processing.
@@ -118,27 +123,27 @@ public:
Size getSize(Relocation::Type pType) const;
-protected:
+ protected:
/// setupRelDynEntry - create dynamic relocation entry.
virtual void setupRelDynEntry(FragmentRef& pFragRef, ResolveInfo* pSym) = 0;
/// isLocalReloc - handle relocation as a local symbol
bool isLocalReloc(ResolveInfo& pSym) const;
-private:
+ private:
typedef std::pair<Fragment*, Fragment*> PLTDescriptor;
typedef llvm::DenseMap<const ResolveInfo*, PLTDescriptor> SymPLTMap;
typedef llvm::DenseSet<Relocation*> RelocationSet;
typedef llvm::DenseMap<const ResolveInfo*, RelocationSet> SymRelocSetMap;
-private:
+ private:
MipsGNULDBackend& m_Target;
SymPLTMap m_SymPLTMap;
Input* m_pApplyingInput;
SymRelocSetMap m_PostponedRelocs;
MipsRelocationInfo* m_CurrentLo16Reloc;
-private:
+ private:
void scanLocalReloc(MipsRelocationInfo& pReloc,
IRBuilder& pBuilder,
const LDSection& pSection);
@@ -167,12 +172,11 @@ private:
/** \class Mips32Relocator
* \brief Mips32Relocator creates and destroys the Mips 32-bit relocations.
*/
-class Mips32Relocator : public MipsRelocator
-{
-public:
+class Mips32Relocator : public MipsRelocator {
+ public:
Mips32Relocator(Mips32GNULDBackend& pParent, const LinkerConfig& pConfig);
-private:
+ private:
// MipsRelocator
void setupRelDynEntry(FragmentRef& pFragRef, ResolveInfo* pSym);
};
@@ -180,16 +184,15 @@ private:
/** \class Mips64Relocator
* \brief Mips64Relocator creates and destroys the Mips 64-bit relocations.
*/
-class Mips64Relocator : public MipsRelocator
-{
-public:
+class Mips64Relocator : public MipsRelocator {
+ public:
Mips64Relocator(Mips64GNULDBackend& pParent, const LinkerConfig& pConfig);
-private:
+ private:
// MipsRelocator
void setupRelDynEntry(FragmentRef& pFragRef, ResolveInfo* pSym);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_MIPS_MIPSRELOCATOR_H_
diff --git a/lib/Target/Mips/MipsTargetMachine.cpp b/lib/Target/Mips/MipsTargetMachine.cpp
deleted file mode 100644
index 2e57868..0000000
--- a/lib/Target/Mips/MipsTargetMachine.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-//===- MipsTargetMachine.cpp ----------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "MipsTargetMachine.h"
-#include "Mips.h"
-#include <mcld/Support/TargetRegistry.h>
-
-typedef mcld::RegisterTargetMachine<mcld::MipsBaseTargetMachine> RegMipsTarget;
-
-extern "C" void MCLDInitializeMipsLDTarget() {
- RegMipsTarget X1(mcld::TheMipselTarget);
- RegMipsTarget X2(mcld::TheMips64elTarget);
-}
-
-using namespace mcld;
-
-//===----------------------------------------------------------------------===//
-// MipsBaseTargetMachine
-//===----------------------------------------------------------------------===//
-MipsBaseTargetMachine::MipsBaseTargetMachine(llvm::TargetMachine& pPM,
- const llvm::Target &pLLVMTarget,
- const mcld::Target &pMCLDTarget,
- const std::string& pTriple)
- : MCLDTargetMachine(pPM, pLLVMTarget, pMCLDTarget, pTriple) {
-}
diff --git a/lib/Target/Mips/MipsTargetMachine.h b/lib/Target/Mips/MipsTargetMachine.h
deleted file mode 100644
index 955d10a..0000000
--- a/lib/Target/Mips/MipsTargetMachine.h
+++ /dev/null
@@ -1,27 +0,0 @@
-//===- MipsTargetMachine.h ------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_MIPS_MIPSTARGETMACHINE_H
-#define TARGET_MIPS_MIPSTARGETMACHINE_H
-
-#include <mcld/CodeGen/TargetMachine.h>
-
-namespace mcld {
-
-class MipsBaseTargetMachine : public MCLDTargetMachine
-{
-public:
- MipsBaseTargetMachine(llvm::TargetMachine &pTM,
- const llvm::Target &pLLVMTarget,
- const mcld::Target &pMCLDTarget,
- const std::string &pTriple);
-};
-
-} // namespace of mcld
-
-#endif
diff --git a/lib/Target/Mips/TargetInfo/MipsTargetInfo.cpp b/lib/Target/Mips/TargetInfo/MipsTargetInfo.cpp
index 4ae7a61..43aac3e 100644
--- a/lib/Target/Mips/TargetInfo/MipsTargetInfo.cpp
+++ b/lib/Target/Mips/TargetInfo/MipsTargetInfo.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Target.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/Support/Target.h"
+#include "mcld/Support/TargetRegistry.h"
namespace mcld {
@@ -15,10 +15,9 @@ mcld::Target TheMipselTarget;
mcld::Target TheMips64elTarget;
extern "C" void MCLDInitializeMipsLDTargetInfo() {
- mcld::RegisterTarget<llvm::Triple::mipsel>
- X1(TheMipselTarget, "mipsel");
- mcld::RegisterTarget<llvm::Triple::mips64el>
- X2(TheMips64elTarget, "mips64el");
+ mcld::RegisterTarget<llvm::Triple::mipsel> X1(TheMipselTarget, "mipsel");
+ mcld::RegisterTarget<llvm::Triple::mips64el> X2(TheMips64elTarget,
+ "mips64el");
}
-} // namespace of mcld
+} // namespace mcld
diff --git a/lib/Target/OutputRelocSection.cpp b/lib/Target/OutputRelocSection.cpp
index 07670a3..40b7b8d 100644
--- a/lib/Target/OutputRelocSection.cpp
+++ b/lib/Target/OutputRelocSection.cpp
@@ -6,58 +6,54 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/OutputRelocSection.h>
+#include "mcld/Target/OutputRelocSection.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/RelocationFactory.h>
-#include <mcld/Module.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/IRBuilder.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/RelocationFactory.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Module.h"
#include <llvm/Support/Casting.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// OutputRelocSection
//===----------------------------------------------------------------------===//
OutputRelocSection::OutputRelocSection(Module& pModule, LDSection& pSection)
- : m_Module(pModule),
- m_pRelocData(NULL),
- m_isVisit(false),
- m_ValidEntryIterator(){
- assert(!pSection.hasRelocData() && "Given section is not a relocation section");
+ : m_Module(pModule),
+ m_pRelocData(NULL),
+ m_isVisit(false),
+ m_ValidEntryIterator() {
+ assert(!pSection.hasRelocData() &&
+ "Given section is not a relocation section");
m_pRelocData = IRBuilder::CreateRelocData(pSection);
}
-OutputRelocSection::~OutputRelocSection()
-{
+OutputRelocSection::~OutputRelocSection() {
}
-Relocation* OutputRelocSection::create()
-{
+Relocation* OutputRelocSection::create() {
Relocation* reloc = Relocation::Create();
m_pRelocData->append(*reloc);
return reloc;
}
-void OutputRelocSection::reserveEntry(size_t pNum)
-{
- for(size_t i=0; i<pNum; i++)
+void OutputRelocSection::reserveEntry(size_t pNum) {
+ for (size_t i = 0; i < pNum; ++i)
m_pRelocData->append(*Relocation::Create());
}
-Relocation* OutputRelocSection::consumeEntry()
-{
+Relocation* OutputRelocSection::consumeEntry() {
// first time visit this function, set m_ValidEntryIterator to
// Fragments.begin()
- if(!m_isVisit) {
+ if (!m_isVisit) {
assert(!m_pRelocData->getRelocationList().empty() &&
- "DynRelSection contains no entries.");
+ "DynRelSection contains no entries.");
m_ValidEntryIterator = m_pRelocData->begin();
m_isVisit = true;
- }
- else {
+ } else {
// Add m_ValidEntryIterator here instead of at the end of this function.
// We may reserve an entry and then consume it immediately, e.g. for COPY
// relocation, so we need to avoid setting this iterator to
@@ -71,14 +67,13 @@ Relocation* OutputRelocSection::consumeEntry()
return &(*m_ValidEntryIterator);
}
-size_t OutputRelocSection::numOfRelocs()
-{
+size_t OutputRelocSection::numOfRelocs() {
return m_pRelocData->size();
}
-bool OutputRelocSection::addSymbolToDynSym(LDSymbol& pSymbol)
-{
+bool OutputRelocSection::addSymbolToDynSym(LDSymbol& pSymbol) {
m_Module.getSymbolTable().changeToDynamic(pSymbol);
return true;
}
+} // namespace mcld
diff --git a/lib/Target/PLT.cpp b/lib/Target/PLT.cpp
index 6f9524e..4548c5d 100644
--- a/lib/Target/PLT.cpp
+++ b/lib/Target/PLT.cpp
@@ -6,24 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#include "mcld/Target/PLT.h"
-#include <mcld/Target/PLT.h>
-#include <mcld/IRBuilder.h>
+#include "mcld/IRBuilder.h"
-using namespace mcld;
+namespace mcld {
class GOT;
//===----------------------------------------------------------------------===//
// PLT
//===----------------------------------------------------------------------===//
-PLT::PLT(LDSection& pSection)
- :m_Section(pSection)
-{
+PLT::PLT(LDSection& pSection) : m_Section(pSection) {
m_pSectionData = IRBuilder::CreateSectionData(pSection);
}
-PLT::~PLT()
-{
+PLT::~PLT() {
}
+} // namespace mcld
diff --git a/lib/Target/TargetLDBackend.cpp b/lib/Target/TargetLDBackend.cpp
index e955916..f5e2865 100644
--- a/lib/Target/TargetLDBackend.cpp
+++ b/lib/Target/TargetLDBackend.cpp
@@ -6,16 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Target/TargetLDBackend.h>
-#include <mcld/LinkerConfig.h>
+#include "mcld/Target/TargetLDBackend.h"
-using namespace mcld;
+#include "mcld/LinkerConfig.h"
+
+namespace mcld {
TargetLDBackend::TargetLDBackend(const LinkerConfig& pConfig)
- : m_Config(pConfig) {
+ : m_Config(pConfig) {
}
-TargetLDBackend::~TargetLDBackend()
-{
+TargetLDBackend::~TargetLDBackend() {
}
+} // namespace mcld
diff --git a/lib/Target/X86/Android.mk b/lib/Target/X86/Android.mk
index 77b7258..ee136ff 100644
--- a/lib/Target/X86/Android.mk
+++ b/lib/Target/X86/Android.mk
@@ -3,15 +3,12 @@ LOCAL_PATH:= $(call my-dir)
mcld_x86_target_SRC_FILES := \
X86Diagnostic.cpp \
X86ELFDynamic.cpp \
- X86ELFMCLinker.cpp \
X86Emulation.cpp \
X86GOT.cpp \
X86GOTPLT.cpp \
X86LDBackend.cpp \
- X86MCLinker.cpp \
X86PLT.cpp \
- X86Relocator.cpp \
- X86TargetMachine.cpp
+ X86Relocator.cpp
# For the host
# =====================================================
diff --git a/lib/Target/X86/TargetInfo/X86TargetInfo.cpp b/lib/Target/X86/TargetInfo/X86TargetInfo.cpp
index 8e3a7c0..f87e531 100644
--- a/lib/Target/X86/TargetInfo/X86TargetInfo.cpp
+++ b/lib/Target/X86/TargetInfo/X86TargetInfo.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Target.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/Support/Target.h"
+#include "mcld/Support/TargetRegistry.h"
namespace mcld {
@@ -16,11 +16,8 @@ mcld::Target TheX86_64Target;
extern "C" void MCLDInitializeX86LDTargetInfo() {
// register into mcld::TargetRegistry
- mcld::RegisterTarget<llvm::Triple::x86>
- X(TheX86_32Target, "x86");
- mcld::RegisterTarget<llvm::Triple::x86_64>
- Y(TheX86_64Target, "x86-64");
+ mcld::RegisterTarget<llvm::Triple::x86> X(TheX86_32Target, "x86");
+ mcld::RegisterTarget<llvm::Triple::x86_64> Y(TheX86_64Target, "x86-64");
}
-} // namespace of mcld
-
+} // namespace mcld
diff --git a/lib/Target/X86/X86.h b/lib/Target/X86/X86.h
index 5090a67..8153478 100644
--- a/lib/Target/X86/X86.h
+++ b/lib/Target/X86/X86.h
@@ -6,13 +6,13 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86_H
-#define TARGET_X86_X86_H
+#ifndef TARGET_X86_X86_H_
+#define TARGET_X86_X86_H_
#include <string>
namespace llvm {
class Target;
-} // namespace of llvm
+} // namespace llvm
namespace mcld {
@@ -22,9 +22,8 @@ class TargetLDBackend;
extern mcld::Target TheX86_32Target;
extern mcld::Target TheX86_64Target;
-TargetLDBackend *createX86LDBackend(const llvm::Target&, const std::string&);
+TargetLDBackend* createX86LDBackend(const llvm::Target&, const std::string&);
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_X86_X86_H_
diff --git a/lib/Target/X86/X86Diagnostic.cpp b/lib/Target/X86/X86Diagnostic.cpp
index 9dab719..3d225ae 100644
--- a/lib/Target/X86/X86Diagnostic.cpp
+++ b/lib/Target/X86/X86Diagnostic.cpp
@@ -6,30 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/LD/DWARFLineInfo.h>
+#include "mcld/LD/DWARFLineInfo.h"
+#include "mcld/Support/TargetRegistry.h"
#include "X86.h"
-using namespace mcld;
-
namespace mcld {
//===----------------------------------------------------------------------===//
// createX86Diagnostic - the help function to create corresponding X86Diagnostic
//===----------------------------------------------------------------------===//
DiagnosticLineInfo* createX86DiagLineInfo(const mcld::Target& pTarget,
- const std::string &pTriple)
-{
+ const std::string& pTriple) {
return new DWARFLineInfo();
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// InitializeX86Diagnostic
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeX86DiagnosticLineInfo() {
// Register the linker frontend
- mcld::TargetRegistry::RegisterDiagnosticLineInfo(TheX86_32Target, createX86DiagLineInfo);
- mcld::TargetRegistry::RegisterDiagnosticLineInfo(TheX86_64Target, createX86DiagLineInfo);
+ mcld::TargetRegistry::RegisterDiagnosticLineInfo(mcld::TheX86_32Target,
+ mcld::createX86DiagLineInfo);
+ mcld::TargetRegistry::RegisterDiagnosticLineInfo(mcld::TheX86_64Target,
+ mcld::createX86DiagLineInfo);
}
-
diff --git a/lib/Target/X86/X86ELFDynamic.cpp b/lib/Target/X86/X86ELFDynamic.cpp
index 74611c5..4db9189 100644
--- a/lib/Target/X86/X86ELFDynamic.cpp
+++ b/lib/Target/X86/X86ELFDynamic.cpp
@@ -8,30 +8,28 @@
//===----------------------------------------------------------------------===//
#include "X86ELFDynamic.h"
-#include <mcld/LD/ELFFileFormat.h>
+#include "mcld/LD/ELFFileFormat.h"
-using namespace mcld;
+namespace mcld {
X86ELFDynamic::X86ELFDynamic(const GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : ELFDynamic(pParent, pConfig)
-{
+ : ELFDynamic(pParent, pConfig) {
}
-X86ELFDynamic::~X86ELFDynamic()
-{
+X86ELFDynamic::~X86ELFDynamic() {
}
-void X86ELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat)
-{
+void X86ELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat) {
// reservePLTGOT
if (pFormat.hasGOTPLT())
reserveOne(llvm::ELF::DT_PLTGOT);
}
-void X86ELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat)
-{
+void X86ELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat) {
// applyPLTGOT
if (pFormat.hasGOTPLT())
applyOne(llvm::ELF::DT_PLTGOT, pFormat.getGOTPLT().addr());
}
+
+} // namespace mcld
diff --git a/lib/Target/X86/X86ELFDynamic.h b/lib/Target/X86/X86ELFDynamic.h
index 931d1f6..df83e14 100644
--- a/lib/Target/X86/X86ELFDynamic.h
+++ b/lib/Target/X86/X86ELFDynamic.h
@@ -6,24 +6,23 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86ELFDYNAMIC_H
-#define TARGET_X86_X86ELFDYNAMIC_H
+#ifndef TARGET_X86_X86ELFDYNAMIC_H_
+#define TARGET_X86_X86ELFDYNAMIC_H_
-#include <mcld/Target/ELFDynamic.h>
+#include "mcld/Target/ELFDynamic.h"
namespace mcld {
-class X86ELFDynamic : public ELFDynamic
-{
-public:
+class X86ELFDynamic : public ELFDynamic {
+ public:
X86ELFDynamic(const GNULDBackend& pParent, const LinkerConfig& pConfig);
~X86ELFDynamic();
-private:
+ private:
void reserveTargetEntries(const ELFFileFormat& pFormat);
void applyTargetEntries(const ELFFileFormat& pFormat);
};
-} // namespace of mcld
+} // namespace mcld
-#endif
+#endif // TARGET_X86_X86ELFDYNAMIC_H_
diff --git a/lib/Target/X86/X86ELFMCLinker.cpp b/lib/Target/X86/X86ELFMCLinker.cpp
deleted file mode 100644
index a57fe37..0000000
--- a/lib/Target/X86/X86ELFMCLinker.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-//===- X86ELFMCLinker.cpp -------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "X86ELFMCLinker.h"
-
-using namespace mcld;
-
-X86ELFMCLinker::X86ELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
- : ELFMCLinker(pConfig, pModule, pFileHandle) {
-}
-
-X86ELFMCLinker::~X86ELFMCLinker()
-{
-}
-
diff --git a/lib/Target/X86/X86ELFMCLinker.h b/lib/Target/X86/X86ELFMCLinker.h
deleted file mode 100644
index 6a184aa..0000000
--- a/lib/Target/X86/X86ELFMCLinker.h
+++ /dev/null
@@ -1,36 +0,0 @@
-//===- X86ELFMCLinker.h ---------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86ELFMCLINKER_H
-#define TARGET_X86_X86ELFMCLINKER_H
-#include <mcld/Target/ELFMCLinker.h>
-
-namespace mcld {
-
-class Module;
-class FileHandle;
-
-/** \class X86ELFMCLinker
- * \brief X86ELFMCLinker sets up the environment for linking.
- *
- * \see
- */
-class X86ELFMCLinker : public ELFMCLinker
-{
-public:
- X86ELFMCLinker(LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle);
-
- ~X86ELFMCLinker();
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/lib/Target/X86/X86Emulation.cpp b/lib/Target/X86/X86Emulation.cpp
index d91d46d..58c797d 100644
--- a/lib/Target/X86/X86Emulation.cpp
+++ b/lib/Target/X86/X86Emulation.cpp
@@ -7,15 +7,14 @@
//
//===----------------------------------------------------------------------===//
#include "X86.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/Target/ELFEmulation.h>
-#include <mcld/Support/TargetRegistry.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/Support/TargetRegistry.h"
+#include "mcld/Target/ELFEmulation.h"
namespace mcld {
-static bool MCLDEmulateX86ELF(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+static bool MCLDEmulateX86ELF(LinkerScript& pScript, LinkerConfig& pConfig) {
if (!MCLDEmulateELF(pScript, pConfig))
return false;
@@ -23,12 +22,11 @@ static bool MCLDEmulateX86ELF(LinkerScript& pScript, LinkerConfig& pConfig)
pConfig.targets().setEndian(TargetOptions::Little);
unsigned int bitclass;
llvm::Triple::ArchType arch = pConfig.targets().triple().getArch();
- assert (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64);
+ assert(arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64);
if (arch == llvm::Triple::x86 ||
pConfig.targets().triple().getEnvironment() == llvm::Triple::GNUX32) {
bitclass = 32;
- }
- else {
+ } else {
bitclass = 64;
}
pConfig.targets().setBitClass(bitclass);
@@ -48,8 +46,7 @@ static bool MCLDEmulateX86ELF(LinkerScript& pScript, LinkerConfig& pConfig)
//===----------------------------------------------------------------------===//
// emulateX86LD - the help function to emulate X86 ld
//===----------------------------------------------------------------------===//
-bool emulateX86LD(LinkerScript& pScript, LinkerConfig& pConfig)
-{
+bool emulateX86LD(LinkerScript& pScript, LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker has not supported yet");
return false;
@@ -62,14 +59,15 @@ bool emulateX86LD(LinkerScript& pScript, LinkerConfig& pConfig)
return MCLDEmulateX86ELF(pScript, pConfig);
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// X86Emulation
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeX86Emulation() {
// Register the emulation
- mcld::TargetRegistry::RegisterEmulation(mcld::TheX86_32Target, mcld::emulateX86LD);
- mcld::TargetRegistry::RegisterEmulation(mcld::TheX86_64Target, mcld::emulateX86LD);
+ mcld::TargetRegistry::RegisterEmulation(mcld::TheX86_32Target,
+ mcld::emulateX86LD);
+ mcld::TargetRegistry::RegisterEmulation(mcld::TheX86_64Target,
+ mcld::emulateX86LD);
}
-
diff --git a/lib/Target/X86/X86GNUInfo.h b/lib/Target/X86/X86GNUInfo.h
index da4cb24..62bd32f 100644
--- a/lib/Target/X86/X86GNUInfo.h
+++ b/lib/Target/X86/X86GNUInfo.h
@@ -6,18 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86GNUINFO_H
-#define TARGET_X86_X86GNUINFO_H
-#include <mcld/Target/GNUInfo.h>
+#ifndef TARGET_X86_X86GNUINFO_H_
+#define TARGET_X86_X86GNUINFO_H_
+#include "mcld/Target/GNUInfo.h"
#include <llvm/Support/ELF.h>
namespace mcld {
-class X86_32GNUInfo : public GNUInfo
-{
-public:
- X86_32GNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) { }
+class X86_32GNUInfo : public GNUInfo {
+ public:
+ explicit X86_32GNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) {}
uint32_t machine() const { return llvm::ELF::EM_386; }
@@ -26,13 +25,11 @@ public:
/// flags - the value of ElfXX_Ehdr::e_flags
/// FIXME
uint64_t flags() const { return 0x0; }
-
};
-class X86_64GNUInfo : public GNUInfo
-{
-public:
- X86_64GNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) { }
+class X86_64GNUInfo : public GNUInfo {
+ public:
+ explicit X86_64GNUInfo(const llvm::Triple& pTriple) : GNUInfo(pTriple) {}
uint32_t machine() const { return llvm::ELF::EM_X86_64; }
@@ -41,10 +38,8 @@ public:
/// flags - the value of ElfXX_Ehdr::e_flags
/// FIXME
uint64_t flags() const { return 0x0; }
-
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_X86_X86GNUINFO_H_
diff --git a/lib/Target/X86/X86GOT.cpp b/lib/Target/X86/X86GOT.cpp
index 79421f1..9518aa7 100644
--- a/lib/Target/X86/X86GOT.cpp
+++ b/lib/Target/X86/X86GOT.cpp
@@ -8,44 +8,37 @@
//===----------------------------------------------------------------------===//
#include "X86GOT.h"
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/LD/SectionData.h>
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/LD/SectionData.h"
#include <llvm/Support/Casting.h>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// X86_32GOT
//===----------------------------------------------------------------------===//
-X86_32GOT::X86_32GOT(LDSection& pSection)
- : GOT(pSection)
-{
+X86_32GOT::X86_32GOT(LDSection& pSection) : GOT(pSection) {
}
-X86_32GOT::~X86_32GOT()
-{
+X86_32GOT::~X86_32GOT() {
}
-X86_32GOTEntry* X86_32GOT::create()
-{
+X86_32GOTEntry* X86_32GOT::create() {
return new X86_32GOTEntry(0, m_SectionData);
}
//===----------------------------------------------------------------------===//
// X86_64GOT
//===----------------------------------------------------------------------===//
-X86_64GOT::X86_64GOT(LDSection& pSection)
- : GOT(pSection)
-{
+X86_64GOT::X86_64GOT(LDSection& pSection) : GOT(pSection) {
}
-X86_64GOT::~X86_64GOT()
-{
+X86_64GOT::~X86_64GOT() {
}
-X86_64GOTEntry* X86_64GOT::create()
-{
+X86_64GOTEntry* X86_64GOT::create() {
return new X86_64GOTEntry(0, m_SectionData);
}
+} // namespace mcld
diff --git a/lib/Target/X86/X86GOT.h b/lib/Target/X86/X86GOT.h
index f977362..c2cc145 100644
--- a/lib/Target/X86/X86GOT.h
+++ b/lib/Target/X86/X86GOT.h
@@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86GOT_H
-#define TARGET_X86_X86GOT_H
+#ifndef TARGET_X86_X86GOT_H_
+#define TARGET_X86_X86GOT_H_
-#include <mcld/Target/GOT.h>
+#include "mcld/Target/GOT.h"
namespace mcld {
@@ -19,22 +19,19 @@ class SectionData;
/** \class X86_32GOTEntry
* \brief GOT Entry with size of 4 bytes
*/
-class X86_32GOTEntry : public GOT::Entry<4>
-{
-public:
+class X86_32GOTEntry : public GOT::Entry<4> {
+ public:
X86_32GOTEntry(uint64_t pContent, SectionData* pParent)
- : GOT::Entry<4>(pContent, pParent)
- {}
+ : GOT::Entry<4>(pContent, pParent) {}
};
/** \class X86_32GOT
* \brief X86_32 Global Offset Table.
*/
-class X86_32GOT : public GOT
-{
-public:
- X86_32GOT(LDSection& pSection);
+class X86_32GOT : public GOT {
+ public:
+ explicit X86_32GOT(LDSection& pSection);
~X86_32GOT();
@@ -44,29 +41,25 @@ public:
/** \class X86_64GOTEntry
* \brief GOT Entry with size of 8 bytes
*/
-class X86_64GOTEntry : public GOT::Entry<8>
-{
-public:
+class X86_64GOTEntry : public GOT::Entry<8> {
+ public:
X86_64GOTEntry(uint64_t pContent, SectionData* pParent)
- : GOT::Entry<8>(pContent, pParent)
- {}
+ : GOT::Entry<8>(pContent, pParent) {}
};
/** \class X86_64GOT
* \brief X86_64 Global Offset Table.
*/
-class X86_64GOT : public GOT
-{
-public:
- X86_64GOT(LDSection& pSection);
+class X86_64GOT : public GOT {
+ public:
+ explicit X86_64GOT(LDSection& pSection);
~X86_64GOT();
X86_64GOTEntry* create();
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_X86_X86GOT_H_
diff --git a/lib/Target/X86/X86GOTPLT.cpp b/lib/Target/X86/X86GOTPLT.cpp
index 7baa5cb..5b97d8d 100644
--- a/lib/Target/X86/X86GOTPLT.cpp
+++ b/lib/Target/X86/X86GOTPLT.cpp
@@ -9,49 +9,43 @@
#include "X86GOTPLT.h"
#include "X86PLT.h"
-#include <llvm/Support/Casting.h>
+#include "mcld/LD/LDSection.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/Support/MsgHandling.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/Support/MsgHandling.h>
+#include <llvm/Support/Casting.h>
namespace mcld {
//===----------------------------------------------------------------------===//
// X86_32GOTPLT
//===----------------------------------------------------------------------===//
-X86_32GOTPLT::X86_32GOTPLT(LDSection& pSection)
- : X86_32GOT(pSection)
-{
+X86_32GOTPLT::X86_32GOTPLT(LDSection& pSection) : X86_32GOT(pSection) {
// create GOT0 entries
for (size_t i = 0; i < X86GOTPLT0Num; ++i)
create();
}
-X86_32GOTPLT::~X86_32GOTPLT()
-{
+X86_32GOTPLT::~X86_32GOTPLT() {
}
-bool X86_32GOTPLT::hasGOT1() const
-{
+bool X86_32GOTPLT::hasGOT1() const {
return (m_SectionData->size() > X86GOTPLT0Num);
}
-void X86_32GOTPLT::applyGOT0(uint64_t pAddress)
-{
- llvm::cast<X86_32GOTEntry>
- (*(m_SectionData->getFragmentList().begin())).setValue(pAddress);
+void X86_32GOTPLT::applyGOT0(uint64_t pAddress) {
+ llvm::cast<X86_32GOTEntry>(*(m_SectionData->getFragmentList().begin()))
+ .setValue(pAddress);
}
-void X86_32GOTPLT::applyAllGOTPLT(const X86PLT& pPLT)
-{
+void X86_32GOTPLT::applyAllGOTPLT(const X86PLT& pPLT) {
iterator it = begin();
// skip GOT0
for (size_t i = 0; i < X86GOTPLT0Num; ++i)
++it;
// address of corresponding plt entry
uint64_t plt_addr = pPLT.addr() + pPLT.getPLT0Size();
- for (; it != end() ; ++it) {
+ for (; it != end(); ++it) {
llvm::cast<X86_32GOTEntry>(*it).setValue(plt_addr + 6);
plt_addr += pPLT.getPLT1Size();
}
@@ -60,40 +54,34 @@ void X86_32GOTPLT::applyAllGOTPLT(const X86PLT& pPLT)
//===----------------------------------------------------------------------===//
// X86_64GOTPLT
//===----------------------------------------------------------------------===//
-X86_64GOTPLT::X86_64GOTPLT(LDSection& pSection)
- : X86_64GOT(pSection)
-{
+X86_64GOTPLT::X86_64GOTPLT(LDSection& pSection) : X86_64GOT(pSection) {
for (size_t i = 0; i < X86GOTPLT0Num; ++i)
create();
}
-X86_64GOTPLT::~X86_64GOTPLT()
-{
+X86_64GOTPLT::~X86_64GOTPLT() {
}
-bool X86_64GOTPLT::hasGOT1() const
-{
+bool X86_64GOTPLT::hasGOT1() const {
return (m_SectionData->size() > X86GOTPLT0Num);
}
-void X86_64GOTPLT::applyGOT0(uint64_t pAddress)
-{
- llvm::cast<X86_64GOTEntry>
- (*(m_SectionData->getFragmentList().begin())).setValue(pAddress);
+void X86_64GOTPLT::applyGOT0(uint64_t pAddress) {
+ llvm::cast<X86_64GOTEntry>(*(m_SectionData->getFragmentList().begin()))
+ .setValue(pAddress);
}
-void X86_64GOTPLT::applyAllGOTPLT(const X86PLT& pPLT)
-{
+void X86_64GOTPLT::applyAllGOTPLT(const X86PLT& pPLT) {
iterator it = begin();
// skip GOT0
for (size_t i = 0; i < X86GOTPLT0Num; ++i)
++it;
// address of corresponding plt entry
uint64_t plt_addr = pPLT.addr() + pPLT.getPLT0Size();
- for (; it != end() ; ++it) {
+ for (; it != end(); ++it) {
llvm::cast<X86_64GOTEntry>(*it).setValue(plt_addr + 6);
plt_addr += pPLT.getPLT1Size();
}
}
-} //end mcld namespace
+} // namespace mcld
diff --git a/lib/Target/X86/X86GOTPLT.h b/lib/Target/X86/X86GOTPLT.h
index 4f9fcbd..f9060e1 100644
--- a/lib/Target/X86/X86GOTPLT.h
+++ b/lib/Target/X86/X86GOTPLT.h
@@ -6,27 +6,26 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86GOTPLT_H
-#define TARGET_X86_X86GOTPLT_H
-
-#include <llvm/ADT/DenseMap.h>
+#ifndef TARGET_X86_X86GOTPLT_H_
+#define TARGET_X86_X86GOTPLT_H_
#include "X86GOT.h"
+#include <llvm/ADT/DenseMap.h>
+
namespace mcld {
-class X86PLT;
class LDSection;
+class X86PLT;
const unsigned int X86GOTPLT0Num = 3;
/** \class X86_32GOTPLT
* \brief X86_32 .got.plt section.
*/
-class X86_32GOTPLT : public X86_32GOT
-{
-public:
- X86_32GOTPLT(LDSection &pSection);
+class X86_32GOTPLT : public X86_32GOT {
+ public:
+ explicit X86_32GOTPLT(LDSection& pSection);
~X86_32GOTPLT();
@@ -41,10 +40,9 @@ public:
/** \class X86_64GOTPLT
* \brief X86_64 .got.plt section.
*/
-class X86_64GOTPLT : public X86_64GOT
-{
-public:
- X86_64GOTPLT(LDSection &pSection);
+class X86_64GOTPLT : public X86_64GOT {
+ public:
+ explicit X86_64GOTPLT(LDSection& pSection);
~X86_64GOTPLT();
@@ -56,7 +54,6 @@ public:
void applyAllGOTPLT(const X86PLT& pPLT);
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_X86_X86GOTPLT_H_
diff --git a/lib/Target/X86/X86LDBackend.cpp b/lib/Target/X86/X86LDBackend.cpp
index eb4c6c6..3a6928a 100644
--- a/lib/Target/X86/X86LDBackend.cpp
+++ b/lib/Target/X86/X86LDBackend.cpp
@@ -12,23 +12,23 @@
#include "X86Relocator.h"
#include "X86GNUInfo.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Fragment/FillFragment.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MsgHandling.h"
+#include "mcld/Support/TargetRegistry.h"
+
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/Triple.h>
#include <llvm/Support/Casting.h>
-
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/Fragment/FillFragment.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <mcld/Object/ObjectBuilder.h>
#include <llvm/Support/Dwarf.h>
#include <cstring>
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// X86GNULDBackend
@@ -36,17 +36,16 @@ using namespace mcld;
X86GNULDBackend::X86GNULDBackend(const LinkerConfig& pConfig,
GNUInfo* pInfo,
Relocation::Type pCopyRel)
- : GNULDBackend(pConfig, pInfo),
- m_pRelocator(NULL),
- m_pPLT(NULL),
- m_pRelDyn(NULL),
- m_pRelPLT(NULL),
- m_pDynamic(NULL),
- m_pGOTSymbol(NULL),
- m_CopyRel(pCopyRel)
-{
+ : GNULDBackend(pConfig, pInfo),
+ m_pRelocator(NULL),
+ m_pPLT(NULL),
+ m_pRelDyn(NULL),
+ m_pRelPLT(NULL),
+ m_pDynamic(NULL),
+ m_pGOTSymbol(NULL),
+ m_CopyRel(pCopyRel) {
llvm::Triple::ArchType arch = pConfig.targets().triple().getArch();
- assert (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64);
+ assert(arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64);
if (arch == llvm::Triple::x86 ||
pConfig.targets().triple().getEnvironment() == llvm::Triple::GNUX32) {
m_RelEntrySize = 8;
@@ -55,16 +54,14 @@ X86GNULDBackend::X86GNULDBackend(const LinkerConfig& pConfig,
m_PointerRel = llvm::ELF::R_386_32;
else
m_PointerRel = llvm::ELF::R_X86_64_32;
- }
- else {
+ } else {
m_RelEntrySize = 16;
m_RelaEntrySize = 24;
m_PointerRel = llvm::ELF::R_X86_64_64;
}
}
-X86GNULDBackend::~X86GNULDBackend()
-{
+X86GNULDBackend::~X86GNULDBackend() {
delete m_pRelocator;
delete m_pPLT;
delete m_pRelDyn;
@@ -72,22 +69,19 @@ X86GNULDBackend::~X86GNULDBackend()
delete m_pDynamic;
}
-const Relocator* X86GNULDBackend::getRelocator() const
-{
- assert(NULL != m_pRelocator);
+const Relocator* X86GNULDBackend::getRelocator() const {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-Relocator* X86GNULDBackend::getRelocator()
-{
- assert(NULL != m_pRelocator);
+Relocator* X86GNULDBackend::getRelocator() {
+ assert(m_pRelocator != NULL);
return m_pRelocator;
}
-void X86GNULDBackend::doPreLayout(IRBuilder& pBuilder)
-{
+void X86GNULDBackend::doPreLayout(IRBuilder& pBuilder) {
// initialize .dynamic data
- if (!config().isCodeStatic() && NULL == m_pDynamic)
+ if (!config().isCodeStatic() && m_pDynamic == NULL)
m_pDynamic = new X86ELFDynamic(*this, config());
// set .got.plt and .got sizes
@@ -101,14 +95,16 @@ void X86GNULDBackend::doPreLayout(IRBuilder& pBuilder)
// set .rel.dyn/.rela.dyn size
if (!m_pRelDyn->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
setRelDynSize();
}
// set .rel.plt/.rela.plt size
if (!m_pRelPLT->empty()) {
- assert(!config().isCodeStatic() &&
- "static linkage should not result in a dynamic relocation section");
+ assert(
+ !config().isCodeStatic() &&
+ "static linkage should not result in a dynamic relocation section");
setRelPLTSize();
}
}
@@ -117,57 +113,50 @@ void X86GNULDBackend::doPreLayout(IRBuilder& pBuilder)
addEhFrameForPLT(pBuilder.getModule());
}
-void X86GNULDBackend::doPostLayout(Module& pModule,
- IRBuilder& pBuilder)
-{
+void X86GNULDBackend::doPostLayout(Module& pModule, IRBuilder& pBuilder) {
}
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-X86ELFDynamic& X86GNULDBackend::dynamic()
-{
- assert(NULL != m_pDynamic);
+X86ELFDynamic& X86GNULDBackend::dynamic() {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
/// dynamic - the dynamic section of the target machine.
/// Use co-variant return type to return its own dynamic section.
-const X86ELFDynamic& X86GNULDBackend::dynamic() const
-{
- assert(NULL != m_pDynamic);
+const X86ELFDynamic& X86GNULDBackend::dynamic() const {
+ assert(m_pDynamic != NULL);
return *m_pDynamic;
}
-void X86GNULDBackend::defineGOTSymbol(IRBuilder& pBuilder, Fragment& pFrag)
-{
+void X86GNULDBackend::defineGOTSymbol(IRBuilder& pBuilder, Fragment& pFrag) {
// define symbol _GLOBAL_OFFSET_TABLE_
if (m_pGOTSymbol != NULL) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Unresolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(pFrag, 0x0),
- ResolveInfo::Hidden);
- }
- else {
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(pFrag, 0x0),
+ ResolveInfo::Hidden);
+ } else {
m_pGOTSymbol = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Create(pFrag, 0x0),
- ResolveInfo::Hidden);
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Create(pFrag, 0x0),
+ ResolveInfo::Hidden);
}
}
uint64_t X86GNULDBackend::emitSectionData(const LDSection& pSection,
- MemoryRegion& pRegion) const
-{
+ MemoryRegion& pRegion) const {
assert(pRegion.size() && "Size of MemoryRegion is zero!");
const ELFFileFormat* FileFormat = getOutputFormat();
@@ -198,61 +187,50 @@ uint64_t X86GNULDBackend::emitSectionData(const LDSection& pSection,
RegionSize += EntrySize;
++it;
}
- }
- else if (FileFormat->hasGOT() && (&pSection == &(FileFormat->getGOT()))) {
+ } else if (FileFormat->hasGOT() && (&pSection == &(FileFormat->getGOT()))) {
RegionSize += emitGOTSectionData(pRegion);
- }
- else if (FileFormat->hasGOTPLT() &&
- (&pSection == &(FileFormat->getGOTPLT()))) {
+ } else if (FileFormat->hasGOTPLT() &&
+ (&pSection == &(FileFormat->getGOTPLT()))) {
RegionSize += emitGOTPLTSectionData(pRegion, FileFormat);
- }
- else {
- fatal(diag::unrecognized_output_sectoin)
- << pSection.name()
- << "mclinker@googlegroups.com";
+ } else {
+ fatal(diag::unrecognized_output_sectoin) << pSection.name()
+ << "mclinker@googlegroups.com";
}
return RegionSize;
}
-X86PLT& X86GNULDBackend::getPLT()
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+X86PLT& X86GNULDBackend::getPLT() {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-const X86PLT& X86GNULDBackend::getPLT() const
-{
- assert(NULL != m_pPLT && "PLT section not exist");
+const X86PLT& X86GNULDBackend::getPLT() const {
+ assert(m_pPLT != NULL && "PLT section not exist");
return *m_pPLT;
}
-OutputRelocSection& X86GNULDBackend::getRelDyn()
-{
- assert(NULL != m_pRelDyn && ".rel.dyn/.rela.dyn section not exist");
+OutputRelocSection& X86GNULDBackend::getRelDyn() {
+ assert(m_pRelDyn != NULL && ".rel.dyn/.rela.dyn section not exist");
return *m_pRelDyn;
}
-const OutputRelocSection& X86GNULDBackend::getRelDyn() const
-{
- assert(NULL != m_pRelDyn && ".rel.dyn/.rela.dyn section not exist");
+const OutputRelocSection& X86GNULDBackend::getRelDyn() const {
+ assert(m_pRelDyn != NULL && ".rel.dyn/.rela.dyn section not exist");
return *m_pRelDyn;
}
-OutputRelocSection& X86GNULDBackend::getRelPLT()
-{
- assert(NULL != m_pRelPLT && ".rel.plt/.rela.plt section not exist");
+OutputRelocSection& X86GNULDBackend::getRelPLT() {
+ assert(m_pRelPLT != NULL && ".rel.plt/.rela.plt section not exist");
return *m_pRelPLT;
}
-const OutputRelocSection& X86GNULDBackend::getRelPLT() const
-{
- assert(NULL != m_pRelPLT && ".rel.plt/.rela.plt section not exist");
+const OutputRelocSection& X86GNULDBackend::getRelPLT() const {
+ assert(m_pRelPLT != NULL && ".rel.plt/.rela.plt section not exist");
return *m_pRelPLT;
}
-unsigned int
-X86GNULDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
-{
+unsigned int X86GNULDBackend::getTargetSectionOrder(
+ const LDSection& pSectHdr) const {
const ELFFileFormat* file_format = getOutputFormat();
if (file_format->hasGOT() && (&pSectHdr == &file_format->getGOT())) {
@@ -273,26 +251,24 @@ X86GNULDBackend::getTargetSectionOrder(const LDSection& pSectHdr) const
return SHO_UNDEFINED;
}
-void X86GNULDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule)
-{
+void X86GNULDBackend::initTargetSymbols(IRBuilder& pBuilder, Module& pModule) {
if (LinkerConfig::Object != config().codeGenType()) {
// Define the symbol _GLOBAL_OFFSET_TABLE_ if there is a symbol with the
// same name in input
m_pGOTSymbol =
- pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
- "_GLOBAL_OFFSET_TABLE_",
- ResolveInfo::Object,
- ResolveInfo::Define,
- ResolveInfo::Local,
- 0x0, // size
- 0x0, // value
- FragmentRef::Null(), // FragRef
- ResolveInfo::Hidden);
+ pBuilder.AddSymbol<IRBuilder::AsReferred, IRBuilder::Resolve>(
+ "_GLOBAL_OFFSET_TABLE_",
+ ResolveInfo::Object,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0x0, // size
+ 0x0, // value
+ FragmentRef::Null(), // FragRef
+ ResolveInfo::Hidden);
}
}
-void X86GNULDBackend::addEhFrameForPLT(Module& pModule)
-{
+void X86GNULDBackend::addEhFrameForPLT(Module& pModule) {
LDSection* plt_sect = pModule.getSection(".plt");
if (!plt_sect || plt_sect->size() == 0u)
return;
@@ -309,8 +285,8 @@ void X86GNULDBackend::addEhFrameForPLT(Module& pModule)
EhFrame::CIE* cie = new EhFrame::GeneratedCIE(cie_region);
EhFrame::FDE* fde = new EhFrame::GeneratedFDE(fde_region, *cie);
// Augmentation data only contains FDE encoding.
- uint8_t aug_data = (uint8_t)(llvm::dwarf::DW_EH_PE_pcrel |
- llvm::dwarf::DW_EH_PE_sdata4);
+ uint8_t aug_data =
+ (uint8_t)(llvm::dwarf::DW_EH_PE_pcrel | llvm::dwarf::DW_EH_PE_sdata4);
cie->setFDEEncode(aug_data);
cie->setAugmentationData(std::string(1, aug_data));
@@ -337,42 +313,37 @@ void X86GNULDBackend::addEhFrameForPLT(Module& pModule)
}
/// finalizeSymbol - finalize the symbol value
-bool X86GNULDBackend::finalizeTargetSymbols()
-{
+bool X86GNULDBackend::finalizeTargetSymbols() {
return true;
}
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
-void X86GNULDBackend::doCreateProgramHdrs(Module& pModule)
-{
+void X86GNULDBackend::doCreateProgramHdrs(Module& pModule) {
// TODO
}
X86_32GNULDBackend::X86_32GNULDBackend(const LinkerConfig& pConfig,
GNUInfo* pInfo)
- : X86GNULDBackend(pConfig, pInfo, llvm::ELF::R_386_COPY),
- m_pGOT (NULL),
- m_pGOTPLT (NULL) {
+ : X86GNULDBackend(pConfig, pInfo, llvm::ELF::R_386_COPY),
+ m_pGOT(NULL),
+ m_pGOTPLT(NULL) {
}
-X86_32GNULDBackend::~X86_32GNULDBackend()
-{
+X86_32GNULDBackend::~X86_32GNULDBackend() {
delete m_pGOT;
delete m_pGOTPLT;
}
-bool X86_32GNULDBackend::initRelocator()
-{
- if (NULL == m_pRelocator) {
+bool X86_32GNULDBackend::initRelocator() {
+ if (m_pRelocator == NULL) {
m_pRelocator = new X86_32Relocator(*this, config());
}
return true;
}
void X86_32GNULDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
+ ObjectBuilder& pBuilder) {
if (LinkerConfig::Object != config().codeGenType()) {
ELFFileFormat* file_format = getOutputFormat();
// initialize .got
@@ -396,107 +367,95 @@ void X86_32GNULDBackend::initTargetSections(Module& pModule,
// initialize .rel.dyn
LDSection& reldyn = file_format->getRelDyn();
m_pRelDyn = new OutputRelocSection(pModule, reldyn);
-
}
}
-X86_32GOT& X86_32GNULDBackend::getGOT()
-{
- assert(NULL != m_pGOT);
+X86_32GOT& X86_32GNULDBackend::getGOT() {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-const X86_32GOT& X86_32GNULDBackend::getGOT() const
-{
- assert(NULL != m_pGOT);
+const X86_32GOT& X86_32GNULDBackend::getGOT() const {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-X86_32GOTPLT& X86_32GNULDBackend::getGOTPLT()
-{
- assert(NULL != m_pGOTPLT);
+X86_32GOTPLT& X86_32GNULDBackend::getGOTPLT() {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-const X86_32GOTPLT& X86_32GNULDBackend::getGOTPLT() const
-{
- assert(NULL != m_pGOTPLT);
+const X86_32GOTPLT& X86_32GNULDBackend::getGOTPLT() const {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-llvm::StringRef X86_32GNULDBackend::createCIERegionForPLT()
-{
- using namespace llvm::dwarf;
- static const uint8_t data[4+4+16] = {
- 0x14, 0, 0, 0, // length
- 0, 0, 0, 0, // ID
- 1, // version
- 'z', 'R', '\0', // augmentation string
- 1, // code alignment factor
- 0x7c, // data alignment factor
- 8, // return address column
- 1, // augmentation data size
- DW_EH_PE_pcrel | DW_EH_PE_sdata4, // FDE encoding
- DW_CFA_def_cfa, 4, 4,
- DW_CFA_offset + 8, 1,
- DW_CFA_nop,
- DW_CFA_nop
+llvm::StringRef X86_32GNULDBackend::createCIERegionForPLT() {
+ static const uint8_t data[4 + 4 + 16] = {
+ 0x14, 0, 0, 0, // length
+ 0, 0, 0, 0, // ID
+ 1, // version
+ 'z', 'R', '\0', // augmentation string
+ 1, // code alignment factor
+ 0x7c, // data alignment factor
+ 8, // return address column
+ 1, // augmentation data size
+ llvm::dwarf::DW_EH_PE_pcrel
+ | llvm::dwarf::DW_EH_PE_sdata4, // FDE encoding
+ llvm::dwarf::DW_CFA_def_cfa, 4, 4,
+ llvm::dwarf::DW_CFA_offset + 8, 1,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop
};
- return llvm::StringRef((const char*)data, 4+4+16);
-}
-
-llvm::StringRef X86_32GNULDBackend::createFDERegionForPLT()
-{
- using namespace llvm::dwarf;
- static const uint8_t data[4+4+32] = {
- 0x24, 0, 0, 0, // length
- 0, 0, 0, 0, // offset to CIE
- 0, 0, 0, 0, // offset to PLT
- 0, 0, 0, 0, // size of PLT
- 0, // augmentation data size
- DW_CFA_def_cfa_offset, 8,
- DW_CFA_advance_loc + 6,
- DW_CFA_def_cfa_offset, 12,
- DW_CFA_advance_loc + 10,
- DW_CFA_def_cfa_expression,
- 11,
- DW_OP_breg4, 4,
- DW_OP_breg8, 0,
- DW_OP_lit15,
- DW_OP_and,
- DW_OP_lit11,
- DW_OP_ge,
- DW_OP_lit2,
- DW_OP_shl,
- DW_OP_plus,
- DW_CFA_nop,
- DW_CFA_nop,
- DW_CFA_nop,
- DW_CFA_nop
+ return llvm::StringRef((const char*)data, 4 + 4 + 16);
+}
+
+llvm::StringRef X86_32GNULDBackend::createFDERegionForPLT() {
+ static const uint8_t data[4 + 4 + 32] = {
+ 0x24, 0, 0, 0, // length
+ 0, 0, 0, 0, // offset to CIE
+ 0, 0, 0, 0, // offset to PLT
+ 0, 0, 0, 0, // size of PLT
+ 0, // augmentation data size
+ llvm::dwarf::DW_CFA_def_cfa_offset, 8,
+ llvm::dwarf::DW_CFA_advance_loc + 6,
+ llvm::dwarf::DW_CFA_def_cfa_offset, 12,
+ llvm::dwarf::DW_CFA_advance_loc + 10,
+ llvm::dwarf::DW_CFA_def_cfa_expression,
+ 11,
+ llvm::dwarf::DW_OP_breg4, 4,
+ llvm::dwarf::DW_OP_breg8, 0,
+ llvm::dwarf::DW_OP_lit15,
+ llvm::dwarf::DW_OP_and,
+ llvm::dwarf::DW_OP_lit11,
+ llvm::dwarf::DW_OP_ge,
+ llvm::dwarf::DW_OP_lit2,
+ llvm::dwarf::DW_OP_shl,
+ llvm::dwarf::DW_OP_plus,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop
};
- return llvm::StringRef((const char*)data, 4+4+32);
+ return llvm::StringRef((const char*)data, 4 + 4 + 32);
}
-void X86_32GNULDBackend::setRelDynSize()
-{
+void X86_32GNULDBackend::setRelDynSize() {
ELFFileFormat* file_format = getOutputFormat();
- file_format->getRelDyn().setSize
- (m_pRelDyn->numOfRelocs() * getRelEntrySize());
+ file_format->getRelDyn().setSize(m_pRelDyn->numOfRelocs() *
+ getRelEntrySize());
}
-void X86_32GNULDBackend::setRelPLTSize()
-{
+void X86_32GNULDBackend::setRelPLTSize() {
ELFFileFormat* file_format = getOutputFormat();
- file_format->getRelPlt().setSize
- (m_pRelPLT->numOfRelocs() * getRelEntrySize());
+ file_format->getRelPlt().setSize(m_pRelPLT->numOfRelocs() *
+ getRelEntrySize());
}
-void X86_32GNULDBackend::setGOTSectionSize(IRBuilder& pBuilder)
-{
+void X86_32GNULDBackend::setGOTSectionSize(IRBuilder& pBuilder) {
// set .got.plt size
- if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOTPLT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ if (LinkerConfig::DynObj == config().codeGenType() || m_pGOTPLT->hasGOT1() ||
+ m_pGOTSymbol != NULL) {
m_pGOTPLT->finalizeSectionSize();
defineGOTSymbol(pBuilder, *(m_pGOTPLT->begin()));
}
@@ -506,8 +465,7 @@ void X86_32GNULDBackend::setGOTSectionSize(IRBuilder& pBuilder)
m_pGOT->finalizeSectionSize();
}
-uint64_t X86_32GNULDBackend::emitGOTSectionData(MemoryRegion& pRegion) const
-{
+uint64_t X86_32GNULDBackend::emitGOTSectionData(MemoryRegion& pRegion) const {
assert(m_pGOT && "emitGOTSectionData failed, m_pGOT is NULL!");
uint32_t* buffer = reinterpret_cast<uint32_t*>(pRegion.begin());
@@ -516,8 +474,8 @@ uint64_t X86_32GNULDBackend::emitGOTSectionData(MemoryRegion& pRegion) const
unsigned int EntrySize = X86_32GOTEntry::EntrySize;
uint64_t RegionSize = 0;
- for (X86_32GOT::iterator it = m_pGOT->begin(),
- ie = m_pGOT->end(); it != ie; ++it, ++buffer) {
+ for (X86_32GOT::iterator it = m_pGOT->begin(), ie = m_pGOT->end(); it != ie;
+ ++it, ++buffer) {
got = &(llvm::cast<X86_32GOTEntry>((*it)));
*buffer = static_cast<uint32_t>(got->getValue());
RegionSize += EntrySize;
@@ -526,9 +484,9 @@ uint64_t X86_32GNULDBackend::emitGOTSectionData(MemoryRegion& pRegion) const
return RegionSize;
}
-uint64_t X86_32GNULDBackend::emitGOTPLTSectionData(MemoryRegion& pRegion,
- const ELFFileFormat* FileFormat) const
-{
+uint64_t X86_32GNULDBackend::emitGOTPLTSectionData(
+ MemoryRegion& pRegion,
+ const ELFFileFormat* FileFormat) const {
assert(m_pGOTPLT && "emitGOTPLTSectionData failed, m_pGOTPLT is NULL!");
m_pGOTPLT->applyGOT0(FileFormat->getDynamic().addr());
m_pGOTPLT->applyAllGOTPLT(*m_pPLT);
@@ -539,8 +497,9 @@ uint64_t X86_32GNULDBackend::emitGOTPLTSectionData(MemoryRegion& pRegion,
unsigned int EntrySize = X86_32GOTEntry::EntrySize;
uint64_t RegionSize = 0;
- for (X86_32GOTPLT::iterator it = m_pGOTPLT->begin(),
- ie = m_pGOTPLT->end(); it != ie; ++it, ++buffer) {
+ for (X86_32GOTPLT::iterator it = m_pGOTPLT->begin(), ie = m_pGOTPLT->end();
+ it != ie;
+ ++it, ++buffer) {
got = &(llvm::cast<X86_32GOTEntry>((*it)));
*buffer = static_cast<uint32_t>(got->getValue());
RegionSize += EntrySize;
@@ -551,119 +510,107 @@ uint64_t X86_32GNULDBackend::emitGOTPLTSectionData(MemoryRegion& pRegion,
X86_64GNULDBackend::X86_64GNULDBackend(const LinkerConfig& pConfig,
GNUInfo* pInfo)
- : X86GNULDBackend(pConfig, pInfo, llvm::ELF::R_X86_64_COPY),
- m_pGOT (NULL),
- m_pGOTPLT (NULL) {
+ : X86GNULDBackend(pConfig, pInfo, llvm::ELF::R_X86_64_COPY),
+ m_pGOT(NULL),
+ m_pGOTPLT(NULL) {
}
-X86_64GNULDBackend::~X86_64GNULDBackend()
-{
+X86_64GNULDBackend::~X86_64GNULDBackend() {
delete m_pGOT;
delete m_pGOTPLT;
}
-bool X86_64GNULDBackend::initRelocator()
-{
- if (NULL == m_pRelocator) {
+bool X86_64GNULDBackend::initRelocator() {
+ if (m_pRelocator == NULL) {
m_pRelocator = new X86_64Relocator(*this, config());
}
return true;
}
-X86_64GOT& X86_64GNULDBackend::getGOT()
-{
- assert(NULL != m_pGOT);
+X86_64GOT& X86_64GNULDBackend::getGOT() {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-const X86_64GOT& X86_64GNULDBackend::getGOT() const
-{
- assert(NULL != m_pGOT);
+const X86_64GOT& X86_64GNULDBackend::getGOT() const {
+ assert(m_pGOT != NULL);
return *m_pGOT;
}
-X86_64GOTPLT& X86_64GNULDBackend::getGOTPLT()
-{
- assert(NULL != m_pGOTPLT);
+X86_64GOTPLT& X86_64GNULDBackend::getGOTPLT() {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-const X86_64GOTPLT& X86_64GNULDBackend::getGOTPLT() const
-{
- assert(NULL != m_pGOTPLT);
+const X86_64GOTPLT& X86_64GNULDBackend::getGOTPLT() const {
+ assert(m_pGOTPLT != NULL);
return *m_pGOTPLT;
}
-llvm::StringRef X86_64GNULDBackend::createCIERegionForPLT()
-{
- using namespace llvm::dwarf;
- static const uint8_t data[4+4+16] = {
- 0x14, 0, 0, 0, // length
- 0, 0, 0, 0, // ID
- 1, // CIE version
- 'z', 'R', '\0', // augmentation string
- 1, // code alignment factor
- 0x78, // data alignment factor
- 16, // return address column
- 1, // augmentation data size
- DW_EH_PE_pcrel | DW_EH_PE_sdata4, // FDE encoding
- DW_CFA_def_cfa, 7, 8,
- DW_CFA_offset + 16, 1,
- DW_CFA_nop,
- DW_CFA_nop
+llvm::StringRef X86_64GNULDBackend::createCIERegionForPLT() {
+ static const uint8_t data[4 + 4 + 16] = {
+ 0x14, 0, 0, 0, // length
+ 0, 0, 0, 0, // ID
+ 1, // CIE version
+ 'z', 'R', '\0', // augmentation string
+ 1, // code alignment factor
+ 0x78, // data alignment factor
+ 16, // return address column
+ 1, // augmentation data size
+ llvm::dwarf::DW_EH_PE_pcrel
+ | llvm::dwarf::DW_EH_PE_sdata4, // FDE encoding
+ llvm::dwarf::DW_CFA_def_cfa, 7, 8,
+ llvm::dwarf::DW_CFA_offset + 16, 1,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop
};
- return llvm::StringRef((const char*)data, 4+4+16);
-}
-
-llvm::StringRef X86_64GNULDBackend::createFDERegionForPLT()
-{
- using namespace llvm::dwarf;
- static const uint8_t data[4+4+32] = {
- 0x24, 0, 0, 0, // length
- 0, 0, 0, 0, // ID
- 0, 0, 0, 0, // offset to PLT
- 0, 0, 0, 0, // size of PLT
- 0, // augmentation data size
- DW_CFA_def_cfa_offset, 16,
- DW_CFA_advance_loc + 6,
- DW_CFA_def_cfa_offset, 24,
- DW_CFA_advance_loc + 10,
- DW_CFA_def_cfa_expression,
- 11,
- DW_OP_breg7, 8,
- DW_OP_breg16, 0,
- DW_OP_lit15,
- DW_OP_and,
- DW_OP_lit11,
- DW_OP_ge,
- DW_OP_lit3,
- DW_OP_shl,
- DW_OP_plus,
- DW_CFA_nop,
- DW_CFA_nop,
- DW_CFA_nop,
- DW_CFA_nop
+ return llvm::StringRef((const char*)data, 4 + 4 + 16);
+}
+
+llvm::StringRef X86_64GNULDBackend::createFDERegionForPLT() {
+ static const uint8_t data[4 + 4 + 32] = {
+ 0x24, 0, 0, 0, // length
+ 0, 0, 0, 0, // ID
+ 0, 0, 0, 0, // offset to PLT
+ 0, 0, 0, 0, // size of PLT
+ 0, // augmentation data size
+ llvm::dwarf::DW_CFA_def_cfa_offset, 16,
+ llvm::dwarf::DW_CFA_advance_loc + 6,
+ llvm::dwarf::DW_CFA_def_cfa_offset, 24,
+ llvm::dwarf::DW_CFA_advance_loc + 10,
+ llvm::dwarf::DW_CFA_def_cfa_expression,
+ 11,
+ llvm::dwarf::DW_OP_breg7, 8,
+ llvm::dwarf::DW_OP_breg16, 0,
+ llvm::dwarf::DW_OP_lit15,
+ llvm::dwarf::DW_OP_and,
+ llvm::dwarf::DW_OP_lit11,
+ llvm::dwarf::DW_OP_ge,
+ llvm::dwarf::DW_OP_lit3,
+ llvm::dwarf::DW_OP_shl,
+ llvm::dwarf::DW_OP_plus,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop,
+ llvm::dwarf::DW_CFA_nop
};
- return llvm::StringRef((const char*)data, 4+4+32);
+ return llvm::StringRef((const char*)data, 4 + 4 + 32);
}
-void X86_64GNULDBackend::setRelDynSize()
-{
+void X86_64GNULDBackend::setRelDynSize() {
ELFFileFormat* file_format = getOutputFormat();
- file_format->getRelaDyn().setSize
- (m_pRelDyn->numOfRelocs() * getRelaEntrySize());
+ file_format->getRelaDyn().setSize(m_pRelDyn->numOfRelocs() *
+ getRelaEntrySize());
}
-void X86_64GNULDBackend::setRelPLTSize()
-{
+void X86_64GNULDBackend::setRelPLTSize() {
ELFFileFormat* file_format = getOutputFormat();
- file_format->getRelaPlt().setSize
- (m_pRelPLT->numOfRelocs() * getRelaEntrySize());
+ file_format->getRelaPlt().setSize(m_pRelPLT->numOfRelocs() *
+ getRelaEntrySize());
}
void X86_64GNULDBackend::initTargetSections(Module& pModule,
- ObjectBuilder& pBuilder)
-{
+ ObjectBuilder& pBuilder) {
if (LinkerConfig::Object != config().codeGenType()) {
ELFFileFormat* file_format = getOutputFormat();
// initialize .got
@@ -687,16 +634,13 @@ void X86_64GNULDBackend::initTargetSections(Module& pModule,
// initialize .rela.dyn
LDSection& reldyn = file_format->getRelaDyn();
m_pRelDyn = new OutputRelocSection(pModule, reldyn);
-
}
}
-void X86_64GNULDBackend::setGOTSectionSize(IRBuilder& pBuilder)
-{
+void X86_64GNULDBackend::setGOTSectionSize(IRBuilder& pBuilder) {
// set .got.plt size
- if (LinkerConfig::DynObj == config().codeGenType() ||
- m_pGOTPLT->hasGOT1() ||
- NULL != m_pGOTSymbol) {
+ if (LinkerConfig::DynObj == config().codeGenType() || m_pGOTPLT->hasGOT1() ||
+ m_pGOTSymbol != NULL) {
m_pGOTPLT->finalizeSectionSize();
defineGOTSymbol(pBuilder, *(m_pGOTPLT->begin()));
}
@@ -706,8 +650,7 @@ void X86_64GNULDBackend::setGOTSectionSize(IRBuilder& pBuilder)
m_pGOT->finalizeSectionSize();
}
-uint64_t X86_64GNULDBackend::emitGOTSectionData(MemoryRegion& pRegion) const
-{
+uint64_t X86_64GNULDBackend::emitGOTSectionData(MemoryRegion& pRegion) const {
assert(m_pGOT && "emitGOTSectionData failed, m_pGOT is NULL!");
uint64_t* buffer = reinterpret_cast<uint64_t*>(pRegion.begin());
@@ -716,8 +659,8 @@ uint64_t X86_64GNULDBackend::emitGOTSectionData(MemoryRegion& pRegion) const
unsigned int EntrySize = X86_64GOTEntry::EntrySize;
uint64_t RegionSize = 0;
- for (X86_64GOT::iterator it = m_pGOT->begin(),
- ie = m_pGOT->end(); it != ie; ++it, ++buffer) {
+ for (X86_64GOT::iterator it = m_pGOT->begin(), ie = m_pGOT->end(); it != ie;
+ ++it, ++buffer) {
got = &(llvm::cast<X86_64GOTEntry>((*it)));
*buffer = static_cast<uint64_t>(got->getValue());
RegionSize += EntrySize;
@@ -726,10 +669,9 @@ uint64_t X86_64GNULDBackend::emitGOTSectionData(MemoryRegion& pRegion) const
return RegionSize;
}
-uint64_t
-X86_64GNULDBackend::emitGOTPLTSectionData(MemoryRegion& pRegion,
- const ELFFileFormat* FileFormat) const
-{
+uint64_t X86_64GNULDBackend::emitGOTPLTSectionData(
+ MemoryRegion& pRegion,
+ const ELFFileFormat* FileFormat) const {
assert(m_pGOTPLT && "emitGOTPLTSectionData failed, m_pGOTPLT is NULL!");
m_pGOTPLT->applyGOT0(FileFormat->getDynamic().addr());
m_pGOTPLT->applyAllGOTPLT(*m_pPLT);
@@ -740,8 +682,9 @@ X86_64GNULDBackend::emitGOTPLTSectionData(MemoryRegion& pRegion,
unsigned int EntrySize = X86_64GOTEntry::EntrySize;
uint64_t RegionSize = 0;
- for (X86_64GOTPLT::iterator it = m_pGOTPLT->begin(),
- ie = m_pGOTPLT->end(); it != ie; ++it, ++buffer) {
+ for (X86_64GOTPLT::iterator it = m_pGOTPLT->begin(), ie = m_pGOTPLT->end();
+ it != ie;
+ ++it, ++buffer) {
got = &(llvm::cast<X86_64GOTEntry>((*it)));
*buffer = static_cast<uint64_t>(got->getValue());
RegionSize += EntrySize;
@@ -750,13 +693,10 @@ X86_64GNULDBackend::emitGOTPLTSectionData(MemoryRegion& pRegion,
return RegionSize;
}
-namespace mcld {
-
//===----------------------------------------------------------------------===//
/// createX86LDBackend - the help funtion to create corresponding X86LDBackend
///
-TargetLDBackend* createX86LDBackend(const LinkerConfig& pConfig)
-{
+TargetLDBackend* createX86LDBackend(const LinkerConfig& pConfig) {
if (pConfig.targets().triple().isOSDarwin()) {
assert(0 && "MachO linker is not supported yet");
/**
@@ -775,20 +715,22 @@ TargetLDBackend* createX86LDBackend(const LinkerConfig& pConfig)
}
llvm::Triple::ArchType arch = pConfig.targets().triple().getArch();
if (arch == llvm::Triple::x86)
- return new X86_32GNULDBackend(pConfig,
- new X86_32GNUInfo(pConfig.targets().triple()));
- assert (arch == llvm::Triple::x86_64);
+ return new X86_32GNULDBackend(
+ pConfig, new X86_32GNUInfo(pConfig.targets().triple()));
+ assert(arch == llvm::Triple::x86_64);
return new X86_64GNULDBackend(pConfig,
new X86_64GNUInfo(pConfig.targets().triple()));
}
-} // namespace of mcld
+} // namespace mcld
//===----------------------------------------------------------------------===//
// Force static initialization.
//===----------------------------------------------------------------------===//
extern "C" void MCLDInitializeX86LDBackend() {
// Register the linker backend
- mcld::TargetRegistry::RegisterTargetLDBackend(TheX86_32Target, createX86LDBackend);
- mcld::TargetRegistry::RegisterTargetLDBackend(TheX86_64Target, createX86LDBackend);
+ mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheX86_32Target,
+ mcld::createX86LDBackend);
+ mcld::TargetRegistry::RegisterTargetLDBackend(mcld::TheX86_64Target,
+ mcld::createX86LDBackend);
}
diff --git a/lib/Target/X86/X86LDBackend.h b/lib/Target/X86/X86LDBackend.h
index 503fca9..411ff51 100644
--- a/lib/Target/X86/X86LDBackend.h
+++ b/lib/Target/X86/X86LDBackend.h
@@ -6,16 +6,17 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86LDBACKEND_H
-#define TARGET_X86_X86LDBACKEND_H
+#ifndef TARGET_X86_X86LDBACKEND_H_
+#define TARGET_X86_X86LDBACKEND_H_
#include "X86ELFDynamic.h"
#include "X86GOT.h"
#include "X86GOTPLT.h"
#include "X86PLT.h"
-#include <mcld/LD/LDSection.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/Target/OutputRelocSection.h>
+
+#include "mcld/LD/LDSection.h"
+#include "mcld/Target/GNULDBackend.h"
+#include "mcld/Target/OutputRelocSection.h"
namespace mcld {
@@ -25,9 +26,8 @@ class GNUInfo;
//===----------------------------------------------------------------------===//
/// X86GNULDBackend - linker backend of X86 target of GNU ELF format
///
-class X86GNULDBackend : public GNULDBackend
-{
-public:
+class X86GNULDBackend : public GNULDBackend {
+ public:
X86GNULDBackend(const LinkerConfig& pConfig,
GNUInfo* pInfo,
Relocation::Type pCopyRel);
@@ -99,24 +99,21 @@ public:
bool finalizeTargetSymbols();
/// getPointerRel - get pointer relocation type.
- Relocation::Type getPointerRel()
- { return m_PointerRel; }
+ Relocation::Type getPointerRel() { return m_PointerRel; }
- Relocation::Type getCopyRelType() const { return m_CopyRel; }
+ Relocation::Type getCopyRelType() const { return m_CopyRel; }
Relocation::Type getPointerRelType() const { return m_PointerRel; }
-protected:
+ protected:
void defineGOTSymbol(IRBuilder& pBuilder, Fragment&);
/// getRelEntrySize - the size in BYTE of rel type relocation
- size_t getRelEntrySize()
- { return m_RelEntrySize; }
+ size_t getRelEntrySize() { return m_RelEntrySize; }
/// getRelEntrySize - the size in BYTE of rela type relocation
- size_t getRelaEntrySize()
- { return m_RelaEntrySize; }
+ size_t getRelaEntrySize() { return m_RelaEntrySize; }
-private:
+ private:
/// doCreateProgramHdrs - backend can implement this function to create the
/// target-dependent segments
void doCreateProgramHdrs(Module& pModule);
@@ -125,9 +122,9 @@ private:
virtual uint64_t emitGOTSectionData(MemoryRegion& pRegion) const = 0;
- virtual uint64_t
- emitGOTPLTSectionData(MemoryRegion& pRegion,
- const ELFFileFormat* FileFormat) const = 0;
+ virtual uint64_t emitGOTPLTSectionData(
+ MemoryRegion& pRegion,
+ const ELFFileFormat* FileFormat) const = 0;
virtual void setRelDynSize() = 0;
virtual void setRelPLTSize() = 0;
@@ -136,7 +133,7 @@ private:
virtual llvm::StringRef createCIERegionForPLT() = 0;
virtual llvm::StringRef createFDERegionForPLT() = 0;
-protected:
+ protected:
Relocator* m_pRelocator;
X86PLT* m_pPLT;
/// m_RelDyn - dynamic relocation table of .rel.dyn
@@ -158,9 +155,8 @@ protected:
//===----------------------------------------------------------------------===//
/// X86_32GNULDBackend - linker backend of X86-32 target of GNU ELF format
///
-class X86_32GNULDBackend : public X86GNULDBackend
-{
-public:
+class X86_32GNULDBackend : public X86GNULDBackend {
+ public:
X86_32GNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo);
~X86_32GNULDBackend();
@@ -175,7 +171,7 @@ public:
const X86_32GOTPLT& getGOTPLT() const;
-private:
+ private:
/// initRelocator - create and initialize Relocator.
bool initRelocator();
@@ -192,7 +188,7 @@ private:
llvm::StringRef createCIERegionForPLT();
llvm::StringRef createFDERegionForPLT();
-private:
+ private:
X86_32GOT* m_pGOT;
X86_32GOTPLT* m_pGOTPLT;
};
@@ -201,9 +197,8 @@ private:
//===----------------------------------------------------------------------===//
/// X86_64GNULDBackend - linker backend of X86-64 target of GNU ELF format
///
-class X86_64GNULDBackend : public X86GNULDBackend
-{
-public:
+class X86_64GNULDBackend : public X86GNULDBackend {
+ public:
X86_64GNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo);
~X86_64GNULDBackend();
@@ -218,7 +213,7 @@ public:
const X86_64GOTPLT& getGOTPLT() const;
-private:
+ private:
/// initRelocator - create and initialize Relocator.
bool initRelocator();
@@ -235,11 +230,11 @@ private:
llvm::StringRef createCIERegionForPLT();
llvm::StringRef createFDERegionForPLT();
-private:
+ private:
X86_64GOT* m_pGOT;
X86_64GOTPLT* m_pGOTPLT;
};
-} // namespace of mcld
-#endif
+} // namespace mcld
+#endif // TARGET_X86_X86LDBACKEND_H_
diff --git a/lib/Target/X86/X86MCLinker.cpp b/lib/Target/X86/X86MCLinker.cpp
deleted file mode 100644
index 46d7bb5..0000000
--- a/lib/Target/X86/X86MCLinker.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-//===- X86MCLinker.cpp ----------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "X86.h"
-#include "X86ELFMCLinker.h"
-#include <mcld/Module.h>
-#include <mcld/Support/TargetRegistry.h>
-#include <llvm/ADT/Triple.h>
-
-using namespace mcld;
-
-namespace mcld {
-
-//===----------------------------------------------------------------------===//
-/// createX86MCLinker - the help funtion to create corresponding X86MCLinker
-//===----------------------------------------------------------------------===//
-MCLinker* createX86MCLinker(const std::string &pTriple,
- LinkerConfig& pConfig,
- mcld::Module& pModule,
- FileHandle& pFileHandle)
-{
- llvm::Triple theTriple(pTriple);
- if (theTriple.isOSDarwin()) {
- assert(0 && "MachO linker has not supported yet");
- return NULL;
- }
- if (theTriple.isOSWindows()) {
- assert(0 && "COFF linker has not supported yet");
- return NULL;
- }
-
- return new X86ELFMCLinker(pConfig, pModule, pFileHandle);
-}
-
-} // namespace of mcld
-
-//===----------------------------------------------------------------------===//
-// X86MCLinker
-//===----------------------------------------------------------------------===//
-extern "C" void MCLDInitializeX86MCLinker() {
- // Register the linker frontend
- mcld::TargetRegistry::RegisterMCLinker(TheX86_32Target, createX86MCLinker);
- mcld::TargetRegistry::RegisterMCLinker(TheX86_64Target, createX86MCLinker);
-}
-
diff --git a/lib/Target/X86/X86PLT.cpp b/lib/Target/X86/X86PLT.cpp
index 09b25c4..38d64e7 100644
--- a/lib/Target/X86/X86PLT.cpp
+++ b/lib/Target/X86/X86PLT.cpp
@@ -9,94 +9,82 @@
#include "X86GOTPLT.h"
#include "X86PLT.h"
+#include "mcld/LD/LDSection.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/Support/MsgHandling.h"
+
#include <llvm/Support/ELF.h>
#include <llvm/Support/Casting.h>
-#include <mcld/LD/LDSection.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/Support/MsgHandling.h>
-
-using namespace mcld;
+namespace mcld {
//===----------------------------------------------------------------------===//
// PLT entry data
//===----------------------------------------------------------------------===//
X86_32DynPLT0::X86_32DynPLT0(SectionData& pParent)
- : PLT::Entry<sizeof(x86_32_dyn_plt0)>(pParent)
-{
+ : PLT::Entry<sizeof(x86_32_dyn_plt0)>(pParent) {
}
X86_32DynPLT1::X86_32DynPLT1(SectionData& pParent)
- : PLT::Entry<sizeof(x86_32_dyn_plt1)>(pParent)
-{
+ : PLT::Entry<sizeof(x86_32_dyn_plt1)>(pParent) {
}
X86_32ExecPLT0::X86_32ExecPLT0(SectionData& pParent)
- : PLT::Entry<sizeof(x86_32_exec_plt0)>(pParent)
-{
+ : PLT::Entry<sizeof(x86_32_exec_plt0)>(pParent) {
}
X86_32ExecPLT1::X86_32ExecPLT1(SectionData& pParent)
- : PLT::Entry<sizeof(x86_32_exec_plt1)>(pParent)
-{
+ : PLT::Entry<sizeof(x86_32_exec_plt1)>(pParent) {
}
X86_64PLT0::X86_64PLT0(SectionData& pParent)
- : PLT::Entry<sizeof(x86_64_plt0)>(pParent)
-{
+ : PLT::Entry<sizeof(x86_64_plt0)>(pParent) {
}
X86_64PLT1::X86_64PLT1(SectionData& pParent)
- : PLT::Entry<sizeof(x86_64_plt1)>(pParent)
-{
+ : PLT::Entry<sizeof(x86_64_plt1)>(pParent) {
}
//===----------------------------------------------------------------------===//
// X86PLT
//===----------------------------------------------------------------------===//
X86PLT::X86PLT(LDSection& pSection, const LinkerConfig& pConfig, int got_size)
- : PLT(pSection),
- m_Config(pConfig)
-{
+ : PLT(pSection), m_Config(pConfig) {
assert(LinkerConfig::DynObj == m_Config.codeGenType() ||
- LinkerConfig::Exec == m_Config.codeGenType() ||
+ LinkerConfig::Exec == m_Config.codeGenType() ||
LinkerConfig::Binary == m_Config.codeGenType());
if (got_size == 32) {
if (LinkerConfig::DynObj == m_Config.codeGenType()) {
m_PLT0 = x86_32_dyn_plt0;
m_PLT1 = x86_32_dyn_plt1;
- m_PLT0Size = sizeof (x86_32_dyn_plt0);
- m_PLT1Size = sizeof (x86_32_dyn_plt1);
+ m_PLT0Size = sizeof(x86_32_dyn_plt0);
+ m_PLT1Size = sizeof(x86_32_dyn_plt1);
// create PLT0
new X86_32DynPLT0(*m_pSectionData);
- }
- else {
+ } else {
m_PLT0 = x86_32_exec_plt0;
m_PLT1 = x86_32_exec_plt1;
- m_PLT0Size = sizeof (x86_32_exec_plt0);
- m_PLT1Size = sizeof (x86_32_exec_plt1);
+ m_PLT0Size = sizeof(x86_32_exec_plt0);
+ m_PLT1Size = sizeof(x86_32_exec_plt1);
// create PLT0
new X86_32ExecPLT0(*m_pSectionData);
}
- }
- else {
+ } else {
assert(got_size == 64);
m_PLT0 = x86_64_plt0;
m_PLT1 = x86_64_plt1;
- m_PLT0Size = sizeof (x86_64_plt0);
- m_PLT1Size = sizeof (x86_64_plt1);
+ m_PLT0Size = sizeof(x86_64_plt0);
+ m_PLT1Size = sizeof(x86_64_plt1);
// create PLT0
new X86_64PLT0(*m_pSectionData);
}
}
-X86PLT::~X86PLT()
-{
+X86PLT::~X86PLT() {
}
-void X86PLT::finalizeSectionSize()
-{
+void X86PLT::finalizeSectionSize() {
uint64_t size = 0;
// plt0 size
size = getPLT0()->size();
@@ -119,21 +107,18 @@ void X86PLT::finalizeSectionSize()
}
}
-bool X86PLT::hasPLT1() const
-{
+bool X86PLT::hasPLT1() const {
return (m_pSectionData->size() > 1);
}
-PLTEntryBase* X86PLT::create()
-{
+PLTEntryBase* X86PLT::create() {
if (LinkerConfig::DynObj == m_Config.codeGenType())
return new X86_32DynPLT1(*m_pSectionData);
else
return new X86_32ExecPLT1(*m_pSectionData);
}
-PLTEntryBase* X86PLT::getPLT0() const
-{
+PLTEntryBase* X86PLT::getPLT0() const {
iterator first = m_pSectionData->getFragmentList().begin();
assert(first != m_pSectionData->getFragmentList().end() &&
@@ -150,13 +135,11 @@ PLTEntryBase* X86PLT::getPLT0() const
X86_32PLT::X86_32PLT(LDSection& pSection,
X86_32GOTPLT& pGOTPLT,
const LinkerConfig& pConfig)
- : X86PLT(pSection, pConfig, 32),
- m_GOTPLT(pGOTPLT) {
+ : X86PLT(pSection, pConfig, 32), m_GOTPLT(pGOTPLT) {
}
// FIXME: It only works on little endian machine.
-void X86_32PLT::applyPLT0()
-{
+void X86_32PLT::applyPLT0() {
PLTEntryBase* plt0 = getPLT0();
unsigned char* data = 0;
@@ -168,7 +151,7 @@ void X86_32PLT::applyPLT0()
memcpy(data, m_PLT0, plt0->size());
if (m_PLT0 == x86_32_exec_plt0) {
- uint32_t *offset = reinterpret_cast<uint32_t*>(data + 2);
+ uint32_t* offset = reinterpret_cast<uint32_t*>(data + 2);
*offset = m_GOTPLT.addr() + 4;
offset = reinterpret_cast<uint32_t*>(data + 8);
*offset = m_GOTPLT.addr() + 8;
@@ -178,8 +161,7 @@ void X86_32PLT::applyPLT0()
}
// FIXME: It only works on little endian machine.
-void X86_32PLT::applyPLT1()
-{
+void X86_32PLT::applyPLT1() {
assert(m_Section.addr() && ".plt base address is NULL!");
X86PLT::iterator it = m_pSectionData->begin();
@@ -193,7 +175,7 @@ void X86_32PLT::applyPLT1()
if (LinkerConfig::Exec == m_Config.codeGenType())
GOTEntryOffset += m_GOTPLT.addr();
- //skip PLT0
+ // skip PLT0
uint64_t PLTEntryOffset = m_PLT0Size;
++it;
@@ -203,7 +185,7 @@ void X86_32PLT::applyPLT1()
while (it != ie) {
plt1 = &(llvm::cast<PLTEntryBase>(*it));
- unsigned char *data;
+ unsigned char* data;
data = static_cast<unsigned char*>(malloc(plt1->size()));
if (!data)
@@ -219,7 +201,7 @@ void X86_32PLT::applyPLT1()
offset = reinterpret_cast<uint32_t*>(data + 7);
*offset = PLTRelOffset;
- PLTRelOffset += sizeof (llvm::ELF::Elf32_Rel);
+ PLTRelOffset += sizeof(llvm::ELF::Elf32_Rel);
offset = reinterpret_cast<uint32_t*>(data + 12);
*offset = -(PLTEntryOffset + 12 + 4);
@@ -236,13 +218,11 @@ void X86_32PLT::applyPLT1()
X86_64PLT::X86_64PLT(LDSection& pSection,
X86_64GOTPLT& pGOTPLT,
const LinkerConfig& pConfig)
- : X86PLT(pSection, pConfig, 64),
- m_GOTPLT(pGOTPLT) {
+ : X86PLT(pSection, pConfig, 64), m_GOTPLT(pGOTPLT) {
}
// FIXME: It only works on little endian machine.
-void X86_64PLT::applyPLT0()
-{
+void X86_64PLT::applyPLT0() {
PLTEntryBase* plt0 = getPLT0();
unsigned char* data = 0;
@@ -254,7 +234,7 @@ void X86_64PLT::applyPLT0()
memcpy(data, m_PLT0, plt0->size());
// pushq GOT + 8(%rip)
- uint32_t *offset = reinterpret_cast<uint32_t*>(data + 2);
+ uint32_t* offset = reinterpret_cast<uint32_t*>(data + 2);
*offset = m_GOTPLT.addr() - addr() + 8 - 6;
// jmq *GOT + 16(%rip)
offset = reinterpret_cast<uint32_t*>(data + 8);
@@ -264,8 +244,7 @@ void X86_64PLT::applyPLT0()
}
// FIXME: It only works on little endian machine.
-void X86_64PLT::applyPLT1()
-{
+void X86_64PLT::applyPLT1() {
assert(m_Section.addr() && ".plt base address is NULL!");
X86PLT::iterator it = m_pSectionData->begin();
@@ -293,7 +272,7 @@ void X86_64PLT::applyPLT1()
while (it != ie) {
plt1 = &(llvm::cast<PLTEntryBase>(*it));
- unsigned char *data;
+ unsigned char* data;
data = static_cast<unsigned char*>(malloc(plt1->size()));
if (!data)
@@ -323,3 +302,4 @@ void X86_64PLT::applyPLT1()
}
}
+} // namespace mcld
diff --git a/lib/Target/X86/X86PLT.h b/lib/Target/X86/X86PLT.h
index a220efc..b4aa8cb 100644
--- a/lib/Target/X86/X86PLT.h
+++ b/lib/Target/X86/X86PLT.h
@@ -6,51 +6,47 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86PLT_H
-#define TARGET_X86_X86PLT_H
+#ifndef TARGET_X86_X86PLT_H_
+#define TARGET_X86_X86PLT_H_
-#include <mcld/Target/PLT.h>
-
-namespace {
+#include "mcld/Target/PLT.h"
const uint8_t x86_32_dyn_plt0[] = {
- 0xff, 0xb3, 0x04, 0, 0, 0, // pushl 0x4(%ebx)
- 0xff, 0xa3, 0x08, 0, 0, 0, // jmp *0x8(%ebx)
- 0x0f, 0x1f, 0x4, 0 // nopl 0(%eax)
+ 0xff, 0xb3, 0x04, 0, 0, 0, // pushl 0x4(%ebx)
+ 0xff, 0xa3, 0x08, 0, 0, 0, // jmp *0x8(%ebx)
+ 0x0f, 0x1f, 0x4, 0 // nopl 0(%eax)
};
const uint8_t x86_32_dyn_plt1[] = {
- 0xff, 0xa3, 0, 0, 0, 0, // jmp *sym@GOT(%ebx)
- 0x68, 0, 0, 0, 0, // pushl $offset
- 0xe9, 0, 0, 0, 0 // jmp plt0
+ 0xff, 0xa3, 0, 0, 0, 0, // jmp *sym@GOT(%ebx)
+ 0x68, 0, 0, 0, 0, // pushl $offset
+ 0xe9, 0, 0, 0, 0 // jmp plt0
};
const uint8_t x86_32_exec_plt0[] = {
- 0xff, 0x35, 0, 0, 0, 0, // pushl .got + 4
- 0xff, 0x25, 0, 0, 0, 0, // jmp *(.got + 8)
- 0x0f, 0x1f, 0x4, 0 // nopl 0(%eax)
+ 0xff, 0x35, 0, 0, 0, 0, // pushl .got + 4
+ 0xff, 0x25, 0, 0, 0, 0, // jmp *(.got + 8)
+ 0x0f, 0x1f, 0x4, 0 // nopl 0(%eax)
};
const uint8_t x86_32_exec_plt1[] = {
- 0xff, 0x25, 0, 0, 0, 0, // jmp *(sym in .got)
- 0x68, 0, 0, 0, 0, // pushl $offset
- 0xe9, 0, 0, 0, 0 // jmp plt0
+ 0xff, 0x25, 0, 0, 0, 0, // jmp *(sym in .got)
+ 0x68, 0, 0, 0, 0, // pushl $offset
+ 0xe9, 0, 0, 0, 0 // jmp plt0
};
const uint8_t x86_64_plt0[] = {
- 0xff, 0x35, 0x8, 0, 0, 0, // pushq GOT + 8(%rip)
- 0xff, 0x25, 0x16, 0, 0, 0, // jmq *GOT + 16(%rip)
- 0x0f, 0x1f, 0x40, 0 // nopl 0(%rax)
+ 0xff, 0x35, 0x8, 0, 0, 0, // pushq GOT + 8(%rip)
+ 0xff, 0x25, 0x16, 0, 0, 0, // jmq *GOT + 16(%rip)
+ 0x0f, 0x1f, 0x40, 0 // nopl 0(%rax)
};
const uint8_t x86_64_plt1[] = {
- 0xff, 0x25, 0, 0, 0, 0, // jmpq *sym@GOTPCREL(%rip)
- 0x68, 0, 0, 0, 0, // pushq $index
- 0xe9, 0, 0, 0, 0 // jmpq plt0
+ 0xff, 0x25, 0, 0, 0, 0, // jmpq *sym@GOTPCREL(%rip)
+ 0x68, 0, 0, 0, 0, // pushq $index
+ 0xe9, 0, 0, 0, 0 // jmpq plt0
};
-} // anonymous namespace
-
namespace mcld {
class X86_32GOTPLT;
@@ -60,42 +56,36 @@ class LinkerConfig;
//===----------------------------------------------------------------------===//
// X86_32PLT Entry
//===----------------------------------------------------------------------===//
-class X86_32DynPLT0 : public PLT::Entry<sizeof(x86_32_dyn_plt0)>
-{
-public:
+class X86_32DynPLT0 : public PLT::Entry<sizeof(x86_32_dyn_plt0)> {
+ public:
X86_32DynPLT0(SectionData& pParent);
};
-class X86_32DynPLT1 : public PLT::Entry<sizeof(x86_32_dyn_plt1)>
-{
-public:
+class X86_32DynPLT1 : public PLT::Entry<sizeof(x86_32_dyn_plt1)> {
+ public:
X86_32DynPLT1(SectionData& pParent);
};
-class X86_32ExecPLT0 : public PLT::Entry<sizeof(x86_32_exec_plt0)>
-{
-public:
+class X86_32ExecPLT0 : public PLT::Entry<sizeof(x86_32_exec_plt0)> {
+ public:
X86_32ExecPLT0(SectionData& pParent);
};
-class X86_32ExecPLT1 : public PLT::Entry<sizeof(x86_32_exec_plt1)>
-{
-public:
+class X86_32ExecPLT1 : public PLT::Entry<sizeof(x86_32_exec_plt1)> {
+ public:
X86_32ExecPLT1(SectionData& pParent);
};
//===----------------------------------------------------------------------===//
// X86_64PLT Entry
//===----------------------------------------------------------------------===//
-class X86_64PLT0 : public PLT::Entry<sizeof(x86_64_plt0)>
-{
-public:
+class X86_64PLT0 : public PLT::Entry<sizeof(x86_64_plt0)> {
+ public:
X86_64PLT0(SectionData& pParent);
};
-class X86_64PLT1 : public PLT::Entry<sizeof(x86_64_plt1)>
-{
-public:
+class X86_64PLT1 : public PLT::Entry<sizeof(x86_64_plt1)> {
+ public:
X86_64PLT1(SectionData& pParent);
};
@@ -105,12 +95,9 @@ public:
/** \class X86PLT
* \brief X86 Procedure Linkage Table
*/
-class X86PLT : public PLT
-{
-public:
- X86PLT(LDSection& pSection,
- const LinkerConfig& pConfig,
- int got_size);
+class X86PLT : public PLT {
+ public:
+ X86PLT(LDSection& pSection, const LinkerConfig& pConfig, int got_size);
~X86PLT();
// finalizeSectionSize - set LDSection size
@@ -128,12 +115,12 @@ public:
unsigned int getPLT0Size() const { return m_PLT0Size; }
unsigned int getPLT1Size() const { return m_PLT1Size; }
-protected:
+ protected:
PLTEntryBase* getPLT0() const;
-protected:
- const uint8_t *m_PLT0;
- const uint8_t *m_PLT1;
+ protected:
+ const uint8_t* m_PLT0;
+ const uint8_t* m_PLT1;
unsigned int m_PLT0Size;
unsigned int m_PLT1Size;
@@ -146,9 +133,8 @@ protected:
/** \class X86_32PLT
* \brief X86_32 Procedure Linkage Table
*/
-class X86_32PLT : public X86PLT
-{
-public:
+class X86_32PLT : public X86PLT {
+ public:
X86_32PLT(LDSection& pSection,
X86_32GOTPLT& pGOTPLT,
const LinkerConfig& pConfig);
@@ -157,7 +143,7 @@ public:
void applyPLT1();
-private:
+ private:
X86_32GOTPLT& m_GOTPLT;
};
@@ -167,9 +153,8 @@ private:
/** \class X86_64PLT
* \brief X86_64 Procedure Linkage Table
*/
-class X86_64PLT : public X86PLT
-{
-public:
+class X86_64PLT : public X86PLT {
+ public:
X86_64PLT(LDSection& pSection,
X86_64GOTPLT& pGOTPLT,
const LinkerConfig& pConfig);
@@ -178,11 +163,10 @@ public:
void applyPLT1();
-private:
+ private:
X86_64GOTPLT& m_GOTPLT;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_X86_X86PLT_H_
diff --git a/lib/Target/X86/X86RelocationFunctions.h b/lib/Target/X86/X86RelocationFunctions.h
index a4568bb..69c877b 100644
--- a/lib/Target/X86/X86RelocationFunctions.h
+++ b/lib/Target/X86/X86RelocationFunctions.h
@@ -6,123 +6,128 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+#ifndef TARGET_X86_X86RELOCATIONFUNCTIONS_H_
+#define TARGET_X86_X86RELOCATIONFUNCTIONS_H_
-#define DECL_X86_32_APPLY_RELOC_FUNC(Name) \
-static X86Relocator::Result Name(Relocation& pEntry, X86_32Relocator& pParent);
+#define DECL_X86_32_APPLY_RELOC_FUNC(Name) \
+ static X86Relocator::Result Name(Relocation& pEntry, \
+ X86_32Relocator& pParent);
-#define DECL_X86_32_APPLY_RELOC_FUNCS \
-DECL_X86_32_APPLY_RELOC_FUNC(none) \
-DECL_X86_32_APPLY_RELOC_FUNC(abs) \
-DECL_X86_32_APPLY_RELOC_FUNC(rel) \
-DECL_X86_32_APPLY_RELOC_FUNC(plt32) \
-DECL_X86_32_APPLY_RELOC_FUNC(got32) \
-DECL_X86_32_APPLY_RELOC_FUNC(gotoff32) \
-DECL_X86_32_APPLY_RELOC_FUNC(gotpc32) \
-DECL_X86_32_APPLY_RELOC_FUNC(tls_gd) \
-DECL_X86_32_APPLY_RELOC_FUNC(tls_ie) \
-DECL_X86_32_APPLY_RELOC_FUNC(tls_gotie) \
-DECL_X86_32_APPLY_RELOC_FUNC(tls_le) \
-DECL_X86_32_APPLY_RELOC_FUNC(tls_ldm) \
-DECL_X86_32_APPLY_RELOC_FUNC(tls_ldo_32) \
-DECL_X86_32_APPLY_RELOC_FUNC(unsupport)
+#define DECL_X86_32_APPLY_RELOC_FUNCS \
+ DECL_X86_32_APPLY_RELOC_FUNC(none) \
+ DECL_X86_32_APPLY_RELOC_FUNC(abs) \
+ DECL_X86_32_APPLY_RELOC_FUNC(rel) \
+ DECL_X86_32_APPLY_RELOC_FUNC(plt32) \
+ DECL_X86_32_APPLY_RELOC_FUNC(got32) \
+ DECL_X86_32_APPLY_RELOC_FUNC(gotoff32) \
+ DECL_X86_32_APPLY_RELOC_FUNC(gotpc32) \
+ DECL_X86_32_APPLY_RELOC_FUNC(tls_gd) \
+ DECL_X86_32_APPLY_RELOC_FUNC(tls_ie) \
+ DECL_X86_32_APPLY_RELOC_FUNC(tls_gotie) \
+ DECL_X86_32_APPLY_RELOC_FUNC(tls_le) \
+ DECL_X86_32_APPLY_RELOC_FUNC(tls_ldm) \
+ DECL_X86_32_APPLY_RELOC_FUNC(tls_ldo_32) \
+ DECL_X86_32_APPLY_RELOC_FUNC(unsupported)
+#define DECL_X86_32_APPLY_RELOC_FUNC_PTRS \
+ { &none, 0, "R_386_NONE", 0 }, \
+ { &abs, 1, "R_386_32", 32 }, \
+ { &rel, 2, "R_386_PC32", 32 }, \
+ { &got32, 3, "R_386_GOT32", 32 }, \
+ { &plt32, 4, "R_386_PLT32", 32 }, \
+ { &none, 5, "R_386_COPY", 0 }, \
+ { &none, 6, "R_386_GLOB_DAT", 0 }, \
+ { &none, 7, "R_386_JMP_SLOT", 0 }, \
+ { &none, 8, "R_386_RELATIVE", 0 }, \
+ { &gotoff32, 9, "R_386_GOTOFF", 32 }, \
+ { &gotpc32, 10, "R_386_GOTPC", 32 }, \
+ { &unsupported, 11, "R_386_32PLT", 0 }, \
+ { &unsupported, 12, "", 0 }, \
+ { &unsupported, 13, "", 0 }, \
+ { &unsupported, 14, "R_386_TLS_TPOFF", 0 }, \
+ { &tls_ie, 15, "R_386_TLS_IE", 32 }, \
+ { &tls_gotie, 16, "R_386_TLS_GOTIE", 32 }, \
+ { &tls_le, 17, "R_386_TLS_LE", 32 }, \
+ { &tls_gd, 18, "R_386_TLS_GD", 32 }, \
+ { &tls_ldm, 19, "R_386_TLS_LDM", 32 }, \
+ { &abs, 20, "R_386_16", 16 }, \
+ { &rel, 21, "R_386_PC16", 16 }, \
+ { &abs, 22, "R_386_8", 8 }, \
+ { &rel, 23, "R_386_PC8", 8 }, \
+ { &unsupported, 24, "R_386_TLS_GD_32", 0 }, \
+ { &unsupported, 25, "R_386_TLS_GD_PUSH", 0 }, \
+ { &unsupported, 26, "R_386_TLS_GD_CALL", 0 }, \
+ { &unsupported, 27, "R_386_TLS_GD_POP", 0 }, \
+ { &unsupported, 28, "R_386_TLS_LDM_32", 0 }, \
+ { &unsupported, 29, "R_386_TLS_LDM_PUSH", 0 }, \
+ { &unsupported, 30, "R_386_TLS_LDM_CALL", 0 }, \
+ { &unsupported, 31, "R_386_TLS_LDM_POP", 0 }, \
+ { &tls_ldo_32, 32, "R_386_TLS_LDO_32", 32 }, \
+ { &unsupported, 33, "R_386_TLS_IE_32", 0 }, \
+ { &unsupported, 34, "R_386_TLS_LE_32", 0 }, \
+ { &unsupported, 35, "R_386_TLS_DTPMOD32", 0 }, \
+ { &unsupported, 36, "R_386_TLS_DTPOFF32", 0 }, \
+ { &unsupported, 37, "R_386_TLS_TPOFF32", 0 }, \
+ { &unsupported, 38, "", 0 }, \
+ { &unsupported, 39, "R_386_TLS_GOTDESC", 0 }, \
+ { &unsupported, 40, "R_386_TLS_DESC_CALL", 0 }, \
+ { &unsupported, 41, "R_386_TLS_DESC", 0 }, \
+ { &unsupported, 42, "R_386_IRELATIVE", 0 }, \
+ { &unsupported, 43, "R_386_NUM", 0 }, \
+ { &none, 44, "R_386_TLS_OPT", 32 }
-#define DECL_X86_32_APPLY_RELOC_FUNC_PTRS \
- { &none, 0, "R_386_NONE", 0 }, \
- { &abs, 1, "R_386_32", 32 }, \
- { &rel, 2, "R_386_PC32", 32 }, \
- { &got32, 3, "R_386_GOT32", 32 }, \
- { &plt32, 4, "R_386_PLT32", 32 }, \
- { &none, 5, "R_386_COPY", 0 }, \
- { &none, 6, "R_386_GLOB_DAT", 0 }, \
- { &none, 7, "R_386_JMP_SLOT", 0 }, \
- { &none, 8, "R_386_RELATIVE", 0 }, \
- { &gotoff32, 9, "R_386_GOTOFF", 32 }, \
- { &gotpc32, 10, "R_386_GOTPC", 32 }, \
- { &unsupport, 11, "R_386_32PLT", 0 }, \
- { &unsupport, 12, "", 0 }, \
- { &unsupport, 13, "", 0 }, \
- { &unsupport, 14, "R_386_TLS_TPOFF", 0 }, \
- { &tls_ie, 15, "R_386_TLS_IE", 32 }, \
- { &tls_gotie, 16, "R_386_TLS_GOTIE", 32 }, \
- { &tls_le, 17, "R_386_TLS_LE", 32 }, \
- { &tls_gd, 18, "R_386_TLS_GD", 32 }, \
- { &tls_ldm, 19, "R_386_TLS_LDM", 32 }, \
- { &abs, 20, "R_386_16", 16 }, \
- { &rel, 21, "R_386_PC16", 16 }, \
- { &abs, 22, "R_386_8", 8 }, \
- { &rel, 23, "R_386_PC8", 8 }, \
- { &unsupport, 24, "R_386_TLS_GD_32", 0 }, \
- { &unsupport, 25, "R_386_TLS_GD_PUSH", 0 }, \
- { &unsupport, 26, "R_386_TLS_GD_CALL", 0 }, \
- { &unsupport, 27, "R_386_TLS_GD_POP", 0 }, \
- { &unsupport, 28, "R_386_TLS_LDM_32", 0 }, \
- { &unsupport, 29, "R_386_TLS_LDM_PUSH", 0 }, \
- { &unsupport, 30, "R_386_TLS_LDM_CALL", 0 }, \
- { &unsupport, 31, "R_386_TLS_LDM_POP", 0 }, \
- { &tls_ldo_32, 32, "R_386_TLS_LDO_32", 32 }, \
- { &unsupport, 33, "R_386_TLS_IE_32", 0 }, \
- { &unsupport, 34, "R_386_TLS_LE_32", 0 }, \
- { &unsupport, 35, "R_386_TLS_DTPMOD32", 0 }, \
- { &unsupport, 36, "R_386_TLS_DTPOFF32", 0 }, \
- { &unsupport, 37, "R_386_TLS_TPOFF32", 0 }, \
- { &unsupport, 38, "", 0 }, \
- { &unsupport, 39, "R_386_TLS_GOTDESC", 0 }, \
- { &unsupport, 40, "R_386_TLS_DESC_CALL", 0 }, \
- { &unsupport, 41, "R_386_TLS_DESC", 0 }, \
- { &unsupport, 42, "R_386_IRELATIVE", 0 }, \
- { &unsupport, 43, "R_386_NUM", 0 }, \
- { &none, 44, "R_386_TLS_OPT", 32 }
+#define DECL_X86_64_APPLY_RELOC_FUNC(Name) \
+ static X86Relocator::Result Name(Relocation& pEntry, \
+ X86_64Relocator& pParent);
-#define DECL_X86_64_APPLY_RELOC_FUNC(Name) \
-static X86Relocator::Result Name(Relocation& pEntry, X86_64Relocator& pParent);
+#define DECL_X86_64_APPLY_RELOC_FUNCS \
+ DECL_X86_64_APPLY_RELOC_FUNC(none) \
+ DECL_X86_64_APPLY_RELOC_FUNC(abs) \
+ DECL_X86_64_APPLY_RELOC_FUNC(signed32) \
+ DECL_X86_64_APPLY_RELOC_FUNC(gotpcrel) \
+ DECL_X86_64_APPLY_RELOC_FUNC(plt32) \
+ DECL_X86_64_APPLY_RELOC_FUNC(rel) \
+ DECL_X86_64_APPLY_RELOC_FUNC(unsupported)
-#define DECL_X86_64_APPLY_RELOC_FUNCS \
-DECL_X86_64_APPLY_RELOC_FUNC(none) \
-DECL_X86_64_APPLY_RELOC_FUNC(abs) \
-DECL_X86_64_APPLY_RELOC_FUNC(signed32) \
-DECL_X86_64_APPLY_RELOC_FUNC(gotpcrel) \
-DECL_X86_64_APPLY_RELOC_FUNC(plt32) \
-DECL_X86_64_APPLY_RELOC_FUNC(rel) \
-DECL_X86_64_APPLY_RELOC_FUNC(unsupport)
+#define DECL_X86_64_APPLY_RELOC_FUNC_PTRS \
+ { &none, 0, "R_X86_64_NONE", 0 }, \
+ { &abs, 1, "R_X86_64_64", 64 }, \
+ { &rel, 2, "R_X86_64_PC32", 32 }, \
+ { &unsupported, 3, "R_X86_64_GOT32", 32 }, \
+ { &plt32, 4, "R_X86_64_PLT32", 32 }, \
+ { &none, 5, "R_X86_64_COPY", 0 }, \
+ { &none, 6, "R_X86_64_GLOB_DAT", 0 }, \
+ { &none, 7, "R_X86_64_JMP_SLOT", 0 }, \
+ { &none, 8, "R_X86_64_RELATIVE", 0 }, \
+ { &gotpcrel, 9, "R_X86_64_GOTPCREL", 32 }, \
+ { &abs, 10, "R_X86_64_32", 32 }, \
+ { &signed32, 11, "R_X86_64_32S", 32 }, \
+ { &abs, 12, "R_X86_64_16", 16 }, \
+ { &rel, 13, "R_X86_64_PC16", 16 }, \
+ { &abs, 14, "R_X86_64_8", 8 }, \
+ { &rel, 15, "R_X86_64_PC8", 8 }, \
+ { &none, 16, "R_X86_64_DTPMOD64", 0 }, \
+ { &unsupported, 17, "R_X86_64_DTPOFF64", 0 }, \
+ { &none, 18, "R_X86_64_TPOFF64", 0 }, \
+ { &unsupported, 19, "R_X86_64_TLSGD", 0 }, \
+ { &unsupported, 20, "R_X86_64_TLSLD", 0 }, \
+ { &unsupported, 21, "R_X86_64_DTPOFF32", 0 }, \
+ { &unsupported, 22, "R_X86_64_GOTTPOFF", 0 }, \
+ { &unsupported, 23, "R_X86_64_TPOFF32", 0 }, \
+ { &unsupported, 24, "R_X86_64_PC64", 64 }, \
+ { &unsupported, 25, "R_X86_64_GOTOFF64", 64 }, \
+ { &unsupported, 26, "R_X86_64_GOTPC32", 32 }, \
+ { &unsupported, 27, "R_X86_64_GOT64", 64 }, \
+ { &unsupported, 28, "R_X86_64_GOTPCREL64", 64 }, \
+ { &unsupported, 29, "R_X86_64_GOTPC64", 64 }, \
+ { &unsupported, 30, "R_X86_64_GOTPLT64", 64 }, \
+ { &unsupported, 31, "R_X86_64_PLTOFF64", 64 }, \
+ { &unsupported, 32, "R_X86_64_SIZE32", 32 }, \
+ { &unsupported, 33, "R_X86_64_SIZE64", 64 }, \
+ { &unsupported, 34, "R_X86_64_GOTPC32_TLSDESC", 0 }, \
+ { &unsupported, 35, "R_X86_64_TLSDESC_CALL", 0 }, \
+ { &none, 36, "R_X86_64_TLSDESC", 0 }, \
+ { &none, 37, "R_X86_64_IRELATIVE", 0 }, \
+ { &none, 38, "R_X86_64_RELATIVE64", 0 }
-#define DECL_X86_64_APPLY_RELOC_FUNC_PTRS \
- { &none, 0, "R_X86_64_NONE", 0 }, \
- { &abs, 1, "R_X86_64_64", 64 }, \
- { &rel, 2, "R_X86_64_PC32", 32 }, \
- { &unsupport, 3, "R_X86_64_GOT32", 32 }, \
- { &plt32, 4, "R_X86_64_PLT32", 32 }, \
- { &none, 5, "R_X86_64_COPY", 0 }, \
- { &none, 6, "R_X86_64_GLOB_DAT", 0 }, \
- { &none, 7, "R_X86_64_JMP_SLOT", 0 }, \
- { &none, 8, "R_X86_64_RELATIVE", 0 }, \
- { &gotpcrel, 9, "R_X86_64_GOTPCREL", 32 }, \
- { &abs, 10, "R_X86_64_32", 32 }, \
- { &signed32, 11, "R_X86_64_32S", 32 }, \
- { &abs, 12, "R_X86_64_16", 16 }, \
- { &rel, 13, "R_X86_64_PC16", 16 }, \
- { &abs, 14, "R_X86_64_8", 8 }, \
- { &rel, 15, "R_X86_64_PC8", 8 }, \
- { &none, 16, "R_X86_64_DTPMOD64", 0 }, \
- { &unsupport, 17, "R_X86_64_DTPOFF64", 0 }, \
- { &none, 18, "R_X86_64_TPOFF64", 0 }, \
- { &unsupport, 19, "R_X86_64_TLSGD", 0 }, \
- { &unsupport, 20, "R_X86_64_TLSLD", 0 }, \
- { &unsupport, 21, "R_X86_64_DTPOFF32", 0 }, \
- { &unsupport, 22, "R_X86_64_GOTTPOFF", 0 }, \
- { &unsupport, 23, "R_X86_64_TPOFF32", 0 }, \
- { &unsupport, 24, "R_X86_64_PC64", 64 }, \
- { &unsupport, 25, "R_X86_64_GOTOFF64", 64 }, \
- { &unsupport, 26, "R_X86_64_GOTPC32", 32 }, \
- { &unsupport, 27, "R_X86_64_GOT64", 64 }, \
- { &unsupport, 28, "R_X86_64_GOTPCREL64", 64 }, \
- { &unsupport, 29, "R_X86_64_GOTPC64", 64 }, \
- { &unsupport, 30, "R_X86_64_GOTPLT64", 64 }, \
- { &unsupport, 31, "R_X86_64_PLTOFF64", 64 }, \
- { &unsupport, 32, "R_X86_64_SIZE32", 32 }, \
- { &unsupport, 33, "R_X86_64_SIZE64", 64 }, \
- { &unsupport, 34, "R_X86_64_GOTPC32_TLSDESC", 0 }, \
- { &unsupport, 35, "R_X86_64_TLSDESC_CALL", 0 }, \
- { &none, 36, "R_X86_64_TLSDESC", 0 }, \
- { &none, 37, "R_X86_64_IRELATIVE", 0 }, \
- { &none, 38, "R_X86_64_RELATIVE64", 0 }
+#endif // TARGET_X86_X86RELOCATIONFUNCTIONS_H_
diff --git a/lib/Target/X86/X86Relocator.cpp b/lib/Target/X86/X86Relocator.cpp
index 794296b..b685d51 100644
--- a/lib/Target/X86/X86Relocator.cpp
+++ b/lib/Target/X86/X86Relocator.cpp
@@ -9,37 +9,35 @@
#include "X86Relocator.h"
#include "X86RelocationFunctions.h"
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/Support/MsgHandling.h>
-#include <mcld/LD/LDSymbol.h>
-#include <mcld/LD/ELFFileFormat.h>
-#include <mcld/LD/ELFSegmentFactory.h>
-#include <mcld/LD/ELFSegment.h>
-#include <mcld/Object/ObjectBuilder.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/ELFFileFormat.h"
+#include "mcld/LD/ELFSegmentFactory.h"
+#include "mcld/LD/ELFSegment.h"
+#include "mcld/LD/LDSymbol.h"
+#include "mcld/Object/ObjectBuilder.h"
+#include "mcld/Support/MsgHandling.h"
#include <llvm/ADT/Twine.h>
#include <llvm/Support/DataTypes.h>
#include <llvm/Support/ELF.h>
-using namespace mcld;
+namespace mcld {
//===--------------------------------------------------------------------===//
// X86_32 Relocation helper function
//===--------------------------------------------------------------------===//
/// helper_DynRel - Get an relocation entry in .rel.dyn
-static
-Relocation& helper_DynRel_init(ResolveInfo* pSym,
- Fragment& pFrag,
- uint64_t pOffset,
- Relocator::Type pType,
- X86_32Relocator& pParent)
-{
+static Relocation& helper_DynRel_init(ResolveInfo* pSym,
+ Fragment& pFrag,
+ uint64_t pOffset,
+ Relocator::Type pType,
+ X86_32Relocator& pParent) {
X86_32GNULDBackend& ld_backend = pParent.getTarget();
Relocation& rel_entry = *ld_backend.getRelDyn().create();
rel_entry.setType(pType);
rel_entry.targetRef().assign(pFrag, pOffset);
- if (pType == llvm::ELF::R_386_RELATIVE || NULL == pSym)
+ if (pType == llvm::ELF::R_386_RELATIVE || pSym == NULL)
rel_entry.setSymInfo(NULL);
else
rel_entry.setSymInfo(pSym);
@@ -49,28 +47,22 @@ Relocation& helper_DynRel_init(ResolveInfo* pSym,
/// helper_use_relative_reloc - Check if symbol ceuse relocation
/// R_386_RELATIVE
-static bool
-helper_use_relative_reloc(const ResolveInfo& pSym,
- const X86_32Relocator& pFactory)
-
-{
+static bool helper_use_relative_reloc(const ResolveInfo& pSym,
+ const X86_32Relocator& pFactory) {
// if symbol is dynamic or undefine or preemptible
- if (pSym.isDyn() ||
- pSym.isUndef() ||
+ if (pSym.isDyn() || pSym.isUndef() ||
pFactory.getTarget().isSymbolPreemptible(pSym))
return false;
return true;
}
-static
-X86_32GOTEntry& helper_GOT_init(Relocation& pReloc,
- bool pHasRel,
- X86_32Relocator& pParent)
-{
+static X86_32GOTEntry& helper_GOT_init(Relocation& pReloc,
+ bool pHasRel,
+ X86_32Relocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
X86_32GNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymGOTMap().lookUp(*rsym));
+ assert(pParent.getSymGOTMap().lookUp(*rsym) == NULL);
X86_32GOTEntry* got_entry = ld_backend.getGOT().create();
pParent.getSymGOTMap().record(*rsym, *got_entry);
@@ -78,51 +70,44 @@ X86_32GOTEntry& helper_GOT_init(Relocation& pReloc,
if (!pHasRel) {
// No corresponding dynamic relocation, initialize to the symbol value.
got_entry->setValue(X86Relocator::SymVal);
- }
- else {
+ } else {
// Initialize got_entry content and the corresponding dynamic relocation.
if (helper_use_relative_reloc(*rsym, pParent)) {
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_386_RELATIVE,
- pParent);
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_386_RELATIVE, pParent);
got_entry->setValue(X86Relocator::SymVal);
- }
- else {
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_386_GLOB_DAT,
- pParent);
+ } else {
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_386_GLOB_DAT, pParent);
got_entry->setValue(0x0);
}
}
return *got_entry;
}
-static
-Relocator::Address helper_GOT_ORG(X86_32Relocator& pParent)
-{
+static Relocator::Address helper_GOT_ORG(X86_32Relocator& pParent) {
return pParent.getTarget().getGOTPLT().addr();
}
-static
-Relocator::Address helper_get_GOT_address(Relocation& pReloc,
- X86_32Relocator& pParent)
-{
+static Relocator::Address helper_get_GOT_address(Relocation& pReloc,
+ X86_32Relocator& pParent) {
X86_32GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
return pParent.getTarget().getGOT().addr() + got_entry->getOffset();
}
-static
-PLTEntryBase& helper_PLT_init(Relocation& pReloc, X86_32Relocator& pParent)
-{
+static PLTEntryBase& helper_PLT_init(Relocation& pReloc,
+ X86_32Relocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
X86_32GNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymPLTMap().lookUp(*rsym));
+ assert(pParent.getSymPLTMap().lookUp(*rsym) == NULL);
PLTEntryBase* plt_entry = ld_backend.getPLT().create();
pParent.getSymPLTMap().record(*rsym, *plt_entry);
// initialize plt and the corresponding gotplt and dyn rel entry.
- assert(NULL == pParent.getSymGOTPLTMap().lookUp(*rsym) &&
+ assert(pParent.getSymGOTPLTMap().lookUp(*rsym) == NULL &&
"PLT entry not exist, but GOTPLT entry exist!");
X86_32GOTEntry* gotplt_entry = ld_backend.getGOTPLT().create();
pParent.getSymGOTPLTMap().record(*rsym, *gotplt_entry);
@@ -135,11 +120,10 @@ PLTEntryBase& helper_PLT_init(Relocation& pReloc, X86_32Relocator& pParent)
return *plt_entry;
}
-static Relocator::Address
-helper_get_PLT_address(ResolveInfo& pSym, X86_32Relocator& pParent)
-{
+static Relocator::Address helper_get_PLT_address(ResolveInfo& pSym,
+ X86_32Relocator& pParent) {
PLTEntryBase* plt_entry = pParent.getSymPLTMap().lookUp(pSym);
- assert(NULL != plt_entry);
+ assert(plt_entry != NULL);
return pParent.getTarget().getPLT().addr() + plt_entry->getOffset();
}
@@ -153,8 +137,7 @@ typedef Relocator::Result (*X86_32ApplyFunctionType)(Relocation& pReloc,
X86_32Relocator& pParent);
// the table entry of applying functions
-struct X86_32ApplyFunctionTriple
-{
+struct X86_32ApplyFunctionTriple {
X86_32ApplyFunctionType func;
unsigned int type;
const char* name;
@@ -163,42 +146,38 @@ struct X86_32ApplyFunctionTriple
// declare the table of applying functions
static const X86_32ApplyFunctionTriple X86_32ApplyFunctions[] = {
- DECL_X86_32_APPLY_RELOC_FUNC_PTRS
-};
+ DECL_X86_32_APPLY_RELOC_FUNC_PTRS};
//===--------------------------------------------------------------------===//
// X86Relocator
//===--------------------------------------------------------------------===//
-X86Relocator::X86Relocator(const LinkerConfig& pConfig)
- : Relocator(pConfig) {
+X86Relocator::X86Relocator(const LinkerConfig& pConfig) : Relocator(pConfig) {
}
-X86Relocator::~X86Relocator()
-{
+X86Relocator::~X86Relocator() {
}
void X86Relocator::scanRelocation(Relocation& pReloc,
IRBuilder& pLinker,
Module& pModule,
LDSection& pSection,
- Input& pInput)
-{
+ Input& pInput) {
if (LinkerConfig::Object == config().codeGenType())
return;
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- assert(NULL != rsym &&
+ assert(rsym != NULL &&
"ResolveInfo of relocation not set while scanRelocation");
- assert(NULL != pSection.getLink());
- if (0 == (pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC))
+ assert(pSection.getLink() != NULL);
+ if ((pSection.getLink()->flag() & llvm::ELF::SHF_ALLOC) == 0)
return;
// Scan relocation type to determine if the GOT/PLT/Dynamic Relocation
// entries should be created.
- if (rsym->isLocal()) // rsym is local
+ if (rsym->isLocal()) // rsym is local
scanLocalReloc(pReloc, pLinker, pModule, pSection);
- else // rsym is external
+ else // rsym is external
scanGlobalReloc(pReloc, pLinker, pModule, pSection);
// check if we should issue undefined reference for the relocation target
@@ -207,8 +186,7 @@ void X86Relocator::scanRelocation(Relocation& pReloc,
issueUndefRef(pReloc, pSection, pInput);
}
-void X86Relocator::addCopyReloc(ResolveInfo& pSym, X86GNULDBackend& pTarget)
-{
+void X86Relocator::addCopyReloc(ResolveInfo& pSym, X86GNULDBackend& pTarget) {
Relocation& rel_entry = *pTarget.getRelDyn().create();
rel_entry.setType(pTarget.getCopyRelType());
assert(pSym.outSymbol()->hasFragRef());
@@ -223,8 +201,7 @@ void X86Relocator::addCopyReloc(ResolveInfo& pSym, X86GNULDBackend& pTarget)
/// @note This is executed at `scan relocation' stage.
LDSymbol& X86Relocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
const ResolveInfo& pSym,
- X86GNULDBackend& pTarget)
-{
+ X86GNULDBackend& pTarget) {
// get or create corresponding BSS LDSection
LDSection* bss_sect_hdr = NULL;
ELFFileFormat* file_format = pTarget.getOutputFormat();
@@ -234,7 +211,7 @@ LDSymbol& X86Relocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
bss_sect_hdr = &file_format->getBSS();
// get or create corresponding BSS SectionData
- assert(NULL != bss_sect_hdr);
+ assert(bss_sect_hdr != NULL);
SectionData* bss_section = NULL;
if (bss_sect_hdr->hasSectionData())
bss_section = bss_sect_hdr->getSectionData();
@@ -247,9 +224,7 @@ LDSymbol& X86Relocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
// allocate space in BSS for the copy symbol
Fragment* frag = new FillFragment(0x0, 1, pSym.size());
- uint64_t size = ObjectBuilder::AppendFragment(*frag,
- *bss_section,
- addralign);
+ uint64_t size = ObjectBuilder::AppendFragment(*frag, *bss_section, addralign);
bss_sect_hdr->setSize(bss_sect_hdr->size() + size);
// change symbol binding to Global if it's a weak symbol
@@ -259,32 +234,32 @@ LDSymbol& X86Relocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
// Define the copy symbol in the bss section and resolve it
LDSymbol* cpy_sym = pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- pSym.name(),
- (ResolveInfo::Type)pSym.type(),
- ResolveInfo::Define,
- binding,
- pSym.size(), // size
- 0x0, // value
- FragmentRef::Create(*frag, 0x0),
- (ResolveInfo::Visibility)pSym.other());
+ pSym.name(),
+ (ResolveInfo::Type)pSym.type(),
+ ResolveInfo::Define,
+ binding,
+ pSym.size(), // size
+ 0x0, // value
+ FragmentRef::Create(*frag, 0x0),
+ (ResolveInfo::Visibility)pSym.other());
// output all other alias symbols if any
- Module &pModule = pBuilder.getModule();
+ Module& pModule = pBuilder.getModule();
Module::AliasList* alias_list = pModule.getAliasList(pSym);
- if (NULL!=alias_list) {
- Module::alias_iterator it, it_e=alias_list->end();
- for (it=alias_list->begin(); it!=it_e; ++it) {
+ if (alias_list != NULL) {
+ Module::alias_iterator it, it_e = alias_list->end();
+ for (it = alias_list->begin(); it != it_e; ++it) {
const ResolveInfo* alias = *it;
- if (alias!=&pSym && alias->isDyn()) {
+ if (alias != &pSym && alias->isDyn()) {
pBuilder.AddSymbol<IRBuilder::Force, IRBuilder::Resolve>(
- alias->name(),
- (ResolveInfo::Type)alias->type(),
- ResolveInfo::Define,
- binding,
- alias->size(), // size
- 0x0, // value
- FragmentRef::Create(*frag, 0x0),
- (ResolveInfo::Visibility)alias->other());
+ alias->name(),
+ (ResolveInfo::Type)alias->type(),
+ ResolveInfo::Define,
+ binding,
+ alias->size(), // size
+ 0x0, // value
+ FragmentRef::Create(*frag, 0x0),
+ (ResolveInfo::Visibility)alias->other());
}
}
}
@@ -292,20 +267,18 @@ LDSymbol& X86Relocator::defineSymbolforCopyReloc(IRBuilder& pBuilder,
return *cpy_sym;
}
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
// X86_32Relocator
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
X86_32Relocator::X86_32Relocator(X86_32GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : X86Relocator(pConfig), m_Target(pParent) {
+ : X86Relocator(pConfig), m_Target(pParent) {
}
-Relocator::Result
-X86_32Relocator::applyRelocation(Relocation& pRelocation)
-{
+Relocator::Result X86_32Relocator::applyRelocation(Relocation& pRelocation) {
Relocation::Type type = pRelocation.type();
- if (type >= sizeof (X86_32ApplyFunctions) / sizeof (X86_32ApplyFunctions[0]) ) {
+ if (type >= sizeof(X86_32ApplyFunctions) / sizeof(X86_32ApplyFunctions[0])) {
return Unknown;
}
@@ -313,19 +286,16 @@ X86_32Relocator::applyRelocation(Relocation& pRelocation)
return X86_32ApplyFunctions[type].func(pRelocation, *this);
}
-const char* X86_32Relocator::getName(Relocation::Type pType) const
-{
+const char* X86_32Relocator::getName(Relocation::Type pType) const {
return X86_32ApplyFunctions[pType].name;
}
-Relocator::Size X86_32Relocator::getSize(Relocation::Type pType) const
-{
- return X86_32ApplyFunctions[pType].size;;
+Relocator::Size X86_32Relocator::getSize(Relocation::Type pType) const {
+ return X86_32ApplyFunctions[pType].size;
}
-bool
-X86_32Relocator::mayHaveFunctionPointerAccess(const Relocation& pReloc) const
-{
+bool X86_32Relocator::mayHaveFunctionPointerAccess(
+ const Relocation& pReloc) const {
switch (pReloc.type()) {
case llvm::ELF::R_386_32:
case llvm::ELF::R_386_16:
@@ -334,22 +304,18 @@ X86_32Relocator::mayHaveFunctionPointerAccess(const Relocation& pReloc) const
case llvm::ELF::R_386_GOT32: {
return true;
}
- default: {
- return false;
- }
+ default: { return false; }
}
}
void X86_32Relocator::scanLocalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
- LDSection& pSection)
-{
+ LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()){
-
+ switch (pReloc.type()) {
case llvm::ELF::R_386_32:
// If buiding PIC object (shared library or PIC executable),
// a dynamic relocations with RELATIVE type to this location is needed.
@@ -374,8 +340,11 @@ void X86_32Relocator::scanLocalReloc(Relocation& pReloc,
// Reserve an entry in .rel.dyn
if (config().isCodeIndep()) {
// set up the dyn rel directly
- helper_DynRel_init(rsym, *pReloc.targetRef().frag(),
- pReloc.targetRef().offset(), pReloc.type(), *this);
+ helper_DynRel_init(rsym,
+ *pReloc.targetRef().frag(),
+ pReloc.targetRef().offset(),
+ pReloc.type(),
+ *this);
// set Rel bit
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
@@ -398,20 +367,14 @@ void X86_32Relocator::scanLocalReloc(Relocation& pReloc,
// FIXME: check STT_GNU_IFUNC symbol
- // If building shared object or the symbol is undefined, a dynamic
- // relocation is needed to relocate this GOT entry. Reserve an
- // entry in .rel.dyn
- if (LinkerConfig::DynObj ==
- config().codeGenType() || rsym->isUndef() || rsym->isDyn()) {
+ // If building PIC object, a dynamic relocation with
+ // type RELATIVE is needed to relocate this GOT entry.
+ if (config().isCodeIndep())
helper_GOT_init(pReloc, true, *this);
- // set GOT bit
- rsym->setReserved(rsym->reserved() | ReserveGOT);
- return;
- }
+ else
+ helper_GOT_init(pReloc, false, *this);
- // elsewhere if the GOT is used in statically linked binaries,
- // the GOT entry is enough and no relocation is needed.
- helper_GOT_init(pReloc, false, *this);
+ // set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
return;
@@ -431,22 +394,21 @@ void X86_32Relocator::scanLocalReloc(Relocation& pReloc,
// need to define that section symbol here
ELFFileFormat* file_format = getTarget().getOutputFormat();
const LDSection* sym_sect =
- &rsym->outSymbol()->fragRef()->frag()->getParent()->getSection();
+ &rsym->outSymbol()->fragRef()->frag()->getParent()->getSection();
LDSymbol* sect_sym = NULL;
if (&file_format->getTData() == sym_sect) {
if (!getTarget().hasTDATASymbol()) {
sect_sym = pModule.getSectionSymbolSet().get(*sym_sect);
getTarget().setTDATASymbol(*sect_sym);
}
- }
- else if (&file_format->getTBSS() == sym_sect || rsym->isCommon()) {
+ } else if (&file_format->getTBSS() == sym_sect || rsym->isCommon()) {
if (!getTarget().hasTBSSSymbol()) {
sect_sym = pModule.getSectionSymbolSet().get(*sym_sect);
getTarget().setTBSSSymbol(*sect_sym);
}
- }
- else
+ } else {
error(diag::invalid_tls) << rsym->name() << sym_sect->name();
+ }
// set up a pair of got entries and a dyn rel
// set GOT bit
@@ -459,8 +421,8 @@ void X86_32Relocator::scanLocalReloc(Relocation& pReloc,
got_entry1->setValue(0x0);
// setup dyn rel for got_entry1
- Relocation& rel_entry1 = helper_DynRel_init(rsym, *got_entry1, 0x0,
- llvm::ELF::R_386_TLS_DTPMOD32, *this);
+ Relocation& rel_entry1 = helper_DynRel_init(
+ rsym, *got_entry1, 0x0, llvm::ELF::R_386_TLS_DTPMOD32, *this);
// for local tls symbol, add rel entry against the section symbol this
// symbol belong to (.tdata or .tbss)
rel_entry1.setSymInfo(sect_sym->resolveInfo());
@@ -478,13 +440,14 @@ void X86_32Relocator::scanLocalReloc(Relocation& pReloc,
// if building shared object, a RELATIVE dynamic relocation is needed
if (LinkerConfig::DynObj == config().codeGenType()) {
- helper_DynRel_init(rsym, *pReloc.targetRef().frag(),
- pReloc.targetRef().offset(),
- llvm::ELF::R_386_RELATIVE, *this);
+ helper_DynRel_init(rsym,
+ *pReloc.targetRef().frag(),
+ pReloc.targetRef().offset(),
+ llvm::ELF::R_386_RELATIVE,
+ *this);
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
- }
- else {
+ } else {
// for local sym, we can convert ie to le if not building shared object
convertTLSIEtoLE(pReloc, pSection);
return;
@@ -497,8 +460,8 @@ void X86_32Relocator::scanLocalReloc(Relocation& pReloc,
X86_32GOTEntry* got_entry = getTarget().getGOT().create();
getSymGOTMap().record(*rsym, *got_entry);
got_entry->setValue(0x0);
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF,
- *this);
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF, *this);
// set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
// add symbol to dyn sym table
@@ -514,8 +477,8 @@ void X86_32Relocator::scanLocalReloc(Relocation& pReloc,
X86_32GOTEntry* got_entry = getTarget().getGOT().create();
getSymGOTMap().record(*rsym, *got_entry);
got_entry->setValue(0x0);
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF,
- *this);
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF, *this);
// set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
getTarget().getRelDyn().addSymbolToDynSym(*rsym->outSymbol());
@@ -536,27 +499,26 @@ void X86_32Relocator::scanLocalReloc(Relocation& pReloc,
getTarget().checkAndSetHasTextRel(*pSection.getLink());
// the target symbol of the dynamic relocation is rsym, so we need to
// emit it into .dynsym
- assert(NULL != rsym->outSymbol());
+ assert(rsym->outSymbol() != NULL);
getTarget().getRelDyn().addSymbolToDynSym(*rsym->outSymbol());
}
return;
default:
- fatal(diag::unsupported_relocation) << (int)pReloc.type()
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
<< "mclinker@googlegroups.com";
break;
- } // end switch
+ } // end switch
}
void X86_32Relocator::scanGlobalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
- LDSection& pSection)
-{
+ LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()) {
+ switch (pReloc.type()) {
case llvm::ELF::R_386_32:
case llvm::ELF::R_386_16:
case llvm::ELF::R_386_8:
@@ -564,7 +526,7 @@ void X86_32Relocator::scanGlobalReloc(Relocation& pReloc,
// dynamic relocation entry
if (getTarget().symbolNeedsPLT(*rsym)) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -574,30 +536,32 @@ void X86_32Relocator::scanGlobalReloc(Relocation& pReloc,
}
}
- if (getTarget().symbolNeedsDynRel(*rsym, (rsym->reserved() & ReservePLT),
- true)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), true)) {
// symbol needs dynamic relocation entry, set up the dynrel entry
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
- LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
+ LDSymbol& cpy_sym =
+ defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
addCopyReloc(*cpy_sym.resolveInfo(), getTarget());
- }
- else {
+ } else {
// set Rel bit and the dyn rel
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
if (llvm::ELF::R_386_32 == pReloc.type() &&
- helper_use_relative_reloc(*rsym, *this))
+ helper_use_relative_reloc(*rsym, *this)) {
helper_DynRel_init(rsym,
*pReloc.targetRef().frag(),
pReloc.targetRef().offset(),
llvm::ELF::R_386_RELATIVE,
*this);
- else
+ } else {
helper_DynRel_init(rsym,
*pReloc.targetRef().frag(),
pReloc.targetRef().offset(),
pReloc.type(),
*this);
+ }
}
}
return;
@@ -638,11 +602,9 @@ void X86_32Relocator::scanGlobalReloc(Relocation& pReloc,
// return if we already create GOT for this symbol
if (rsym->reserved() & ReserveGOT)
return;
- // If building shared object or the symbol is undefined, a dynamic
- // relocation is needed to relocate this GOT entry. Reserve an
- // entry in .rel.dyn
- if (LinkerConfig::DynObj ==
- config().codeGenType() || rsym->isUndef() || rsym->isDyn())
+ // if the symbol cannot be fully resolved at link time, then we need a
+ // dynamic relocation
+ if (!getTarget().symbolFinalValueIsKnown(*rsym))
helper_GOT_init(pReloc, true, *this);
else
helper_GOT_init(pReloc, false, *this);
@@ -657,7 +619,7 @@ void X86_32Relocator::scanGlobalReloc(Relocation& pReloc,
if (getTarget().symbolNeedsPLT(*rsym) &&
LinkerConfig::DynObj != config().codeGenType()) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -667,31 +629,32 @@ void X86_32Relocator::scanGlobalReloc(Relocation& pReloc,
}
}
- if (getTarget().symbolNeedsDynRel(*rsym, (rsym->reserved() & ReservePLT),
- false)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), false)) {
// symbol needs dynamic relocation entry, setup an entry in .rel.dyn
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
- LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym,
- getTarget());
+ LDSymbol& cpy_sym =
+ defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
addCopyReloc(*cpy_sym.resolveInfo(), getTarget());
- }
- else {
+ } else {
// set Rel bit and the dyn rel
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
if (llvm::ELF::R_386_32 == pReloc.type() &&
- helper_use_relative_reloc(*rsym, *this))
+ helper_use_relative_reloc(*rsym, *this)) {
helper_DynRel_init(rsym,
*pReloc.targetRef().frag(),
pReloc.targetRef().offset(),
llvm::ELF::R_386_RELATIVE,
*this);
- else
+ } else {
helper_DynRel_init(rsym,
*pReloc.targetRef().frag(),
pReloc.targetRef().offset(),
pReloc.type(),
*this);
+ }
}
}
return;
@@ -708,10 +671,10 @@ void X86_32Relocator::scanGlobalReloc(Relocation& pReloc,
got_entry1->setValue(0x0);
got_entry2->setValue(0x0);
// setup dyn rel for got entries against rsym
- helper_DynRel_init(rsym, *got_entry1, 0x0,
- llvm::ELF::R_386_TLS_DTPMOD32, *this);
- helper_DynRel_init(rsym, *got_entry2, 0x0,
- llvm::ELF::R_386_TLS_DTPOFF32, *this);
+ helper_DynRel_init(
+ rsym, *got_entry1, 0x0, llvm::ELF::R_386_TLS_DTPMOD32, *this);
+ helper_DynRel_init(
+ rsym, *got_entry2, 0x0, llvm::ELF::R_386_TLS_DTPOFF32, *this);
// add the rsym to dynamic symbol table
getTarget().getRelDyn().addSymbolToDynSym(*rsym->outSymbol());
@@ -731,9 +694,11 @@ void X86_32Relocator::scanGlobalReloc(Relocation& pReloc,
getTarget().setHasStaticTLS();
// if buildint shared object, a RELATIVE dynamic relocation is needed
if (LinkerConfig::DynObj == config().codeGenType()) {
- helper_DynRel_init(rsym, *pReloc.targetRef().frag(),
- pReloc.targetRef().offset(),
- llvm::ELF::R_386_RELATIVE, *this);
+ helper_DynRel_init(rsym,
+ *pReloc.targetRef().frag(),
+ pReloc.targetRef().offset(),
+ llvm::ELF::R_386_RELATIVE,
+ *this);
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
} else {
@@ -749,8 +714,8 @@ void X86_32Relocator::scanGlobalReloc(Relocation& pReloc,
X86_32GOTEntry* got_entry = getTarget().getGOT().create();
getSymGOTMap().record(*rsym, *got_entry);
got_entry->setValue(0x0);
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF,
- *this);
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF, *this);
// set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
return;
@@ -764,8 +729,8 @@ void X86_32Relocator::scanGlobalReloc(Relocation& pReloc,
X86_32GOTEntry* got_entry = getTarget().getGOT().create();
getSymGOTMap().record(*rsym, *got_entry);
got_entry->setValue(0x0);
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF,
- *this);
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_386_TLS_TPOFF, *this);
getTarget().getRelDyn().addSymbolToDynSym(*rsym->outSymbol());
// set GOT bit
rsym->setReserved(rsym->reserved() | ReserveGOT);
@@ -789,55 +754,54 @@ void X86_32Relocator::scanGlobalReloc(Relocation& pReloc,
return;
default: {
- fatal(diag::unsupported_relocation) << (int)pReloc.type()
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
<< "mclinker@googlegroups.com";
break;
}
- } // end switch
+ } // end switch
}
// Create a GOT entry for the TLS module index
-X86_32GOTEntry& X86_32Relocator::getTLSModuleID()
-{
+X86_32GOTEntry& X86_32Relocator::getTLSModuleID() {
static X86_32GOTEntry* got_entry = NULL;
- if (NULL != got_entry)
+ if (got_entry != NULL)
return *got_entry;
// Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
got_entry = getTarget().getGOT().create();
getTarget().getGOT().create()->setValue(0x0);
- helper_DynRel_init(NULL, *got_entry, 0x0, llvm::ELF::R_386_TLS_DTPMOD32,
- *this);
+ helper_DynRel_init(
+ NULL, *got_entry, 0x0, llvm::ELF::R_386_TLS_DTPMOD32, *this);
return *got_entry;
}
/// convert R_386_TLS_IE to R_386_TLS_LE
void X86_32Relocator::convertTLSIEtoLE(Relocation& pReloc,
- LDSection& pSection)
-{
+ LDSection& pSection) {
assert(pReloc.type() == llvm::ELF::R_386_TLS_IE);
- assert(NULL != pReloc.targetRef().frag());
+ assert(pReloc.targetRef().frag() != NULL);
// 1. create the new relocs
Relocation* reloc =
- Relocation::Create(X86_32Relocator::R_386_TLS_OPT,
- *FragmentRef::Create(*pReloc.targetRef().frag(),
- pReloc.targetRef().offset() - 1),
- 0x0);
+ Relocation::Create(X86_32Relocator::R_386_TLS_OPT,
+ *FragmentRef::Create(*pReloc.targetRef().frag(),
+ pReloc.targetRef().offset() - 1),
+ 0x0);
// FIXME: should we create a special symbol for the tls opt instead?
reloc->setSymInfo(pReloc.symInfo());
// 2. modify the opcodes to the appropriate ones
- uint8_t* op = (reinterpret_cast<uint8_t*>(&reloc->target()));
+ uint8_t* op = (reinterpret_cast<uint8_t*>(&reloc->target()));
if (op[0] == 0xa1) {
op[0] = 0xb8;
} else {
// create the new reloc (move 1 byte forward).
- reloc = Relocation::Create(X86_32Relocator::R_386_TLS_OPT,
- *FragmentRef::Create(*pReloc.targetRef().frag(),
- pReloc.targetRef().offset() - 2),
- 0x0);
+ reloc = Relocation::Create(
+ X86_32Relocator::R_386_TLS_OPT,
+ *FragmentRef::Create(*pReloc.targetRef().frag(),
+ pReloc.targetRef().offset() - 2),
+ 0x0);
reloc->setSymInfo(pReloc.symInfo());
op = (reinterpret_cast<uint8_t*>(&reloc->target()));
switch (op[0]) {
@@ -860,40 +824,52 @@ void X86_32Relocator::convertTLSIEtoLE(Relocation& pReloc,
// 3. insert the new relocs "BEFORE" the original reloc.
assert(reloc != NULL);
pSection.getRelocData()->getRelocationList().insert(
- RelocData::iterator(pReloc), reloc);
+ RelocData::iterator(pReloc), reloc);
// 4. change the type of the original reloc
pReloc.setType(llvm::ELF::R_386_TLS_LE);
}
+uint32_t X86_32Relocator::getDebugStringOffset(Relocation& pReloc) const {
+ if (pReloc.type() != llvm::ELF::R_386_32)
+ error(diag::unsupport_reloc_for_debug_string)
+ << getName(pReloc.type()) << "mclinker@googlegroups.com";
+
+ if (pReloc.symInfo()->type() == ResolveInfo::Section)
+ return pReloc.target();
+ else
+ return pReloc.symInfo()->outSymbol()->fragRef()->offset() +
+ pReloc.target() + pReloc.addend();
+}
+
+void X86_32Relocator::applyDebugStringOffset(Relocation& pReloc,
+ uint32_t pOffset) {
+ pReloc.target() = pOffset;
+}
+
//================================================//
// X86_32 Each relocation function implementation //
//================================================//
// R_386_NONE
-Relocator::Result none(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result none(Relocation& pReloc, X86_32Relocator& pParent) {
return Relocator::OK;
}
// R_386_32: S + A
// R_386_16
// R_386_8
-Relocator::Result abs(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result abs(Relocation& pReloc, X86_32Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::DWord S = pReloc.symValue();
bool has_dyn_rel = pParent.getTarget().symbolNeedsDynRel(
- *rsym,
- (rsym->reserved() & X86Relocator::ReservePLT),
- true);
-
+ *rsym, (rsym->reserved() & X86Relocator::ReservePLT), true);
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
- // but perform static relocation. (e.g., applying .debug section)
- if (0x0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation but perform static relocation. (e.g., applying .debug section)
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) == 0x0) {
pReloc.target() = S + A;
return Relocator::OK;
}
@@ -920,21 +896,19 @@ Relocator::Result abs(Relocation& pReloc, X86_32Relocator& pParent)
// R_386_PC32: S + A - P
// R_386_PC16
// R_386_PC8
-Relocator::Result rel(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result rel(Relocation& pReloc, X86_32Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::DWord S = pReloc.symValue();
Relocator::DWord P = pReloc.place();
bool has_dyn_rel = pParent.getTarget().symbolNeedsDynRel(
- *rsym,
- (rsym->reserved() & X86Relocator::ReservePLT),
- true);
+ *rsym, (rsym->reserved() & X86Relocator::ReservePLT), true);
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation
// but perform static relocation. (e.g., applying .debug section)
- if (0x0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) == 0x0) {
pReloc.target() = S + A - P;
return Relocator::OK;
}
@@ -950,15 +924,14 @@ Relocator::Result rel(Relocation& pReloc, X86_32Relocator& pParent)
return Relocator::OK;
}
- // perform static relocation
+ // perform static relocation
pReloc.target() = S + A - P;
return Relocator::OK;
}
// R_386_GOTOFF: S + A - GOT_ORG
-Relocator::Result gotoff32(Relocation& pReloc, X86_32Relocator& pParent)
-{
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+Relocator::Result gotoff32(Relocation& pReloc, X86_32Relocator& pParent) {
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address GOT_ORG = helper_GOT_ORG(pParent);
Relocator::Address S = pReloc.symValue();
@@ -967,9 +940,8 @@ Relocator::Result gotoff32(Relocation& pReloc, X86_32Relocator& pParent)
}
// R_386_GOTPC: GOT_ORG + A - P
-Relocator::Result gotpc32(Relocation& pReloc, X86_32Relocator& pParent)
-{
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+Relocator::Result gotpc32(Relocation& pReloc, X86_32Relocator& pParent) {
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address GOT_ORG = helper_GOT_ORG(pParent);
// Apply relocation.
pReloc.target() = GOT_ORG + A - pReloc.place();
@@ -977,8 +949,7 @@ Relocator::Result gotpc32(Relocation& pReloc, X86_32Relocator& pParent)
}
// R_386_GOT32: GOT(S) + A - GOT_ORG
-Relocator::Result got32(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result got32(Relocation& pReloc, X86_32Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
if (!(rsym->reserved() & (X86Relocator::ReserveGOT)))
return Relocator::BadReloc;
@@ -986,12 +957,12 @@ Relocator::Result got32(Relocation& pReloc, X86_32Relocator& pParent)
// set up got entry value if the got has no dyn rel or
// the dyn rel is RELATIVE
X86_32GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
if (got_entry->getValue() == X86Relocator::SymVal)
got_entry->setValue(pReloc.symValue());
- Relocator::Address GOT_S = helper_get_GOT_address(pReloc, pParent);
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::Address GOT_S = helper_get_GOT_address(pReloc, pParent);
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address GOT_ORG = helper_GOT_ORG(pParent);
// Apply relocation.
pReloc.target() = GOT_S + A - GOT_ORG;
@@ -999,23 +970,21 @@ Relocator::Result got32(Relocation& pReloc, X86_32Relocator& pParent)
}
// R_386_PLT32: PLT(S) + A - P
-Relocator::Result plt32(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result plt32(Relocation& pReloc, X86_32Relocator& pParent) {
// PLT_S depends on if there is a PLT entry.
Relocator::Address PLT_S;
if ((pReloc.symInfo()->reserved() & X86Relocator::ReservePLT))
PLT_S = helper_get_PLT_address(*pReloc.symInfo(), pParent);
else
PLT_S = pReloc.symValue();
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address P = pReloc.place();
pReloc.target() = PLT_S + A - P;
return Relocator::OK;
}
// R_386_TLS_GD:
-Relocator::Result tls_gd(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result tls_gd(Relocation& pReloc, X86_32Relocator& pParent) {
// global-dynamic
ResolveInfo* rsym = pReloc.symInfo();
// must reserve two pairs of got and dynamic relocation
@@ -1031,30 +1000,29 @@ Relocator::Result tls_gd(Relocation& pReloc, X86_32Relocator& pParent)
// set the got_entry2 value to symbol value
if (rsym->isLocal())
- pParent.getSymGOTMap().lookUpSecondEntry(*rsym)->setValue(pReloc.symValue());
+ pParent.getSymGOTMap().lookUpSecondEntry(*rsym)->setValue(
+ pReloc.symValue());
// perform relocation to the first got entry
Relocator::DWord A = pReloc.target() + pReloc.addend();
// GOT_OFF - the offset between the got_entry1 and _GLOBAL_OFFSET_TABLE (the
// .got.plt section)
- Relocator::Address GOT_OFF =
- file_format->getGOT().addr() +
- got_entry1->getOffset() -
- file_format->getGOTPLT().addr();
+ Relocator::Address GOT_OFF = file_format->getGOT().addr() +
+ got_entry1->getOffset() -
+ file_format->getGOTPLT().addr();
pReloc.target() = GOT_OFF + A;
return Relocator::OK;
}
// R_386_TLS_LDM
-Relocator::Result tls_ldm(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result tls_ldm(Relocation& pReloc, X86_32Relocator& pParent) {
// FIXME: no linker optimization for TLS relocation
const X86_32GOTEntry& got_entry = pParent.getTLSModuleID();
// All GOT offsets are relative to the end of the GOT.
- X86Relocator::SWord GOT_S = got_entry.getOffset() -
- (pParent.getTarget().getGOTPLT().addr() -
- pParent.getTarget().getGOT().addr());
+ X86Relocator::SWord GOT_S =
+ got_entry.getOffset() - (pParent.getTarget().getGOTPLT().addr() -
+ pParent.getTarget().getGOT().addr());
Relocator::DWord A = pReloc.target() + pReloc.addend();
pReloc.target() = GOT_S + A;
@@ -1062,8 +1030,7 @@ Relocator::Result tls_ldm(Relocation& pReloc, X86_32Relocator& pParent)
}
// R_386_TLS_LDO_32
-Relocator::Result tls_ldo_32(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result tls_ldo_32(Relocation& pReloc, X86_32Relocator& pParent) {
// FIXME: no linker optimization for TLS relocation
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address S = pReloc.symValue();
@@ -1072,19 +1039,18 @@ Relocator::Result tls_ldo_32(Relocation& pReloc, X86_32Relocator& pParent)
}
// R_X86_TLS_IE
-Relocator::Result tls_ie(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result tls_ie(Relocation& pReloc, X86_32Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
if (!(rsym->reserved() & X86Relocator::ReserveGOT)) {
- return Relocator::BadReloc;
+ return Relocator::BadReloc;
}
// set up the got and dynamic relocation entries if not exist
X86_32GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*rsym);
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
// perform relocation to the absolute address of got_entry
Relocator::Address GOT_S =
- pParent.getTarget().getGOT().addr() + got_entry->getOffset();
+ pParent.getTarget().getGOT().addr() + got_entry->getOffset();
Relocator::DWord A = pReloc.target() + pReloc.addend();
pReloc.target() = GOT_S + A;
@@ -1093,20 +1059,20 @@ Relocator::Result tls_ie(Relocation& pReloc, X86_32Relocator& pParent)
}
// R_386_TLS_GOTIE
-Relocator::Result tls_gotie(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result tls_gotie(Relocation& pReloc, X86_32Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
if (!(rsym->reserved() & X86Relocator::ReserveGOT)) {
- return Relocator::BadReloc;
+ return Relocator::BadReloc;
}
// set up the got and dynamic relocation entries if not exist
X86_32GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*rsym);
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
// All GOT offsets are relative to the end of the GOT.
- X86Relocator::SWord GOT_S = got_entry->getOffset() -
- (pParent.getTarget().getGOTPLT().addr() - pParent.getTarget().getGOT().addr());
+ X86Relocator::SWord GOT_S =
+ got_entry->getOffset() - (pParent.getTarget().getGOTPLT().addr() -
+ pParent.getTarget().getGOT().addr());
Relocator::DWord A = pReloc.target() + pReloc.addend();
pReloc.target() = GOT_S + A;
@@ -1114,17 +1080,15 @@ Relocator::Result tls_gotie(Relocation& pReloc, X86_32Relocator& pParent)
}
// R_X86_TLS_LE
-Relocator::Result tls_le(Relocation& pReloc, X86_32Relocator& pParent)
-{
+Relocator::Result tls_le(Relocation& pReloc, X86_32Relocator& pParent) {
if (pReloc.symInfo()->reserved() & X86Relocator::ReserveRel)
return Relocator::OK;
// perform static relocation
// get TLS segment
ELFSegmentFactory::const_iterator tls_seg =
- pParent.getTarget().elfSegmentTable().find(llvm::ELF::PT_TLS,
- llvm::ELF::PF_R,
- 0x0);
+ pParent.getTarget().elfSegmentTable().find(
+ llvm::ELF::PT_TLS, llvm::ELF::PF_R, 0x0);
assert(tls_seg != pParent.getTarget().elfSegmentTable().end());
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address S = pReloc.symValue();
@@ -1132,27 +1096,24 @@ Relocator::Result tls_le(Relocation& pReloc, X86_32Relocator& pParent)
return Relocator::OK;
}
-Relocator::Result unsupport(Relocation& pReloc, X86_32Relocator& pParent)
-{
- return Relocator::Unsupport;
+Relocator::Result unsupported(Relocation& pReloc, X86_32Relocator& pParent) {
+ return Relocator::Unsupported;
}
//===--------------------------------------------------------------------===//
// X86_64 Relocation helper function
//===--------------------------------------------------------------------===//
/// helper_DynRel - Get an relocation entry in .rela.dyn
-static
-Relocation& helper_DynRel_init(ResolveInfo* pSym,
- Fragment& pFrag,
- uint64_t pOffset,
- Relocator::Type pType,
- X86_64Relocator& pParent)
-{
+static Relocation& helper_DynRel_init(ResolveInfo* pSym,
+ Fragment& pFrag,
+ uint64_t pOffset,
+ Relocator::Type pType,
+ X86_64Relocator& pParent) {
X86_64GNULDBackend& ld_backend = pParent.getTarget();
Relocation& rel_entry = *ld_backend.getRelDyn().create();
rel_entry.setType(pType);
rel_entry.targetRef().assign(pFrag, pOffset);
- if (pType == llvm::ELF::R_X86_64_RELATIVE || NULL == pSym)
+ if (pType == llvm::ELF::R_X86_64_RELATIVE || pSym == NULL)
rel_entry.setSymInfo(NULL);
else
rel_entry.setSymInfo(pSym);
@@ -1160,31 +1121,24 @@ Relocation& helper_DynRel_init(ResolveInfo* pSym,
return rel_entry;
}
-
/// helper_use_relative_reloc - Check if symbol can use relocation
/// R_X86_64_RELATIVE
-static bool
-helper_use_relative_reloc(const ResolveInfo& pSym,
- const X86_64Relocator& pFactory)
-
-{
+static bool helper_use_relative_reloc(const ResolveInfo& pSym,
+ const X86_64Relocator& pFactory) {
// if symbol is dynamic or undefine or preemptible
- if (pSym.isDyn() ||
- pSym.isUndef() ||
+ if (pSym.isDyn() || pSym.isUndef() ||
pFactory.getTarget().isSymbolPreemptible(pSym))
return false;
return true;
}
-static
-X86_64GOTEntry& helper_GOT_init(Relocation& pReloc,
- bool pHasRel,
- X86_64Relocator& pParent)
-{
+static X86_64GOTEntry& helper_GOT_init(Relocation& pReloc,
+ bool pHasRel,
+ X86_64Relocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
X86_64GNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymGOTMap().lookUp(*rsym));
+ assert(pParent.getSymGOTMap().lookUp(*rsym) == NULL);
X86_64GOTEntry* got_entry = ld_backend.getGOT().create();
pParent.getSymGOTMap().record(*rsym, *got_entry);
@@ -1193,61 +1147,52 @@ X86_64GOTEntry& helper_GOT_init(Relocation& pReloc,
if (!pHasRel) {
// No corresponding dynamic relocation, initialize to the symbol value.
got_entry->setValue(X86Relocator::SymVal);
- }
- else {
+ } else {
// Initialize got_entry content and the corresponding dynamic relocation.
if (helper_use_relative_reloc(*rsym, pParent)) {
- Relocation& rel_entry = helper_DynRel_init(rsym, *got_entry, 0x0,
- llvm::ELF::R_X86_64_RELATIVE, pParent);
- rel_entry.setAddend(X86Relocator::SymVal);
- pParent.getRelRelMap().record(pReloc, rel_entry);
- }
- else {
- helper_DynRel_init(rsym, *got_entry, 0x0, llvm::ELF::R_X86_64_GLOB_DAT,
- pParent);
+ Relocation& rel_entry = helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_X86_64_RELATIVE, pParent);
+ rel_entry.setAddend(X86Relocator::SymVal);
+ pParent.getRelRelMap().record(pReloc, rel_entry);
+ } else {
+ helper_DynRel_init(
+ rsym, *got_entry, 0x0, llvm::ELF::R_X86_64_GLOB_DAT, pParent);
}
got_entry->setValue(0);
}
return *got_entry;
}
-static
-Relocator::Address helper_GOT_ORG(X86_64Relocator& pParent)
-{
+static Relocator::Address helper_GOT_ORG(X86_64Relocator& pParent) {
return pParent.getTarget().getGOT().addr();
}
-static
-Relocator::Address helper_get_GOT_address(Relocation& pReloc,
- X86_64Relocator& pParent)
-{
+static Relocator::Address helper_get_GOT_address(Relocation& pReloc,
+ X86_64Relocator& pParent) {
X86_64GOTEntry* got_entry = pParent.getSymGOTMap().lookUp(*pReloc.symInfo());
- assert(NULL != got_entry);
+ assert(got_entry != NULL);
return got_entry->getOffset();
}
-static
-Relocator::Address helper_get_PLT_address(ResolveInfo& pSym,
- X86_64Relocator& pParent)
-{
+static Relocator::Address helper_get_PLT_address(ResolveInfo& pSym,
+ X86_64Relocator& pParent) {
PLTEntryBase* plt_entry = pParent.getSymPLTMap().lookUp(pSym);
- assert(NULL != plt_entry);
+ assert(plt_entry != NULL);
return pParent.getTarget().getPLT().addr() + plt_entry->getOffset();
}
-static
-PLTEntryBase& helper_PLT_init(Relocation& pReloc, X86_64Relocator& pParent)
-{
+static PLTEntryBase& helper_PLT_init(Relocation& pReloc,
+ X86_64Relocator& pParent) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
X86_64GNULDBackend& ld_backend = pParent.getTarget();
- assert(NULL == pParent.getSymPLTMap().lookUp(*rsym));
+ assert(pParent.getSymPLTMap().lookUp(*rsym) == NULL);
PLTEntryBase* plt_entry = ld_backend.getPLT().create();
pParent.getSymPLTMap().record(*rsym, *plt_entry);
// initialize plt and the corresponding gotplt and dyn rel entry.
- assert(NULL == pParent.getSymGOTPLTMap().lookUp(*rsym) &&
+ assert(pParent.getSymGOTPLTMap().lookUp(*rsym) == NULL &&
"PLT entry not exist, but DynRel entry exist!");
X86_64GOTEntry* gotplt_entry = ld_backend.getGOTPLT().create();
pParent.getSymGOTPLTMap().record(*rsym, *gotplt_entry);
@@ -1260,9 +1205,9 @@ PLTEntryBase& helper_PLT_init(Relocation& pReloc, X86_64Relocator& pParent)
return *plt_entry;
}
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
// X86_64 Relocation Functions and Tables
-//===--------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
DECL_X86_64_APPLY_RELOC_FUNCS
/// the prototype of applying function
@@ -1270,8 +1215,7 @@ typedef Relocator::Result (*X86_64ApplyFunctionType)(Relocation& pReloc,
X86_64Relocator& pParent);
// the table entry of applying functions
-struct X86_64ApplyFunctionTriple
-{
+struct X86_64ApplyFunctionTriple {
X86_64ApplyFunctionType func;
unsigned int type;
const char* name;
@@ -1280,23 +1224,20 @@ struct X86_64ApplyFunctionTriple
// declare the table of applying functions
static const X86_64ApplyFunctionTriple X86_64ApplyFunctions[] = {
- DECL_X86_64_APPLY_RELOC_FUNC_PTRS
-};
+ DECL_X86_64_APPLY_RELOC_FUNC_PTRS};
//===--------------------------------------------------------------------===//
// X86_64Relocator
//===--------------------------------------------------------------------===//
X86_64Relocator::X86_64Relocator(X86_64GNULDBackend& pParent,
const LinkerConfig& pConfig)
- : X86Relocator(pConfig), m_Target(pParent) {
+ : X86Relocator(pConfig), m_Target(pParent) {
}
-Relocator::Result
-X86_64Relocator::applyRelocation(Relocation& pRelocation)
-{
+Relocator::Result X86_64Relocator::applyRelocation(Relocation& pRelocation) {
Relocation::Type type = pRelocation.type();
- if (type >= sizeof (X86_64ApplyFunctions) / sizeof (X86_64ApplyFunctions[0]) ) {
+ if (type >= sizeof(X86_64ApplyFunctions) / sizeof(X86_64ApplyFunctions[0])) {
return Unknown;
}
@@ -1304,19 +1245,16 @@ X86_64Relocator::applyRelocation(Relocation& pRelocation)
return X86_64ApplyFunctions[type].func(pRelocation, *this);
}
-const char* X86_64Relocator::getName(Relocation::Type pType) const
-{
+const char* X86_64Relocator::getName(Relocation::Type pType) const {
return X86_64ApplyFunctions[pType].name;
}
-Relocator::Size X86_64Relocator::getSize(Relocation::Type pType) const
-{
+Relocator::Size X86_64Relocator::getSize(Relocation::Type pType) const {
return X86_64ApplyFunctions[pType].size;
}
-bool
-X86_64Relocator::mayHaveFunctionPointerAccess(const Relocation& pReloc) const
-{
+bool X86_64Relocator::mayHaveFunctionPointerAccess(
+ const Relocation& pReloc) const {
bool possible_funcptr_reloc = false;
switch (pReloc.type()) {
case llvm::ELF::R_X86_64_64:
@@ -1338,25 +1276,24 @@ X86_64Relocator::mayHaveFunctionPointerAccess(const Relocation& pReloc) const
}
}
- if (pReloc.symInfo()->isGlobal()) {
+ if (pReloc.symInfo()->isGlobal()) {
return (config().codeGenType() == LinkerConfig::DynObj) &&
((pReloc.symInfo()->visibility() != ResolveInfo::Default) ||
possible_funcptr_reloc);
- } else {
+ } else {
return (config().codeGenType() == LinkerConfig::DynObj) ||
possible_funcptr_reloc;
- }
+ }
}
void X86_64Relocator::scanLocalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
- LDSection& pSection)
-{
+ LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()){
+ switch (pReloc.type()) {
case llvm::ELF::R_X86_64_64:
// If buiding PIC object (shared library or PIC executable),
// a dynamic relocations with RELATIVE type to this location is needed.
@@ -1405,11 +1342,9 @@ void X86_64Relocator::scanLocalReloc(Relocation& pReloc,
if (rsym->reserved() & ReserveGOT)
return;
- // If building shared object or the symbol is undefined, a dynamic
- // relocation is needed to relocate this GOT entry. Reserve an
- // entry in .rela.dyn
- if (LinkerConfig::DynObj ==
- config().codeGenType() || rsym->isUndef() || rsym->isDyn())
+ // If building PIC object, a dynamic relocation with
+ // type RELATIVE is needed to relocate this GOT entry.
+ if (config().isCodeIndep())
helper_GOT_init(pReloc, true, *this);
else
helper_GOT_init(pReloc, false, *this);
@@ -1417,21 +1352,20 @@ void X86_64Relocator::scanLocalReloc(Relocation& pReloc,
return;
default:
- fatal(diag::unsupported_relocation) << (int)pReloc.type()
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
<< "mclinker@googlegroups.com";
break;
- } // end switch
+ } // end switch
}
void X86_64Relocator::scanGlobalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
- LDSection& pSection)
-{
+ LDSection& pSection) {
// rsym - The relocation target symbol
ResolveInfo* rsym = pReloc.symInfo();
- switch(pReloc.type()) {
+ switch (pReloc.type()) {
case llvm::ELF::R_X86_64_64:
case llvm::ELF::R_X86_64_32:
case llvm::ELF::R_X86_64_16:
@@ -1441,7 +1375,7 @@ void X86_64Relocator::scanGlobalReloc(Relocation& pReloc,
// dynamic relocation entry
if (getTarget().symbolNeedsPLT(*rsym)) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need to reserve a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rela.plt.
@@ -1451,14 +1385,15 @@ void X86_64Relocator::scanGlobalReloc(Relocation& pReloc,
}
}
- if (getTarget().symbolNeedsDynRel(*rsym, (rsym->reserved() & ReservePLT),
- true)) {
+ if (getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), true)) {
// symbol needs dynamic relocation entry, set up the dynrel entry
if (getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
- LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
+ LDSymbol& cpy_sym =
+ defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
addCopyReloc(*cpy_sym.resolveInfo(), getTarget());
- }
- else {
+ } else {
// set Rel bit and the dyn rel
rsym->setReserved(rsym->reserved() | ReserveRel);
getTarget().checkAndSetHasTextRel(*pSection.getLink());
@@ -1470,8 +1405,7 @@ void X86_64Relocator::scanGlobalReloc(Relocation& pReloc,
llvm::ELF::R_X86_64_RELATIVE,
*this);
getRelRelMap().record(pReloc, reloc);
- }
- else {
+ } else {
Relocation& reloc = helper_DynRel_init(rsym,
*pReloc.targetRef().frag(),
pReloc.targetRef().offset(),
@@ -1490,11 +1424,9 @@ void X86_64Relocator::scanGlobalReloc(Relocation& pReloc,
if (rsym->reserved() & ReserveGOT)
return;
- // If building shared object or the symbol is undefined, a dynamic
- // relocation is needed to relocate this GOT entry. Reserve an
- // entry in .rela.dyn
- if (LinkerConfig::DynObj ==
- config().codeGenType() || rsym->isUndef() || rsym->isDyn())
+ // if the symbol cannot be fully resolved at link time, then we need a
+ // dynamic relocation
+ if (!getTarget().symbolFinalValueIsKnown(*rsym))
helper_GOT_init(pReloc, true, *this);
else
helper_GOT_init(pReloc, false, *this);
@@ -1516,7 +1448,7 @@ void X86_64Relocator::scanGlobalReloc(Relocation& pReloc,
// if symbol is defined in the ouput file and it's not
// preemptible, no need plt
if (rsym->isDefine() && !rsym->isDyn() &&
- !getTarget().isSymbolPreemptible(*rsym)) {
+ !getTarget().isSymbolPreemptible(*rsym)) {
return;
}
@@ -1534,7 +1466,7 @@ void X86_64Relocator::scanGlobalReloc(Relocation& pReloc,
if (getTarget().symbolNeedsPLT(*rsym) &&
LinkerConfig::DynObj != config().codeGenType()) {
// create plt for this symbol if it does not have one
- if (!(rsym->reserved() & ReservePLT)){
+ if (!(rsym->reserved() & ReservePLT)) {
// Symbol needs PLT entry, we need a PLT entry
// and the corresponding GOT and dynamic relocation entry
// in .got and .rel.plt.
@@ -1550,28 +1482,45 @@ void X86_64Relocator::scanGlobalReloc(Relocation& pReloc,
// All other dynamic relocations may lead to run-time relocation
// overflow.
if (getTarget().isDynamicSymbol(*rsym) &&
- getTarget().symbolNeedsDynRel(*rsym,
- (rsym->reserved() & ReservePLT),
- false) &&
- getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
- LDSymbol& cpy_sym = defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
+ getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & ReservePLT), false) &&
+ getTarget().symbolNeedsCopyReloc(pReloc, *rsym)) {
+ LDSymbol& cpy_sym =
+ defineSymbolforCopyReloc(pBuilder, *rsym, getTarget());
addCopyReloc(*cpy_sym.resolveInfo(), getTarget());
}
return;
default:
- fatal(diag::unsupported_relocation) << (int)pReloc.type()
+ fatal(diag::unsupported_relocation) << static_cast<int>(pReloc.type())
<< "mclinker@googlegroups.com";
break;
- } // end switch
+ } // end switch
}
-// ===
-//
-// ===
+uint32_t X86_64Relocator::getDebugStringOffset(Relocation& pReloc) const {
+ if (pReloc.type() != llvm::ELF::R_X86_64_32)
+ error(diag::unsupport_reloc_for_debug_string)
+ << getName(pReloc.type()) << "mclinker@googlegroups.com";
+
+ if (pReloc.symInfo()->type() == ResolveInfo::Section)
+ return pReloc.target();
+ else
+ return pReloc.symInfo()->outSymbol()->fragRef()->offset() +
+ pReloc.target() + pReloc.addend();
+}
+
+void X86_64Relocator::applyDebugStringOffset(Relocation& pReloc,
+ uint32_t pOffset) {
+ pReloc.target() = pOffset;
+}
+
+//------------------------------------------------//
+// X86_64 Each relocation function implementation //
+//------------------------------------------------//
// R_X86_64_NONE
-Relocator::Result none(Relocation& pReloc, X86_64Relocator& pParent)
-{
+Relocator::Result none(Relocation& pReloc, X86_64Relocator& pParent) {
return Relocator::OK;
}
@@ -1579,18 +1528,17 @@ Relocator::Result none(Relocation& pReloc, X86_64Relocator& pParent)
// R_X86_64_32:
// R_X86_64_16:
// R_X86_64_8
-Relocator::Result abs(Relocation& pReloc, X86_64Relocator& pParent)
-{
+Relocator::Result abs(Relocation& pReloc, X86_64Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::DWord S = pReloc.symValue();
Relocation* dyn_rel = pParent.getRelRelMap().lookUp(pReloc);
- bool has_dyn_rel = (NULL != dyn_rel);
+ bool has_dyn_rel = (dyn_rel != NULL);
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
- // but perform static relocation. (e.g., applying .debug section)
- if (0x0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation but perform static relocation. (e.g., applying .debug section)
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) == 0x0) {
pReloc.target() = S + A;
return Relocator::OK;
}
@@ -1613,8 +1561,7 @@ Relocator::Result abs(Relocation& pReloc, X86_64Relocator& pParent)
if (llvm::ELF::R_X86_64_64 == pReloc.type() &&
helper_use_relative_reloc(*rsym, pParent)) {
dyn_rel->setAddend(S + A);
- }
- else {
+ } else {
dyn_rel->setAddend(A);
return Relocator::OK;
}
@@ -1627,22 +1574,21 @@ Relocator::Result abs(Relocation& pReloc, X86_64Relocator& pParent)
}
// R_X86_64_32S: S + A
-Relocator::Result signed32(Relocation& pReloc, X86_64Relocator& pParent)
-{
+Relocator::Result signed32(Relocation& pReloc, X86_64Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::DWord S = pReloc.symValue();
// There should be no dynamic relocations for R_X86_64_32S.
- if (NULL != pParent.getRelRelMap().lookUp(pReloc))
+ if (pParent.getRelRelMap().lookUp(pReloc) != NULL)
return Relocator::BadReloc;
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
- // but perform static relocation. (e.g., applying .debug section)
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation but perform static relocation. (e.g., applying .debug section)
// An external symbol may need PLT and dynamic relocation
- if (0x0 != (llvm::ELF::SHF_ALLOC & target_sect.flag()) &&
- !rsym->isLocal() && rsym->reserved() & X86Relocator::ReservePLT)
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) != 0x0 && !rsym->isLocal() &&
+ rsym->reserved() & X86Relocator::ReservePLT)
S = helper_get_PLT_address(*rsym, pParent);
#if notyet
@@ -1658,8 +1604,7 @@ Relocator::Result signed32(Relocation& pReloc, X86_64Relocator& pParent)
}
// R_X86_64_GOTPCREL: GOT(S) + GOT_ORG + A - P
-Relocator::Result gotpcrel(Relocation& pReloc, X86_64Relocator& pParent)
-{
+Relocator::Result gotpcrel(Relocation& pReloc, X86_64Relocator& pParent) {
if (!(pReloc.symInfo()->reserved() & X86Relocator::ReserveGOT)) {
return Relocator::BadReloc;
}
@@ -1671,12 +1616,12 @@ Relocator::Result gotpcrel(Relocation& pReloc, X86_64Relocator& pParent)
// setup relocation addend if needed
Relocation* dyn_rel = pParent.getRelRelMap().lookUp(pReloc);
- if ((NULL != dyn_rel) && (X86Relocator::SymVal == dyn_rel->addend())) {
+ if ((dyn_rel != NULL) && (X86Relocator::SymVal == dyn_rel->addend())) {
dyn_rel->setAddend(pReloc.symValue());
}
- Relocator::Address GOT_S = helper_get_GOT_address(pReloc, pParent);
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::Address GOT_S = helper_get_GOT_address(pReloc, pParent);
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address GOT_ORG = helper_GOT_ORG(pParent);
// Apply relocation.
pReloc.target() = GOT_S + GOT_ORG + A - pReloc.place();
@@ -1684,15 +1629,14 @@ Relocator::Result gotpcrel(Relocation& pReloc, X86_64Relocator& pParent)
}
// R_X86_64_PLT32: PLT(S) + A - P
-Relocator::Result plt32(Relocation& pReloc, X86_64Relocator& pParent)
-{
+Relocator::Result plt32(Relocation& pReloc, X86_64Relocator& pParent) {
// PLT_S depends on if there is a PLT entry.
Relocator::Address PLT_S;
if ((pReloc.symInfo()->reserved() & X86Relocator::ReservePLT))
PLT_S = helper_get_PLT_address(*pReloc.symInfo(), pParent);
else
PLT_S = pReloc.symValue();
- Relocator::DWord A = pReloc.target() + pReloc.addend();
+ Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::Address P = pReloc.place();
pReloc.target() = PLT_S + A - P;
return Relocator::OK;
@@ -1701,46 +1645,45 @@ Relocator::Result plt32(Relocation& pReloc, X86_64Relocator& pParent)
// R_X86_64_PC32: S + A - P
// R_X86_64_PC16
// R_X86_64_PC8
-Relocator::Result rel(Relocation& pReloc, X86_64Relocator& pParent)
-{
+Relocator::Result rel(Relocation& pReloc, X86_64Relocator& pParent) {
ResolveInfo* rsym = pReloc.symInfo();
Relocator::DWord A = pReloc.target() + pReloc.addend();
Relocator::DWord S = pReloc.symValue();
Relocator::DWord P = pReloc.place();
LDSection& target_sect = pReloc.targetRef().frag()->getParent()->getSection();
- // If the flag of target section is not ALLOC, we will not scan this relocation
- // but perform static relocation. (e.g., applying .debug section)
- if (0x0 == (llvm::ELF::SHF_ALLOC & target_sect.flag())) {
+ // If the flag of target section is not ALLOC, we will not scan this
+ // relocation but perform static relocation. (e.g., applying .debug section)
+ if ((llvm::ELF::SHF_ALLOC & target_sect.flag()) == 0x0) {
pReloc.target() = S + A - P;
return Relocator::OK;
}
// setup relocation addend if needed
Relocation* dyn_rel = pParent.getRelRelMap().lookUp(pReloc);
- if ((NULL != dyn_rel) && (X86Relocator::SymVal == dyn_rel->addend())) {
+ if ((dyn_rel != NULL) && (X86Relocator::SymVal == dyn_rel->addend())) {
dyn_rel->setAddend(S);
}
// An external symbol may need PLT and dynamic relocation
if (!rsym->isLocal()) {
if (rsym->reserved() & X86Relocator::ReservePLT) {
- S = helper_get_PLT_address(*rsym, pParent);
+ S = helper_get_PLT_address(*rsym, pParent);
}
- if (pParent.getTarget().symbolNeedsDynRel(
- *rsym,
- (rsym->reserved() & X86Relocator::ReservePLT),
- false)) {
+ if (pParent.getTarget()
+ .symbolNeedsDynRel(
+ *rsym, (rsym->reserved() & X86Relocator::ReservePLT), false)) {
return Relocator::Overflow;
}
}
- // perform static relocation
+ // perform static relocation
pReloc.target() = S + A - P;
return Relocator::OK;
}
-Relocator::Result unsupport(Relocation& pReloc, X86_64Relocator& pParent)
-{
- return Relocator::Unsupport;
+Relocator::Result unsupported(Relocation& pReloc, X86_64Relocator& pParent) {
+ return Relocator::Unsupported;
}
+
+} // namespace mcld
diff --git a/lib/Target/X86/X86Relocator.h b/lib/Target/X86/X86Relocator.h
index 84170fe..77ce188 100644
--- a/lib/Target/X86/X86Relocator.h
+++ b/lib/Target/X86/X86Relocator.h
@@ -6,27 +6,26 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86RELOCATOR_H
-#define TARGET_X86_X86RELOCATOR_H
+#ifndef TARGET_X86_X86RELOCATOR_H_
+#define TARGET_X86_X86RELOCATOR_H_
-#include <mcld/LD/Relocator.h>
-#include <mcld/Target/GOT.h>
-#include <mcld/Target/PLT.h>
-#include <mcld/Target/KeyEntryMap.h>
+#include "mcld/LD/Relocator.h"
+#include "mcld/Target/GOT.h"
+#include "mcld/Target/PLT.h"
+#include "mcld/Target/KeyEntryMap.h"
#include "X86LDBackend.h"
namespace mcld {
-class ResolveInfo;
class LinkerConfig;
+class ResolveInfo;
/** \class X86Relocator
* \brief X86Relocator creates and destroys the X86 relocations.
*
*/
-class X86Relocator : public Relocator
-{
-public:
+class X86Relocator : public Relocator {
+ public:
typedef KeyEntryMap<ResolveInfo, PLTEntryBase> SymPLTMap;
/** \enum ReservedEntryType
@@ -48,10 +47,10 @@ public:
*
*/
enum ReservedEntryType {
- None = 0,
- ReserveRel = 1,
- ReserveGOT = 2,
- ReservePLT = 4,
+ None = 0,
+ ReserveRel = 1,
+ ReserveGOT = 2,
+ ReservePLT = 4,
};
/** \enum EntryValue
@@ -59,13 +58,10 @@ public:
* layout, so we mark the entry during scanRelocation and fill up the actual
* value when applying relocations.
*/
- enum EntryValue {
- Default = 0,
- SymVal = 1
- };
+ enum EntryValue { Default = 0, SymVal = 1 };
-public:
- X86Relocator(const LinkerConfig& pConfig);
+ public:
+ explicit X86Relocator(const LinkerConfig& pConfig);
~X86Relocator();
virtual Result applyRelocation(Relocation& pRelocation) = 0;
@@ -73,7 +69,7 @@ public:
virtual const char* getName(Relocation::Type pType) const = 0;
const SymPLTMap& getSymPLTMap() const { return m_SymPLTMap; }
- SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
+ SymPLTMap& getSymPLTMap() { return m_SymPLTMap; }
/// scanRelocation - determine the empty entries are needed or not and create
/// the empty entries if needed.
@@ -87,7 +83,7 @@ public:
LDSection& pSection,
Input& pInput);
-protected:
+ protected:
/// addCopyReloc - add a copy relocation into .rel.dyn for pSym
/// @param pSym - A resolved copy symbol that defined in BSS section
void addCopyReloc(ResolveInfo& pSym, X86GNULDBackend& pTarget);
@@ -99,7 +95,7 @@ protected:
const ResolveInfo& pSym,
X86GNULDBackend& pTarget);
-private:
+ private:
virtual void scanLocalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
@@ -110,7 +106,7 @@ private:
Module& pModule,
LDSection& pSection) = 0;
-private:
+ private:
SymPLTMap m_SymPLTMap;
};
@@ -118,36 +114,33 @@ private:
* \brief X86_32Relocator creates and destroys the X86-32 relocations.
*
*/
-class X86_32Relocator : public X86Relocator
-{
-public:
+class X86_32Relocator : public X86Relocator {
+ public:
typedef KeyEntryMap<ResolveInfo, X86_32GOTEntry> SymGOTMap;
typedef KeyEntryMap<ResolveInfo, X86_32GOTEntry> SymGOTPLTMap;
enum {
- R_386_TLS_OPT = 44 // mcld internal relocation type
+ R_386_TLS_OPT = 44 // mcld internal relocation type
};
-public:
+ public:
X86_32Relocator(X86_32GNULDBackend& pParent, const LinkerConfig& pConfig);
Result applyRelocation(Relocation& pRelocation);
- X86_32GNULDBackend& getTarget()
- { return m_Target; }
+ X86_32GNULDBackend& getTarget() { return m_Target; }
- const X86_32GNULDBackend& getTarget() const
- { return m_Target; }
+ const X86_32GNULDBackend& getTarget() const { return m_Target; }
const char* getName(Relocation::Type pType) const;
Size getSize(Relocation::Type pType) const;
const SymGOTMap& getSymGOTMap() const { return m_SymGOTMap; }
- SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
+ SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
const SymGOTPLTMap& getSymGOTPLTMap() const { return m_SymGOTPLTMap; }
- SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
+ SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
X86_32GOTEntry& getTLSModuleID();
@@ -155,7 +148,15 @@ public:
/// access a function pointer.
virtual bool mayHaveFunctionPointerAccess(const Relocation& pReloc) const;
-private:
+ /// getDebugStringOffset - get the offset from the relocation target. This is
+ /// used to get the debug string offset.
+ uint32_t getDebugStringOffset(Relocation& pReloc) const;
+
+ /// applyDebugStringOffset - apply the relocation target to specific offset.
+ /// This is used to set the debug string offset.
+ void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset);
+
+ private:
void scanLocalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
@@ -170,7 +171,7 @@ private:
/// convert R_386_TLS_IE to R_386_TLS_LE
void convertTLSIEtoLE(Relocation& pReloc, LDSection& pSection);
-private:
+ private:
X86_32GNULDBackend& m_Target;
SymGOTMap m_SymGOTMap;
SymGOTPLTMap m_SymGOTPLTMap;
@@ -180,42 +181,47 @@ private:
* \brief X86_64Relocator creates and destroys the X86-64 relocations.
*
*/
-class X86_64Relocator : public X86Relocator
-{
-public:
+class X86_64Relocator : public X86Relocator {
+ public:
typedef KeyEntryMap<ResolveInfo, X86_64GOTEntry> SymGOTMap;
typedef KeyEntryMap<ResolveInfo, X86_64GOTEntry> SymGOTPLTMap;
typedef KeyEntryMap<Relocation, Relocation> RelRelMap;
-public:
+ public:
X86_64Relocator(X86_64GNULDBackend& pParent, const LinkerConfig& pConfig);
Result applyRelocation(Relocation& pRelocation);
- X86_64GNULDBackend& getTarget()
- { return m_Target; }
+ X86_64GNULDBackend& getTarget() { return m_Target; }
- const X86_64GNULDBackend& getTarget() const
- { return m_Target; }
+ const X86_64GNULDBackend& getTarget() const { return m_Target; }
const char* getName(Relocation::Type pType) const;
Size getSize(Relocation::Type pType) const;
const SymGOTMap& getSymGOTMap() const { return m_SymGOTMap; }
- SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
+ SymGOTMap& getSymGOTMap() { return m_SymGOTMap; }
const SymGOTPLTMap& getSymGOTPLTMap() const { return m_SymGOTPLTMap; }
- SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
+ SymGOTPLTMap& getSymGOTPLTMap() { return m_SymGOTPLTMap; }
const RelRelMap& getRelRelMap() const { return m_RelRelMap; }
- RelRelMap& getRelRelMap() { return m_RelRelMap; }
+ RelRelMap& getRelRelMap() { return m_RelRelMap; }
/// mayHaveFunctionPointerAccess - check if the given reloc would possibly
/// access a function pointer.
virtual bool mayHaveFunctionPointerAccess(const Relocation& pReloc) const;
-private:
+ /// getDebugStringOffset - get the offset from the relocation target. This is
+ /// used to get the debug string offset.
+ uint32_t getDebugStringOffset(Relocation& pReloc) const;
+
+ /// applyDebugStringOffset - apply the relocation target to specific offset.
+ /// This is used to set the debug string offset.
+ void applyDebugStringOffset(Relocation& pReloc, uint32_t pOffset);
+
+ private:
void scanLocalReloc(Relocation& pReloc,
IRBuilder& pBuilder,
Module& pModule,
@@ -226,14 +232,13 @@ private:
Module& pModule,
LDSection& pSection);
-private:
+ private:
X86_64GNULDBackend& m_Target;
SymGOTMap m_SymGOTMap;
SymGOTPLTMap m_SymGOTPLTMap;
RelRelMap m_RelRelMap;
};
-} // namespace of mcld
-
-#endif
+} // namespace mcld
+#endif // TARGET_X86_X86RELOCATOR_H_
diff --git a/lib/Target/X86/X86TargetMachine.cpp b/lib/Target/X86/X86TargetMachine.cpp
deleted file mode 100644
index 82fea93..0000000
--- a/lib/Target/X86/X86TargetMachine.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-//===- X86TargetMachine.cpp -----------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "X86TargetMachine.h"
-
-#include "X86.h"
-#include <mcld/Support/TargetRegistry.h>
-
-extern "C" void MCLDInitializeX86LDTarget() {
- // Register createTargetMachine function pointer to mcld::Target
- mcld::RegisterTargetMachine<mcld::X86TargetMachine> X(mcld::TheX86_32Target);
- mcld::RegisterTargetMachine<mcld::X86TargetMachine> Y(mcld::TheX86_64Target);
-}
-
-using namespace mcld;
-
-//===----------------------------------------------------------------------===//
-// X86TargetMachine
-//===----------------------------------------------------------------------===//
-X86TargetMachine::X86TargetMachine(llvm::TargetMachine& pPM,
- const llvm::Target& pLLVMTarget,
- const mcld::Target& pMCLDTarget,
- const std::string& pTriple)
- : MCLDTargetMachine(pPM, pLLVMTarget, pMCLDTarget, pTriple) {
-}
-
diff --git a/lib/Target/X86/X86TargetMachine.h b/lib/Target/X86/X86TargetMachine.h
deleted file mode 100644
index c3893da..0000000
--- a/lib/Target/X86/X86TargetMachine.h
+++ /dev/null
@@ -1,28 +0,0 @@
-//===- X86TargetMachine.h -------------------------------------------------===//
-//
-// The MCLinker Project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef TARGET_X86_X86TARGETMACHINE_H
-#define TARGET_X86_X86TARGETMACHINE_H
-#include "X86.h"
-#include <mcld/CodeGen/TargetMachine.h>
-
-namespace mcld {
-
-class X86TargetMachine : public MCLDTargetMachine
-{
-public:
- X86TargetMachine(llvm::TargetMachine& pTM,
- const llvm::Target& pLLVMTarget,
- const mcld::Target& pMCLDTarget,
- const std::string& pTriple);
-};
-
-} // namespace of mcld
-
-#endif
-
diff --git a/tools/mcld/include/mcld/DynamicSectionOptions.h b/tools/mcld/include/mcld/DynamicSectionOptions.h
index 9bf70d3..67e7c40 100644
--- a/tools/mcld/include/mcld/DynamicSectionOptions.h
+++ b/tools/mcld/include/mcld/DynamicSectionOptions.h
@@ -18,23 +18,20 @@ class ZOption;
class LinkerConfig;
class LinkerScript;
-class DynamicSectionOptions
-{
-public:
+class DynamicSectionOptions {
+ public:
DynamicSectionOptions();
bool parse(LinkerConfig& pConfig, LinkerScript& pScript);
-private:
+ private:
llvm::cl::opt<std::string>& m_Entry;
llvm::cl::opt<bool>& m_Bsymbolic;
llvm::cl::opt<bool>& m_Bgroup;
llvm::cl::opt<std::string>& m_SOName;
llvm::cl::opt<llvm::cl::boolOrDefault>& m_NoUndefined;
llvm::cl::opt<llvm::cl::boolOrDefault>& m_AllowMulDefs;
- llvm::cl::list<ZOption,
- bool,
- llvm::cl::parser<ZOption> >& m_ZOptionList;
+ llvm::cl::list<ZOption, bool, llvm::cl::parser<ZOption> >& m_ZOptionList;
llvm::cl::opt<std::string>& m_Dyld;
llvm::cl::opt<bool>& m_EnableNewDTags;
@@ -42,7 +39,6 @@ private:
llvm::cl::opt<std::string>& m_Filter;
};
-} // namespace of mcld
+} // namespace of mcld
#endif
-
diff --git a/tools/mcld/include/mcld/OptimizationOptions.h b/tools/mcld/include/mcld/OptimizationOptions.h
index 5385f91..1016c87 100644
--- a/tools/mcld/include/mcld/OptimizationOptions.h
+++ b/tools/mcld/include/mcld/OptimizationOptions.h
@@ -16,14 +16,13 @@ namespace mcld {
class LinkerConfig;
-class OptimizationOptions
-{
-public:
+class OptimizationOptions {
+ public:
OptimizationOptions();
bool parse(LinkerConfig& pConfig);
-private:
+ private:
bool& m_GCSections;
bool& m_PrintGCSections;
bool& m_GenUnwindInfo;
@@ -35,7 +34,6 @@ private:
llvm::cl::list<std::string>& m_PluginOpt;
};
-} // namespace of mcld
+} // namespace of mcld
#endif
-
diff --git a/tools/mcld/include/mcld/OutputFormatOptions.h b/tools/mcld/include/mcld/OutputFormatOptions.h
index c9982d5..81810eb 100644
--- a/tools/mcld/include/mcld/OutputFormatOptions.h
+++ b/tools/mcld/include/mcld/OutputFormatOptions.h
@@ -20,16 +20,15 @@ namespace mcld {
class Module;
-class OutputFormatOptions
-{
-public:
+class OutputFormatOptions {
+ public:
OutputFormatOptions();
bool parse(Module& pModule, LinkerConfig& pConfig);
bool parseOutput(Module& pModule, LinkerConfig& pConfig);
-private:
+ private:
llvm::cl::opt<mcld::sys::fs::Path,
false,
llvm::cl::parser<mcld::sys::fs::Path> >& m_OutputFilename;
@@ -55,7 +54,6 @@ private:
llvm::cl::opt<bool>& m_NoWarnMismatch;
};
-} // namespace of mcld
+} // namespace of mcld
#endif
-
diff --git a/tools/mcld/include/mcld/PositionalOptions.h b/tools/mcld/include/mcld/PositionalOptions.h
index fab4850..326a2d0 100644
--- a/tools/mcld/include/mcld/PositionalOptions.h
+++ b/tools/mcld/include/mcld/PositionalOptions.h
@@ -33,21 +33,20 @@ class LinkerScript;
* in groups until there is no new undefined symbols.
* 5. Definitions of symbols. --defsym option depends on
*/
-class PositionalOptions
-{
-public:
+class PositionalOptions {
+ public:
PositionalOptions();
size_t numOfInputs() const;
bool parse(std::vector<InputAction*>& pActions,
- const LinkerConfig& pConfig,
+ LinkerConfig& pConfig,
const LinkerScript& pScript);
-private:
+ private:
size_t numOfActions() const;
-private:
+ private:
llvm::cl::list<mcld::sys::fs::Path>& m_InputObjectFiles;
llvm::cl::list<std::string>& m_LinkerScript;
llvm::cl::list<std::string>& m_NameSpecList;
@@ -62,10 +61,8 @@ private:
llvm::cl::list<bool>& m_StartGroupList;
llvm::cl::list<bool>& m_EndGroupList;
llvm::cl::list<std::string>& m_DefSymList;
-
};
-} // namespace of mcld
+} // namespace of mcld
#endif
-
diff --git a/tools/mcld/include/mcld/PreferenceOptions.h b/tools/mcld/include/mcld/PreferenceOptions.h
index abee90c..523c133 100644
--- a/tools/mcld/include/mcld/PreferenceOptions.h
+++ b/tools/mcld/include/mcld/PreferenceOptions.h
@@ -15,32 +15,26 @@ namespace mcld {
class LinkerConfig;
-class PreferenceOptions
-{
-public:
- enum Color {
- COLOR_Never,
- COLOR_Always,
- COLOR_Auto
- };
-
-public:
+class PreferenceOptions {
+ public:
+ enum Color { COLOR_Never, COLOR_Always, COLOR_Auto };
+
+ public:
PreferenceOptions();
bool parse(LinkerConfig& pConfig);
-private:
- llvm::cl::opt<bool>& m_Trace;
- llvm::cl::opt<int>& m_Verbose;
- llvm::cl::opt<bool>& m_Version;
- llvm::cl::opt<int>& m_MaxErrorNum;
- llvm::cl::opt<int>& m_MaxWarnNum;
+ private:
+ llvm::cl::opt<bool>& m_Trace;
+ llvm::cl::opt<int>& m_Verbose;
+ llvm::cl::opt<bool>& m_Version;
+ llvm::cl::opt<int>& m_MaxErrorNum;
+ llvm::cl::opt<int>& m_MaxWarnNum;
llvm::cl::opt<Color>& m_Color;
- llvm::cl::opt<bool>& m_PrintMap;
+ llvm::cl::opt<bool>& m_PrintMap;
bool& m_FatalWarnings;
};
-} // namespace of mcld
+} // namespace of mcld
#endif
-
diff --git a/tools/mcld/include/mcld/ScriptOptions.h b/tools/mcld/include/mcld/ScriptOptions.h
index 0a0768a..55e3204 100644
--- a/tools/mcld/include/mcld/ScriptOptions.h
+++ b/tools/mcld/include/mcld/ScriptOptions.h
@@ -20,14 +20,13 @@ class LinkerScript;
* positional options, such as --defsym, also can modify default link script
* is not listed here. These special options belong to Positional Options.
*/
-class ScriptOptions
-{
-public:
+class ScriptOptions {
+ public:
ScriptOptions();
bool parse(LinkerScript& pScript);
-private:
+ private:
llvm::cl::list<std::string>& m_WrapList;
llvm::cl::list<std::string>& m_PortList;
llvm::cl::list<std::string>& m_AddressMapList;
@@ -36,7 +35,6 @@ private:
llvm::cl::opt<unsigned long long>& m_TextSegAddr;
};
-} // namespace of mcld
+} // namespace of mcld
#endif
-
diff --git a/tools/mcld/include/mcld/SearchPathOptions.h b/tools/mcld/include/mcld/SearchPathOptions.h
index babdf92..ec5a956 100644
--- a/tools/mcld/include/mcld/SearchPathOptions.h
+++ b/tools/mcld/include/mcld/SearchPathOptions.h
@@ -18,33 +18,26 @@ namespace mcld {
class LinkerConfig;
class LinkerScript;
-class SearchPathOptions
-{
-public:
+class SearchPathOptions {
+ public:
SearchPathOptions();
bool parse(LinkerConfig& pConfig, LinkerScript& pScript);
-private:
+ private:
llvm::cl::opt<mcld::sys::fs::Path,
- false,
- llvm::cl::parser<mcld::sys::fs::Path> >& m_SysRoot;
- llvm::cl::list<std::string,
- bool,
- llvm::cl::SearchDirParser>& m_SearchDirList;
+ false,
+ llvm::cl::parser<mcld::sys::fs::Path> >& m_SysRoot;
+ llvm::cl::list<std::string, bool, llvm::cl::SearchDirParser>& m_SearchDirList;
llvm::cl::opt<bool>& m_NoStdlib;
- llvm::cl::list<std::string,
- bool,
- llvm::cl::SearchDirParser>& m_RuntimePath;
+ llvm::cl::list<std::string, bool, llvm::cl::SearchDirParser>& m_RuntimePath;
// not supported yet
- llvm::cl::list<std::string,
- bool,
- llvm::cl::SearchDirParser>& m_RuntimePathLink;
+ llvm::cl::list<std::string, bool, llvm::cl::SearchDirParser>&
+ m_RuntimePathLink;
llvm::cl::list<std::string>& m_Y;
};
-} // namespace of mcld
+} // namespace of mcld
#endif
-
diff --git a/tools/mcld/include/mcld/SymbolOptions.h b/tools/mcld/include/mcld/SymbolOptions.h
index 60f5e06..8e7124c 100644
--- a/tools/mcld/include/mcld/SymbolOptions.h
+++ b/tools/mcld/include/mcld/SymbolOptions.h
@@ -15,14 +15,13 @@ namespace mcld {
class LinkerConfig;
-class SymbolOptions
-{
-public:
+class SymbolOptions {
+ public:
SymbolOptions();
bool parse(LinkerConfig& pConfig);
-private:
+ private:
// not supported yet
llvm::cl::list<std::string>& m_ForceUndefined;
llvm::cl::opt<std::string>& m_VersionScript;
@@ -30,7 +29,6 @@ private:
llvm::cl::opt<bool>& m_DefineCommon;
};
-} // namespace of mcld
+} // namespace of mcld
#endif
-
diff --git a/tools/mcld/include/mcld/TargetControlOptions.h b/tools/mcld/include/mcld/TargetControlOptions.h
index a4c0ba7..5f6a187 100644
--- a/tools/mcld/include/mcld/TargetControlOptions.h
+++ b/tools/mcld/include/mcld/TargetControlOptions.h
@@ -14,14 +14,13 @@ namespace mcld {
class LinkerConfig;
-class TargetControlOptions
-{
-public:
+class TargetControlOptions {
+ public:
TargetControlOptions();
bool parse(LinkerConfig& pConfig);
-private:
+ private:
llvm::cl::opt<int>& m_GPSize;
llvm::cl::opt<bool>& m_WarnSharedTextrel;
llvm::cl::opt<bool>& m_FIXCA8;
@@ -30,7 +29,6 @@ private:
llvm::cl::opt<bool>& m_SVR4Compatibility;
};
-} // namespace of mcld
+} // namespace of mcld
#endif
-
diff --git a/tools/mcld/include/mcld/TripleOptions.h b/tools/mcld/include/mcld/TripleOptions.h
index b561597..1149d9a 100644
--- a/tools/mcld/include/mcld/TripleOptions.h
+++ b/tools/mcld/include/mcld/TripleOptions.h
@@ -15,22 +15,20 @@ namespace mcld {
class LinkerConfig;
-class TripleOptions
-{
-public:
+class TripleOptions {
+ public:
TripleOptions();
bool parse(int pArgc, char* pArgv[], LinkerConfig& pConfig);
-private:
- llvm::cl::opt<std::string>& m_TargetTriple;
- llvm::cl::opt<std::string>& m_MArch;
- llvm::cl::opt<std::string>& m_MCPU;
+ private:
+ llvm::cl::opt<std::string>& m_TargetTriple;
+ llvm::cl::opt<std::string>& m_MArch;
+ llvm::cl::opt<std::string>& m_MCPU;
llvm::cl::list<std::string>& m_MAttrs;
- llvm::cl::opt<std::string>& m_Emulation;
+ llvm::cl::opt<std::string>& m_Emulation;
};
-} // namespace of mcld
+} // namespace of mcld
#endif
-
diff --git a/tools/mcld/lib/DynamicSectionOptions.cpp b/tools/mcld/lib/DynamicSectionOptions.cpp
index 5ceeaef..6bd8ccd 100644
--- a/tools/mcld/lib/DynamicSectionOptions.cpp
+++ b/tools/mcld/lib/DynamicSectionOptions.cpp
@@ -13,73 +13,82 @@
namespace {
-llvm::cl::opt<std::string> ArgEntry("e",
- llvm::cl::desc("Use the explicit symbol as the entrance of your program."),
- llvm::cl::value_desc("entry"),
- llvm::cl::ValueRequired);
+llvm::cl::opt<std::string> ArgEntry(
+ "e",
+ llvm::cl::desc("Use the explicit symbol as the entrance of your program."),
+ llvm::cl::value_desc("entry"),
+ llvm::cl::ValueRequired);
llvm::cl::alias ArgEntryAlias("entry",
- llvm::cl::desc("alias for -e"),
- llvm::cl::aliasopt(ArgEntry));
-
-llvm::cl::opt<bool> ArgBsymbolic("Bsymbolic",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Bind references within the shared library."),
- llvm::cl::init(false));
-
-llvm::cl::opt<bool> ArgBgroup("Bgroup",
- llvm::cl::desc("Info the dynamic linker to lookups only inside the group."),
- llvm::cl::init(false));
-
-llvm::cl::opt<std::string> ArgSOName("soname",
- llvm::cl::desc("Set internal name of shared library"),
- llvm::cl::value_desc("name"));
-
-llvm::cl::opt<llvm::cl::boolOrDefault> ArgNoUndefined("no-undefined",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Do not allow unresolved references"));
-
-llvm::cl::opt<llvm::cl::boolOrDefault> ArgAllowMulDefs("allow-multiple-definition",
- llvm::cl::desc("Allow multiple definition"));
-
-llvm::cl::list<mcld::ZOption,
- bool,
- llvm::cl::parser<mcld::ZOption> > ArgZOptionList("z",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("The -z options for GNU ld compatibility."),
- llvm::cl::value_desc("keyword"),
- llvm::cl::Prefix);
-
-llvm::cl::opt<std::string> ArgDyld("dynamic-linker",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Set the name of the dynamic linker."),
- llvm::cl::value_desc("Program"));
-
-llvm::cl::opt<bool> ArgEnableNewDTags("enable-new-dtags",
- llvm::cl::desc("Enable use of DT_RUNPATH and DT_FLAGS"),
- llvm::cl::init(false));
+ llvm::cl::desc("alias for -e"),
+ llvm::cl::aliasopt(ArgEntry));
+
+llvm::cl::opt<bool> ArgBsymbolic(
+ "Bsymbolic",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Bind references within the shared library."),
+ llvm::cl::init(false));
+
+llvm::cl::opt<bool> ArgBgroup(
+ "Bgroup",
+ llvm::cl::desc("Info the dynamic linker to lookups only inside the group."),
+ llvm::cl::init(false));
+
+llvm::cl::opt<std::string> ArgSOName(
+ "soname",
+ llvm::cl::desc("Set internal name of shared library"),
+ llvm::cl::value_desc("name"));
+
+llvm::cl::opt<llvm::cl::boolOrDefault> ArgNoUndefined(
+ "no-undefined",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Do not allow unresolved references"));
+
+llvm::cl::opt<llvm::cl::boolOrDefault> ArgAllowMulDefs(
+ "allow-multiple-definition",
+ llvm::cl::desc("Allow multiple definition"));
+
+llvm::cl::list<mcld::ZOption, bool, llvm::cl::parser<mcld::ZOption> >
+ ArgZOptionList("z",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("The -z options for GNU ld compatibility."),
+ llvm::cl::value_desc("keyword"),
+ llvm::cl::Prefix);
+
+llvm::cl::opt<std::string> ArgDyld(
+ "dynamic-linker",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Set the name of the dynamic linker."),
+ llvm::cl::value_desc("Program"));
+
+llvm::cl::opt<bool> ArgEnableNewDTags(
+ "enable-new-dtags",
+ llvm::cl::desc("Enable use of DT_RUNPATH and DT_FLAGS"),
+ llvm::cl::init(false));
// Not supported yet {
-llvm::cl::list<std::string> ArgAuxiliary("f",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Auxiliary filter for shared object symbol table"),
- llvm::cl::value_desc("name"));
+llvm::cl::list<std::string> ArgAuxiliary(
+ "f",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Auxiliary filter for shared object symbol table"),
+ llvm::cl::value_desc("name"));
llvm::cl::alias ArgAuxiliaryAlias("auxiliary",
- llvm::cl::desc("alias for -f"),
- llvm::cl::aliasopt(ArgAuxiliary));
+ llvm::cl::desc("alias for -f"),
+ llvm::cl::aliasopt(ArgAuxiliary));
-llvm::cl::opt<std::string> ArgFilter("F",
- llvm::cl::desc("Filter for shared object symbol table"),
- llvm::cl::value_desc("name"));
+llvm::cl::opt<std::string> ArgFilter(
+ "F",
+ llvm::cl::desc("Filter for shared object symbol table"),
+ llvm::cl::value_desc("name"));
llvm::cl::alias ArgFilterAlias("filter",
- llvm::cl::desc("alias for -F"),
- llvm::cl::aliasopt(ArgFilter));
+ llvm::cl::desc("alias for -F"),
+ llvm::cl::aliasopt(ArgFilter));
// } Not supported yet
-} // anonymous namespace
+} // anonymous namespace
using namespace mcld;
@@ -87,21 +96,21 @@ using namespace mcld;
// DynamicSectionOptions
//===----------------------------------------------------------------------===//
DynamicSectionOptions::DynamicSectionOptions()
- : m_Entry(ArgEntry),
- m_Bsymbolic(ArgBsymbolic),
- m_Bgroup(ArgBgroup),
- m_SOName(ArgSOName),
- m_NoUndefined(ArgNoUndefined),
- m_AllowMulDefs(ArgAllowMulDefs),
- m_ZOptionList(ArgZOptionList),
- m_Dyld(ArgDyld),
- m_EnableNewDTags(ArgEnableNewDTags),
- m_Auxiliary(ArgAuxiliary),
- m_Filter(ArgFilter) {
+ : m_Entry(ArgEntry),
+ m_Bsymbolic(ArgBsymbolic),
+ m_Bgroup(ArgBgroup),
+ m_SOName(ArgSOName),
+ m_NoUndefined(ArgNoUndefined),
+ m_AllowMulDefs(ArgAllowMulDefs),
+ m_ZOptionList(ArgZOptionList),
+ m_Dyld(ArgDyld),
+ m_EnableNewDTags(ArgEnableNewDTags),
+ m_Auxiliary(ArgAuxiliary),
+ m_Filter(ArgFilter) {
}
-bool DynamicSectionOptions::parse(LinkerConfig& pConfig, LinkerScript& pScript)
-{
+bool DynamicSectionOptions::parse(LinkerConfig& pConfig,
+ LinkerScript& pScript) {
// set up entry point from -e
pScript.setEntry(m_Entry);
@@ -146,4 +155,3 @@ bool DynamicSectionOptions::parse(LinkerConfig& pConfig, LinkerScript& pScript)
return true;
}
-
diff --git a/tools/mcld/lib/OptimizationOptions.cpp b/tools/mcld/lib/OptimizationOptions.cpp
index 9de70f4..b3c7f66 100644
--- a/tools/mcld/lib/OptimizationOptions.cpp
+++ b/tools/mcld/lib/OptimizationOptions.cpp
@@ -15,88 +15,103 @@ namespace {
bool ArgGCSections;
-llvm::cl::opt<bool, true> ArgGCSectionsFlag("gc-sections",
- llvm::cl::ZeroOrMore,
- llvm::cl::location(ArgGCSections),
- llvm::cl::desc("Enable garbage collection of unused input sections."),
- llvm::cl::init(false));
-
-llvm::cl::opt<bool, true, llvm::cl::FalseParser> ArgNoGCSectionsFlag("no-gc-sections",
- llvm::cl::ZeroOrMore,
- llvm::cl::location(ArgGCSections),
- llvm::cl::desc("disable garbage collection of unused input sections."),
- llvm::cl::init(false));
+llvm::cl::opt<bool, true> ArgGCSectionsFlag(
+ "gc-sections",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::location(ArgGCSections),
+ llvm::cl::desc("Enable garbage collection of unused input sections."),
+ llvm::cl::init(false));
+
+llvm::cl::opt<bool, true, llvm::cl::FalseParser> ArgNoGCSectionsFlag(
+ "no-gc-sections",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::location(ArgGCSections),
+ llvm::cl::desc("disable garbage collection of unused input sections."),
+ llvm::cl::init(false));
bool ArgPrintGCSections;
-llvm::cl::opt<bool, true> ArgPrintGCSectionsFlag("print-gc-sections",
- llvm::cl::ZeroOrMore,
- llvm::cl::location(ArgPrintGCSections),
- llvm::cl::desc("List all sections removed by garbage collection."),
- llvm::cl::init(false));
+llvm::cl::opt<bool, true> ArgPrintGCSectionsFlag(
+ "print-gc-sections",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::location(ArgPrintGCSections),
+ llvm::cl::desc("List all sections removed by garbage collection."),
+ llvm::cl::init(false));
-llvm::cl::opt<bool, true, llvm::cl::FalseParser> ArgNoPrintGCSectionsFlag("no-print-gc-sections",
- llvm::cl::ZeroOrMore,
- llvm::cl::location(ArgPrintGCSections),
- llvm::cl::desc("disable --print-gc-sections"),
- llvm::cl::init(false));
+llvm::cl::opt<bool, true, llvm::cl::FalseParser> ArgNoPrintGCSectionsFlag(
+ "no-print-gc-sections",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::location(ArgPrintGCSections),
+ llvm::cl::desc("disable --print-gc-sections"),
+ llvm::cl::init(false));
bool ArgGenUnwindInfo;
-llvm::cl::opt<bool, true, llvm::cl::FalseParser>
-ArgNoGenUnwindInfoFlag("no-ld-generated-unwind-info",
- llvm::cl::ZeroOrMore,
- llvm::cl::location(ArgGenUnwindInfo),
- llvm::cl::desc("Don't create unwind info for linker"
- " generated sections to save size"),
- llvm::cl::init(false),
- llvm::cl::ValueDisallowed);
-llvm::cl::opt<bool, true>
-ArgGenUnwindInfoFlag("ld-generated-unwind-info",
- llvm::cl::ZeroOrMore,
- llvm::cl::location(ArgGenUnwindInfo),
- llvm::cl::desc("Request creation of unwind info for linker"
- " generated code sections like PLT."),
- llvm::cl::init(true),
- llvm::cl::ValueDisallowed);
-
-llvm::cl::opt<mcld::GeneralOptions::ICF> ArgICF("icf",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Identical Code Folding"),
- llvm::cl::init(mcld::GeneralOptions::ICF_None),
- llvm::cl::values(
- clEnumValN(mcld::GeneralOptions::ICF_None, "none",
- "do not perform cold folding"),
- clEnumValN(mcld::GeneralOptions::ICF_All, "all",
- "always preform cold folding"),
- clEnumValN(mcld::GeneralOptions::ICF_Safe, "safe",
- "Folds those whose pointers are definitely not taken."),
- clEnumValEnd));
-
-llvm::cl::opt<unsigned> ArgICFIterations("icf-iterations",
- llvm::cl::desc("Number of iterations to do ICF."),
- llvm::cl::init(2));
-
-llvm::cl::opt<bool> ArgPrintICFSections("print-icf-sections",
- llvm::cl::desc("Print the folded identical sections."),
- llvm::cl::init(false));
-
-llvm::cl::opt<char> ArgOptLevel("O",
- llvm::cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] "
- "(default = '-O2')"),
- llvm::cl::Prefix,
- llvm::cl::ZeroOrMore,
- llvm::cl::init(' '));
+llvm::cl::opt<bool, true, llvm::cl::FalseParser> ArgNoGenUnwindInfoFlag(
+ "no-ld-generated-unwind-info",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::location(ArgGenUnwindInfo),
+ llvm::cl::desc(
+ "Don't create unwind info for linker"
+ " generated sections to save size"),
+ llvm::cl::init(false),
+ llvm::cl::ValueDisallowed);
+llvm::cl::opt<bool, true> ArgGenUnwindInfoFlag(
+ "ld-generated-unwind-info",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::location(ArgGenUnwindInfo),
+ llvm::cl::desc(
+ "Request creation of unwind info for linker"
+ " generated code sections like PLT."),
+ llvm::cl::init(true),
+ llvm::cl::ValueDisallowed);
+
+llvm::cl::opt<mcld::GeneralOptions::ICF> ArgICF(
+ "icf",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Identical Code Folding"),
+ llvm::cl::init(mcld::GeneralOptions::ICF_None),
+ llvm::cl::values(
+ clEnumValN(mcld::GeneralOptions::ICF_None,
+ "none",
+ "do not perform cold folding"),
+ clEnumValN(mcld::GeneralOptions::ICF_All,
+ "all",
+ "always preform cold folding"),
+ clEnumValN(mcld::GeneralOptions::ICF_Safe,
+ "safe",
+ "Folds those whose pointers are definitely not taken."),
+ clEnumValEnd));
+
+llvm::cl::opt<unsigned> ArgICFIterations(
+ "icf-iterations",
+ llvm::cl::desc("Number of iterations to do ICF."),
+ llvm::cl::init(2));
+
+llvm::cl::opt<bool> ArgPrintICFSections(
+ "print-icf-sections",
+ llvm::cl::desc("Print the folded identical sections."),
+ llvm::cl::init(false));
+
+llvm::cl::opt<char> ArgOptLevel(
+ "O",
+ llvm::cl::desc(
+ "Optimization level. [-O0, -O1, -O2, or -O3] "
+ "(default = '-O2')"),
+ llvm::cl::Prefix,
+ llvm::cl::ZeroOrMore,
+ llvm::cl::init(' '));
llvm::cl::list<std::string> ArgPlugin("plugin",
- llvm::cl::desc("Load a plugin library."),
- llvm::cl::value_desc("plugin"));
+ llvm::cl::desc("Load a plugin library."),
+ llvm::cl::value_desc("plugin"));
-llvm::cl::list<std::string> ArgPluginOpt("plugin-opt",
- llvm::cl::desc("Pass an option to the plugin."),
- llvm::cl::value_desc("option"));
+llvm::cl::list<std::string> ArgPluginOpt(
+ "plugin-opt",
+ llvm::cl::desc("Pass an option to the plugin."),
+ llvm::cl::value_desc("option"));
-} // anonymous namespace
+} // anonymous namespace
using namespace mcld;
@@ -104,19 +119,18 @@ using namespace mcld;
// OptimizationOptions
//===----------------------------------------------------------------------===//
OptimizationOptions::OptimizationOptions()
- : m_GCSections(ArgGCSections),
- m_PrintGCSections(ArgPrintGCSections),
- m_GenUnwindInfo(ArgGenUnwindInfo),
- m_ICF(ArgICF),
- m_ICFIterations(ArgICFIterations),
- m_PrintICFSections(ArgPrintICFSections),
- m_OptLevel(ArgOptLevel),
- m_Plugin(ArgPlugin),
- m_PluginOpt(ArgPluginOpt) {
+ : m_GCSections(ArgGCSections),
+ m_PrintGCSections(ArgPrintGCSections),
+ m_GenUnwindInfo(ArgGenUnwindInfo),
+ m_ICF(ArgICF),
+ m_ICFIterations(ArgICFIterations),
+ m_PrintICFSections(ArgPrintICFSections),
+ m_OptLevel(ArgOptLevel),
+ m_Plugin(ArgPlugin),
+ m_PluginOpt(ArgPluginOpt) {
}
-bool OptimizationOptions::parse(LinkerConfig& pConfig)
-{
+bool OptimizationOptions::parse(LinkerConfig& pConfig) {
// set --gc-sections
if (m_GCSections)
pConfig.options().setGCSections();
diff --git a/tools/mcld/lib/OutputFormatOptions.cpp b/tools/mcld/lib/OutputFormatOptions.cpp
index 87a3638..9676268 100644
--- a/tools/mcld/lib/OutputFormatOptions.cpp
+++ b/tools/mcld/lib/OutputFormatOptions.cpp
@@ -14,166 +14,194 @@ namespace {
llvm::cl::opt<mcld::sys::fs::Path,
false,
- llvm::cl::parser<mcld::sys::fs::Path> > ArgOutputFilename("o",
- llvm::cl::desc("Output filename"),
- llvm::cl::value_desc("filename"));
+ llvm::cl::parser<mcld::sys::fs::Path> >
+ ArgOutputFilename("o",
+ llvm::cl::desc("Output filename"),
+ llvm::cl::value_desc("filename"));
llvm::cl::alias AliasOutputFilename("output",
- llvm::cl::desc("alias for -o"),
- llvm::cl::aliasopt(ArgOutputFilename));
-
-llvm::cl::opt<mcld::LinkerConfig::CodeGenType> ArgFileType("filetype",
- llvm::cl::init(mcld::LinkerConfig::Exec),
- llvm::cl::desc("Choose a file type\n"
- "(not all types are supported by all targets):"),
- llvm::cl::values(
- clEnumValN(mcld::LinkerConfig::Object, "obj",
- "Emit a relocatable object ('.o') file"),
- clEnumValN(mcld::LinkerConfig::DynObj, "dso",
- "Emit an dynamic shared object ('.so') file"),
- clEnumValN(mcld::LinkerConfig::Exec, "exe",
- "Emit an executable ('.exe') file"),
- clEnumValN(mcld::LinkerConfig::Binary, "bin",
- "Emit a binary file"),
- clEnumValN(mcld::LinkerConfig::External, "null",
- "Emit nothing for performance testing"),
- clEnumValEnd));
-
-llvm::cl::opt<mcld::LinkerConfig::CodeGenType> ArgOFormat("oformat",
- llvm::cl::value_desc("Format"),
- llvm::cl::desc("set output format"),
- llvm::cl::init(mcld::LinkerConfig::Unknown),
- llvm::cl::values(
- clEnumValN(mcld::LinkerConfig::Binary, "binary",
- "generate binary machine code."),
- clEnumValEnd));
+ llvm::cl::desc("alias for -o"),
+ llvm::cl::aliasopt(ArgOutputFilename));
+
+llvm::cl::opt<mcld::LinkerConfig::CodeGenType> ArgFileType(
+ "filetype",
+ llvm::cl::init(mcld::LinkerConfig::Exec),
+ llvm::cl::desc(
+ "Choose a file type\n"
+ "(not all types are supported by all targets):"),
+ llvm::cl::values(
+ clEnumValN(mcld::LinkerConfig::Object,
+ "obj",
+ "Emit a relocatable object ('.o') file"),
+ clEnumValN(mcld::LinkerConfig::DynObj,
+ "dso",
+ "Emit an dynamic shared object ('.so') file"),
+ clEnumValN(mcld::LinkerConfig::Exec,
+ "exe",
+ "Emit an executable ('.exe') file"),
+ clEnumValN(mcld::LinkerConfig::Binary, "bin", "Emit a binary file"),
+ clEnumValN(mcld::LinkerConfig::External,
+ "null",
+ "Emit nothing for performance testing"),
+ clEnumValEnd));
+
+llvm::cl::opt<mcld::LinkerConfig::CodeGenType> ArgOFormat(
+ "oformat",
+ llvm::cl::value_desc("Format"),
+ llvm::cl::desc("set output format"),
+ llvm::cl::init(mcld::LinkerConfig::Unknown),
+ llvm::cl::values(clEnumValN(mcld::LinkerConfig::Binary,
+ "binary",
+ "generate binary machine code."),
+ clEnumValEnd));
llvm::cl::opt<bool> ArgShared("shared",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Create a shared library."),
- llvm::cl::init(false));
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Create a shared library."),
+ llvm::cl::init(false));
llvm::cl::alias ArgSharedAlias("Bshareable",
- llvm::cl::desc("alias for -shared"),
- llvm::cl::aliasopt(ArgShared));
+ llvm::cl::desc("alias for -shared"),
+ llvm::cl::aliasopt(ArgShared));
-llvm::cl::opt<bool> ArgPIE("pie",
- llvm::cl::desc("Emit a position-independent executable file"),
- llvm::cl::init(false));
+llvm::cl::opt<bool> ArgPIE(
+ "pie",
+ llvm::cl::desc("Emit a position-independent executable file"),
+ llvm::cl::init(false));
-llvm::cl::opt<bool> ArgRelocatable("relocatable",
- llvm::cl::desc("Generate relocatable output"),
- llvm::cl::init(false));
+llvm::cl::opt<bool> ArgRelocatable(
+ "relocatable",
+ llvm::cl::desc("Generate relocatable output"),
+ llvm::cl::init(false));
llvm::cl::alias ArgRelocatableAlias("r",
- llvm::cl::desc("alias for --relocatable"),
- llvm::cl::aliasopt(ArgRelocatable));
-
-llvm::cl::opt<mcld::Input::Type> ArgFormat("b",
- llvm::cl::value_desc("Format"),
- llvm::cl::desc("set input format"),
- llvm::cl::init(mcld::Input::Unknown),
- llvm::cl::values(
- clEnumValN(mcld::Input::Binary, "binary",
- "read in binary machine code."),
- clEnumValEnd));
+ llvm::cl::desc("alias for --relocatable"),
+ llvm::cl::aliasopt(ArgRelocatable));
+
+llvm::cl::opt<mcld::Input::Type> ArgFormat(
+ "b",
+ llvm::cl::value_desc("Format"),
+ llvm::cl::desc("set input format"),
+ llvm::cl::init(mcld::Input::Unknown),
+ llvm::cl::values(clEnumValN(mcld::Input::Binary,
+ "binary",
+ "read in binary machine code."),
+ clEnumValEnd));
llvm::cl::alias ArgFormatAlias("format",
- llvm::cl::desc("alias for -b"),
- llvm::cl::aliasopt(ArgFormat));
+ llvm::cl::desc("alias for -b"),
+ llvm::cl::aliasopt(ArgFormat));
-llvm::cl::opt<bool> ArgStripDebug("strip-debug",
- llvm::cl::desc("Omit debugger symbol information from the output file."),
- llvm::cl::init(false));
+llvm::cl::opt<bool> ArgStripDebug(
+ "strip-debug",
+ llvm::cl::desc("Omit debugger symbol information from the output file."),
+ llvm::cl::init(false));
llvm::cl::alias ArgStripDebugAlias("S",
- llvm::cl::desc("alias for --strip-debug"),
- llvm::cl::aliasopt(ArgStripDebug));
+ llvm::cl::desc("alias for --strip-debug"),
+ llvm::cl::aliasopt(ArgStripDebug));
-llvm::cl::opt<bool> ArgStripAll("strip-all",
- llvm::cl::desc("Omit all symbol information from the output file."),
- llvm::cl::init(false));
+llvm::cl::opt<bool> ArgStripAll(
+ "strip-all",
+ llvm::cl::desc("Omit all symbol information from the output file."),
+ llvm::cl::init(false));
llvm::cl::alias ArgStripAllAlias("s",
- llvm::cl::desc("alias for --strip-all"),
- llvm::cl::aliasopt(ArgStripAll));
+ llvm::cl::desc("alias for --strip-all"),
+ llvm::cl::aliasopt(ArgStripAll));
llvm::cl::opt<bool> ArgDiscardAll("discard-all",
- llvm::cl::desc("Delete all local symbols."),
- llvm::cl::init(false));
+ llvm::cl::desc("Delete all local symbols."),
+ llvm::cl::init(false));
llvm::cl::alias ArgDiscardAllAlias("x",
- llvm::cl::desc("alias for --discard-all"),
- llvm::cl::aliasopt(ArgDiscardAll));
-
-llvm::cl::opt<bool> ArgDiscardLocals("discard-locals",
- llvm::cl::desc("Delete all temporary local symbols."),
- llvm::cl::init(false));
-
-llvm::cl::alias ArgDiscardLocalsAlias("X",
- llvm::cl::desc("alias for --discard-locals"),
- llvm::cl::aliasopt(ArgDiscardLocals));
-
-llvm::cl::opt<bool> ArgEhFrameHdr("eh-frame-hdr",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Request creation of \".eh_frame_hdr\" section and\n"
- "ELF \"PT_GNU_EH_FRAME\" segment header."),
- llvm::cl::init(false));
+ llvm::cl::desc("alias for --discard-all"),
+ llvm::cl::aliasopt(ArgDiscardAll));
+
+llvm::cl::opt<bool> ArgDiscardLocals(
+ "discard-locals",
+ llvm::cl::desc("Delete all temporary local symbols."),
+ llvm::cl::init(false));
+
+llvm::cl::alias ArgDiscardLocalsAlias(
+ "X",
+ llvm::cl::desc("alias for --discard-locals"),
+ llvm::cl::aliasopt(ArgDiscardLocals));
+
+llvm::cl::opt<bool> ArgEhFrameHdr(
+ "eh-frame-hdr",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc(
+ "Request creation of \".eh_frame_hdr\" section and\n"
+ "ELF \"PT_GNU_EH_FRAME\" segment header."),
+ llvm::cl::init(false));
llvm::cl::opt<bool> ArgNMagic("nmagic",
- llvm::cl::desc("Do not page align data"),
- llvm::cl::init(false));
+ llvm::cl::desc("Do not page align data"),
+ llvm::cl::init(false));
llvm::cl::alias ArgNMagicAlias("n",
- llvm::cl::desc("alias for --nmagic"),
- llvm::cl::aliasopt(ArgNMagic));
+ llvm::cl::desc("alias for --nmagic"),
+ llvm::cl::aliasopt(ArgNMagic));
-llvm::cl::opt<bool> ArgOMagic("omagic",
- llvm::cl::desc("Do not page align data, do not make text readonly"),
- llvm::cl::init(false));
+llvm::cl::opt<bool> ArgOMagic(
+ "omagic",
+ llvm::cl::desc("Do not page align data, do not make text readonly"),
+ llvm::cl::init(false));
llvm::cl::alias ArgOMagicAlias("N",
- llvm::cl::desc("alias for --omagic"),
- llvm::cl::aliasopt(ArgOMagic));
-
-llvm::cl::opt<mcld::GeneralOptions::HashStyle> ArgHashStyle("hash-style",
- llvm::cl::init(mcld::GeneralOptions::SystemV),
- llvm::cl::desc("Set the type of linker's hash table(s)."),
- llvm::cl::values(
- clEnumValN(mcld::GeneralOptions::SystemV, "sysv",
- "classic ELF .hash section"),
- clEnumValN(mcld::GeneralOptions::GNU, "gnu",
- "new style GNU .gnu.hash section"),
- clEnumValN(mcld::GeneralOptions::Both, "both",
- "both the classic ELF and new style GNU hash tables"),
- clEnumValEnd));
-
-llvm::cl::opt<bool> ArgNoWarnMismatch("no-warn-mismatch",
- llvm::cl::desc("Allow linking together mismatched input files."),
- llvm::cl::init(false));
+ llvm::cl::desc("alias for --omagic"),
+ llvm::cl::aliasopt(ArgOMagic));
+
+llvm::cl::opt<mcld::GeneralOptions::HashStyle> ArgHashStyle(
+ "hash-style",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::init(mcld::GeneralOptions::SystemV),
+ llvm::cl::desc("Set the type of linker's hash table(s)."),
+ llvm::cl::values(
+ clEnumValN(mcld::GeneralOptions::SystemV,
+ "sysv",
+ "classic ELF .hash section"),
+ clEnumValN(mcld::GeneralOptions::GNU,
+ "gnu",
+ "new style GNU .gnu.hash section"),
+ clEnumValN(mcld::GeneralOptions::Both,
+ "both",
+ "both the classic ELF and new style GNU hash tables"),
+ clEnumValEnd));
+
+llvm::cl::opt<bool> ArgNoWarnMismatch(
+ "no-warn-mismatch",
+ llvm::cl::desc("Allow linking together mismatched input files."),
+ llvm::cl::init(false));
// Not supported yet {
-llvm::cl::opt<bool> ArgExportDynamic("export-dynamic",
- llvm::cl::desc("Export all dynamic symbols"),
- llvm::cl::init(false));
-
-llvm::cl::alias ArgExportDynamicAlias("E",
- llvm::cl::desc("alias for --export-dynamic"),
- llvm::cl::aliasopt(ArgExportDynamic));
-
-llvm::cl::opt<std::string> ArgBuildID("build-id",
- llvm::cl::desc("Request creation of \".note.gnu.build-id\" ELF note section."),
- llvm::cl::value_desc("style"),
- llvm::cl::ValueOptional);
-
-llvm::cl::list<std::string> ArgExcludeLIBS("exclude-libs",
- llvm::cl::CommaSeparated,
- llvm::cl::desc("Exclude libraries from automatic export"),
- llvm::cl::value_desc("lib1,lib2,..."));
+llvm::cl::opt<bool> ArgExportDynamic(
+ "export-dynamic",
+ llvm::cl::desc("Export all dynamic symbols"),
+ llvm::cl::init(false));
+
+llvm::cl::alias ArgExportDynamicAlias(
+ "E",
+ llvm::cl::desc("alias for --export-dynamic"),
+ llvm::cl::aliasopt(ArgExportDynamic));
+
+llvm::cl::opt<std::string> ArgBuildID(
+ "build-id",
+ llvm::cl::desc(
+ "Request creation of \".note.gnu.build-id\" ELF note section."),
+ llvm::cl::value_desc("style"),
+ llvm::cl::ValueOptional);
+
+llvm::cl::list<std::string> ArgExcludeLIBS(
+ "exclude-libs",
+ llvm::cl::CommaSeparated,
+ llvm::cl::desc("Exclude libraries from automatic export"),
+ llvm::cl::value_desc("lib1,lib2,..."));
// } Not supported yet
-} // anonymous namespace
+} // anonymous namespace
using namespace mcld;
@@ -181,29 +209,28 @@ using namespace mcld;
// OutputFormatOptions
//===----------------------------------------------------------------------===//
OutputFormatOptions::OutputFormatOptions()
- : m_OutputFilename(ArgOutputFilename),
- m_FileType(ArgFileType),
- m_OFormat(ArgOFormat),
- m_Shared(ArgShared),
- m_PIE(ArgPIE),
- m_Relocatable(ArgRelocatable),
- m_Format(ArgFormat),
- m_StripDebug(ArgStripDebug),
- m_StripAll(ArgStripAll),
- m_DiscardAll(ArgDiscardAll),
- m_DiscardLocals(ArgDiscardLocals),
- m_EhFrameHdr(ArgEhFrameHdr),
- m_NMagic(ArgNMagic),
- m_OMagic(ArgOMagic),
- m_HashStyle(ArgHashStyle),
- m_ExportDynamic(ArgExportDynamic),
- m_BuildID(ArgBuildID),
- m_ExcludeLIBS(ArgExcludeLIBS),
- m_NoWarnMismatch(ArgNoWarnMismatch) {
+ : m_OutputFilename(ArgOutputFilename),
+ m_FileType(ArgFileType),
+ m_OFormat(ArgOFormat),
+ m_Shared(ArgShared),
+ m_PIE(ArgPIE),
+ m_Relocatable(ArgRelocatable),
+ m_Format(ArgFormat),
+ m_StripDebug(ArgStripDebug),
+ m_StripAll(ArgStripAll),
+ m_DiscardAll(ArgDiscardAll),
+ m_DiscardLocals(ArgDiscardLocals),
+ m_EhFrameHdr(ArgEhFrameHdr),
+ m_NMagic(ArgNMagic),
+ m_OMagic(ArgOMagic),
+ m_HashStyle(ArgHashStyle),
+ m_ExportDynamic(ArgExportDynamic),
+ m_BuildID(ArgBuildID),
+ m_ExcludeLIBS(ArgExcludeLIBS),
+ m_NoWarnMismatch(ArgNoWarnMismatch) {
}
-bool OutputFormatOptions::parse(mcld::Module& pModule, LinkerConfig& pConfig)
-{
+bool OutputFormatOptions::parse(mcld::Module& pModule, LinkerConfig& pConfig) {
if (!parseOutput(pModule, pConfig)) {
mcld::unreachable(mcld::diag::unrecognized_output_file) << pModule.name();
return false;
@@ -231,7 +258,7 @@ bool OutputFormatOptions::parse(mcld::Module& pModule, LinkerConfig& pConfig)
// --exclude-libs
llvm::cl::list<std::string>::iterator exclude,
- excludeEnd = m_ExcludeLIBS.end();
+ excludeEnd = m_ExcludeLIBS.end();
for (exclude = m_ExcludeLIBS.begin(); exclude != excludeEnd; ++exclude) {
pConfig.options().excludeLIBS().insert(*exclude);
}
@@ -247,17 +274,14 @@ bool OutputFormatOptions::parse(mcld::Module& pModule, LinkerConfig& pConfig)
}
/// configure the output filename
-bool OutputFormatOptions::parseOutput(Module& pModule, LinkerConfig& pConfig)
-{
+bool OutputFormatOptions::parseOutput(Module& pModule, LinkerConfig& pConfig) {
if (true == m_Shared || true == m_PIE) {
// -shared or -pie
m_FileType = mcld::LinkerConfig::DynObj;
- }
- else if (true == m_Relocatable) {
+ } else if (true == m_Relocatable) {
// partial linking
m_FileType = mcld::LinkerConfig::Object;
- }
- else if (mcld::LinkerConfig::Binary == m_OFormat) {
+ } else if (mcld::LinkerConfig::Binary == m_OFormat) {
// binary output
m_FileType = mcld::LinkerConfig::Binary;
}
@@ -267,13 +291,12 @@ bool OutputFormatOptions::parseOutput(Module& pModule, LinkerConfig& pConfig)
std::string output_filename(m_OutputFilename.native());
if (m_OutputFilename.empty()) {
-
if (llvm::Triple::Win32 == pConfig.targets().triple().getOS()) {
output_filename.assign("_out");
switch (m_FileType) {
case mcld::LinkerConfig::Object: {
output_filename += ".obj";
- break;
+ break;
}
case mcld::LinkerConfig::DynObj: {
output_filename += ".dll";
@@ -289,20 +312,18 @@ bool OutputFormatOptions::parseOutput(Module& pModule, LinkerConfig& pConfig)
return false;
break;
}
- } // switch
- }
- else {
- if (mcld::LinkerConfig::Object == m_FileType ||
- mcld::LinkerConfig::DynObj == m_FileType ||
- mcld::LinkerConfig::Exec == m_FileType ||
+ } // switch
+ } else {
+ if (mcld::LinkerConfig::Object == m_FileType ||
+ mcld::LinkerConfig::DynObj == m_FileType ||
+ mcld::LinkerConfig::Exec == m_FileType ||
mcld::LinkerConfig::External == m_FileType) {
output_filename.assign("a.out");
- }
- else {
+ } else {
return false;
}
}
- } // end of if empty m_OutputFilename
+ } // end of if empty m_OutputFilename
pModule.setName(output_filename);
return true;
diff --git a/tools/mcld/lib/PositionalOptions.cpp b/tools/mcld/lib/PositionalOptions.cpp
index 471d733..43d271b 100644
--- a/tools/mcld/lib/PositionalOptions.cpp
+++ b/tools/mcld/lib/PositionalOptions.cpp
@@ -19,131 +19,151 @@ namespace {
//===----------------------------------------------------------------------===//
// Normal input files
//===----------------------------------------------------------------------===//
-llvm::cl::list<mcld::sys::fs::Path> ArgInputObjectFiles(llvm::cl::Positional,
- llvm::cl::desc("[input object files]"),
- llvm::cl::ZeroOrMore);
+llvm::cl::list<mcld::sys::fs::Path> ArgInputObjectFiles(
+ llvm::cl::Positional,
+ llvm::cl::desc("[input object files]"),
+ llvm::cl::ZeroOrMore);
// --script is an alias, but cl::alias doesn't work correctly with cl::list.
llvm::cl::list<std::string> ArgLinkerScript("T",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Linker script"),
- llvm::cl::value_desc("file"));
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Linker script"),
+ llvm::cl::value_desc("file"));
//===----------------------------------------------------------------------===//
// Namespecs
//===----------------------------------------------------------------------===//
-llvm::cl::list<std::string> ArgNameSpecList("l",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Add the archive or object file specified by namespec to\n"
- "the list of files to link."),
- llvm::cl::value_desc("namespec"),
- llvm::cl::Prefix);
+llvm::cl::list<std::string> ArgNameSpecList(
+ "l",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc(
+ "Add the archive or object file specified by namespec to\n"
+ "the list of files to link."),
+ llvm::cl::value_desc("namespec"),
+ llvm::cl::Prefix);
llvm::cl::alias ArgNameSpecListAlias("library",
- llvm::cl::desc("alias for -l"),
- llvm::cl::aliasopt(ArgNameSpecList));
+ llvm::cl::desc("alias for -l"),
+ llvm::cl::aliasopt(ArgNameSpecList));
//===----------------------------------------------------------------------===//
// Attributes
//===----------------------------------------------------------------------===//
-llvm::cl::list<bool> ArgWholeArchiveList("whole-archive",
- llvm::cl::ValueDisallowed,
- llvm::cl::desc("For each archive mentioned on the command line after\n"
- "the --whole-archive option, include all object files\n"
- "in the archive."));
-
-llvm::cl::list<bool> ArgNoWholeArchiveList("no-whole-archive",
- llvm::cl::ValueDisallowed,
- llvm::cl::desc("Turn off the effect of the --whole-archive option for\n"
- "subsequent archive files."));
-
-llvm::cl::list<bool> ArgAsNeededList("as-needed",
- llvm::cl::ValueDisallowed,
- llvm::cl::desc("This option affects ELF DT_NEEDED tags for dynamic\n"
- "libraries mentioned on the command line after the\n"
- "--as-needed option."));
-
-llvm::cl::list<bool> ArgNoAsNeededList("no-as-needed",
- llvm::cl::ValueDisallowed,
- llvm::cl::desc("Turn off the effect of the --as-needed option for\n"
- "subsequent dynamic libraries"));
-
-llvm::cl::list<bool> ArgAddNeededList("add-needed",
- llvm::cl::ValueDisallowed,
- llvm::cl::desc("--add-needed causes DT_NEEDED tags are always\n"
- "emitted for those libraries from DT_NEEDED tags.\n"
- "This is the default behavior."));
-
-llvm::cl::list<bool> ArgNoAddNeededList("no-add-needed",
- llvm::cl::ValueDisallowed,
- llvm::cl::desc("--no-add-needed causes DT_NEEDED tags will never be\n"
- "emitted for those libraries from DT_NEEDED tags"));
-
-llvm::cl::list<bool> ArgBDynamicList("Bdynamic",
- llvm::cl::ValueDisallowed,
- llvm::cl::desc("Link against dynamic library"));
+llvm::cl::list<bool> ArgWholeArchiveList(
+ "whole-archive",
+ llvm::cl::ValueDisallowed,
+ llvm::cl::desc(
+ "For each archive mentioned on the command line after\n"
+ "the --whole-archive option, include all object files\n"
+ "in the archive."));
+
+llvm::cl::list<bool> ArgNoWholeArchiveList(
+ "no-whole-archive",
+ llvm::cl::ValueDisallowed,
+ llvm::cl::desc(
+ "Turn off the effect of the --whole-archive option for\n"
+ "subsequent archive files."));
+
+llvm::cl::list<bool> ArgAsNeededList(
+ "as-needed",
+ llvm::cl::ValueDisallowed,
+ llvm::cl::desc(
+ "This option affects ELF DT_NEEDED tags for dynamic\n"
+ "libraries mentioned on the command line after the\n"
+ "--as-needed option."));
+
+llvm::cl::list<bool> ArgNoAsNeededList(
+ "no-as-needed",
+ llvm::cl::ValueDisallowed,
+ llvm::cl::desc(
+ "Turn off the effect of the --as-needed option for\n"
+ "subsequent dynamic libraries"));
+
+llvm::cl::list<bool> ArgAddNeededList(
+ "add-needed",
+ llvm::cl::ValueDisallowed,
+ llvm::cl::desc(
+ "--add-needed causes DT_NEEDED tags are always\n"
+ "emitted for those libraries from DT_NEEDED tags.\n"
+ "This is the default behavior."));
+
+llvm::cl::list<bool> ArgNoAddNeededList(
+ "no-add-needed",
+ llvm::cl::ValueDisallowed,
+ llvm::cl::desc(
+ "--no-add-needed causes DT_NEEDED tags will never be\n"
+ "emitted for those libraries from DT_NEEDED tags"));
+
+llvm::cl::list<bool> ArgBDynamicList(
+ "Bdynamic",
+ llvm::cl::ValueDisallowed,
+ llvm::cl::desc("Link against dynamic library"));
llvm::cl::alias ArgBDynamicListAlias1("dy",
- llvm::cl::desc("alias for --Bdynamic"),
- llvm::cl::aliasopt(ArgBDynamicList));
+ llvm::cl::desc("alias for --Bdynamic"),
+ llvm::cl::aliasopt(ArgBDynamicList));
llvm::cl::alias ArgBDynamicListAlias2("call_shared",
- llvm::cl::desc("alias for --Bdynamic"),
- llvm::cl::aliasopt(ArgBDynamicList));
+ llvm::cl::desc("alias for --Bdynamic"),
+ llvm::cl::aliasopt(ArgBDynamicList));
-llvm::cl::list<bool> ArgBStaticList("Bstatic",
- llvm::cl::ValueDisallowed,
- llvm::cl::desc("Link against static library"));
+llvm::cl::list<bool> ArgBStaticList(
+ "Bstatic",
+ llvm::cl::ValueDisallowed,
+ llvm::cl::desc("Link against static library"));
llvm::cl::alias ArgBStaticListAlias1("dn",
- llvm::cl::desc("alias for --Bstatic"),
- llvm::cl::aliasopt(ArgBStaticList));
+ llvm::cl::desc("alias for --Bstatic"),
+ llvm::cl::aliasopt(ArgBStaticList));
llvm::cl::alias ArgBStaticListAlias2("static",
- llvm::cl::desc("alias for --Bstatic"),
- llvm::cl::aliasopt(ArgBStaticList));
+ llvm::cl::desc("alias for --Bstatic"),
+ llvm::cl::aliasopt(ArgBStaticList));
llvm::cl::alias ArgBStaticListAlias3("non_shared",
- llvm::cl::desc("alias for --Bstatic"),
- llvm::cl::aliasopt(ArgBStaticList));
+ llvm::cl::desc("alias for --Bstatic"),
+ llvm::cl::aliasopt(ArgBStaticList));
//===----------------------------------------------------------------------===//
// Groups
//===----------------------------------------------------------------------===//
-llvm::cl::list<bool> ArgStartGroupList("start-group",
- llvm::cl::ValueDisallowed,
- llvm::cl::desc("start to record a group of archives"));
+llvm::cl::list<bool> ArgStartGroupList(
+ "start-group",
+ llvm::cl::ValueDisallowed,
+ llvm::cl::desc("start to record a group of archives"));
-llvm::cl::alias ArgStartGroupListAlias("(",
- llvm::cl::desc("alias for --start-group"),
- llvm::cl::aliasopt(ArgStartGroupList));
+llvm::cl::alias ArgStartGroupListAlias(
+ "(",
+ llvm::cl::desc("alias for --start-group"),
+ llvm::cl::aliasopt(ArgStartGroupList));
-llvm::cl::list<bool> ArgEndGroupList("end-group",
- llvm::cl::ValueDisallowed,
- llvm::cl::desc("stop recording a group of archives"));
+llvm::cl::list<bool> ArgEndGroupList(
+ "end-group",
+ llvm::cl::ValueDisallowed,
+ llvm::cl::desc("stop recording a group of archives"));
llvm::cl::alias ArgEndGroupListAlias(")",
- llvm::cl::desc("alias for --end-group"),
- llvm::cl::aliasopt(ArgEndGroupList));
+ llvm::cl::desc("alias for --end-group"),
+ llvm::cl::aliasopt(ArgEndGroupList));
//===----------------------------------------------------------------------===//
// --defsym
//===----------------------------------------------------------------------===//
-llvm::cl::list<std::string> ArgDefSymList("defsym",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Define a symbol"),
- llvm::cl::value_desc("symbol=expression"));
+llvm::cl::list<std::string> ArgDefSymList(
+ "defsym",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Define a symbol"),
+ llvm::cl::value_desc("symbol=expression"));
//===----------------------------------------------------------------------===//
// Help Functions
//===----------------------------------------------------------------------===//
-inline bool
-CompareAction(const mcld::InputAction* X, const mcld::InputAction* Y)
-{
+inline bool CompareAction(const mcld::InputAction* X,
+ const mcld::InputAction* Y) {
return (X->position() < Y->position());
}
-} // anonymous namespace
+} // anonymous namespace
using namespace mcld;
@@ -151,51 +171,40 @@ using namespace mcld;
// PositionalOptions
//===----------------------------------------------------------------------===//
PositionalOptions::PositionalOptions()
- : m_InputObjectFiles(ArgInputObjectFiles),
- m_LinkerScript(ArgLinkerScript),
- m_NameSpecList(ArgNameSpecList),
- m_WholeArchiveList(ArgWholeArchiveList),
- m_NoWholeArchiveList(ArgNoWholeArchiveList),
- m_AsNeededList(ArgAsNeededList),
- m_NoAsNeededList(ArgNoAsNeededList),
- m_AddNeededList(ArgAddNeededList),
- m_NoAddNeededList(ArgNoAddNeededList),
- m_BDynamicList(ArgBDynamicList),
- m_BStaticList(ArgBStaticList),
- m_StartGroupList(ArgStartGroupList),
- m_EndGroupList(ArgEndGroupList),
- m_DefSymList(ArgDefSymList) {
+ : m_InputObjectFiles(ArgInputObjectFiles),
+ m_LinkerScript(ArgLinkerScript),
+ m_NameSpecList(ArgNameSpecList),
+ m_WholeArchiveList(ArgWholeArchiveList),
+ m_NoWholeArchiveList(ArgNoWholeArchiveList),
+ m_AsNeededList(ArgAsNeededList),
+ m_NoAsNeededList(ArgNoAsNeededList),
+ m_AddNeededList(ArgAddNeededList),
+ m_NoAddNeededList(ArgNoAddNeededList),
+ m_BDynamicList(ArgBDynamicList),
+ m_BStaticList(ArgBStaticList),
+ m_StartGroupList(ArgStartGroupList),
+ m_EndGroupList(ArgEndGroupList),
+ m_DefSymList(ArgDefSymList) {
}
-size_t PositionalOptions::numOfActions() const
-{
- return m_InputObjectFiles.size() +
- m_LinkerScript.size() +
- m_NameSpecList.size() +
- m_WholeArchiveList.size() +
- m_NoWholeArchiveList.size() +
- m_AsNeededList.size() +
- m_NoAsNeededList.size() +
- m_AddNeededList.size() +
- m_NoAddNeededList.size() +
- m_BDynamicList.size() +
- m_BStaticList.size() +
- m_StartGroupList.size() +
- m_EndGroupList.size() +
- m_DefSymList.size();
+size_t PositionalOptions::numOfActions() const {
+ return m_InputObjectFiles.size() + m_LinkerScript.size() +
+ m_NameSpecList.size() + m_WholeArchiveList.size() +
+ m_NoWholeArchiveList.size() + m_AsNeededList.size() +
+ m_NoAsNeededList.size() + m_AddNeededList.size() +
+ m_NoAddNeededList.size() + m_BDynamicList.size() +
+ m_BStaticList.size() + m_StartGroupList.size() +
+ m_EndGroupList.size() + m_DefSymList.size();
}
-size_t PositionalOptions::numOfInputs() const
-{
- return (m_InputObjectFiles.size() +
- m_LinkerScript.size() +
+size_t PositionalOptions::numOfInputs() const {
+ return (m_InputObjectFiles.size() + m_LinkerScript.size() +
m_NameSpecList.size());
}
bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
- const LinkerConfig& pConfig,
- const LinkerScript& pScript)
-{
+ LinkerConfig& pConfig,
+ const LinkerScript& pScript) {
if (0 == numOfInputs()) {
fatal(diag::err_no_inputs);
return false;
@@ -208,10 +217,10 @@ bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
llvm::cl::list<std::string>::iterator sp;
llvm::cl::list<std::string>::iterator spEnd = m_LinkerScript.end();
for (sp = m_LinkerScript.begin(); sp != spEnd; ++sp) {
- pActions.push_back(new ScriptAction(0x0,
- *sp,
- ScriptFile::LDScript,
- pScript.directories()));
+ pConfig.options().getScriptList().push_back(*sp);
+
+ pActions.push_back(new ScriptAction(
+ 0x0, *sp, ScriptFile::LDScript, pScript.directories()));
pActions.push_back(new ContextAction(0x0));
pActions.push_back(new MemoryAreaAction(0x0, FileHandle::ReadOnly));
}
@@ -242,8 +251,8 @@ bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
nsEnd = m_NameSpecList.end();
for (namespec = nsBegin; namespec != nsEnd; ++namespec) {
unsigned int pos = m_NameSpecList.getPosition(namespec - nsBegin);
- pActions.push_back(new NamespecAction(pos, *namespec,
- pScript.directories()));
+ pActions.push_back(
+ new NamespecAction(pos, *namespec, pScript.directories()));
pActions.push_back(new ContextAction(pos));
pActions.push_back(new MemoryAreaAction(pos, FileHandle::ReadOnly));
}
@@ -251,7 +260,7 @@ bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
// set --whole-archive
llvm::cl::list<bool>::iterator attr, attrBegin, attrEnd;
attrBegin = m_WholeArchiveList.begin();
- attrEnd = m_WholeArchiveList.end();
+ attrEnd = m_WholeArchiveList.end();
for (attr = attrBegin; attr != attrEnd; ++attr) {
unsigned int pos = m_WholeArchiveList.getPosition(attr - attrBegin);
pActions.push_back(new WholeArchiveAction(pos));
@@ -259,7 +268,7 @@ bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
// set --no-whole-archive
attrBegin = m_NoWholeArchiveList.begin();
- attrEnd = m_NoWholeArchiveList.end();
+ attrEnd = m_NoWholeArchiveList.end();
for (attr = attrBegin; attr != attrEnd; ++attr) {
unsigned int pos = m_NoWholeArchiveList.getPosition(attr - attrBegin);
pActions.push_back(new NoWholeArchiveAction(pos));
@@ -267,7 +276,7 @@ bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
// set --as-needed
attrBegin = m_AsNeededList.begin();
- attrEnd = m_AsNeededList.end();
+ attrEnd = m_AsNeededList.end();
for (attr = attrBegin; attr != attrEnd; ++attr) {
unsigned int pos = m_AsNeededList.getPosition(attr - attrBegin);
pActions.push_back(new AsNeededAction(pos));
@@ -275,7 +284,7 @@ bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
// set --no-as-needed
attrBegin = m_NoAsNeededList.begin();
- attrEnd = m_NoAsNeededList.end();
+ attrEnd = m_NoAsNeededList.end();
for (attr = attrBegin; attr != attrEnd; ++attr) {
unsigned int pos = m_NoAsNeededList.getPosition(attr - attrBegin);
pActions.push_back(new NoAsNeededAction(pos));
@@ -283,7 +292,7 @@ bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
// set --add--needed
attrBegin = m_AddNeededList.begin();
- attrEnd = m_AddNeededList.end();
+ attrEnd = m_AddNeededList.end();
for (attr = attrBegin; attr != attrEnd; ++attr) {
unsigned int pos = m_AddNeededList.getPosition(attr - attrBegin);
pActions.push_back(new AddNeededAction(pos));
@@ -291,7 +300,7 @@ bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
// set --no-add--needed
attrBegin = m_NoAddNeededList.begin();
- attrEnd = m_NoAddNeededList.end();
+ attrEnd = m_NoAddNeededList.end();
for (attr = attrBegin; attr != attrEnd; ++attr) {
unsigned int pos = m_NoAddNeededList.getPosition(attr - attrBegin);
pActions.push_back(new NoAddNeededAction(pos));
@@ -299,7 +308,7 @@ bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
// set --Bdynamic
attrBegin = m_BDynamicList.begin();
- attrEnd = m_BDynamicList.end();
+ attrEnd = m_BDynamicList.end();
for (attr = attrBegin; attr != attrEnd; ++attr) {
unsigned int pos = m_BDynamicList.getPosition(attr - attrBegin);
pActions.push_back(new BDynamicAction(pos));
@@ -307,7 +316,7 @@ bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
// set --Bstatic
attrBegin = m_BStaticList.begin();
- attrEnd = m_BStaticList.end();
+ attrEnd = m_BStaticList.end();
for (attr = attrBegin; attr != attrEnd; ++attr) {
unsigned int pos = m_BStaticList.getPosition(attr - attrBegin);
pActions.push_back(new BStaticAction(pos));
@@ -316,7 +325,7 @@ bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
// set --start-group
llvm::cl::list<bool>::iterator group, gsBegin, gsEnd;
gsBegin = m_StartGroupList.begin();
- gsEnd = m_StartGroupList.end();
+ gsEnd = m_StartGroupList.end();
for (group = gsBegin; group != gsEnd; ++group) {
unsigned int pos = m_StartGroupList.getPosition(group - gsBegin);
pActions.push_back(new StartGroupAction(pos));
@@ -324,7 +333,7 @@ bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
// set --end-group
gsBegin = m_EndGroupList.begin();
- gsEnd = m_EndGroupList.end();
+ gsEnd = m_EndGroupList.end();
for (group = gsBegin; group != gsEnd; ++group) {
unsigned int pos = m_EndGroupList.getPosition(group - gsBegin);
pActions.push_back(new EndGroupAction(pos));
@@ -335,4 +344,3 @@ bool PositionalOptions::parse(std::vector<InputAction*>& pActions,
return true;
}
-
diff --git a/tools/mcld/lib/PreferenceOptions.cpp b/tools/mcld/lib/PreferenceOptions.cpp
index e5fa3df..2717af3 100644
--- a/tools/mcld/lib/PreferenceOptions.cpp
+++ b/tools/mcld/lib/PreferenceOptions.cpp
@@ -13,102 +13,120 @@
#include <llvm/Support/Process.h>
#if defined(HAVE_UNISTD_H)
-# include <unistd.h>
+#include <unistd.h>
#endif
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <io.h>
#ifndef STDIN_FILENO
-# define STDIN_FILENO 0
+#define STDIN_FILENO 0
#endif
#ifndef STDOUT_FILENO
-# define STDOUT_FILENO 1
+#define STDOUT_FILENO 1
#endif
#ifndef STDERR_FILENO
-# define STDERR_FILENO 2
+#define STDERR_FILENO 2
#endif
#endif
namespace {
-llvm::cl::opt<bool> ArgTrace("t",
- llvm::cl::desc("Print the names of the input files as ld processes them."));
+llvm::cl::opt<bool> ArgTrace(
+ "t",
+ llvm::cl::desc("Print the names of the input files as ld processes them."));
llvm::cl::alias ArgTraceAlias("trace",
- llvm::cl::desc("alias for -t"),
- llvm::cl::aliasopt(ArgTrace));
-
-llvm::cl::opt<int> ArgVerbose("verbose",
- llvm::cl::init(-1),
- llvm::cl::desc("Display the version number for ld and list the\n"
- "linker emulations supported."));
-
-llvm::cl::opt<bool> ArgVersion("V",
- llvm::cl::init(false),
- llvm::cl::desc("Display the version number for MCLinker."));
-
-llvm::cl::opt<int> ArgMaxErrorNum("error-limit",
- llvm::cl::init(-1),
- llvm::cl::desc("limits the maximum number of erros."));
-
-llvm::cl::opt<int> ArgMaxWarnNum("warning-limit",
- llvm::cl::init(-1),
- llvm::cl::desc("limits the maximum number of warnings."));
-
-llvm::cl::opt<mcld::PreferenceOptions::Color> ArgColor("color",
- llvm::cl::value_desc("When"),
- llvm::cl::desc("Surround the result strings with the marker"),
- llvm::cl::init(mcld::PreferenceOptions::COLOR_Auto),
- llvm::cl::values(
- clEnumValN(mcld::PreferenceOptions::COLOR_Never, "never",
- "do not surround result"),
- clEnumValN(mcld::PreferenceOptions::COLOR_Always, "always",
- "always surround results, even the output is a plain file"),
- clEnumValN(mcld::PreferenceOptions::COLOR_Auto, "auto",
- "surround result strings only if the output is a tty"),
- clEnumValEnd));
-
-llvm::cl::opt<bool> ArgPrintMap("M",
- llvm::cl::desc("Print a link map to the standard output."),
- llvm::cl::init(false));
+ llvm::cl::desc("alias for -t"),
+ llvm::cl::aliasopt(ArgTrace));
+
+llvm::cl::opt<int> ArgVerbose(
+ "verbose",
+ llvm::cl::init(-1),
+ llvm::cl::desc(
+ "Display the version number for ld and list the\n"
+ "linker emulations supported."));
+
+llvm::cl::opt<bool> ArgVersion(
+ "Version",
+ llvm::cl::init(false),
+ llvm::cl::desc("Display the version number for MCLinker."));
+
+llvm::cl::alias ArgVersionAlias("v",
+ llvm::cl::desc("alias for -Version"),
+ llvm::cl::aliasopt(ArgVersion));
+
+llvm::cl::opt<int> ArgMaxErrorNum(
+ "error-limit",
+ llvm::cl::init(-1),
+ llvm::cl::desc("limits the maximum number of erros."));
+
+llvm::cl::opt<int> ArgMaxWarnNum(
+ "warning-limit",
+ llvm::cl::init(-1),
+ llvm::cl::desc("limits the maximum number of warnings."));
+
+llvm::cl::opt<mcld::PreferenceOptions::Color> ArgColor(
+ "color",
+ llvm::cl::value_desc("When"),
+ llvm::cl::desc("Surround the result strings with the marker"),
+ llvm::cl::init(mcld::PreferenceOptions::COLOR_Auto),
+ llvm::cl::values(
+ clEnumValN(mcld::PreferenceOptions::COLOR_Never,
+ "never",
+ "do not surround result"),
+ clEnumValN(mcld::PreferenceOptions::COLOR_Always,
+ "always",
+ "always surround results, even the output is a plain file"),
+ clEnumValN(mcld::PreferenceOptions::COLOR_Auto,
+ "auto",
+ "surround result strings only if the output is a tty"),
+ clEnumValEnd));
+
+llvm::cl::opt<bool> ArgPrintMap(
+ "M",
+ llvm::cl::desc("Print a link map to the standard output."),
+ llvm::cl::init(false));
llvm::cl::alias ArgPrintMapAlias("print-map",
- llvm::cl::desc("alias for -M"),
- llvm::cl::aliasopt(ArgPrintMap));
+ llvm::cl::desc("alias for -M"),
+ llvm::cl::aliasopt(ArgPrintMap));
bool ArgFatalWarnings;
-llvm::cl::opt<bool, true, llvm::cl::FalseParser> ArgNoFatalWarnings("no-fatal-warnings",
- llvm::cl::location(ArgFatalWarnings),
- llvm::cl::desc("do not turn warnings into errors"),
- llvm::cl::init(false),
- llvm::cl::ValueDisallowed);
-
-llvm::cl::opt<bool, true> ArgFatalWarningsFlag("fatal-warnings",
- llvm::cl::ZeroOrMore,
- llvm::cl::location(ArgFatalWarnings),
- llvm::cl::desc("turn all warnings into errors"),
- llvm::cl::init(false),
- llvm::cl::ValueDisallowed);
-
-llvm::cl::opt<std::string> ArgUseLD("fuse-ld",
- llvm::cl::desc("Ignored for GCC/collect2 linker compatibility."),
- llvm::cl::init("mcld"));
-
-llvm::cl::opt<std::string> ArgUseMCLD("use-mcld",
- llvm::cl::desc("Ignored for GCC/collect2 linker compatibility."),
- llvm::cl::init("mcld"));
+llvm::cl::opt<bool, true, llvm::cl::FalseParser> ArgNoFatalWarnings(
+ "no-fatal-warnings",
+ llvm::cl::location(ArgFatalWarnings),
+ llvm::cl::desc("do not turn warnings into errors"),
+ llvm::cl::init(false),
+ llvm::cl::ValueDisallowed);
+
+llvm::cl::opt<bool, true> ArgFatalWarningsFlag(
+ "fatal-warnings",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::location(ArgFatalWarnings),
+ llvm::cl::desc("turn all warnings into errors"),
+ llvm::cl::init(false),
+ llvm::cl::ValueDisallowed);
+
+llvm::cl::opt<std::string> ArgUseLD(
+ "fuse-ld",
+ llvm::cl::desc("Ignored for GCC/collect2 linker compatibility."),
+ llvm::cl::init("mcld"));
+
+llvm::cl::opt<bool> ArgUseMCLD(
+ "use-mcld",
+ llvm::cl::desc("Ignored for GCC/collect2 linker compatibility."),
+ llvm::cl::init(false));
//===----------------------------------------------------------------------===//
// Non-member functions
//===----------------------------------------------------------------------===//
-inline bool ShouldColorize()
-{
- const char* term = getenv("TERM");
- return term && (0 != strcmp(term, "dumb"));
+inline bool ShouldColorize() {
+ const char* term = getenv("TERM");
+ return term && (0 != strcmp(term, "dumb"));
}
-} // anonymous namespace
+} // anonymous namespace
using namespace mcld;
@@ -116,18 +134,17 @@ using namespace mcld;
// PreferenceOptions
//===----------------------------------------------------------------------===//
PreferenceOptions::PreferenceOptions()
- : m_Trace(ArgTrace),
- m_Verbose(ArgVerbose),
- m_Version(ArgVersion),
- m_MaxErrorNum(ArgMaxErrorNum),
- m_MaxWarnNum(ArgMaxWarnNum),
- m_Color(ArgColor),
- m_PrintMap(ArgPrintMap),
- m_FatalWarnings(ArgFatalWarnings) {
+ : m_Trace(ArgTrace),
+ m_Verbose(ArgVerbose),
+ m_Version(ArgVersion),
+ m_MaxErrorNum(ArgMaxErrorNum),
+ m_MaxWarnNum(ArgMaxWarnNum),
+ m_Color(ArgColor),
+ m_PrintMap(ArgPrintMap),
+ m_FatalWarnings(ArgFatalWarnings) {
}
-bool PreferenceOptions::parse(LinkerConfig& pConfig)
-{
+bool PreferenceOptions::parse(LinkerConfig& pConfig) {
// set -t
pConfig.options().setTrace(m_Trace);
@@ -144,20 +161,23 @@ bool PreferenceOptions::parse(LinkerConfig& pConfig)
switch (m_Color) {
case COLOR_Never:
pConfig.options().setColor(false);
- break;
+ break;
case COLOR_Always:
pConfig.options().setColor(true);
- break;
+ break;
case COLOR_Auto:
- bool color_option = ShouldColorize() &&
- llvm::sys::Process::FileDescriptorIsDisplayed(STDOUT_FILENO);
+ bool color_option =
+ ShouldColorize() &&
+ llvm::sys::Process::FileDescriptorIsDisplayed(STDOUT_FILENO);
pConfig.options().setColor(color_option);
- break;
+ break;
}
mcld::outs().setColor(pConfig.options().color());
mcld::errs().setColor(pConfig.options().color());
+ if (m_Version)
+ mcld::outs() << pConfig.options().getVersionString() << "\n";
+
return true;
}
-
diff --git a/tools/mcld/lib/ScriptOptions.cpp b/tools/mcld/lib/ScriptOptions.cpp
index 611acd1..55dadab 100644
--- a/tools/mcld/lib/ScriptOptions.cpp
+++ b/tools/mcld/lib/ScriptOptions.cpp
@@ -19,46 +19,45 @@ namespace {
// options, such as --defsym, also can modify default link script is not listed
// here. These special options belong to Positional Options.
//===----------------------------------------------------------------------===//
-static llvm::cl::list<std::string>
-ArgWrapList("wrap",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Use a wrap function fo symbol."),
- llvm::cl::value_desc("symbol"));
-
-static llvm::cl::list<std::string>
-ArgPortList("portable",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Use a portable function fo symbol."),
- llvm::cl::value_desc("symbol"));
-
-static llvm::cl::list<std::string>
-ArgAddressMapList("section-start",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Locate a output section at the given absolute address"),
- llvm::cl::value_desc("Set address of section"),
- llvm::cl::Prefix);
-
-static llvm::cl::opt<unsigned long long>
-ArgBssSegAddr("Tbss",
- llvm::cl::desc("Set the address of the bss segment"),
- llvm::cl::init(-1U));
-
-static llvm::cl::opt<unsigned long long>
-ArgDataSegAddr("Tdata",
- llvm::cl::desc("Set the address of the data segment"),
- llvm::cl::init(-1U));
-
-static llvm::cl::opt<unsigned long long>
-ArgTextSegAddr("Ttext",
- llvm::cl::desc("Set the address of the text segment"),
- llvm::cl::init(-1U));
-
-static llvm::cl::alias
-ArgTextSegAddrAlias("Ttext-segment",
- llvm::cl::desc("alias for -Ttext"),
- llvm::cl::aliasopt(ArgTextSegAddr));
-
-} // anonymous namespace
+static llvm::cl::list<std::string> ArgWrapList(
+ "wrap",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Use a wrap function fo symbol."),
+ llvm::cl::value_desc("symbol"));
+
+static llvm::cl::list<std::string> ArgPortList(
+ "portable",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Use a portable function fo symbol."),
+ llvm::cl::value_desc("symbol"));
+
+static llvm::cl::list<std::string> ArgAddressMapList(
+ "section-start",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Locate a output section at the given absolute address"),
+ llvm::cl::value_desc("Set address of section"),
+ llvm::cl::Prefix);
+
+static llvm::cl::opt<unsigned long long> ArgBssSegAddr(
+ "Tbss",
+ llvm::cl::desc("Set the address of the bss segment"),
+ llvm::cl::init(-1U));
+
+static llvm::cl::opt<unsigned long long> ArgDataSegAddr(
+ "Tdata",
+ llvm::cl::desc("Set the address of the data segment"),
+ llvm::cl::init(-1U));
+
+static llvm::cl::opt<unsigned long long> ArgTextSegAddr(
+ "Ttext",
+ llvm::cl::desc("Set the address of the text segment"),
+ llvm::cl::init(-1U));
+
+static llvm::cl::alias ArgTextSegAddrAlias("Ttext-segment",
+ llvm::cl::desc("alias for -Ttext"),
+ llvm::cl::aliasopt(ArgTextSegAddr));
+
+} // anonymous namespace
using namespace mcld;
@@ -66,16 +65,15 @@ using namespace mcld;
// ScriptOptions
//===----------------------------------------------------------------------===//
ScriptOptions::ScriptOptions()
- : m_WrapList(ArgWrapList),
- m_PortList(ArgPortList),
- m_AddressMapList(ArgAddressMapList),
- m_BssSegAddr(ArgBssSegAddr),
- m_DataSegAddr(ArgDataSegAddr),
- m_TextSegAddr(ArgTextSegAddr) {
+ : m_WrapList(ArgWrapList),
+ m_PortList(ArgPortList),
+ m_AddressMapList(ArgAddressMapList),
+ m_BssSegAddr(ArgBssSegAddr),
+ m_DataSegAddr(ArgDataSegAddr),
+ m_TextSegAddr(ArgTextSegAddr) {
}
-bool ScriptOptions::parse(LinkerScript& pScript)
-{
+bool ScriptOptions::parse(LinkerScript& pScript) {
// set up rename map, for --wrap
llvm::cl::list<std::string>::iterator wname;
llvm::cl::list<std::string>::iterator wnameEnd = ArgWrapList.end();
@@ -84,7 +82,7 @@ bool ScriptOptions::parse(LinkerScript& pScript)
// add wname -> __wrap_wname
StringEntry<llvm::StringRef>* to_wrap =
- pScript.renameMap().insert(*wname, exist);
+ pScript.renameMap().insert(*wname, exist);
std::string to_wrap_str = "__wrap_" + *wname;
to_wrap->setValue(to_wrap_str);
@@ -95,7 +93,7 @@ bool ScriptOptions::parse(LinkerScript& pScript)
// add __real_wname -> wname
std::string from_real_str = "__real_" + *wname;
StringEntry<llvm::StringRef>* from_real =
- pScript.renameMap().insert(from_real_str, exist);
+ pScript.renameMap().insert(from_real_str, exist);
from_real->setValue(*wname);
if (exist)
mcld::warning(mcld::diag::rewrap) << *wname << from_real_str;
@@ -109,7 +107,7 @@ bool ScriptOptions::parse(LinkerScript& pScript)
// add pname -> pname_portable
StringEntry<llvm::StringRef>* to_port =
- pScript.renameMap().insert(*pname, exist);
+ pScript.renameMap().insert(*pname, exist);
std::string to_port_str = *pname + "_portable";
to_port->setValue(to_port_str);
@@ -120,17 +118,18 @@ bool ScriptOptions::parse(LinkerScript& pScript)
// add __real_pname -> pname
std::string from_real_str = "__real_" + *pname;
StringEntry<llvm::StringRef>* from_real =
- pScript.renameMap().insert(from_real_str, exist);
+ pScript.renameMap().insert(from_real_str, exist);
from_real->setValue(*pname);
if (exist)
warning(mcld::diag::rewrap) << *pname << from_real_str;
- } // end of for
+ } // end of for
// set --section-start SECTION=ADDRESS
- for (llvm::cl::list<std::string>::iterator
- it = ArgAddressMapList.begin(), ie = ArgAddressMapList.end();
- it != ie; ++it) {
+ for (llvm::cl::list<std::string>::iterator it = ArgAddressMapList.begin(),
+ ie = ArgAddressMapList.end();
+ it != ie;
+ ++it) {
// FIXME: Add a cl::parser
size_t pos = (*it).find_last_of('=');
llvm::StringRef script(*it);
@@ -138,7 +137,7 @@ bool ScriptOptions::parse(LinkerScript& pScript)
script.substr(pos + 1).getAsInteger(0, address);
bool exist = false;
StringEntry<uint64_t>* addr_mapping =
- pScript.addressMap().insert(script.substr(0, pos), exist);
+ pScript.addressMap().insert(script.substr(0, pos), exist);
addr_mapping->setValue(address);
}
@@ -146,7 +145,7 @@ bool ScriptOptions::parse(LinkerScript& pScript)
if (-1U != ArgBssSegAddr) {
bool exist = false;
StringEntry<uint64_t>* bss_mapping =
- pScript.addressMap().insert(".bss", exist);
+ pScript.addressMap().insert(".bss", exist);
bss_mapping->setValue(ArgBssSegAddr);
}
@@ -154,7 +153,7 @@ bool ScriptOptions::parse(LinkerScript& pScript)
if (-1U != ArgDataSegAddr) {
bool exist = false;
StringEntry<uint64_t>* data_mapping =
- pScript.addressMap().insert(".data", exist);
+ pScript.addressMap().insert(".data", exist);
data_mapping->setValue(ArgDataSegAddr);
}
@@ -162,10 +161,9 @@ bool ScriptOptions::parse(LinkerScript& pScript)
if (-1U != ArgTextSegAddr) {
bool exist = false;
StringEntry<uint64_t>* text_mapping =
- pScript.addressMap().insert(".text", exist);
+ pScript.addressMap().insert(".text", exist);
text_mapping->setValue(ArgTextSegAddr);
}
return true;
}
-
diff --git a/tools/mcld/lib/SearchPathOptions.cpp b/tools/mcld/lib/SearchPathOptions.cpp
index 378d9c3..8096b90 100644
--- a/tools/mcld/lib/SearchPathOptions.cpp
+++ b/tools/mcld/lib/SearchPathOptions.cpp
@@ -15,52 +15,53 @@ namespace {
llvm::cl::opt<mcld::sys::fs::Path,
false,
- llvm::cl::parser<mcld::sys::fs::Path> > ArgSysRoot("sysroot",
- llvm::cl::desc("Use directory as the location of the sysroot"),
- llvm::cl::value_desc("directory"),
- llvm::cl::ValueRequired);
-
-llvm::cl::list<std::string,
- bool,
- llvm::cl::SearchDirParser> ArgSearchDirList("L",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Add [searchdir] to the list of search paths"),
- llvm::cl::value_desc("searchdir"),
- llvm::cl::Prefix);
+ llvm::cl::parser<mcld::sys::fs::Path> >
+ ArgSysRoot("sysroot",
+ llvm::cl::desc("Use directory as the location of the sysroot"),
+ llvm::cl::value_desc("directory"),
+ llvm::cl::ValueRequired);
+
+llvm::cl::list<std::string, bool, llvm::cl::SearchDirParser> ArgSearchDirList(
+ "L",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Add [searchdir] to the list of search paths"),
+ llvm::cl::value_desc("searchdir"),
+ llvm::cl::Prefix);
llvm::cl::alias ArgSearchDirListAlias("library-path",
- llvm::cl::desc("alias for -L"),
- llvm::cl::aliasopt(ArgSearchDirList));
+ llvm::cl::desc("alias for -L"),
+ llvm::cl::aliasopt(ArgSearchDirList));
-llvm::cl::opt<bool> ArgNoStdlib("nostdlib",
- llvm::cl::desc("Only search lib dirs explicitly specified on cmdline"),
- llvm::cl::init(false));
+llvm::cl::opt<bool> ArgNoStdlib(
+ "nostdlib",
+ llvm::cl::desc("Only search lib dirs explicitly specified on cmdline"),
+ llvm::cl::init(false));
-llvm::cl::list<std::string,
- bool,
- llvm::cl::SearchDirParser> ArgRuntimePath("rpath",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Add a directory to the runtime library search path"),
- llvm::cl::value_desc("dir"));
+llvm::cl::list<std::string, bool, llvm::cl::SearchDirParser> ArgRuntimePath(
+ "rpath",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Add a directory to the runtime library search path"),
+ llvm::cl::value_desc("dir"));
llvm::cl::alias ArgRuntimePathAlias("R",
- llvm::cl::desc("alias for --rpath"),
- llvm::cl::aliasopt(ArgRuntimePath), llvm::cl::Prefix);
+ llvm::cl::desc("alias for --rpath"),
+ llvm::cl::aliasopt(ArgRuntimePath),
+ llvm::cl::Prefix);
// Not supported yet {
-llvm::cl::list<std::string,
- bool,
- llvm::cl::SearchDirParser> ArgRuntimePathLink("rpath-link",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Add a directory to the link time library search path"),
- llvm::cl::value_desc("dir"));
-
-llvm::cl::list<std::string> ArgY("Y",
- llvm::cl::desc("Add path to the default library search path"),
- llvm::cl::value_desc("default-search-path"));
+llvm::cl::list<std::string, bool, llvm::cl::SearchDirParser> ArgRuntimePathLink(
+ "rpath-link",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Add a directory to the link time library search path"),
+ llvm::cl::value_desc("dir"));
+
+llvm::cl::list<std::string> ArgY(
+ "Y",
+ llvm::cl::desc("Add path to the default library search path"),
+ llvm::cl::value_desc("default-search-path"));
// } Not supported yet
-} // anonymous namespace
+} // anonymous namespace
using namespace mcld;
@@ -68,16 +69,15 @@ using namespace mcld;
// SearchPathOptions
//===----------------------------------------------------------------------===//
SearchPathOptions::SearchPathOptions()
- : m_SysRoot(ArgSysRoot),
- m_SearchDirList(ArgSearchDirList),
- m_NoStdlib(ArgNoStdlib),
- m_RuntimePath(ArgRuntimePath),
- m_RuntimePathLink(ArgRuntimePathLink),
- m_Y(ArgY) {
+ : m_SysRoot(ArgSysRoot),
+ m_SearchDirList(ArgSearchDirList),
+ m_NoStdlib(ArgNoStdlib),
+ m_RuntimePath(ArgRuntimePath),
+ m_RuntimePathLink(ArgRuntimePathLink),
+ m_Y(ArgY) {
}
-bool SearchPathOptions::parse(LinkerConfig& pConfig, LinkerScript& pScript)
-{
+bool SearchPathOptions::parse(LinkerConfig& pConfig, LinkerScript& pScript) {
// set --sysroot
if (!m_SysRoot.empty()) {
if (exists(m_SysRoot) && is_directory(m_SysRoot))
@@ -90,9 +90,7 @@ bool SearchPathOptions::parse(LinkerConfig& pConfig, LinkerScript& pScript)
for (sd = m_SearchDirList.begin(); sd != sdEnd; ++sd) {
if (!pScript.directories().insert(*sd)) {
// FIXME: need a warning function
- errs() << "WARNING: can not open search directory `-L"
- << *sd
- << "'.\n";
+ errs() << "WARNING: can not open search directory `-L" << *sd << "'.\n";
}
}
@@ -108,4 +106,3 @@ bool SearchPathOptions::parse(LinkerConfig& pConfig, LinkerScript& pScript)
return true;
}
-
diff --git a/tools/mcld/lib/SymbolOptions.cpp b/tools/mcld/lib/SymbolOptions.cpp
index 4de764a..389aa12 100644
--- a/tools/mcld/lib/SymbolOptions.cpp
+++ b/tools/mcld/lib/SymbolOptions.cpp
@@ -12,42 +12,44 @@
namespace {
// Not supprted yet {
-llvm::cl::list<std::string> ArgForceUndefined("u",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Force symbol to be undefined in the output file"),
- llvm::cl::value_desc("symbol"));
+llvm::cl::list<std::string> ArgForceUndefined(
+ "u",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Force symbol to be undefined in the output file"),
+ llvm::cl::value_desc("symbol"));
llvm::cl::alias ArgForceUndefinedAlias("undefined",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("alias for -u"),
- llvm::cl::aliasopt(ArgForceUndefined));
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("alias for -u"),
+ llvm::cl::aliasopt(ArgForceUndefined));
-llvm::cl::opt<std::string> ArgVersionScript("version-script",
- llvm::cl::desc("Version script."),
- llvm::cl::value_desc("Version script"));
+llvm::cl::opt<std::string> ArgVersionScript(
+ "version-script",
+ llvm::cl::desc("Version script."),
+ llvm::cl::value_desc("Version script"));
llvm::cl::opt<bool> ArgWarnCommon("warn-common",
- llvm::cl::desc("warn common symbol"),
- llvm::cl::init(false));
+ llvm::cl::desc("warn common symbol"),
+ llvm::cl::init(false));
llvm::cl::opt<bool> ArgDefineCommon("d",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Define common symbol"),
- llvm::cl::init(false));
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Define common symbol"),
+ llvm::cl::init(false));
llvm::cl::alias ArgDefineCommonAlias1("dc",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("alias for -d"),
- llvm::cl::aliasopt(ArgDefineCommon));
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("alias for -d"),
+ llvm::cl::aliasopt(ArgDefineCommon));
llvm::cl::alias ArgDefineCommonAlias2("dp",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("alias for -d"),
- llvm::cl::aliasopt(ArgDefineCommon));
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("alias for -d"),
+ llvm::cl::aliasopt(ArgDefineCommon));
// } Not supported yet
-} // anonymous namespace
+} // anonymous namespace
using namespace mcld;
@@ -55,14 +57,13 @@ using namespace mcld;
// SymbolOptions
//===----------------------------------------------------------------------===//
SymbolOptions::SymbolOptions()
- : m_ForceUndefined(ArgForceUndefined),
- m_VersionScript(ArgVersionScript),
- m_WarnCommon(ArgWarnCommon),
- m_DefineCommon(ArgDefineCommon) {
+ : m_ForceUndefined(ArgForceUndefined),
+ m_VersionScript(ArgVersionScript),
+ m_WarnCommon(ArgWarnCommon),
+ m_DefineCommon(ArgDefineCommon) {
}
-bool SymbolOptions::parse(LinkerConfig& pConfig)
-{
+bool SymbolOptions::parse(LinkerConfig& pConfig) {
// set -d
pConfig.options().setDefineCommon(m_DefineCommon);
@@ -73,4 +74,3 @@ bool SymbolOptions::parse(LinkerConfig& pConfig)
return true;
}
-
diff --git a/tools/mcld/lib/TargetControlOptions.cpp b/tools/mcld/lib/TargetControlOptions.cpp
index ef09af3..58ef3a0 100644
--- a/tools/mcld/lib/TargetControlOptions.cpp
+++ b/tools/mcld/lib/TargetControlOptions.cpp
@@ -12,35 +12,42 @@
namespace {
-llvm::cl::opt<int> ArgGPSize("G",
- llvm::cl::desc("Set the maximum size of objects to be optimized using GP"),
- llvm::cl::init(8));
+llvm::cl::opt<int> ArgGPSize(
+ "G",
+ llvm::cl::desc("Set the maximum size of objects to be optimized using GP"),
+ llvm::cl::init(8));
-llvm::cl::opt<bool> ArgWarnSharedTextrel("warn-shared-textrel",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Warn if adding DT_TEXTREL in a shared object."),
- llvm::cl::init(false));
+llvm::cl::opt<bool> ArgWarnSharedTextrel(
+ "warn-shared-textrel",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Warn if adding DT_TEXTREL in a shared object."),
+ llvm::cl::init(false));
// Not supported yet {
-llvm::cl::opt<bool> ArgFIXCA8("fix-cortex-a8",
- llvm::cl::desc("Enable Cortex-A8 Thumb-2 branch erratum fix"),
- llvm::cl::init(false));
-
-llvm::cl::opt<bool> ArgEB("EB",
- llvm::cl::desc("Link big-endian objects. This affects the output format."),
- llvm::cl::init(false));
-
-llvm::cl::opt<bool> ArgEL("EL",
- llvm::cl::desc("Link little-endian objects. This affects the output format."),
- llvm::cl::init(false));
-
-llvm::cl::opt<bool> ArgSVR4Compatibility("Qy",
- llvm::cl::desc("This option is ignored for SVR4 compatibility"),
- llvm::cl::init(false));
+llvm::cl::opt<bool> ArgFIXCA8(
+ "fix-cortex-a8",
+ llvm::cl::desc("Enable Cortex-A8 Thumb-2 branch erratum fix"),
+ llvm::cl::init(false));
+
+llvm::cl::opt<bool> ArgEB(
+ "EB",
+ llvm::cl::desc("Link big-endian objects. This affects the output format."),
+ llvm::cl::init(false));
+
+llvm::cl::opt<bool> ArgEL(
+ "EL",
+ llvm::cl::desc(
+ "Link little-endian objects. This affects the output format."),
+ llvm::cl::init(false));
+
+llvm::cl::opt<bool> ArgSVR4Compatibility(
+ "Qy",
+ llvm::cl::desc("This option is ignored for SVR4 compatibility"),
+ llvm::cl::init(false));
// } Not supported yet
-} // anonymous namespace
+} // anonymous namespace
using namespace mcld;
@@ -48,16 +55,15 @@ using namespace mcld;
// TargetControlOptions
//===----------------------------------------------------------------------===//
TargetControlOptions::TargetControlOptions()
- : m_GPSize(ArgGPSize),
- m_WarnSharedTextrel(ArgWarnSharedTextrel),
- m_FIXCA8(ArgFIXCA8),
- m_EB(ArgEB),
- m_EL(ArgEL),
- m_SVR4Compatibility(ArgSVR4Compatibility) {
+ : m_GPSize(ArgGPSize),
+ m_WarnSharedTextrel(ArgWarnSharedTextrel),
+ m_FIXCA8(ArgFIXCA8),
+ m_EB(ArgEB),
+ m_EL(ArgEL),
+ m_SVR4Compatibility(ArgSVR4Compatibility) {
}
-bool TargetControlOptions::parse(LinkerConfig& pConfig)
-{
+bool TargetControlOptions::parse(LinkerConfig& pConfig) {
// set -G [size]
pConfig.options().setGPSize(m_GPSize);
@@ -70,4 +76,3 @@ bool TargetControlOptions::parse(LinkerConfig& pConfig)
return true;
}
-
diff --git a/tools/mcld/lib/TripleOptions.cpp b/tools/mcld/lib/TripleOptions.cpp
index 90f1bf3..c64e2bb 100644
--- a/tools/mcld/lib/TripleOptions.cpp
+++ b/tools/mcld/lib/TripleOptions.cpp
@@ -19,38 +19,39 @@
namespace {
-llvm::cl::opt<std::string> ArgTargetTriple("mtriple",
- llvm::cl::desc("Override target triple for module"));
-
-llvm::cl::opt<std::string> ArgMArch("march",
- llvm::cl::desc("Architecture to generate code for (see --version)"));
-
-llvm::cl::opt<std::string> ArgMCPU("mcpu",
- llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)"),
- llvm::cl::value_desc("cpu-name"),
- llvm::cl::init(""));
-
-llvm::cl::list<std::string> ArgMAttrs("mattr",
- llvm::cl::CommaSeparated,
- llvm::cl::desc("Target specific attributes (-mattr=help for details)"),
- llvm::cl::value_desc("a1,+a2,-a3,..."));
-
-llvm::cl::opt<std::string> ArgEmulation("m",
- llvm::cl::ZeroOrMore,
- llvm::cl::desc("Set GNU linker emulation"),
- llvm::cl::value_desc("emulation"),
- llvm::cl::Prefix);
+llvm::cl::opt<std::string> ArgTargetTriple(
+ "mtriple",
+ llvm::cl::desc("Override target triple for module"));
+
+llvm::cl::opt<std::string> ArgMArch(
+ "march",
+ llvm::cl::desc("Architecture to generate code for (see --version)"));
+
+llvm::cl::opt<std::string> ArgMCPU(
+ "mcpu",
+ llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)"),
+ llvm::cl::value_desc("cpu-name"),
+ llvm::cl::init(""));
+
+llvm::cl::list<std::string> ArgMAttrs(
+ "mattr",
+ llvm::cl::CommaSeparated,
+ llvm::cl::desc("Target specific attributes (-mattr=help for details)"),
+ llvm::cl::value_desc("a1,+a2,-a3,..."));
+
+llvm::cl::opt<std::string> ArgEmulation(
+ "m",
+ llvm::cl::ZeroOrMore,
+ llvm::cl::desc("Set GNU linker emulation"),
+ llvm::cl::value_desc("emulation"),
+ llvm::cl::Prefix);
/// ParseProgName - Parse program name
/// This function simplifies cross-compiling by reading triple from the program
/// name. For example, if the program name is `arm-linux-eabi-ld.mcld', we can
/// get the triple is arm-linux-eabi by the program name.
-inline std::string ParseProgName(const char *pProgName)
-{
- static const char *suffixes[] = {
- "ld",
- "ld.mcld"
- };
+inline std::string ParseProgName(const char* pProgName) {
+ static const char* suffixes[] = {"ld", "ld.mcld"};
std::string ProgName(mcld::sys::fs::Path(pProgName).stem().native());
@@ -66,8 +67,8 @@ inline std::string ParseProgName(const char *pProgName)
if (!ProgNameRef.endswith(suffixes[i]))
continue;
- llvm::StringRef::size_type LastComponent = ProgNameRef.rfind('-',
- ProgNameRef.size() - strlen(suffixes[i]));
+ llvm::StringRef::size_type LastComponent =
+ ProgNameRef.rfind('-', ProgNameRef.size() - strlen(suffixes[i]));
if (LastComponent == llvm::StringRef::npos)
continue;
llvm::StringRef Prefix = ProgNameRef.slice(0, LastComponent);
@@ -79,37 +80,38 @@ inline std::string ParseProgName(const char *pProgName)
return std::string();
}
-inline void
-ParseEmulation(llvm::Triple& pTriple, const std::string& pEmulation)
-{
- llvm::Triple triple = llvm::StringSwitch<llvm::Triple>(pEmulation)
- .Case("aarch64linux", llvm::Triple("aarch64", "", "linux", "gnu"))
- .Case("armelf_linux_eabi", llvm::Triple("arm", "", "linux", "gnueabi"))
- .Case("elf_i386", llvm::Triple("i386", "", "", "gnu"))
- .Case("elf_x86_64", llvm::Triple("x86_64", "", "", "gnu"))
- .Case("elf32_x86_64", llvm::Triple("x86_64", "", "", "gnux32"))
- .Case("elf_i386_fbsd", llvm::Triple("i386", "", "freebsd", "gnu"))
- .Case("elf_x86_64_fbsd", llvm::Triple("x86_64", "", "freebsd", "gnu"))
- .Case("elf32ltsmip", llvm::Triple("mipsel", "", "", "gnu"))
- .Default(llvm::Triple());
-
- if (triple.getArch() == llvm::Triple::UnknownArch &&
- triple.getOS() == llvm::Triple::UnknownOS &&
+inline void ParseEmulation(llvm::Triple& pTriple,
+ const std::string& pEmulation) {
+ llvm::Triple triple =
+ llvm::StringSwitch<llvm::Triple>(pEmulation)
+ .Case("aarch64linux", llvm::Triple("aarch64", "", "linux", "gnu"))
+ .Case("armelf_linux_eabi",
+ llvm::Triple("arm", "", "linux", "gnueabi"))
+ .Case("elf_i386", llvm::Triple("i386", "", "", "gnu"))
+ .Case("elf_x86_64", llvm::Triple("x86_64", "", "", "gnu"))
+ .Case("elf32_x86_64", llvm::Triple("x86_64", "", "", "gnux32"))
+ .Case("elf_i386_fbsd", llvm::Triple("i386", "", "freebsd", "gnu"))
+ .Case("elf_x86_64_fbsd", llvm::Triple("x86_64", "", "freebsd", "gnu"))
+ .Case("elf32ltsmip", llvm::Triple("mipsel", "", "", "gnu"))
+ .Case("elf64ltsmip", llvm::Triple("mips64el", "", "", "gnu"))
+ .Default(llvm::Triple());
+
+ if (triple.getArch() == llvm::Triple::UnknownArch &&
+ triple.getOS() == llvm::Triple::UnknownOS &&
triple.getEnvironment() == llvm::Triple::UnknownEnvironment)
mcld::error(mcld::diag::err_invalid_emulation) << pEmulation << "\n";
- if (triple.getArch() != llvm::Triple::UnknownArch)
+ if (triple.getArch() != llvm::Triple::UnknownArch)
pTriple.setArch(triple.getArch());
- if (triple.getOS() != llvm::Triple::UnknownOS)
+ if (triple.getOS() != llvm::Triple::UnknownOS)
pTriple.setOS(triple.getOS());
if (triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
pTriple.setEnvironment(triple.getEnvironment());
-
}
-} // anonymous namespace
+} // anonymous namespace
using namespace mcld;
@@ -117,27 +119,24 @@ using namespace mcld;
// TripleOptions
//===----------------------------------------------------------------------===//
TripleOptions::TripleOptions()
- : m_TargetTriple(ArgTargetTriple),
- m_MArch(ArgMArch),
- m_MCPU(ArgMCPU),
- m_MAttrs(ArgMAttrs),
- m_Emulation(ArgEmulation) {
+ : m_TargetTriple(ArgTargetTriple),
+ m_MArch(ArgMArch),
+ m_MCPU(ArgMCPU),
+ m_MAttrs(ArgMAttrs),
+ m_Emulation(ArgEmulation) {
}
-bool TripleOptions::parse(int pArgc, char* pArgv[], LinkerConfig& pConfig)
-{
+bool TripleOptions::parse(int pArgc, char* pArgv[], LinkerConfig& pConfig) {
llvm::Triple triple;
if (!m_TargetTriple.empty()) {
// 1. Use the triple from command.
triple.setTriple(m_TargetTriple);
- }
- else {
+ } else {
std::string prog_triple = ParseProgName(pArgv[0]);
if (!prog_triple.empty()) {
// 2. Use the triple from the program name prefix.
triple.setTriple(prog_triple);
- }
- else {
+ } else {
// 3. Use the default target triple.
triple.setTriple(mcld::sys::getDefaultTargetTriple());
}
@@ -163,4 +162,3 @@ bool TripleOptions::parse(int pArgc, char* pArgv[], LinkerConfig& pConfig)
pConfig.targets().setTargetFeatureString(feature_str);
return true;
}
-
diff --git a/tools/mcld/main.cpp b/tools/mcld/main.cpp
index 1717d46..68900ba 100644
--- a/tools/mcld/main.cpp
+++ b/tools/mcld/main.cpp
@@ -30,27 +30,28 @@
#include <llvm/Support/Signals.h>
#include <string>
#include <cassert>
+#include <cstdlib>
/// configure linker
-static inline bool ConfigLinker(int pArgc,
- char* pArgv[],
- const char* pName,
- mcld::Module& pModule,
- mcld::LinkerScript& pScript,
- mcld::LinkerConfig& pConfig,
- mcld::IRBuilder& pBuilder,
- std::vector<mcld::InputAction*>& pInputActions)
-{
- mcld::PreferenceOptions preference;
- mcld::TripleOptions triple;
+static inline bool ConfigLinker(
+ int pArgc,
+ char* pArgv[],
+ const char* pName,
+ mcld::Module& pModule,
+ mcld::LinkerScript& pScript,
+ mcld::LinkerConfig& pConfig,
+ mcld::IRBuilder& pBuilder,
+ std::vector<mcld::InputAction*>& pInputActions) {
+ mcld::PreferenceOptions preference;
+ mcld::TripleOptions triple;
mcld::DynamicSectionOptions dynamic_section;
- mcld::OutputFormatOptions output_format;
- mcld::SearchPathOptions search_path;
- mcld::OptimizationOptions optimization;
- mcld::SymbolOptions symbol;
- mcld::TargetControlOptions target_control;
- mcld::ScriptOptions script;
- mcld::PositionalOptions positional;
+ mcld::OutputFormatOptions output_format;
+ mcld::SearchPathOptions search_path;
+ mcld::OptimizationOptions optimization;
+ mcld::SymbolOptions symbol;
+ mcld::TargetControlOptions target_control;
+ mcld::ScriptOptions script;
+ mcld::PositionalOptions positional;
llvm::cl::ParseCommandLineOptions(pArgc, pArgv, pName);
@@ -90,12 +91,14 @@ static inline bool ConfigLinker(int pArgc,
return true;
}
-static
-inline bool InitializeInputs(mcld::IRBuilder& pBuilder,
- std::vector<mcld::InputAction*>& pInputActions)
-{
- for (std::vector<mcld::InputAction*>::iterator action = pInputActions.begin(),
- actionEnd = pInputActions.end(); action != actionEnd; ++action) {
+static inline bool InitializeInputs(
+ mcld::IRBuilder& pBuilder,
+ std::vector<mcld::InputAction*>& pInputActions) {
+ for (
+ std::vector<mcld::InputAction*>::iterator action = pInputActions.begin(),
+ actionEnd = pInputActions.end();
+ action != actionEnd;
+ ++action) {
assert(*action != NULL);
(*action)->activate(pBuilder.getInputBuilder());
delete *action;
@@ -109,8 +112,7 @@ inline bool InitializeInputs(mcld::IRBuilder& pBuilder,
return true;
}
-int main(int argc, char* argv[])
-{
+int main(int argc, char* argv[]) {
llvm::sys::PrintStackTraceOnErrorSignal();
llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
mcld::Initialize();
@@ -121,40 +123,42 @@ int main(int argc, char* argv[])
mcld::IRBuilder builder(module, config);
std::vector<mcld::InputAction*> input_actions;
- if (!ConfigLinker(argc, argv, "MCLinker\n", module, script, config, builder,
+ if (!ConfigLinker(argc,
+ argv,
+ "MCLinker\n",
+ module,
+ script,
+ config,
+ builder,
input_actions)) {
mcld::errs() << argv[0]
<< ": failed to process linker options from command line!\n";
- return 1;
+ return EXIT_FAILURE;
}
mcld::Linker linker;
if (!linker.emulate(script, config)) {
- mcld::errs() << argv[0]
- << ": failed to emulate target!\n";
- return 1;
+ mcld::errs() << argv[0] << ": failed to emulate target!\n";
+ return EXIT_FAILURE;
}
// FIXME: is it possible to have a lightweight MCLinker pass?
if (!InitializeInputs(builder, input_actions)) {
- mcld::errs() << argv[0]
- << ": failed to initialize input tree!\n";
- return 1;
+ mcld::errs() << argv[0] << ": failed to initialize input tree!\n";
+ return EXIT_FAILURE;
}
if (!linker.link(module, builder)) {
- mcld::errs() << argv[0]
- << ": failed to link objects!\n";
- return 1;
+ mcld::errs() << argv[0] << ": failed to link objects!\n";
+ return EXIT_FAILURE;
}
if (!linker.emit(module, module.name())) {
- mcld::errs() << argv[0]
- << ": failed to emit output!\n";
- return 1;
+ mcld::errs() << argv[0] << ": failed to emit output!\n";
+ return EXIT_FAILURE;
}
mcld::Finalize();
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/unittests/BinTreeTest.cpp b/unittests/BinTreeTest.cpp
index e436752..adad138 100644
--- a/unittests/BinTreeTest.cpp
+++ b/unittests/BinTreeTest.cpp
@@ -8,132 +8,121 @@
//===----------------------------------------------------------------------===//
#include "BinTreeTest.h"
-#include <mcld/ADT/TypeTraits.h>
-#include <mcld/InputTree.h>
+#include "mcld/ADT/TypeTraits.h"
+#include "mcld/InputTree.h"
#include <string>
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-BinTreeTest::BinTreeTest()
-{
- // create testee. modify it if need
- m_pTestee = new BinaryTree<int>();
+BinTreeTest::BinTreeTest() {
+ // create testee. modify it if need
+ m_pTestee = new BinaryTree<int>();
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-BinTreeTest::~BinTreeTest()
-{
- delete m_pTestee;
+BinTreeTest::~BinTreeTest() {
+ delete m_pTestee;
}
// SetUp() will be called immediately before each test.
-void BinTreeTest::SetUp()
-{
+void BinTreeTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void BinTreeTest::TearDown()
-{
+void BinTreeTest::TearDown() {
}
//==========================================================================//
// Testcases
//
-
/// General
-TEST_F( BinTreeTest,Two_non_null_tree_merge)
-{
+TEST_F(BinTreeTest, Two_non_null_tree_merge) {
BinaryTree<int>::iterator pos = m_pTestee->root();
- m_pTestee->join<TreeIteratorBase::Rightward>(pos,0);
+ m_pTestee->join<TreeIteratorBase::Rightward>(pos, 0);
--pos;
- m_pTestee->join<TreeIteratorBase::Rightward>(pos,1);
- m_pTestee->join<TreeIteratorBase::Leftward>(pos,1);
+ m_pTestee->join<TreeIteratorBase::Rightward>(pos, 1);
+ m_pTestee->join<TreeIteratorBase::Leftward>(pos, 1);
--pos;
- m_pTestee->join<TreeIteratorBase::Rightward>(pos,2);
- m_pTestee->join<TreeIteratorBase::Leftward>(pos,2);
+ m_pTestee->join<TreeIteratorBase::Rightward>(pos, 2);
+ m_pTestee->join<TreeIteratorBase::Leftward>(pos, 2);
- BinaryTree<int> *mergeTree = new BinaryTree<int>;
+ BinaryTree<int>* mergeTree = new BinaryTree<int>;
BinaryTree<int>::iterator pos2 = mergeTree->root();
- mergeTree->join<TreeIteratorBase::Rightward>(pos2,1);
+ mergeTree->join<TreeIteratorBase::Rightward>(pos2, 1);
--pos2;
- mergeTree->join<TreeIteratorBase::Rightward>(pos2,1);
- mergeTree->join<TreeIteratorBase::Leftward>(pos2,1);
+ mergeTree->join<TreeIteratorBase::Rightward>(pos2, 1);
+ mergeTree->join<TreeIteratorBase::Leftward>(pos2, 1);
- m_pTestee->merge<TreeIteratorBase::Rightward>(pos,*mergeTree);
+ m_pTestee->merge<TreeIteratorBase::Rightward>(pos, *mergeTree);
delete mergeTree;
- EXPECT_TRUE(m_pTestee->size()==8);
+ EXPECT_TRUE(m_pTestee->size() == 8);
}
/// ---- TEST - 2 ----
-TEST_F( BinTreeTest, A_null_tree_merge_a_non_null_tree)
-{
+TEST_F(BinTreeTest, A_null_tree_merge_a_non_null_tree) {
BinaryTree<int>::iterator pos = m_pTestee->root();
- BinaryTree<int> *mergeTree = new BinaryTree<int>;
- mergeTree->join<TreeIteratorBase::Rightward>(pos,0);
+ BinaryTree<int>* mergeTree = new BinaryTree<int>;
+ mergeTree->join<TreeIteratorBase::Rightward>(pos, 0);
--pos;
- mergeTree->join<TreeIteratorBase::Rightward>(pos,1);
- mergeTree->join<TreeIteratorBase::Leftward>(pos,1);
+ mergeTree->join<TreeIteratorBase::Rightward>(pos, 1);
+ mergeTree->join<TreeIteratorBase::Leftward>(pos, 1);
--pos;
- mergeTree->join<TreeIteratorBase::Rightward>(pos,2);
- mergeTree->join<TreeIteratorBase::Leftward>(pos,2);
+ mergeTree->join<TreeIteratorBase::Rightward>(pos, 2);
+ mergeTree->join<TreeIteratorBase::Leftward>(pos, 2);
- m_pTestee->merge<TreeIteratorBase::Rightward>(pos,*mergeTree);
+ m_pTestee->merge<TreeIteratorBase::Rightward>(pos, *mergeTree);
delete mergeTree;
- EXPECT_TRUE(m_pTestee->size()==5);
+ EXPECT_TRUE(m_pTestee->size() == 5);
}
-TEST_F( BinTreeTest, A_non_null_tree_merge_a_null_tree)
-{
+TEST_F(BinTreeTest, A_non_null_tree_merge_a_null_tree) {
BinaryTree<int>::iterator pos = m_pTestee->root();
- m_pTestee->join<TreeIteratorBase::Rightward>(pos,0);
+ m_pTestee->join<TreeIteratorBase::Rightward>(pos, 0);
--pos;
- m_pTestee->join<TreeIteratorBase::Rightward>(pos,1);
- m_pTestee->join<TreeIteratorBase::Leftward>(pos,1);
+ m_pTestee->join<TreeIteratorBase::Rightward>(pos, 1);
+ m_pTestee->join<TreeIteratorBase::Leftward>(pos, 1);
--pos;
- m_pTestee->join<TreeIteratorBase::Rightward>(pos,2);
- m_pTestee->join<TreeIteratorBase::Leftward>(pos,2);
+ m_pTestee->join<TreeIteratorBase::Rightward>(pos, 2);
+ m_pTestee->join<TreeIteratorBase::Leftward>(pos, 2);
- BinaryTree<int> *mergeTree = new BinaryTree<int>;
+ BinaryTree<int>* mergeTree = new BinaryTree<int>;
BinaryTree<int>::iterator pos2 = mergeTree->root();
- mergeTree->merge<TreeIteratorBase::Rightward>(pos2,*m_pTestee);
+ mergeTree->merge<TreeIteratorBase::Rightward>(pos2, *m_pTestee);
- //delete m_pTestee;
- EXPECT_TRUE(mergeTree->size()==5);
+ // delete m_pTestee;
+ EXPECT_TRUE(mergeTree->size() == 5);
delete mergeTree;
}
-TEST_F( BinTreeTest, Two_null_tree_merge)
-{
+TEST_F(BinTreeTest, Two_null_tree_merge) {
BinaryTree<int>::iterator pos = m_pTestee->root();
- BinaryTree<int> *mergeTree = new BinaryTree<int>;
+ BinaryTree<int>* mergeTree = new BinaryTree<int>;
BinaryTree<int>::iterator pos2 = mergeTree->root();
- mergeTree->merge<TreeIteratorBase::Rightward>(pos2,*m_pTestee);
+ mergeTree->merge<TreeIteratorBase::Rightward>(pos2, *m_pTestee);
- //delete m_pTestee;
- EXPECT_TRUE(mergeTree->size()==0);
+ // delete m_pTestee;
+ EXPECT_TRUE(mergeTree->size() == 0);
delete mergeTree;
}
-TEST_F( BinTreeTest, DFSIterator_BasicTraversal)
-{
+TEST_F(BinTreeTest, DFSIterator_BasicTraversal) {
int a = 111, b = 10, c = 9, d = 8, e = 7;
BinaryTree<int>::iterator pos = m_pTestee->root();
- m_pTestee->join<InputTree::Inclusive>(pos,a);
+ m_pTestee->join<InputTree::Inclusive>(pos, a);
pos.move<InputTree::Inclusive>();
- m_pTestee->join<InputTree::Positional>(pos,b);
- m_pTestee->join<InputTree::Inclusive>(pos,c);
+ m_pTestee->join<InputTree::Positional>(pos, b);
+ m_pTestee->join<InputTree::Inclusive>(pos, c);
pos.move<InputTree::Inclusive>();
- m_pTestee->join<InputTree::Positional>(pos,d);
- m_pTestee->join<InputTree::Inclusive>(pos,e);
+ m_pTestee->join<InputTree::Positional>(pos, d);
+ m_pTestee->join<InputTree::Inclusive>(pos, e);
BinaryTree<int>::dfs_iterator dfs_it = m_pTestee->dfs_begin();
BinaryTree<int>::dfs_iterator dfs_end = m_pTestee->dfs_end();
@@ -148,22 +137,21 @@ TEST_F( BinTreeTest, DFSIterator_BasicTraversal)
++dfs_it;
EXPECT_EQ(10, **dfs_it);
++dfs_it;
- EXPECT_TRUE( dfs_it == dfs_end);
+ EXPECT_TRUE(dfs_it == dfs_end);
}
-TEST_F( BinTreeTest, DFSIterator_RightMostTree)
-{
+TEST_F(BinTreeTest, DFSIterator_RightMostTree) {
int a = 0, b = 1, c = 2, d = 3, e = 4;
BinaryTree<int>::iterator pos = m_pTestee->root();
- m_pTestee->join<InputTree::Inclusive>(pos,a);
+ m_pTestee->join<InputTree::Inclusive>(pos, a);
pos.move<InputTree::Inclusive>();
- m_pTestee->join<InputTree::Positional>(pos,b);
+ m_pTestee->join<InputTree::Positional>(pos, b);
pos.move<InputTree::Positional>();
- m_pTestee->join<InputTree::Positional>(pos,c);
+ m_pTestee->join<InputTree::Positional>(pos, c);
pos.move<InputTree::Positional>();
- m_pTestee->join<InputTree::Positional>(pos,d);
+ m_pTestee->join<InputTree::Positional>(pos, d);
pos.move<InputTree::Positional>();
- m_pTestee->join<InputTree::Positional>(pos,e);
+ m_pTestee->join<InputTree::Positional>(pos, e);
BinaryTree<int>::dfs_iterator dfs_it = m_pTestee->dfs_begin();
BinaryTree<int>::dfs_iterator dfs_end = m_pTestee->dfs_end();
@@ -178,36 +166,33 @@ TEST_F( BinTreeTest, DFSIterator_RightMostTree)
++dfs_it;
ASSERT_EQ(4, **dfs_it);
++dfs_it;
- ASSERT_TRUE( dfs_it == dfs_end);
+ ASSERT_TRUE(dfs_it == dfs_end);
}
-
-TEST_F( BinTreeTest, DFSIterator_SingleNode)
-{
+TEST_F(BinTreeTest, DFSIterator_SingleNode) {
BinaryTree<int>::iterator pos = m_pTestee->root();
- m_pTestee->join<InputTree::Inclusive>(pos,0);
+ m_pTestee->join<InputTree::Inclusive>(pos, 0);
BinaryTree<int>::dfs_iterator dfs_it = m_pTestee->dfs_begin();
BinaryTree<int>::dfs_iterator dfs_end = m_pTestee->dfs_end();
int counter = 0;
- while( dfs_it != dfs_end ) {
+ while (dfs_it != dfs_end) {
++counter;
++dfs_it;
}
ASSERT_EQ(1, counter);
}
-TEST_F( BinTreeTest, BFSIterator_BasicTraversal)
-{
+TEST_F(BinTreeTest, BFSIterator_BasicTraversal) {
int a = 111, b = 10, c = 9, d = 8, e = 7;
BinaryTree<int>::iterator pos = m_pTestee->root();
- m_pTestee->join<InputTree::Inclusive>(pos,a);
+ m_pTestee->join<InputTree::Inclusive>(pos, a);
pos.move<InputTree::Inclusive>();
- m_pTestee->join<InputTree::Positional>(pos,b);
- m_pTestee->join<InputTree::Inclusive>(pos,c);
+ m_pTestee->join<InputTree::Positional>(pos, b);
+ m_pTestee->join<InputTree::Inclusive>(pos, c);
pos.move<InputTree::Inclusive>();
- m_pTestee->join<InputTree::Positional>(pos,d);
- m_pTestee->join<InputTree::Inclusive>(pos,e);
+ m_pTestee->join<InputTree::Positional>(pos, d);
+ m_pTestee->join<InputTree::Inclusive>(pos, e);
BinaryTree<int>::bfs_iterator bfs_it = m_pTestee->bfs_begin();
BinaryTree<int>::bfs_iterator bfs_end = m_pTestee->bfs_end();
@@ -222,24 +207,23 @@ TEST_F( BinTreeTest, BFSIterator_BasicTraversal)
++bfs_it;
ASSERT_EQ(7, **bfs_it);
++bfs_it;
- ASSERT_TRUE(bfs_it == bfs_end);
+ ASSERT_TRUE(bfs_it == bfs_end);
bfs_it = m_pTestee->bfs_begin();
bfs_end = m_pTestee->bfs_end();
}
-TEST_F( BinTreeTest, BFSIterator_RightMostTree)
-{
+TEST_F(BinTreeTest, BFSIterator_RightMostTree) {
int a = 0, b = 1, c = 2, d = 3, e = 4;
BinaryTree<int>::iterator pos = m_pTestee->root();
- m_pTestee->join<InputTree::Inclusive>(pos,a);
+ m_pTestee->join<InputTree::Inclusive>(pos, a);
pos.move<InputTree::Inclusive>();
- m_pTestee->join<InputTree::Positional>(pos,b);
+ m_pTestee->join<InputTree::Positional>(pos, b);
pos.move<InputTree::Positional>();
- m_pTestee->join<InputTree::Positional>(pos,c);
+ m_pTestee->join<InputTree::Positional>(pos, c);
pos.move<InputTree::Positional>();
- m_pTestee->join<InputTree::Positional>(pos,d);
+ m_pTestee->join<InputTree::Positional>(pos, d);
pos.move<InputTree::Positional>();
- m_pTestee->join<InputTree::Positional>(pos,e);
+ m_pTestee->join<InputTree::Positional>(pos, e);
BinaryTree<int>::bfs_iterator bfs_it = m_pTestee->bfs_begin();
BinaryTree<int>::bfs_iterator bfs_end = m_pTestee->bfs_end();
@@ -254,38 +238,35 @@ TEST_F( BinTreeTest, BFSIterator_RightMostTree)
++bfs_it;
ASSERT_EQ(4, **bfs_it);
++bfs_it;
- ASSERT_TRUE( bfs_it == bfs_end);
+ ASSERT_TRUE(bfs_it == bfs_end);
}
-
-TEST_F( BinTreeTest, BFSIterator_SingleNode)
-{
+TEST_F(BinTreeTest, BFSIterator_SingleNode) {
BinaryTree<int>::iterator pos = m_pTestee->root();
- m_pTestee->join<InputTree::Inclusive>(pos,0);
+ m_pTestee->join<InputTree::Inclusive>(pos, 0);
BinaryTree<int>::bfs_iterator bfs_it = m_pTestee->bfs_begin();
BinaryTree<int>::bfs_iterator bfs_end = m_pTestee->bfs_end();
int counter = 0;
- while( bfs_it != bfs_end ) {
+ while (bfs_it != bfs_end) {
++counter;
++bfs_it;
}
ASSERT_EQ(1, counter);
}
-TEST_F( BinTreeTest, TreeIterator)
-{
+TEST_F(BinTreeTest, TreeIterator) {
int a = 0, b = 1, c = 2, d = 3, e = 4, f = 5;
BinaryTree<int>::iterator pos = m_pTestee->root();
- m_pTestee->join<InputTree::Inclusive>(pos,a);
+ m_pTestee->join<InputTree::Inclusive>(pos, a);
pos.move<InputTree::Inclusive>();
- m_pTestee->join<InputTree::Positional>(pos,b);
+ m_pTestee->join<InputTree::Positional>(pos, b);
pos.move<InputTree::Positional>();
- m_pTestee->join<InputTree::Inclusive>(pos,c);
- m_pTestee->join<InputTree::Positional>(pos,f);
+ m_pTestee->join<InputTree::Inclusive>(pos, c);
+ m_pTestee->join<InputTree::Positional>(pos, f);
pos.move<InputTree::Inclusive>();
- m_pTestee->join<InputTree::Positional>(pos,d);
+ m_pTestee->join<InputTree::Positional>(pos, d);
pos.move<InputTree::Positional>();
- m_pTestee->join<InputTree::Positional>(pos,e);
+ m_pTestee->join<InputTree::Positional>(pos, e);
BinaryTree<int>::iterator it = m_pTestee->begin();
BinaryTree<int>::iterator end = m_pTestee->end();
@@ -309,4 +290,3 @@ TEST_F( BinTreeTest, TreeIterator)
++it;
ASSERT_TRUE(it == end);
}
-
diff --git a/unittests/BinTreeTest.h b/unittests/BinTreeTest.h
index 7f4a7f7..0f4b26f 100644
--- a/unittests/BinTreeTest.h
+++ b/unittests/BinTreeTest.h
@@ -13,40 +13,37 @@
#include <gtest.h>
-namespace mcld
-{
+namespace mcld {
class BinTree;
-} // namespace for mcld
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
/** \class BinTreeTest
- * \brief Make sure the interface of BinTree , such as insert , traversal , etc..
+ * \brief Make sure the interface of BinTree , such as insert , traversal ,
+ *etc..
*
* \see BinTree
*/
-class BinTreeTest : public ::testing::Test
-{
-public:
- // Constructor can do set-up work for all test here.
- BinTreeTest();
+class BinTreeTest : public ::testing::Test {
+ public:
+ // Constructor can do set-up work for all test here.
+ BinTreeTest();
- // Destructor can do clean-up work that doesn't throw exceptions here.
- virtual ~BinTreeTest();
+ // Destructor can do clean-up work that doesn't throw exceptions here.
+ virtual ~BinTreeTest();
- // SetUp() will be called immediately before each test.
- virtual void SetUp();
+ // SetUp() will be called immediately before each test.
+ virtual void SetUp();
- // TearDown() will be called immediately after each test.
- virtual void TearDown();
+ // TearDown() will be called immediately after each test.
+ virtual void TearDown();
-protected:
- mcld::BinaryTree<int>* m_pTestee;
+ protected:
+ mcld::BinaryTree<int>* m_pTestee;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/DirIteratorTest.cpp b/unittests/DirIteratorTest.cpp
index 13472ac..2684466 100644
--- a/unittests/DirIteratorTest.cpp
+++ b/unittests/DirIteratorTest.cpp
@@ -6,7 +6,7 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Directory.h>
+#include "mcld/Support/Directory.h"
#include "DirIteratorTest.h"
#include <errno.h>
@@ -14,11 +14,9 @@ using namespace mcld;
using namespace mcld::sys::fs;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-DirIteratorTest::DirIteratorTest()
-{
- //FIXME:Some bugs modifies the global value "errno" to non-zero.
+DirIteratorTest::DirIteratorTest() {
+ // FIXME:Some bugs modifies the global value "errno" to non-zero.
// This makes readir() failed when daily build system runs unittest
// Remove this after fixing those bugs
errno = 0;
@@ -28,37 +26,32 @@ DirIteratorTest::DirIteratorTest()
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-DirIteratorTest::~DirIteratorTest()
-{
+DirIteratorTest::~DirIteratorTest() {
delete m_pDir;
}
// SetUp() will be called immediately before each test.
-void DirIteratorTest::SetUp()
-{
+void DirIteratorTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void DirIteratorTest::TearDown()
-{
+void DirIteratorTest::TearDown() {
}
//==========================================================================//
// Testcases
//
-TEST_F( DirIteratorTest, open_dir ) {
- ASSERT_TRUE( m_pDir->isGood() );
+TEST_F(DirIteratorTest, open_dir) {
+ ASSERT_TRUE(m_pDir->isGood());
Directory::iterator entry = m_pDir->begin();
Directory::iterator enEnd = m_pDir->end();
size_t size = 0;
- while( entry!=enEnd ) {
+ while (entry != enEnd) {
if (0 != entry.path())
size = entry.path()->native().size();
++entry;
}
}
-
-
diff --git a/unittests/DirIteratorTest.h b/unittests/DirIteratorTest.h
index ea6aaf7..20bf208 100644
--- a/unittests/DirIteratorTest.h
+++ b/unittests/DirIteratorTest.h
@@ -18,35 +18,33 @@ class Directory;
class DirIterator;
}
}
-} // namespace for mcld
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
/** \class DirIteratorTest
* \brief
*
* \see DirIterator
*/
-class DirIteratorTest : public ::testing::Test
-{
-public:
- // Constructor can do set-up work for all test here.
- DirIteratorTest();
-
- // Destructor can do clean-up work that doesn't throw exceptions here.
- virtual ~DirIteratorTest();
-
- // SetUp() will be called immediately before each test.
- virtual void SetUp();
-
- // TearDown() will be called immediately after each test.
- virtual void TearDown();
-protected:
- mcld::sys::fs::Directory *m_pDir;
+class DirIteratorTest : public ::testing::Test {
+ public:
+ // Constructor can do set-up work for all test here.
+ DirIteratorTest();
+
+ // Destructor can do clean-up work that doesn't throw exceptions here.
+ virtual ~DirIteratorTest();
+
+ // SetUp() will be called immediately before each test.
+ virtual void SetUp();
+
+ // TearDown() will be called immediately after each test.
+ virtual void TearDown();
+
+ protected:
+ mcld::sys::fs::Directory* m_pDir;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/ELFBinaryReaderTest.cpp b/unittests/ELFBinaryReaderTest.cpp
index 7792717..3fe9f3f 100644
--- a/unittests/ELFBinaryReaderTest.cpp
+++ b/unittests/ELFBinaryReaderTest.cpp
@@ -6,49 +6,44 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/ELFBinaryReader.h>
-#include <mcld/Module.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/GeneralOptions.h>
-#include <mcld/MC/Input.h>
+#include "mcld/LD/ELFBinaryReader.h"
+#include "mcld/Module.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/GeneralOptions.h"
+#include "mcld/MC/Input.h"
#include "ELFBinaryReaderTest.h"
using namespace mcld;
using namespace mcld::test;
-
// Constructor can do set-up work for all test here.
-ELFBinaryReaderTest::ELFBinaryReaderTest()
-{
+ELFBinaryReaderTest::ELFBinaryReaderTest() {
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-ELFBinaryReaderTest::~ELFBinaryReaderTest()
-{
+ELFBinaryReaderTest::~ELFBinaryReaderTest() {
}
// SetUp() will be called immediately before each test.
-void ELFBinaryReaderTest::SetUp()
-{
+void ELFBinaryReaderTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void ELFBinaryReaderTest::TearDown()
-{
+void ELFBinaryReaderTest::TearDown() {
}
//===----------------------------------------------------------------------===//
// Testcases
//===----------------------------------------------------------------------===//
-TEST_F( ELFBinaryReaderTest, is_myformat) {
+TEST_F(ELFBinaryReaderTest, is_myformat) {
LinkerScript script;
Module module("test", script);
LinkerConfig config;
IRBuilder builder(module, config);
- ELFBinaryReader *reader = new ELFBinaryReader(builder, config);
+ ELFBinaryReader* reader = new ELFBinaryReader(builder, config);
Input input("test.bin");
@@ -61,4 +56,3 @@ TEST_F( ELFBinaryReaderTest, is_myformat) {
delete reader;
}
-
diff --git a/unittests/ELFBinaryReaderTest.h b/unittests/ELFBinaryReaderTest.h
index a9ea042..bc8ee71 100644
--- a/unittests/ELFBinaryReaderTest.h
+++ b/unittests/ELFBinaryReaderTest.h
@@ -16,9 +16,8 @@ class ELFBinaryReader;
namespace test {
-class ELFBinaryReaderTest : public ::testing::Test
-{
-public:
+class ELFBinaryReaderTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
ELFBinaryReaderTest();
@@ -32,8 +31,7 @@ public:
virtual void TearDown();
};
-} // namespace of test
-} // namespace of mcld
+} // namespace of test
+} // namespace of mcld
#endif
-
diff --git a/unittests/ELFReaderTest.cpp b/unittests/ELFReaderTest.cpp
index 1ff2a31..bacddce 100644
--- a/unittests/ELFReaderTest.cpp
+++ b/unittests/ELFReaderTest.cpp
@@ -6,48 +6,46 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <cstdio>
+#include "ELFReaderTest.h"
-#include <llvm/ADT/StringRef.h>
-#include <llvm/Support/ELF.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/TargetOptions.h>
-#include <mcld/LD/ELFReader.h>
-#include <mcld/MC/Input.h>
-#include <mcld/Support/Path.h>
-#include <mcld/Support/MemoryArea.h>
+#include "mcld/IRBuilder.h"
+#include "mcld/TargetOptions.h"
+#include "mcld/LD/ELFReader.h"
+#include "mcld/LD/LDContext.h"
+#include "mcld/MC/Input.h"
+#include "mcld/Support/Path.h"
+#include "mcld/Support/MemoryArea.h"
#include <../lib/Target/X86/X86LDBackend.h>
#include <../lib/Target/X86/X86GNUInfo.h>
-#include "ELFReaderTest.h"
+#include <llvm/ADT/StringRef.h>
+#include <llvm/Support/ELF.h>
+
+#include <cstdio>
using namespace mcld;
using namespace mcld::sys::fs;
using namespace mcldtest;
// Constructor can do set-up work for all test here.
-ELFReaderTest::ELFReaderTest()
- : m_pInput(NULL)
-{
+ELFReaderTest::ELFReaderTest() : m_pInput(NULL) {
m_pConfig = new LinkerConfig("x86_64-linux-gnueabi");
- m_pConfig->targets().setEndian( TargetOptions::Little );
- m_pConfig->targets().setBitClass( 64 );
- Relocation::SetUp( *m_pConfig );
+ m_pConfig->targets().setEndian(TargetOptions::Little);
+ m_pConfig->targets().setBitClass(64);
+ Relocation::SetUp(*m_pConfig);
m_pScript = new LinkerScript();
- m_pInfo = new X86_64GNUInfo( m_pConfig->targets().triple() );
- m_pLDBackend = new X86_64GNULDBackend( *m_pConfig, m_pInfo );
- m_pELFReader = new ELFReader<64, true>( *m_pLDBackend );
+ m_pInfo = new X86_64GNUInfo(m_pConfig->targets().triple());
+ m_pLDBackend = new X86_64GNULDBackend(*m_pConfig, m_pInfo);
+ m_pELFReader = new ELFReader<64, true>(*m_pLDBackend);
m_pModule = new Module(*m_pScript);
- m_pIRBuilder = new IRBuilder( *m_pModule, *m_pConfig);
- m_pELFObjReader = new ELFObjectReader(*m_pLDBackend,
- *m_pIRBuilder,
- *m_pConfig);
+ m_pIRBuilder = new IRBuilder(*m_pModule, *m_pConfig);
+ m_pELFObjReader =
+ new ELFObjectReader(*m_pLDBackend, *m_pIRBuilder, *m_pConfig);
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-ELFReaderTest::~ELFReaderTest()
-{
+ELFReaderTest::~ELFReaderTest() {
delete m_pConfig;
delete m_pLDBackend;
delete m_pELFReader;
@@ -58,57 +56,54 @@ ELFReaderTest::~ELFReaderTest()
}
// SetUp() will be called immediately before each test.
-void ELFReaderTest::SetUp()
-{
+void ELFReaderTest::SetUp() {
Path path(TOPDIR);
path.append("unittests/test_x86_64.o");
m_pInput = m_pIRBuilder->ReadInput("test_x86_64", path);
- ASSERT_TRUE(NULL!=m_pInput);
+ ASSERT_TRUE(NULL != m_pInput);
ASSERT_TRUE(m_pInput->hasMemArea());
size_t hdr_size = m_pELFReader->getELFHeaderSize();
- llvm::StringRef region = m_pInput->memArea()->request(m_pInput->fileOffset(),
- hdr_size);
+ llvm::StringRef region =
+ m_pInput->memArea()->request(m_pInput->fileOffset(), hdr_size);
const char* ELF_hdr = region.begin();
bool shdr_result = m_pELFReader->readSectionHeaders(*m_pInput, ELF_hdr);
ASSERT_TRUE(shdr_result);
}
// TearDown() will be called immediately after each test.
-void ELFReaderTest::TearDown()
-{
+void ELFReaderTest::TearDown() {
}
//===----------------------------------------------------------------------===//
// Testcases
//===----------------------------------------------------------------------===//
-TEST_F( ELFReaderTest, read_section_headers ) {
+TEST_F(ELFReaderTest, read_section_headers) {
ASSERT_EQ(m_pInput->context()->numOfSections(), 13);
LDContext::const_sect_iterator iter = m_pInput->context()->sectBegin();
- ++iter; /// test section[1]
+ ++iter; /// test section[1]
ASSERT_EQ(".text", (*iter)->name());
ASSERT_EQ(llvm::ELF::SHT_PROGBITS, (*iter)->type());
ASSERT_EQ(0x40, (*iter)->offset());
ASSERT_EQ(0x15, (*iter)->size());
- ASSERT_TRUE(llvm::ELF::SHF_ALLOC & (*iter)->flag()); //AX
+ ASSERT_TRUE(llvm::ELF::SHF_ALLOC & (*iter)->flag()); // AX
ASSERT_EQ(0x4, (*iter)->align());
ASSERT_EQ(NULL, (*iter)->getLink());
ASSERT_EQ(0, (*iter)->getInfo());
}
-TEST_F( ELFReaderTest, read_symbol_and_rela )
-{
+TEST_F(ELFReaderTest, read_symbol_and_rela) {
ASSERT_TRUE(m_pInput->hasMemArea());
ASSERT_TRUE(m_pInput->hasContext());
m_pInput->setType(Input::Object);
// -- read symbols
LDSection* symtab_shdr = m_pInput->context()->getSection(".symtab");
- ASSERT_TRUE(NULL!=symtab_shdr);
+ ASSERT_TRUE(NULL != symtab_shdr);
LDSection* strtab_shdr = symtab_shdr->getLink();
- ASSERT_TRUE(NULL!=strtab_shdr);
+ ASSERT_TRUE(NULL != strtab_shdr);
llvm::StringRef symtab_region = m_pInput->memArea()->request(
m_pInput->fileOffset() + symtab_shdr->offset(), symtab_shdr->size());
@@ -116,46 +111,44 @@ TEST_F( ELFReaderTest, read_symbol_and_rela )
llvm::StringRef strtab_region = m_pInput->memArea()->request(
m_pInput->fileOffset() + strtab_shdr->offset(), strtab_shdr->size());
const char* strtab = strtab_region.begin();
- bool result = m_pELFReader->readSymbols(*m_pInput, *m_pIRBuilder,
- symtab_region, strtab);
+ bool result = m_pELFReader->readSymbols(
+ *m_pInput, *m_pIRBuilder, symtab_region, strtab);
ASSERT_TRUE(result);
ASSERT_EQ("hello.c", std::string(m_pInput->context()->getSymbol(1)->name()));
ASSERT_EQ("puts", std::string(m_pInput->context()->getSymbol(10)->name()));
- ASSERT_TRUE(NULL==m_pInput->context()->getSymbol(11));
+ ASSERT_TRUE(NULL == m_pInput->context()->getSymbol(11));
// -- read relocations
MemoryArea* mem = m_pInput->memArea();
LDContext::sect_iterator rs = m_pInput->context()->relocSectBegin();
- ASSERT_TRUE(rs!=m_pInput->context()->relocSectEnd());
+ ASSERT_TRUE(rs != m_pInput->context()->relocSectEnd());
ASSERT_EQ(".rela.text", (*rs)->name());
uint64_t offset = m_pInput->fileOffset() + (*rs)->offset();
uint64_t size = (*rs)->size();
llvm::StringRef region = mem->request(offset, size);
- IRBuilder::CreateRelocData(**rs); /// create relocation data for the header
+ IRBuilder::CreateRelocData(**rs); /// create relocation data for the header
ASSERT_EQ(llvm::ELF::SHT_RELA, (*rs)->type());
ASSERT_TRUE(m_pELFReader->readRela(*m_pInput, **rs, region));
- const RelocData::RelocationListType &rRelocs =
- (*rs)->getRelocData()->getRelocationList();
+ const RelocData::RelocationListType& rRelocs =
+ (*rs)->getRelocData()->getRelocationList();
RelocData::const_iterator rReloc = rRelocs.begin();
ASSERT_EQ(2, rRelocs.size());
- ASSERT_TRUE(rRelocs.end()!=rReloc);
- ++rReloc; /// test rRelocs[1]
+ ASSERT_TRUE(rRelocs.end() != rReloc);
+ ++rReloc; /// test rRelocs[1]
ASSERT_EQ("puts", std::string(rReloc->symInfo()->name()));
ASSERT_EQ(llvm::ELF::R_X86_64_PC32, rReloc->type());
ASSERT_EQ(0x0, rReloc->symValue());
ASSERT_EQ(-0x4, rReloc->addend());
}
-TEST_F( ELFReaderTest, read_regular_sections ) {
- ASSERT_TRUE( m_pELFObjReader->readSections(*m_pInput) );
+TEST_F(ELFReaderTest, read_regular_sections) {
+ ASSERT_TRUE(m_pELFObjReader->readSections(*m_pInput));
}
-TEST_F( ELFReaderTest, is_my_format ) {
+TEST_F(ELFReaderTest, is_my_format) {
bool doContinue;
- ASSERT_TRUE( m_pELFObjReader->isMyFormat(*m_pInput, doContinue) );
+ ASSERT_TRUE(m_pELFObjReader->isMyFormat(*m_pInput, doContinue));
}
-
-
diff --git a/unittests/ELFReaderTest.h b/unittests/ELFReaderTest.h
index abe99b1..b36eede 100644
--- a/unittests/ELFReaderTest.h
+++ b/unittests/ELFReaderTest.h
@@ -10,24 +10,23 @@
#define MCLD_ELFREADER_TEST_H
#include <gtest.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
-#include <mcld/LD/ELFReaderIf.h>
-#include <mcld/LD/ELFReader.h>
-#include <mcld/LD/ELFObjectReader.h>
-#include <mcld/Target/GNULDBackend.h>
-#include <mcld/MC/InputBuilder.h>
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
+#include "mcld/LD/ELFReaderIf.h"
+#include "mcld/LD/ELFReader.h"
+#include "mcld/LD/ELFObjectReader.h"
+#include "mcld/Target/GNULDBackend.h"
+#include "mcld/MC/InputBuilder.h"
namespace mcld {
- template<> class ELFReader<64, true>;
-} // namespace for mcld
+template <>
+class ELFReader<64, true>;
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
-class ELFReaderTest : public ::testing::Test
-{
-public:
+class ELFReaderTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
ELFReaderTest();
@@ -40,7 +39,7 @@ public:
// TearDown() will be called immediately after each test.
virtual void TearDown();
-protected:
+ protected:
mcld::Input* m_pInput;
mcld::LinkerConfig* m_pConfig;
mcld::LinkerScript* m_pScript;
@@ -52,7 +51,6 @@ protected:
mcld::ELFObjectReader* m_pELFObjReader;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/FactoriesTest.cpp b/unittests/FactoriesTest.cpp
index 9301fb9..fdc7109 100644
--- a/unittests/FactoriesTest.cpp
+++ b/unittests/FactoriesTest.cpp
@@ -13,208 +13,200 @@
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-FactoriesTest::FactoriesTest()
-{
- m_pNodeAlloc = new NodeAlloc();
- m_pFileAlloc = new FileAlloc();
+FactoriesTest::FactoriesTest() {
+ m_pNodeAlloc = new NodeAlloc();
+ m_pFileAlloc = new FileAlloc();
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-FactoriesTest::~FactoriesTest()
-{
- delete m_pNodeAlloc;
- delete m_pFileAlloc;
+FactoriesTest::~FactoriesTest() {
+ delete m_pNodeAlloc;
+ delete m_pFileAlloc;
}
// SetUp() will be called immediately before each test.
-void FactoriesTest::SetUp()
-{
+void FactoriesTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void FactoriesTest::TearDown()
-{
+void FactoriesTest::TearDown() {
}
//==========================================================================//
// Testcases
//
-TEST_F( FactoriesTest, node_produce ) {
- NodeAlloc::NodeType* node = m_pNodeAlloc->produce();
- ASSERT_EQ(1, m_pNodeAlloc->size());
- ASSERT_FALSE(m_pNodeAlloc->empty());
- node = m_pNodeAlloc->produce();
- ASSERT_EQ(2, m_pNodeAlloc->size());
- ASSERT_FALSE(m_pNodeAlloc->empty());
- node = m_pNodeAlloc->produce();
- ASSERT_EQ(3, m_pNodeAlloc->size());
- ASSERT_FALSE(m_pNodeAlloc->empty());
+TEST_F(FactoriesTest, node_produce) {
+ NodeAlloc::NodeType* node = m_pNodeAlloc->produce();
+ ASSERT_EQ(1, m_pNodeAlloc->size());
+ ASSERT_FALSE(m_pNodeAlloc->empty());
+ node = m_pNodeAlloc->produce();
+ ASSERT_EQ(2, m_pNodeAlloc->size());
+ ASSERT_FALSE(m_pNodeAlloc->empty());
+ node = m_pNodeAlloc->produce();
+ ASSERT_EQ(3, m_pNodeAlloc->size());
+ ASSERT_FALSE(m_pNodeAlloc->empty());
}
-TEST_F( FactoriesTest, node_iterate ) {
- NodeAlloc::NodeType* node = 0;
- for (int i=0 ; i<100; ++i) {
- node = m_pNodeAlloc->produce();
- node->data = (int*)malloc(sizeof(int));
- *(node->data) = i;
- }
-
- int counter = 0;
- NodeAlloc::iterator data = m_pNodeAlloc->begin();
- NodeAlloc::iterator dEnd = m_pNodeAlloc->end();
- for (; data!=dEnd; ++data) {
- ASSERT_EQ(counter, *(*data).data );
- free((*data).data);
- (*data).data = 0;
- ++counter;
- }
+TEST_F(FactoriesTest, node_iterate) {
+ NodeAlloc::NodeType* node = 0;
+ for (int i = 0; i < 100; ++i) {
+ node = m_pNodeAlloc->produce();
+ node->data = (int*)malloc(sizeof(int));
+ *(node->data) = i;
+ }
+
+ int counter = 0;
+ NodeAlloc::iterator data = m_pNodeAlloc->begin();
+ NodeAlloc::iterator dEnd = m_pNodeAlloc->end();
+ for (; data != dEnd; ++data) {
+ ASSERT_EQ(counter, *(*data).data);
+ free((*data).data);
+ (*data).data = 0;
+ ++counter;
+ }
}
-TEST_F( FactoriesTest, node_delegate_empty ) {
- NodeAlloc::NodeType* node = 0;
- for (int i=0 ; i<100; ++i) {
- node = m_pNodeAlloc->produce();
- node->data = (int*)malloc(sizeof(int));
- *(node->data) = i;
- }
- NodeAlloc* delegatee = new NodeAlloc();
- m_pNodeAlloc->delegate(*delegatee);
- ASSERT_EQ(100, m_pNodeAlloc->size());
- int counter = 0;
- NodeAlloc::iterator data = m_pNodeAlloc->begin();
- NodeAlloc::iterator dEnd = m_pNodeAlloc->end();
- for (; data!=dEnd; ++data) {
- ASSERT_EQ(counter, *(*data).data );
- free((*data).data);
- (*data).data = 0;
- ++counter;
- }
- delete delegatee;
+TEST_F(FactoriesTest, node_delegate_empty) {
+ NodeAlloc::NodeType* node = 0;
+ for (int i = 0; i < 100; ++i) {
+ node = m_pNodeAlloc->produce();
+ node->data = (int*)malloc(sizeof(int));
+ *(node->data) = i;
+ }
+ NodeAlloc* delegatee = new NodeAlloc();
+ m_pNodeAlloc->delegate(*delegatee);
+ ASSERT_EQ(100, m_pNodeAlloc->size());
+ int counter = 0;
+ NodeAlloc::iterator data = m_pNodeAlloc->begin();
+ NodeAlloc::iterator dEnd = m_pNodeAlloc->end();
+ for (; data != dEnd; ++data) {
+ ASSERT_EQ(counter, *(*data).data);
+ free((*data).data);
+ (*data).data = 0;
+ ++counter;
+ }
+ delete delegatee;
}
-TEST_F( FactoriesTest, node_empty_delegate ) {
- NodeAlloc::NodeType* node = 0;
- NodeAlloc* delegatee = new NodeAlloc();
- for (int i=0 ; i<100; ++i) {
- node = delegatee->produce();
- node->data = (int*)malloc(sizeof(int));
- *(node->data) = i;
- }
- m_pNodeAlloc->delegate(*delegatee);
- ASSERT_EQ(100, m_pNodeAlloc->size());
- int counter = 0;
- NodeAlloc::iterator data = m_pNodeAlloc->begin();
- NodeAlloc::iterator dEnd = m_pNodeAlloc->end();
- for (; data!=dEnd; ++data) {
- ASSERT_EQ(counter, *(*data).data );
- free((*data).data);
- (*data).data = 0;
- ++counter;
- }
- ASSERT_EQ(0, delegatee->size());
- ASSERT_TRUE(delegatee->empty());
- delete delegatee;
+TEST_F(FactoriesTest, node_empty_delegate) {
+ NodeAlloc::NodeType* node = 0;
+ NodeAlloc* delegatee = new NodeAlloc();
+ for (int i = 0; i < 100; ++i) {
+ node = delegatee->produce();
+ node->data = (int*)malloc(sizeof(int));
+ *(node->data) = i;
+ }
+ m_pNodeAlloc->delegate(*delegatee);
+ ASSERT_EQ(100, m_pNodeAlloc->size());
+ int counter = 0;
+ NodeAlloc::iterator data = m_pNodeAlloc->begin();
+ NodeAlloc::iterator dEnd = m_pNodeAlloc->end();
+ for (; data != dEnd; ++data) {
+ ASSERT_EQ(counter, *(*data).data);
+ free((*data).data);
+ (*data).data = 0;
+ ++counter;
+ }
+ ASSERT_EQ(0, delegatee->size());
+ ASSERT_TRUE(delegatee->empty());
+ delete delegatee;
}
-TEST_F( FactoriesTest, node_delegate ) {
- NodeAlloc::NodeType* node = 0;
- NodeAlloc* delegatee = new NodeAlloc();
- int counter = 0;
- // produce agent
- for (int i=0 ; i<100; ++i) {
- node = m_pNodeAlloc->produce();
- node->data = (int*)malloc(sizeof(int));
- *(node->data) = counter;
- ++counter;
- }
-
- // produce delegatee
- for (int i=0 ; i<100; ++i) {
- node = delegatee->produce();
- node->data = (int*)malloc(sizeof(int));
- *(node->data) = counter;
- ++counter;
- }
-
- m_pNodeAlloc->delegate(*delegatee);
- ASSERT_EQ(200, m_pNodeAlloc->size());
- ASSERT_FALSE(m_pNodeAlloc->empty());
- NodeAlloc::iterator data = m_pNodeAlloc->begin();
- NodeAlloc::iterator dEnd = m_pNodeAlloc->end();
- for ( counter = 0; data!=dEnd; ++data) {
- ASSERT_EQ(counter, *(*data).data );
- free((*data).data);
- (*data).data = 0;
- ++counter;
- }
- ASSERT_EQ(0, delegatee->size());
- ASSERT_TRUE(delegatee->empty());
- delete delegatee;
+TEST_F(FactoriesTest, node_delegate) {
+ NodeAlloc::NodeType* node = 0;
+ NodeAlloc* delegatee = new NodeAlloc();
+ int counter = 0;
+ // produce agent
+ for (int i = 0; i < 100; ++i) {
+ node = m_pNodeAlloc->produce();
+ node->data = (int*)malloc(sizeof(int));
+ *(node->data) = counter;
+ ++counter;
+ }
+
+ // produce delegatee
+ for (int i = 0; i < 100; ++i) {
+ node = delegatee->produce();
+ node->data = (int*)malloc(sizeof(int));
+ *(node->data) = counter;
+ ++counter;
+ }
+
+ m_pNodeAlloc->delegate(*delegatee);
+ ASSERT_EQ(200, m_pNodeAlloc->size());
+ ASSERT_FALSE(m_pNodeAlloc->empty());
+ NodeAlloc::iterator data = m_pNodeAlloc->begin();
+ NodeAlloc::iterator dEnd = m_pNodeAlloc->end();
+ for (counter = 0; data != dEnd; ++data) {
+ ASSERT_EQ(counter, *(*data).data);
+ free((*data).data);
+ (*data).data = 0;
+ ++counter;
+ }
+ ASSERT_EQ(0, delegatee->size());
+ ASSERT_TRUE(delegatee->empty());
+ delete delegatee;
}
-TEST_F( FactoriesTest, node_delegate_self ) {
- NodeAlloc::NodeType* node = 0;
- for (int i=0 ; i<100; ++i) {
- node = m_pNodeAlloc->produce();
- node->data = (int*)malloc(sizeof(int));
- *(node->data) = i;
- }
- ASSERT_EQ(100, m_pNodeAlloc->size());
- m_pNodeAlloc->delegate(*m_pNodeAlloc);
- ASSERT_EQ(100, m_pNodeAlloc->size());
- ASSERT_FALSE(m_pNodeAlloc->empty());
+TEST_F(FactoriesTest, node_delegate_self) {
+ NodeAlloc::NodeType* node = 0;
+ for (int i = 0; i < 100; ++i) {
+ node = m_pNodeAlloc->produce();
+ node->data = (int*)malloc(sizeof(int));
+ *(node->data) = i;
+ }
+ ASSERT_EQ(100, m_pNodeAlloc->size());
+ m_pNodeAlloc->delegate(*m_pNodeAlloc);
+ ASSERT_EQ(100, m_pNodeAlloc->size());
+ ASSERT_FALSE(m_pNodeAlloc->empty());
}
-TEST_F( FactoriesTest, file_produce ) {
- int counter = 0;
- for (counter=1; counter<1000; ++counter) {
- MCLDFile* file = m_pFileAlloc->produce();
- ASSERT_EQ(counter, m_pFileAlloc->size());
- ASSERT_FALSE(m_pFileAlloc->empty());
- }
+TEST_F(FactoriesTest, file_produce) {
+ int counter = 0;
+ for (counter = 1; counter < 1000; ++counter) {
+ MCLDFile* file = m_pFileAlloc->produce();
+ ASSERT_EQ(counter, m_pFileAlloc->size());
+ ASSERT_FALSE(m_pFileAlloc->empty());
+ }
}
-TEST_F( FactoriesTest, file_produce_by_params ) {
- int counter = 0;
- for (counter=1; counter<1000; ++counter) {
- char name[100];
- sprintf(name, "file %d", counter);
- char path_name[100];
- sprintf(path_name, "/proj/mtk%d", counter);
- MCLDFile* file = m_pFileAlloc->produce( string(name),
- sys::fs::Path(string(path_name)),
- MCLDFile::Archive);
- ASSERT_EQ(counter, m_pFileAlloc->size());
- ASSERT_FALSE(m_pFileAlloc->empty());
- ASSERT_TRUE(file->isRecognized());
- ASSERT_STREQ(name, file->name().data());
- }
+TEST_F(FactoriesTest, file_produce_by_params) {
+ int counter = 0;
+ for (counter = 1; counter < 1000; ++counter) {
+ char name[100];
+ sprintf(name, "file %d", counter);
+ char path_name[100];
+ sprintf(path_name, "/proj/mtk%d", counter);
+ MCLDFile* file = m_pFileAlloc->produce(
+ string(name), sys::fs::Path(string(path_name)), MCLDFile::Archive);
+ ASSERT_EQ(counter, m_pFileAlloc->size());
+ ASSERT_FALSE(m_pFileAlloc->empty());
+ ASSERT_TRUE(file->isRecognized());
+ ASSERT_STREQ(name, file->name().data());
+ }
}
-TEST_F( FactoriesTest, file_iterate ) {
- int counter = 0;
- for (counter=1; counter<1000; ++counter) {
- char name[100];
- sprintf(name, "file %d", counter);
- char path_name[100];
- sprintf(path_name, "/proj/mtk%d", counter);
- MCLDFile* file = m_pFileAlloc->produce( string(name),
- sys::fs::Path(string(path_name)),
- MCLDFile::Archive);
- }
-
- ASSERT_EQ(counter-1, m_pFileAlloc->size());
- ASSERT_FALSE(m_pFileAlloc->empty());
-
- MCLDFileFactory::iterator file = m_pFileAlloc->begin();
- MCLDFileFactory::iterator fEnd = m_pFileAlloc->end();
-
- while (file!=fEnd) {
- ASSERT_TRUE((*file).isRecognized());
- ASSERT_FALSE((*file).name().empty());
- ++file;
- }
+TEST_F(FactoriesTest, file_iterate) {
+ int counter = 0;
+ for (counter = 1; counter < 1000; ++counter) {
+ char name[100];
+ sprintf(name, "file %d", counter);
+ char path_name[100];
+ sprintf(path_name, "/proj/mtk%d", counter);
+ MCLDFile* file = m_pFileAlloc->produce(
+ string(name), sys::fs::Path(string(path_name)), MCLDFile::Archive);
+ }
+
+ ASSERT_EQ(counter - 1, m_pFileAlloc->size());
+ ASSERT_FALSE(m_pFileAlloc->empty());
+
+ MCLDFileFactory::iterator file = m_pFileAlloc->begin();
+ MCLDFileFactory::iterator fEnd = m_pFileAlloc->end();
+
+ while (file != fEnd) {
+ ASSERT_TRUE((*file).isRecognized());
+ ASSERT_FALSE((*file).name().empty());
+ ++file;
+ }
}
-
diff --git a/unittests/FactoriesTest.h b/unittests/FactoriesTest.h
index 484b801..e89732e 100644
--- a/unittests/FactoriesTest.h
+++ b/unittests/FactoriesTest.h
@@ -12,38 +12,36 @@
#include "mcld/ADT/TreeAllocator.h"
#include "mcld/MC/MCLDFile.h"
-namespace mcldtest
-{
+namespace mcldtest {
/** \class FactoriesTest
* \brief Test cases for factories - NodeFactory and MCLDFileFactory.
*
* \see Factories
*/
-class FactoriesTest : public ::testing::Test
-{
-public:
- // Constructor can do set-up work for all test here.
- FactoriesTest();
-
- // Destructor can do clean-up work that doesn't throw exceptions here.
- virtual ~FactoriesTest();
-
- // SetUp() will be called immediately before each test.
- virtual void SetUp();
-
- // TearDown() will be called immediately after each test.
- virtual void TearDown();
-
-protected:
- typedef mcld::NodeFactory<int> NodeAlloc;
- typedef mcld::MCLDFileFactory FileAlloc;
-protected:
- NodeAlloc* m_pNodeAlloc;
- FileAlloc *m_pFileAlloc;
+class FactoriesTest : public ::testing::Test {
+ public:
+ // Constructor can do set-up work for all test here.
+ FactoriesTest();
+
+ // Destructor can do clean-up work that doesn't throw exceptions here.
+ virtual ~FactoriesTest();
+
+ // SetUp() will be called immediately before each test.
+ virtual void SetUp();
+
+ // TearDown() will be called immediately after each test.
+ virtual void TearDown();
+
+ protected:
+ typedef mcld::NodeFactory<int> NodeAlloc;
+ typedef mcld::MCLDFileFactory FileAlloc;
+
+ protected:
+ NodeAlloc* m_pNodeAlloc;
+ FileAlloc* m_pFileAlloc;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/FileHandleTest.cpp b/unittests/FileHandleTest.cpp
index dc9ecdd..e810430 100644
--- a/unittests/FileHandleTest.cpp
+++ b/unittests/FileHandleTest.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/Path.h>
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/Path.h"
#include <fcntl.h>
#include <errno.h>
#include "FileHandleTest.h"
@@ -15,28 +15,23 @@
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-FileHandleTest::FileHandleTest()
-{
+FileHandleTest::FileHandleTest() {
// create testee. modify it if need
m_pTestee = new FileHandle();
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-FileHandleTest::~FileHandleTest()
-{
+FileHandleTest::~FileHandleTest() {
delete m_pTestee;
}
// SetUp() will be called immediately before each test.
-void FileHandleTest::SetUp()
-{
+void FileHandleTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void FileHandleTest::TearDown()
-{
+void FileHandleTest::TearDown() {
}
//===----------------------------------------------------------------------===//
@@ -45,7 +40,8 @@ void FileHandleTest::TearDown()
TEST_F(FileHandleTest, open_close) {
mcld::sys::fs::Path path(TOPDIR);
path.append("unittests/test.txt");
- ASSERT_TRUE(m_pTestee->open(path, FileHandle::ReadOnly));
+ ASSERT_TRUE(m_pTestee->open(path, FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System)));
ASSERT_TRUE(m_pTestee->isOpened());
ASSERT_TRUE(m_pTestee->isGood());
ASSERT_TRUE(m_pTestee->isOwned());
@@ -86,7 +82,8 @@ TEST_F(FileHandleTest, delegate_close) {
TEST_F(FileHandleTest, fail_close) {
mcld::sys::fs::Path path(TOPDIR);
path.append("unittests/test.txt");
- ASSERT_TRUE(m_pTestee->open(path, FileHandle::ReadOnly));
+ ASSERT_TRUE(m_pTestee->open(path, FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System)));
ASSERT_TRUE(m_pTestee->isOpened());
ASSERT_TRUE(m_pTestee->isGood());
diff --git a/unittests/FileHandleTest.h b/unittests/FileHandleTest.h
index 45d4ab1..650c97d 100644
--- a/unittests/FileHandleTest.h
+++ b/unittests/FileHandleTest.h
@@ -11,23 +11,20 @@
#include <gtest.h>
-namespace mcld
-{
+namespace mcld {
class FileHandle;
-} // namespace for mcld
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
/** \class FileHandleTest
* \brief
*
* \see FileHandle
*/
-class FileHandleTest : public ::testing::Test
-{
-public:
+class FileHandleTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
FileHandleTest();
@@ -40,11 +37,10 @@ public:
// TearDown() will be called immediately after each test.
virtual void TearDown();
-protected:
+ protected:
mcld::FileHandle* m_pTestee;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/FragmentRefTest.cpp b/unittests/FragmentRefTest.cpp
index 881cdb8..a067542 100644
--- a/unittests/FragmentRefTest.cpp
+++ b/unittests/FragmentRefTest.cpp
@@ -8,12 +8,12 @@
//===----------------------------------------------------------------------===//
#include "FragmentRefTest.h"
-#include <mcld/Fragment/FragmentRef.h>
-#include <mcld/Fragment/RegionFragment.h>
-#include <mcld/Support/MemoryAreaFactory.h>
-#include <mcld/Support/FileHandle.h>
-#include <mcld/Support/MemoryRegion.h>
-#include <mcld/Support/Path.h>
+#include "mcld/Fragment/FragmentRef.h"
+#include "mcld/Fragment/RegionFragment.h"
+#include "mcld/Support/MemoryAreaFactory.h"
+#include "mcld/Support/FileHandle.h"
+#include "mcld/Support/MemoryRegion.h"
+#include "mcld/Support/Path.h"
#include <llvm/ADT/StringRef.h>
using namespace mcld;
@@ -21,50 +21,49 @@ using namespace mcld::sys::fs;
using namespace mcldtest;
// Constructor can do set-up work for all test here.
-FragmentRefTest::FragmentRefTest()
-{
+FragmentRefTest::FragmentRefTest() {
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-FragmentRefTest::~FragmentRefTest()
-{
+FragmentRefTest::~FragmentRefTest() {
}
// SetUp() will be called immediately before each test.
-void FragmentRefTest::SetUp()
-{
+void FragmentRefTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void FragmentRefTest::TearDown()
-{
+void FragmentRefTest::TearDown() {
}
-//==========================================================================//
+//============================================================================//
// Testcases
//
-TEST_F( FragmentRefTest, ) {
+TEST_F(FragmentRefTest, ) {
Path path(TOPDIR);
path.append("unittests/test3.txt");
MemoryAreaFactory* areaFactory = new MemoryAreaFactory(1);
- MemoryArea* area = areaFactory->produce(path, FileHandle::ReadWrite);
+ MemoryArea* area =
+ areaFactory->produce(path, FileHandle::OpenMode(FileHandle::ReadWrite),
+ FileHandle::Permission(FileHandle::System));
llvm::StringRef region = area->request(0, 4096);
- RegionFragment *frag = new RegionFragment(region);
- FragmentRef *ref = FragmentRef::Create(*frag, 0x0);
+ RegionFragment* frag = new RegionFragment(region);
+ FragmentRef* ref = FragmentRef::Create(*frag, 0x0);
ASSERT_EQ('H', region.data()[0]);
ASSERT_TRUE(4096 == region.size());
ASSERT_EQ('H', frag->getRegion().data()[0]);
ASSERT_TRUE(4096 == frag->getRegion().size());
ASSERT_EQ(frag, ref->frag());
- ASSERT_EQ('H', static_cast<RegionFragment*>(ref->frag())->getRegion().data()[0]);
- ASSERT_TRUE(4096 == static_cast<RegionFragment*>(ref->frag())->getRegion().size());
- //ASSERT_EQ('H', ref->deref()[0]);
+ ASSERT_EQ('H',
+ static_cast<RegionFragment*>(ref->frag())->getRegion().data()[0]);
+ ASSERT_TRUE(4096 ==
+ static_cast<RegionFragment*>(ref->frag())->getRegion().size());
+ // ASSERT_EQ('H', ref->deref()[0]);
ASSERT_TRUE(RegionFragment::classof(frag));
delete frag;
delete areaFactory;
}
-
diff --git a/unittests/FragmentRefTest.h b/unittests/FragmentRefTest.h
index 17de587..c5e8d91 100644
--- a/unittests/FragmentRefTest.h
+++ b/unittests/FragmentRefTest.h
@@ -12,23 +12,20 @@
#include <gtest.h>
-namespace mcld
-{
+namespace mcld {
class FragmentRef;
-} // namespace for mcld
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
/** \class FragmentRefTest
* \brief Reference Test
*
* \see FragmentRef
*/
-class FragmentRefTest : public ::testing::Test
-{
-public:
+class FragmentRefTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
FragmentRefTest();
@@ -42,7 +39,6 @@ public:
virtual void TearDown();
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/FragmentTest.cpp b/unittests/FragmentTest.cpp
index 273c98d..ae93015 100644
--- a/unittests/FragmentTest.cpp
+++ b/unittests/FragmentTest.cpp
@@ -1,4 +1,4 @@
-//===- FragmentTest.cpp -------------------------------------------------------===//
+//===- FragmentTest.cpp ---------------------------------------------------===//
//
// The MCLinker Project
//
@@ -8,38 +8,33 @@
//===----------------------------------------------------------------------===//
#include "FragmentTest.h"
-#include <mcld/Fragment/Fragment.h>
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/LDSection.h>
+#include "mcld/Fragment/Fragment.h"
+#include "mcld/LD/SectionData.h"
+#include "mcld/LD/LDSection.h"
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-FragmentTest::FragmentTest()
-{
+FragmentTest::FragmentTest() {
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-FragmentTest::~FragmentTest()
-{
+FragmentTest::~FragmentTest() {
}
// SetUp() will be called immediately before each test.
-void FragmentTest::SetUp()
-{
+void FragmentTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void FragmentTest::TearDown()
-{
+void FragmentTest::TearDown() {
}
//===----------------------------------------------------------------------===//
// Testcases
-TEST_F( FragmentTest, Fragment_constructor ) {
+TEST_F(FragmentTest, Fragment_constructor) {
LDSection* test = LDSection::Create("test", LDFileFormat::Null, 0, 0);
SectionData* s = SectionData::Create(*test);
new Fragment(Fragment::Alignment, s);
@@ -51,10 +46,10 @@ TEST_F( FragmentTest, Fragment_constructor ) {
EXPECT_TRUE(5 == s->size());
LDSection::Destroy(test);
-// SectionData::Destroy(s);
+ // SectionData::Destroy(s);
}
-TEST_F( FragmentTest, Fragment_trivial_function ) {
+TEST_F(FragmentTest, Fragment_trivial_function) {
LDSection* test = LDSection::Create("test", LDFileFormat::Null, 0, 0);
SectionData* s = SectionData::Create(*test);
Fragment* f = new Fragment(Fragment::Alignment, s);
@@ -64,11 +59,9 @@ TEST_F( FragmentTest, Fragment_trivial_function ) {
f->setOffset(5566);
EXPECT_TRUE(5566 == f->getOffset());
- //always return true
- EXPECT_TRUE(f->classof(new Fragment(Fragment::Region, s)) );
+ // always return true
+ EXPECT_TRUE(f->classof(new Fragment(Fragment::Region, s)));
LDSection::Destroy(test);
-// SectionData::Destroy(s);
+ // SectionData::Destroy(s);
}
-
-
diff --git a/unittests/FragmentTest.h b/unittests/FragmentTest.h
index 8c1489c..938cd9a 100644
--- a/unittests/FragmentTest.h
+++ b/unittests/FragmentTest.h
@@ -11,23 +11,20 @@
#include <gtest.h>
-namespace mcld
-{
+namespace mcld {
class Fragment;
-} // namespace for mcld
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
/** \class FragmentTest
* \brief Unit test for mcld::Fragment.
*
* \see Fragment
*/
-class FragmentTest : public ::testing::Test
-{
-public:
+class FragmentTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
FragmentTest();
@@ -40,11 +37,10 @@ public:
// TearDown() will be called immediately after each test.
virtual void TearDown();
-protected:
+ protected:
mcld::Fragment* m_pTestee;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/GCFactoryListTraitsTest.cpp b/unittests/GCFactoryListTraitsTest.cpp
index db8842c..7fecb26 100644
--- a/unittests/GCFactoryListTraitsTest.cpp
+++ b/unittests/GCFactoryListTraitsTest.cpp
@@ -12,8 +12,7 @@ using namespace mcld;
using namespace mcldtest;
// Constructor can do set-up work for all test here.
-GCFactoryListTraitsTest::GCFactoryListTraitsTest()
-{
+GCFactoryListTraitsTest::GCFactoryListTraitsTest() {
// Allocate the nodes.
m_pNodesAlloc = new Node* [10];
#define ALLOCATE_NODE(i) m_pNodesAlloc[(i)] = m_NodeFactory.produce(i);
@@ -31,13 +30,11 @@ GCFactoryListTraitsTest::GCFactoryListTraitsTest()
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-GCFactoryListTraitsTest::~GCFactoryListTraitsTest()
-{
+GCFactoryListTraitsTest::~GCFactoryListTraitsTest() {
}
// SetUp() will be called immediately before each test.
-void GCFactoryListTraitsTest::SetUp()
-{
+void GCFactoryListTraitsTest::SetUp() {
// Reset the node value and (re)insert into the iplist.
for (unsigned i = 0; i < 10; i++) {
m_pNodesAlloc[i]->setValue(m_pNodesAlloc[i]->getInitialValue());
@@ -46,8 +43,7 @@ void GCFactoryListTraitsTest::SetUp()
}
// TearDown() will be called immediately after each test.
-void GCFactoryListTraitsTest::TearDown()
-{
+void GCFactoryListTraitsTest::TearDown() {
// Erasing of llvm::iplist won't destroy the allocation of the nodes managed
// by the GCFactory (i.e., NodeFactory.)
m_pNodeList.clear();
@@ -57,62 +53,66 @@ void GCFactoryListTraitsTest::TearDown()
// Testcases
//
-#define CHECK_NODE_VALUE(v_) do { \
- ASSERT_TRUE(v_ == it->getValue()); \
- it++; \
-} while (false)
-
-#define CHECK_LIST_VALUE(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) do { \
- llvm::iplist<Node>::const_iterator it = m_pNodeList.begin(); \
- CHECK_NODE_VALUE(v1); \
- CHECK_NODE_VALUE(v2); \
- CHECK_NODE_VALUE(v3); \
- CHECK_NODE_VALUE(v4); \
- CHECK_NODE_VALUE(v5); \
- CHECK_NODE_VALUE(v6); \
- CHECK_NODE_VALUE(v7); \
- CHECK_NODE_VALUE(v8); \
- CHECK_NODE_VALUE(v9); \
- CHECK_NODE_VALUE(v10); \
-} while (false)
-
-TEST_F( GCFactoryListTraitsTest, Basic) {
+#define CHECK_NODE_VALUE(v_) \
+ do { \
+ ASSERT_TRUE(v_ == it->getValue()); \
+ it++; \
+ } while (false)
+
+#define CHECK_LIST_VALUE(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) \
+ do { \
+ llvm::iplist<Node>::const_iterator it = m_pNodeList.begin(); \
+ CHECK_NODE_VALUE(v1); \
+ CHECK_NODE_VALUE(v2); \
+ CHECK_NODE_VALUE(v3); \
+ CHECK_NODE_VALUE(v4); \
+ CHECK_NODE_VALUE(v5); \
+ CHECK_NODE_VALUE(v6); \
+ CHECK_NODE_VALUE(v7); \
+ CHECK_NODE_VALUE(v8); \
+ CHECK_NODE_VALUE(v9); \
+ CHECK_NODE_VALUE(v10); \
+ } while (false)
+
+TEST_F(GCFactoryListTraitsTest, Basic) {
ASSERT_TRUE(10 == m_pNodeList.size());
CHECK_LIST_VALUE(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
-TEST_F( GCFactoryListTraitsTest, BasicAgain) {
+TEST_F(GCFactoryListTraitsTest, BasicAgain) {
ASSERT_TRUE(10 == m_pNodeList.size());
CHECK_LIST_VALUE(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
-TEST_F( GCFactoryListTraitsTest, Clear) {
+TEST_F(GCFactoryListTraitsTest, Clear) {
m_pNodeList.clear();
ASSERT_TRUE(0 == m_pNodeList.size());
}
-TEST_F( GCFactoryListTraitsTest, PushThenPop) {
- Node *NewNode = m_NodeFactory.produce(11);
+TEST_F(GCFactoryListTraitsTest, PushThenPop) {
+ Node* NewNode = m_NodeFactory.produce(11);
m_pNodeList.push_back(NewNode);
ASSERT_TRUE(11 == m_pNodeList.size());
m_pNodeList.pop_back();
ASSERT_TRUE(10 == m_pNodeList.size());
}
-TEST_F( GCFactoryListTraitsTest, CodeIterator) {
+TEST_F(GCFactoryListTraitsTest, CodeIterator) {
// to test whether there's compilation error for const template
for (llvm::iplist<Node>::const_iterator I = m_pNodeList.begin(),
- E = m_pNodeList.end(); I != E; I++)
+ E = m_pNodeList.end();
+ I != E;
+ I++)
I->getValue();
}
-TEST_F( GCFactoryListTraitsTest, Empty) {
+TEST_F(GCFactoryListTraitsTest, Empty) {
ASSERT_FALSE(m_pNodeList.empty());
m_pNodeList.clear();
ASSERT_TRUE(m_pNodeList.empty());
}
-TEST_F( GCFactoryListTraitsTest, EraseAndSize) {
+TEST_F(GCFactoryListTraitsTest, EraseAndSize) {
ASSERT_FALSE(m_pNodeList.empty());
m_pNodeList.erase(m_pNodeList.begin());
m_pNodeList.erase(m_pNodeList.begin());
diff --git a/unittests/GCFactoryListTraitsTest.h b/unittests/GCFactoryListTraitsTest.h
index a551848..9326b5b 100644
--- a/unittests/GCFactoryListTraitsTest.h
+++ b/unittests/GCFactoryListTraitsTest.h
@@ -11,89 +11,85 @@
#include <gtest.h>
-#include <mcld/Support/GCFactoryListTraits.h>
+#include "mcld/Support/GCFactoryListTraits.h"
#include <llvm/ADT/ilist_node.h>
-#include <mcld/Support/GCFactory.h>
+#include "mcld/Support/GCFactory.h"
-namespace mcldtest
-{
+namespace mcldtest {
/** \class GCFactoryListTraitsTest
* \brief
*
* \see GCFactoryListTraits
*/
-class GCFactoryListTraitsTest : public ::testing::Test
-{
-public:
+class GCFactoryListTraitsTest : public ::testing::Test {
+ public:
/** \class GCFactoryListTraitsTest
* \brief Node used in the test
*
*/
class NodeFactory;
- class Node : public llvm::ilist_node<Node>
- {
+ class Node : public llvm::ilist_node<Node> {
friend class NodeFactory;
- private:
+
+ private:
unsigned m_Init;
unsigned m_Value;
- public:
- Node() : m_Init(0), m_Value(0) { }
+ public:
+ Node() : m_Init(0), m_Value(0) {}
- Node(unsigned pInit) : m_Init(pInit), m_Value(pInit) { }
+ Node(unsigned pInit) : m_Init(pInit), m_Value(pInit) {}
- unsigned getInitialValue() const {
- return m_Init;
- }
+ unsigned getInitialValue() const { return m_Init; }
- inline unsigned getValue() const
- { return m_Value; }
+ inline unsigned getValue() const { return m_Value; }
- inline void setValue(unsigned pValue)
- { m_Value = pValue; }
+ inline void setValue(unsigned pValue) { m_Value = pValue; }
};
class NodeFactory : public mcld::GCFactory<Node, 0> {
- public:
- NodeFactory() : mcld::GCFactory<Node, 0>(16) { }
+ public:
+ NodeFactory() : mcld::GCFactory<Node, 0>(16) {}
- Node *produce(unsigned pInit) {
- Node *result = allocate();
+ Node* produce(unsigned pInit) {
+ Node* result = allocate();
new (result) Node(pInit);
return result;
}
};
- // Constructor can do set-up work for all test here.
- GCFactoryListTraitsTest();
+ // Constructor can do set-up work for all test here.
+ GCFactoryListTraitsTest();
- // Destructor can do clean-up work that doesn't throw exceptions here.
- virtual ~GCFactoryListTraitsTest();
+ // Destructor can do clean-up work that doesn't throw exceptions here.
+ virtual ~GCFactoryListTraitsTest();
- // SetUp() will be called immediately before each test.
- virtual void SetUp();
+ // SetUp() will be called immediately before each test.
+ virtual void SetUp();
- // TearDown() will be called immediately after each test.
- virtual void TearDown();
+ // TearDown() will be called immediately after each test.
+ virtual void TearDown();
- const llvm::iplist<Node, mcld::GCFactoryListTraits<Node> > &getNodeList() const
- { return m_pNodeList; }
+ const llvm::iplist<Node, mcld::GCFactoryListTraits<Node> >& getNodeList()
+ const {
+ return m_pNodeList;
+ }
- llvm::iplist<Node, mcld::GCFactoryListTraits<Node> > &getNodeList()
- { return m_pNodeList; }
+ llvm::iplist<Node, mcld::GCFactoryListTraits<Node> >& getNodeList() {
+ return m_pNodeList;
+ }
-protected:
+ protected:
NodeFactory m_NodeFactory;
- Node **m_pNodesAlloc;
+ Node** m_pNodesAlloc;
llvm::iplist<Node, mcld::GCFactoryListTraits<Node> > m_pNodeList;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/GraphTest.cpp b/unittests/GraphTest.cpp
index 0c97567..bd25707 100644
--- a/unittests/GraphTest.cpp
+++ b/unittests/GraphTest.cpp
@@ -7,38 +7,33 @@
//
//===----------------------------------------------------------------------===//
#include "GraphTest.h"
-#include <mcld/ADT/GraphLite/Digraph.h>
-#include <mcld/ADT/GraphLite/ListDigraph.h>
+#include "mcld/ADT/GraphLite/Digraph.h"
+#include "mcld/ADT/GraphLite/ListDigraph.h"
using namespace mcld;
using namespace mcld::test;
using namespace mcld::graph;
// Constructor can do set-up work for all test here.
-GraphTest::GraphTest()
-{
+GraphTest::GraphTest() {
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-GraphTest::~GraphTest()
-{
+GraphTest::~GraphTest() {
}
// SetUp() will be called immediately before each test.
-void GraphTest::SetUp()
-{
+void GraphTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void GraphTest::TearDown()
-{
+void GraphTest::TearDown() {
}
//===----------------------------------------------------------------------===//
// Testcases
//===----------------------------------------------------------------------===//
-TEST_F(GraphTest, list_digraph_add_n_erase_nodes_1)
-{
+TEST_F(GraphTest, list_digraph_add_n_erase_nodes_1) {
ListDigraph graph;
ListDigraph::Node* u1 = graph.addNode();
@@ -47,17 +42,17 @@ TEST_F(GraphTest, list_digraph_add_n_erase_nodes_1)
ASSERT_TRUE(NULL == u1->first_in);
ASSERT_TRUE(NULL == u1->first_out);
- ASSERT_TRUE(u2 == u1->prev);
+ ASSERT_TRUE(u2 == u1->prev);
ASSERT_TRUE(NULL == u1->next);
ASSERT_TRUE(NULL == u2->first_in);
ASSERT_TRUE(NULL == u2->first_out);
- ASSERT_TRUE(u3 == u2->prev);
- ASSERT_TRUE(u1 == u2->next);
+ ASSERT_TRUE(u3 == u2->prev);
+ ASSERT_TRUE(u1 == u2->next);
ASSERT_TRUE(NULL == u3->first_in);
ASSERT_TRUE(NULL == u3->first_out);
- ASSERT_TRUE(u2 == u3->next);
+ ASSERT_TRUE(u2 == u3->next);
ASSERT_TRUE(NULL == u3->prev);
ListDigraph::Node* head = NULL;
@@ -68,12 +63,12 @@ TEST_F(GraphTest, list_digraph_add_n_erase_nodes_1)
ASSERT_TRUE(NULL == u1->first_in);
ASSERT_TRUE(NULL == u1->first_out);
- ASSERT_TRUE(u3 == u1->prev);
+ ASSERT_TRUE(u3 == u1->prev);
ASSERT_TRUE(NULL == u1->next);
ASSERT_TRUE(NULL == u3->first_in);
ASSERT_TRUE(NULL == u3->first_out);
- ASSERT_TRUE(u1 == u3->next);
+ ASSERT_TRUE(u1 == u3->next);
ASSERT_TRUE(NULL == u3->prev);
ASSERT_TRUE(NULL == u2->first_in);
@@ -85,8 +80,7 @@ TEST_F(GraphTest, list_digraph_add_n_erase_nodes_1)
ASSERT_TRUE(head == u3);
}
-TEST_F(GraphTest, list_digraph_add_n_erase_nodes_2)
-{
+TEST_F(GraphTest, list_digraph_add_n_erase_nodes_2) {
ListDigraph graph;
ListDigraph::Node* u1 = graph.addNode();
@@ -95,17 +89,17 @@ TEST_F(GraphTest, list_digraph_add_n_erase_nodes_2)
ASSERT_TRUE(NULL == u1->first_in);
ASSERT_TRUE(NULL == u1->first_out);
- ASSERT_TRUE(u2 == u1->prev);
+ ASSERT_TRUE(u2 == u1->prev);
ASSERT_TRUE(NULL == u1->next);
ASSERT_TRUE(NULL == u2->first_in);
ASSERT_TRUE(NULL == u2->first_out);
- ASSERT_TRUE(u3 == u2->prev);
- ASSERT_TRUE(u1 == u2->next);
+ ASSERT_TRUE(u3 == u2->prev);
+ ASSERT_TRUE(u1 == u2->next);
ASSERT_TRUE(NULL == u3->first_in);
ASSERT_TRUE(NULL == u3->first_out);
- ASSERT_TRUE(u2 == u3->next);
+ ASSERT_TRUE(u2 == u3->next);
ASSERT_TRUE(NULL == u3->prev);
ListDigraph::Node* head = NULL;
@@ -121,20 +115,19 @@ TEST_F(GraphTest, list_digraph_add_n_erase_nodes_2)
ASSERT_TRUE(NULL == u2->first_in);
ASSERT_TRUE(NULL == u2->first_out);
- ASSERT_TRUE(u3 == u2->prev);
+ ASSERT_TRUE(u3 == u2->prev);
ASSERT_TRUE(NULL == u2->next);
ASSERT_TRUE(NULL == u3->first_in);
ASSERT_TRUE(NULL == u3->first_out);
- ASSERT_TRUE(u2 == u3->next);
+ ASSERT_TRUE(u2 == u3->next);
ASSERT_TRUE(NULL == u3->prev);
graph.getHead(head);
ASSERT_TRUE(head == u3);
}
-TEST_F(GraphTest, list_digraph_add_n_erase_nodes_3)
-{
+TEST_F(GraphTest, list_digraph_add_n_erase_nodes_3) {
ListDigraph graph;
ListDigraph::Node* u1 = graph.addNode();
@@ -143,17 +136,17 @@ TEST_F(GraphTest, list_digraph_add_n_erase_nodes_3)
ASSERT_TRUE(NULL == u1->first_in);
ASSERT_TRUE(NULL == u1->first_out);
- ASSERT_TRUE(u2 == u1->prev);
+ ASSERT_TRUE(u2 == u1->prev);
ASSERT_TRUE(NULL == u1->next);
ASSERT_TRUE(NULL == u2->first_in);
ASSERT_TRUE(NULL == u2->first_out);
- ASSERT_TRUE(u3 == u2->prev);
- ASSERT_TRUE(u1 == u2->next);
+ ASSERT_TRUE(u3 == u2->prev);
+ ASSERT_TRUE(u1 == u2->next);
ASSERT_TRUE(NULL == u3->first_in);
ASSERT_TRUE(NULL == u3->first_out);
- ASSERT_TRUE(u2 == u3->next);
+ ASSERT_TRUE(u2 == u3->next);
ASSERT_TRUE(NULL == u3->prev);
ListDigraph::Node* head = NULL;
@@ -169,21 +162,19 @@ TEST_F(GraphTest, list_digraph_add_n_erase_nodes_3)
ASSERT_TRUE(NULL == u1->first_in);
ASSERT_TRUE(NULL == u1->first_out);
- ASSERT_TRUE(u2 == u1->prev);
+ ASSERT_TRUE(u2 == u1->prev);
ASSERT_TRUE(NULL == u1->next);
ASSERT_TRUE(NULL == u2->first_in);
ASSERT_TRUE(NULL == u2->first_out);
- ASSERT_TRUE(u1 == u2->next);
+ ASSERT_TRUE(u1 == u2->next);
ASSERT_TRUE(NULL == u2->prev);
graph.getHead(head);
ASSERT_TRUE(head == u2);
-
}
-TEST_F(GraphTest, list_digraph_add_arcs_1)
-{
+TEST_F(GraphTest, list_digraph_add_arcs_1) {
ListDigraph graph;
ListDigraph::Node* u1 = graph.addNode();
@@ -203,8 +194,7 @@ TEST_F(GraphTest, list_digraph_add_arcs_1)
ASSERT_TRUE(u3->first_in == a2 && u3->first_out == a3);
}
-TEST_F(GraphTest, list_digraph_add_arcs_2)
-{
+TEST_F(GraphTest, list_digraph_add_arcs_2) {
ListDigraph graph;
ListDigraph::Node* u1 = graph.addNode();
@@ -224,8 +214,7 @@ TEST_F(GraphTest, list_digraph_add_arcs_2)
ASSERT_TRUE(u3->first_in == a3 && u3->first_out == NULL);
}
-TEST_F(GraphTest, list_digraph_add_n_erase_arcs_1)
-{
+TEST_F(GraphTest, list_digraph_add_n_erase_arcs_1) {
ListDigraph graph;
ListDigraph::Node* u1 = graph.addNode();
@@ -251,9 +240,7 @@ TEST_F(GraphTest, list_digraph_add_n_erase_arcs_1)
ASSERT_TRUE(NULL == a2->next_in);
}
-
-TEST_F(GraphTest, list_digraph_add_n_erase_arcs_2)
-{
+TEST_F(GraphTest, list_digraph_add_n_erase_arcs_2) {
ListDigraph graph;
ListDigraph::Node* u1 = graph.addNode();
@@ -279,8 +266,7 @@ TEST_F(GraphTest, list_digraph_add_n_erase_arcs_2)
ASSERT_TRUE(NULL == a1->next_in);
}
-TEST_F(GraphTest, list_digraph_add_n_erase_arcs_3)
-{
+TEST_F(GraphTest, list_digraph_add_n_erase_arcs_3) {
ListDigraph graph;
ListDigraph::Node* u1 = graph.addNode();
@@ -306,8 +292,7 @@ TEST_F(GraphTest, list_digraph_add_n_erase_arcs_3)
ASSERT_TRUE(NULL == a3->next_in);
}
-TEST_F(GraphTest, list_digraph_add_n_erase_arcs_4)
-{
+TEST_F(GraphTest, list_digraph_add_n_erase_arcs_4) {
ListDigraph graph;
ListDigraph::Node* u1 = graph.addNode();
@@ -323,11 +308,9 @@ TEST_F(GraphTest, list_digraph_add_n_erase_arcs_4)
ASSERT_TRUE(u2->first_in == NULL);
ASSERT_TRUE(u3->first_in == NULL);
ASSERT_TRUE(a1->next_in == NULL);
-
}
-TEST_F(GraphTest, api_test)
-{
+TEST_F(GraphTest, api_test) {
Digraph graph;
Digraph::Node node = graph.addNode();
diff --git a/unittests/GraphTest.h b/unittests/GraphTest.h
index a71276b..0e18b74 100644
--- a/unittests/GraphTest.h
+++ b/unittests/GraphTest.h
@@ -11,13 +11,11 @@
#include <gtest.h>
-
namespace mcld {
namespace test {
-class GraphTest : public ::testing::Test
-{
-public:
+class GraphTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
GraphTest();
@@ -31,8 +29,7 @@ public:
virtual void TearDown();
};
-} // namespace of test
-} // namespace of mcld
+} // namespace of test
+} // namespace of mcld
#endif
-
diff --git a/unittests/HashTableTest.cpp b/unittests/HashTableTest.cpp
index fe67e95..595b1e1 100644
--- a/unittests/HashTableTest.cpp
+++ b/unittests/HashTableTest.cpp
@@ -8,78 +8,63 @@
//===----------------------------------------------------------------------===//
#include "HashTableTest.h"
-#include <mcld/ADT/HashEntry.h>
-#include <mcld/ADT/HashTable.h>
+#include "mcld/ADT/HashEntry.h"
+#include "mcld/ADT/HashTable.h"
#include <cstdlib>
using namespace std;
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-HashTableTest::HashTableTest()
-{
+HashTableTest::HashTableTest() {
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-HashTableTest::~HashTableTest()
-{
+HashTableTest::~HashTableTest() {
}
// SetUp() will be called immediately before each test.
-void HashTableTest::SetUp()
-{
+void HashTableTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void HashTableTest::TearDown()
-{
+void HashTableTest::TearDown() {
}
//==========================================================================//
// Testcases
//
-struct IntCompare
-{
- bool operator()(int X, int Y) const
- { return (X==Y); }
+struct IntCompare {
+ bool operator()(int X, int Y) const { return (X == Y); }
};
-struct PtrCompare
-{
- bool operator()(const int* X, const int* Y) const
- { return (X==Y); }
+struct PtrCompare {
+ bool operator()(const int* X, const int* Y) const { return (X == Y); }
};
-struct PtrHash
-{
- size_t operator()(const int* pKey) const
- {
- return (unsigned((uintptr_t)pKey) >> 4) ^
- (unsigned((uintptr_t)pKey) >> 9);
+struct PtrHash {
+ size_t operator()(const int* pKey) const {
+ return (unsigned((uintptr_t)pKey) >> 4) ^ (unsigned((uintptr_t)pKey) >> 9);
}
};
-struct IntHash
-{
- size_t operator()(int pKey) const
- { return pKey; }
+struct IntHash {
+ size_t operator()(int pKey) const { return pKey; }
};
-struct IntMod3Hash
-{
- size_t operator()(int pKey) const
- { return pKey % 3; }
+struct IntMod3Hash {
+ size_t operator()(int pKey) const { return pKey % 3; }
};
-TEST_F( HashTableTest, ptr_entry ) {
+TEST_F(HashTableTest, ptr_entry) {
int A = 1;
int* pA = &A;
typedef HashEntry<int*, int, PtrCompare> HashEntryType;
- typedef HashTable<HashEntryType, PtrHash, EntryFactory<HashEntryType> > HashTableTy;
- HashTableTy *hashTable = new HashTableTy(0);
+ typedef HashTable<HashEntryType, PtrHash, EntryFactory<HashEntryType> >
+ HashTableTy;
+ HashTableTy* hashTable = new HashTableTy(0);
bool exist;
HashTableTy::entry_type* entry = 0;
@@ -90,11 +75,11 @@ TEST_F( HashTableTest, ptr_entry ) {
HashTableTy::iterator iter;
iter = hashTable->find(NULL);
- EXPECT_TRUE(iter==hashTable->end());
+ EXPECT_TRUE(iter == hashTable->end());
delete hashTable;
}
-TEST_F( HashTableTest, constructor ) {
+TEST_F(HashTableTest, constructor) {
typedef HashEntry<int, int, IntCompare> HashEntryType;
HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> > hashTable(16);
EXPECT_TRUE(17 == hashTable.numOfBuckets());
@@ -102,10 +87,11 @@ TEST_F( HashTableTest, constructor ) {
EXPECT_TRUE(0 == hashTable.numOfEntries());
}
-TEST_F( HashTableTest, allocattion ) {
+TEST_F(HashTableTest, allocattion) {
typedef HashEntry<int, int, IntCompare> HashEntryType;
- typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> > HashTableTy;
- HashTableTy *hashTable = new HashTableTy(22);
+ typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> >
+ HashTableTy;
+ HashTableTy* hashTable = new HashTableTy(22);
bool exist;
int key = 100;
@@ -119,20 +105,21 @@ TEST_F( HashTableTest, allocattion ) {
delete hashTable;
}
-TEST_F( HashTableTest, alloc100 ) {
+TEST_F(HashTableTest, alloc100) {
typedef HashEntry<int, int, IntCompare> HashEntryType;
- typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> > HashTableTy;
- HashTableTy *hashTable = new HashTableTy(22);
+ typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> >
+ HashTableTy;
+ HashTableTy* hashTable = new HashTableTy(22);
bool exist;
HashTableTy::entry_type* entry = 0;
- for (int key=0; key<100; ++key) {
+ for (int key = 0; key < 100; ++key) {
entry = hashTable->insert(key, exist);
EXPECT_FALSE(hashTable->empty());
EXPECT_FALSE(exist);
EXPECT_FALSE(NULL == entry);
EXPECT_TRUE(key == entry->key());
- entry->setValue(key+10);
+ entry->setValue(key + 10);
}
EXPECT_FALSE(hashTable->empty());
@@ -141,21 +128,22 @@ TEST_F( HashTableTest, alloc100 ) {
delete hashTable;
}
-TEST_F( HashTableTest, erase100 ) {
+TEST_F(HashTableTest, erase100) {
typedef HashEntry<int, int, IntCompare> HashEntryType;
- typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> > HashTableTy;
- HashTableTy *hashTable = new HashTableTy(0);
+ typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> >
+ HashTableTy;
+ HashTableTy* hashTable = new HashTableTy(0);
bool exist;
HashTableTy::entry_type* entry = 0;
- for (unsigned int key=0; key<100; ++key)
+ for (unsigned int key = 0; key < 100; ++key)
entry = hashTable->insert(key, exist);
EXPECT_FALSE(hashTable->empty());
int count;
HashTableTy::iterator iter;
- for (unsigned int key=0; key<100; ++key) {
+ for (unsigned int key = 0; key < 100; ++key) {
count = hashTable->erase(key);
EXPECT_EQ(1, count);
iter = hashTable->find(key);
@@ -166,21 +154,22 @@ TEST_F( HashTableTest, erase100 ) {
delete hashTable;
}
-TEST_F( HashTableTest, clear) {
+TEST_F(HashTableTest, clear) {
typedef HashEntry<int, int, IntCompare> HashEntryType;
- typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> > HashTableTy;
- HashTableTy *hashTable = new HashTableTy(22);
+ typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> >
+ HashTableTy;
+ HashTableTy* hashTable = new HashTableTy(22);
bool exist;
HashTableTy::entry_type* entry = 0;
- for (unsigned int key=0; key<100; ++key) {
+ for (unsigned int key = 0; key < 100; ++key) {
entry = hashTable->insert(key, exist);
}
hashTable->clear();
HashTableTy::iterator iter;
- for (unsigned int key=0; key<100; ++key) {
+ for (unsigned int key = 0; key < 100; ++key) {
iter = hashTable->find(key);
EXPECT_TRUE(iter == hashTable->end());
}
@@ -189,21 +178,22 @@ TEST_F( HashTableTest, clear) {
delete hashTable;
}
-TEST_F( HashTableTest, tombstone ) {
+TEST_F(HashTableTest, tombstone) {
typedef HashEntry<int, int, IntCompare> HashEntryType;
- typedef HashTable<HashEntryType, IntMod3Hash, EntryFactory<HashEntryType> > HashTableTy;
- HashTableTy *hashTable = new HashTableTy();
+ typedef HashTable<HashEntryType, IntMod3Hash, EntryFactory<HashEntryType> >
+ HashTableTy;
+ HashTableTy* hashTable = new HashTableTy();
bool exist;
HashTableTy::entry_type* entry = 0;
- for (unsigned int key=0; key<100; ++key) {
+ for (unsigned int key = 0; key < 100; ++key) {
entry = hashTable->insert(key, exist);
}
EXPECT_FALSE(hashTable->empty());
int count;
HashTableTy::iterator iter;
- for (unsigned int key=0; key<20; ++key) {
+ for (unsigned int key = 0; key < 20; ++key) {
count = hashTable->erase(key);
EXPECT_EQ(1, count);
iter = hashTable->find(key);
@@ -211,12 +201,12 @@ TEST_F( HashTableTest, tombstone ) {
}
EXPECT_TRUE(80 == hashTable->numOfEntries());
- for (unsigned int key=20; key<100; ++key) {
+ for (unsigned int key = 20; key < 100; ++key) {
iter = hashTable->find(key);
EXPECT_TRUE(iter != hashTable->end());
}
- for (unsigned int key=0; key<20; ++key) {
+ for (unsigned int key = 0; key < 20; ++key) {
entry = hashTable->insert(key, exist);
}
EXPECT_TRUE(100 == hashTable->numOfEntries());
@@ -225,66 +215,68 @@ TEST_F( HashTableTest, tombstone ) {
delete hashTable;
}
-TEST_F( HashTableTest, rehash_test ) {
+TEST_F(HashTableTest, rehash_test) {
typedef HashEntry<int, int, IntCompare> HashEntryType;
- typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> > HashTableTy;
- HashTableTy *hashTable = new HashTableTy(0);
+ typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> >
+ HashTableTy;
+ HashTableTy* hashTable = new HashTableTy(0);
bool exist;
HashTableTy::entry_type* entry = 0;
- for (unsigned int key=0; key<400000; ++key) {
+ for (unsigned int key = 0; key < 400000; ++key) {
entry = hashTable->insert(key, exist);
- entry->setValue(key+10);
+ entry->setValue(key + 10);
}
HashTableTy::iterator iter;
- for (int key=0; key<400000; ++key) {
+ for (int key = 0; key < 400000; ++key) {
iter = hashTable->find(key);
- EXPECT_EQ((key+10), iter.getEntry()->value());
+ EXPECT_EQ((key + 10), iter.getEntry()->value());
}
delete hashTable;
}
-TEST_F( HashTableTest, bucket_iterator ) {
+TEST_F(HashTableTest, bucket_iterator) {
typedef HashEntry<int, int, IntCompare> HashEntryType;
- typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> > HashTableTy;
- HashTableTy *hashTable = new HashTableTy(0);
+ typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> >
+ HashTableTy;
+ HashTableTy* hashTable = new HashTableTy(0);
bool exist;
HashTableTy::entry_type* entry = 0;
- for (unsigned int key=0; key<400000; ++key) {
+ for (unsigned int key = 0; key < 400000; ++key) {
entry = hashTable->insert(key, exist);
- entry->setValue(key+10);
+ entry->setValue(key + 10);
}
HashTableTy::iterator iter, iEnd = hashTable->end();
int counter = 0;
for (iter = hashTable->begin(); iter != iEnd; ++iter) {
- EXPECT_EQ(iter.getEntry()->key()+10, iter.getEntry()->value());
+ EXPECT_EQ(iter.getEntry()->key() + 10, iter.getEntry()->value());
++counter;
}
EXPECT_EQ(400000, counter);
delete hashTable;
}
-
-TEST_F( HashTableTest, chain_iterator_single ) {
+TEST_F(HashTableTest, chain_iterator_single) {
typedef HashEntry<int, int, IntCompare> HashEntryType;
- typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> > HashTableTy;
- HashTableTy *hashTable = new HashTableTy();
+ typedef HashTable<HashEntryType, IntHash, EntryFactory<HashEntryType> >
+ HashTableTy;
+ HashTableTy* hashTable = new HashTableTy();
bool exist;
HashTableTy::entry_type* entry = 0;
- for (int key=0; key<16; ++key) {
- entry = hashTable->insert(key*37, exist);
- entry->setValue(key+10);
+ for (int key = 0; key < 16; ++key) {
+ entry = hashTable->insert(key * 37, exist);
+ entry->setValue(key + 10);
}
- for (int key=0; key<16; ++key) {
+ for (int key = 0; key < 16; ++key) {
int counter = 0;
- HashTableTy::chain_iterator iter, iEnd = hashTable->end(key*37);
- for (iter = hashTable->begin(key*37); iter != iEnd; ++iter) {
- EXPECT_EQ(key+10, iter.getEntry()->value());
+ HashTableTy::chain_iterator iter, iEnd = hashTable->end(key * 37);
+ for (iter = hashTable->begin(key * 37); iter != iEnd; ++iter) {
+ EXPECT_EQ(key + 10, iter.getEntry()->value());
++counter;
}
EXPECT_EQ(1, counter);
@@ -292,22 +284,19 @@ TEST_F( HashTableTest, chain_iterator_single ) {
delete hashTable;
}
-struct FixHash
-{
- size_t operator()(int pKey) const {
- return 10;
- }
+struct FixHash {
+ size_t operator()(int pKey) const { return 10; }
};
-
-TEST_F( HashTableTest, chain_iterator_list ) {
+TEST_F(HashTableTest, chain_iterator_list) {
typedef HashEntry<int, int, IntCompare> HashEntryType;
- typedef HashTable<HashEntryType, FixHash, EntryFactory<HashEntryType> > HashTableTy;
- HashTableTy *hashTable = new HashTableTy();
+ typedef HashTable<HashEntryType, FixHash, EntryFactory<HashEntryType> >
+ HashTableTy;
+ HashTableTy* hashTable = new HashTableTy();
bool exist;
HashTableTy::entry_type* entry = 0;
- for (unsigned int key=0; key<16; ++key) {
+ for (unsigned int key = 0; key < 16; ++key) {
entry = hashTable->insert(key, exist);
ASSERT_FALSE(exist);
entry->setValue(key);
diff --git a/unittests/HashTableTest.h b/unittests/HashTableTest.h
index c07c991..dd4739a 100644
--- a/unittests/HashTableTest.h
+++ b/unittests/HashTableTest.h
@@ -12,31 +12,28 @@
#include <gtest.h>
-namespace mcldtest
-{
+namespace mcldtest {
/** \class HashTableTest
* \brief Testcase for HashTable
*
* \see HashTable
*/
-class HashTableTest : public ::testing::Test
-{
-public:
- // Constructor can do set-up work for all test here.
- HashTableTest();
+class HashTableTest : public ::testing::Test {
+ public:
+ // Constructor can do set-up work for all test here.
+ HashTableTest();
- // Destructor can do clean-up work that doesn't throw exceptions here.
- virtual ~HashTableTest();
+ // Destructor can do clean-up work that doesn't throw exceptions here.
+ virtual ~HashTableTest();
- // SetUp() will be called immediately before each test.
- virtual void SetUp();
+ // SetUp() will be called immediately before each test.
+ virtual void SetUp();
- // TearDown() will be called immediately after each test.
- virtual void TearDown();
+ // TearDown() will be called immediately after each test.
+ virtual void TearDown();
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/InputTreeTest.cpp b/unittests/InputTreeTest.cpp
index 6af81d8..d8951b9 100644
--- a/unittests/InputTreeTest.cpp
+++ b/unittests/InputTreeTest.cpp
@@ -11,36 +11,29 @@
#include <vector>
#include <iostream>
-#include <mcld/InputTree.h>
-#include <mcld/MC/InputFactory.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/MC/InputBuilder.h>
-#include <mcld/MC/FileAction.h>
-#include <mcld/MC/CommandAction.h>
+#include "mcld/InputTree.h"
+#include "mcld/MC/InputFactory.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/MC/InputBuilder.h"
+#include "mcld/MC/FileAction.h"
+#include "mcld/MC/CommandAction.h"
using namespace mcld;
using namespace mcld::test;
-
// Constructor can do set-up work for all test here.
-InputTreeTest::InputTreeTest()
- : m_MemFactory(10), m_ContextFactory(4) {
-
+InputTreeTest::InputTreeTest() : m_MemFactory(10), m_ContextFactory(4) {
// create testee. modify it if need
m_pConfig = new mcld::LinkerConfig("arm-none-linux-gnueabi");
- m_pAlloc = new mcld::InputFactory(10, *m_pConfig);
- m_pBuilder = new mcld::InputBuilder(*m_pConfig,
- *m_pAlloc,
- m_ContextFactory,
- m_MemFactory,
- false);
+ m_pAlloc = new mcld::InputFactory(10, *m_pConfig);
+ m_pBuilder = new mcld::InputBuilder(
+ *m_pConfig, *m_pAlloc, m_ContextFactory, m_MemFactory, false);
m_pTestee = new mcld::InputTree();
m_pBuilder->setCurrentTree(*m_pTestee);
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-InputTreeTest::~InputTreeTest()
-{
+InputTreeTest::~InputTreeTest() {
delete m_pTestee;
delete m_pAlloc;
delete m_pBuilder;
@@ -48,20 +41,17 @@ InputTreeTest::~InputTreeTest()
}
// SetUp() will be called immediately before each test.
-void InputTreeTest::SetUp()
-{
+void InputTreeTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void InputTreeTest::TearDown()
-{
+void InputTreeTest::TearDown() {
}
//===----------------------------------------------------------------------===//
// Testcases
//
-TEST_F( InputTreeTest, Basic_operation ) {
-
+TEST_F(InputTreeTest, Basic_operation) {
std::vector<InputAction*> actions;
size_t position = 0;
@@ -96,22 +86,20 @@ TEST_F( InputTreeTest, Basic_operation ) {
ASSERT_FALSE(isGroup(node));
ASSERT_FALSE(isGroup(const_node2));
ASSERT_FALSE(m_pAlloc->empty());
- ASSERT_FALSE(m_pAlloc->size()==0);
+ ASSERT_FALSE(m_pAlloc->size() == 0);
- ASSERT_TRUE(m_pTestee->size()==3);
+ ASSERT_TRUE(m_pTestee->size() == 3);
}
-TEST_F( InputTreeTest, forLoop_TEST ) {
+TEST_F(InputTreeTest, forLoop_TEST) {
InputTree::iterator node = m_pTestee->root();
-
Input* input = m_pAlloc->produce("FileSpec", "path1");
m_pTestee->insert<InputTree::Inclusive>(node, *input);
InputTree::const_iterator const_node = node;
--node;
- for(int i=0 ; i<100 ; ++i)
- {
+ for (int i = 0; i < 100; ++i) {
Input* input = m_pAlloc->produce("FileSpec", "path1");
m_pTestee->insert<InputTree::Inclusive>(node, *input);
++node;
@@ -123,16 +111,15 @@ TEST_F( InputTreeTest, forLoop_TEST ) {
ASSERT_FALSE(node.isRoot());
ASSERT_TRUE(isGroup(node));
ASSERT_FALSE(m_pAlloc->empty());
- ASSERT_FALSE(m_pAlloc->size()==100);
+ ASSERT_FALSE(m_pAlloc->size() == 100);
- ASSERT_TRUE(m_pTestee->size()==102);
+ ASSERT_TRUE(m_pTestee->size() == 102);
}
-TEST_F( InputTreeTest, Nesting_Case ) {
+TEST_F(InputTreeTest, Nesting_Case) {
InputTree::iterator node = m_pTestee->root();
- for(int i=0 ; i<50 ; ++i)
- {
+ for (int i = 0; i < 50; ++i) {
m_pTestee->enterGroup(node, InputTree::Downward);
--node;
@@ -144,13 +131,11 @@ TEST_F( InputTreeTest, Nesting_Case ) {
ASSERT_FALSE(node.isRoot());
ASSERT_FALSE(isGroup(node));
ASSERT_FALSE(m_pAlloc->empty());
- ASSERT_TRUE(m_pAlloc->size()==50);
- ASSERT_TRUE(m_pTestee->size()==100);
+ ASSERT_TRUE(m_pAlloc->size() == 50);
+ ASSERT_TRUE(m_pTestee->size() == 100);
}
-TEST_F( InputTreeTest, DFSIterator_BasicTraversal)
-{
-
+TEST_F(InputTreeTest, DFSIterator_BasicTraversal) {
InputTree::iterator node = m_pTestee->root();
Input* input = m_pAlloc->produce("111", "/");
m_pTestee->insert<InputTree::Inclusive>(node, *input);
@@ -176,6 +161,5 @@ TEST_F( InputTreeTest, DFSIterator_BasicTraversal)
++dfs_it;
ASSERT_STREQ("10", (**dfs_it).name().c_str());
++dfs_it;
- ASSERT_TRUE(dfs_it == dfs_end);
+ ASSERT_TRUE(dfs_it == dfs_end);
}
-
diff --git a/unittests/InputTreeTest.h b/unittests/InputTreeTest.h
index 31be6fd..dc522d8 100644
--- a/unittests/InputTreeTest.h
+++ b/unittests/InputTreeTest.h
@@ -10,8 +10,8 @@
#define UNITTESTS_INPUTTREE_TEST_H
#include <gtest.h>
-#include <mcld/MC/ContextFactory.h>
-#include <mcld/Support/MemoryAreaFactory.h>
+#include "mcld/MC/ContextFactory.h"
+#include "mcld/Support/MemoryAreaFactory.h"
namespace mcld {
@@ -27,9 +27,8 @@ namespace test {
*
* \see InputTree
*/
-class InputTreeTest : public ::testing::Test
-{
-public:
+class InputTreeTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
InputTreeTest();
@@ -42,7 +41,7 @@ public:
// TearDown() will be called immediately after each test.
virtual void TearDown();
-protected:
+ protected:
mcld::LinkerConfig* m_pConfig;
mcld::InputFactory* m_pAlloc;
@@ -53,8 +52,7 @@ protected:
mcld::InputTree* m_pTestee;
};
-} // namespace of test
-} // namespace of mcld
+} // namespace of test
+} // namespace of mcld
#endif
-
diff --git a/unittests/LDSymbolTest.cpp b/unittests/LDSymbolTest.cpp
index e0e681d..e2479e7 100644
--- a/unittests/LDSymbolTest.cpp
+++ b/unittests/LDSymbolTest.cpp
@@ -7,36 +7,30 @@
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/LDSymbol.h>
+#include "mcld/LD/LDSymbol.h"
#include "LDSymbolTest.h"
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-LDSymbolTest::LDSymbolTest()
-{
+LDSymbolTest::LDSymbolTest() {
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-LDSymbolTest::~LDSymbolTest()
-{
+LDSymbolTest::~LDSymbolTest() {
}
// SetUp() will be called immediately before each test.
-void LDSymbolTest::SetUp()
-{
+void LDSymbolTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void LDSymbolTest::TearDown()
-{
+void LDSymbolTest::TearDown() {
}
//==========================================================================//
// Testcases
//
-TEST_F( LDSymbolTest, produce ) {
+TEST_F(LDSymbolTest, produce) {
}
-
diff --git a/unittests/LDSymbolTest.h b/unittests/LDSymbolTest.h
index 43d6b8a..42d7fb0 100644
--- a/unittests/LDSymbolTest.h
+++ b/unittests/LDSymbolTest.h
@@ -12,20 +12,17 @@
#include <gtest.h>
-namespace mcld
-{
+namespace mcld {
class LDSymbol;
-} // namespace for mcld
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
/** \class LDSymbolTest
*/
-class LDSymbolTest : public ::testing::Test
-{
-public:
+class LDSymbolTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
LDSymbolTest();
@@ -37,10 +34,8 @@ public:
// TearDown() will be called immediately after each test.
virtual void TearDown();
-
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/LEB128Test.cpp b/unittests/LEB128Test.cpp
index b310262..97aa7d9 100644
--- a/unittests/LEB128Test.cpp
+++ b/unittests/LEB128Test.cpp
@@ -6,46 +6,41 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/LEB128.h>
+#include "mcld/Support/LEB128.h"
#include "LEB128Test.h"
-#include <mcld/Support/SystemUtils.h>
+#include "mcld/Support/SystemUtils.h"
#include <ctime>
#include <cstdlib>
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-LEB128Test::LEB128Test()
-{
- // Initialize the seed for random number generator using during the tests.
+LEB128Test::LEB128Test() {
+ // Initialize the seed for random number generator using during the tests.
sys::SetRandomSeed(::time(NULL));
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-LEB128Test::~LEB128Test()
-{
+LEB128Test::~LEB128Test() {
}
// SetUp() will be called immediately before each test.
-void LEB128Test::SetUp()
-{
+void LEB128Test::SetUp() {
}
// TearDown() will be called immediately after each test.
-void LEB128Test::TearDown()
-{
+void LEB128Test::TearDown() {
}
//==========================================================================//
// Testcases
//
-TEST_F( LEB128Test, EncodeULEB_Example_from_Dwarf3_Figure22_Using_32bits) {
+TEST_F(LEB128Test, EncodeULEB_Example_from_Dwarf3_Figure22_Using_32bits) {
leb128::ByteType buffer[2];
- leb128::ByteType *result;
+ leb128::ByteType* result;
size_t size;
result = buffer;
@@ -89,9 +84,9 @@ TEST_F( LEB128Test, EncodeULEB_Example_from_Dwarf3_Figure22_Using_32bits) {
ASSERT_TRUE(size == 2);
}
-TEST_F( LEB128Test, EncodeULEB_Example_from_Dwarf3_Figure22_Using_64bits) {
+TEST_F(LEB128Test, EncodeULEB_Example_from_Dwarf3_Figure22_Using_64bits) {
leb128::ByteType buffer[2];
- leb128::ByteType *result;
+ leb128::ByteType* result;
size_t size;
result = buffer;
@@ -135,9 +130,9 @@ TEST_F( LEB128Test, EncodeULEB_Example_from_Dwarf3_Figure22_Using_64bits) {
ASSERT_TRUE(size == 2);
}
-TEST_F( LEB128Test, EncodeSLEB_Example_from_Dwarf3_Figure22) {
+TEST_F(LEB128Test, EncodeSLEB_Example_from_Dwarf3_Figure22) {
leb128::ByteType buffer[2];
- leb128::ByteType *result;
+ leb128::ByteType* result;
size_t size;
result = buffer;
@@ -195,7 +190,7 @@ TEST_F( LEB128Test, EncodeSLEB_Example_from_Dwarf3_Figure22) {
ASSERT_TRUE(size == 2);
}
-TEST_F( LEB128Test, DecodeULEB_Example_from_Dwarf3_Figure22) {
+TEST_F(LEB128Test, DecodeULEB_Example_from_Dwarf3_Figure22) {
leb128::ByteType buffer[2];
size_t size;
@@ -228,10 +223,9 @@ TEST_F( LEB128Test, DecodeULEB_Example_from_Dwarf3_Figure22) {
buffer[1] = 100;
ASSERT_TRUE(leb128::decode<uint64_t>(buffer, size) == 12857);
ASSERT_TRUE(size == 2);
-
}
-TEST_F( LEB128Test, DecodeSLEB_Example_from_Dwarf3_Figure22) {
+TEST_F(LEB128Test, DecodeSLEB_Example_from_Dwarf3_Figure22) {
leb128::ByteType buffer[2];
size_t size;
@@ -276,9 +270,9 @@ TEST_F( LEB128Test, DecodeSLEB_Example_from_Dwarf3_Figure22) {
ASSERT_TRUE(size == 2);
}
-TEST_F( LEB128Test, DecodeULEB_Tests_Found_in_Android_dalvik_dx) {
+TEST_F(LEB128Test, DecodeULEB_Tests_Found_in_Android_dalvik_dx) {
leb128::ByteType content[2];
- const leb128::ByteType *p;
+ const leb128::ByteType* p;
content[0] = 0;
p = content;
@@ -297,9 +291,9 @@ TEST_F( LEB128Test, DecodeULEB_Tests_Found_in_Android_dalvik_dx) {
ASSERT_EQ(p, content + 2);
}
-TEST_F( LEB128Test, EncodeULEB_Tests_Found_in_Android_dalvik_dx) {
+TEST_F(LEB128Test, EncodeULEB_Tests_Found_in_Android_dalvik_dx) {
leb128::ByteType buffer[5];
- leb128::ByteType *result;
+ leb128::ByteType* result;
size_t size;
result = buffer;
@@ -389,9 +383,9 @@ TEST_F( LEB128Test, EncodeULEB_Tests_Found_in_Android_dalvik_dx) {
ASSERT_TRUE(size == 5);
}
-TEST_F( LEB128Test, DecodeSLEB_Tests_Found_in_Android_dalvik_dx) {
+TEST_F(LEB128Test, DecodeSLEB_Tests_Found_in_Android_dalvik_dx) {
leb128::ByteType content[2];
- const leb128::ByteType *p;
+ const leb128::ByteType* p;
content[0] = 0;
p = content;
@@ -414,9 +408,9 @@ TEST_F( LEB128Test, DecodeSLEB_Tests_Found_in_Android_dalvik_dx) {
ASSERT_EQ(p, content + 1);
}
-TEST_F( LEB128Test, EncodeSLEB_Tests_Found_in_Android_dalvik_dx) {
+TEST_F(LEB128Test, EncodeSLEB_Tests_Found_in_Android_dalvik_dx) {
leb128::ByteType buffer[5];
- leb128::ByteType *result;
+ leb128::ByteType* result;
size_t size;
result = buffer;
@@ -456,14 +450,14 @@ TEST_F( LEB128Test, EncodeSLEB_Tests_Found_in_Android_dalvik_dx) {
ASSERT_TRUE(size == 1);
}
-TEST_F( LEB128Test, Random_Regression_Test) {
+TEST_F(LEB128Test, Random_Regression_Test) {
leb128::ByteType buffer[9];
for (int i = 0; i < 20; i++) {
unsigned long int value = sys::GetRandomNum();
uint64_t value2 = value * value;
int64_t value3 = value * value;
- leb128::ByteType *result;
+ leb128::ByteType* result;
size_t encode_size, decode_size;
// Test encode<uint32_t> and decode<uint64_t> on value
@@ -496,9 +490,9 @@ TEST_F( LEB128Test, Random_Regression_Test) {
}
}
-TEST_F( LEB128Test, Other_Test) {
+TEST_F(LEB128Test, Other_Test) {
leb128::ByteType buffer[5];
- leb128::ByteType *result;
+ leb128::ByteType* result;
size_t size;
result = buffer;
@@ -512,9 +506,9 @@ TEST_F( LEB128Test, Other_Test) {
ASSERT_TRUE(size == 3);
}
-TEST_F( LEB128Test, Type_Conversion_Test) {
+TEST_F(LEB128Test, Type_Conversion_Test) {
char buffer[5];
- char *result;
+ char* result;
size_t size;
result = buffer;
@@ -527,7 +521,7 @@ TEST_F( LEB128Test, Type_Conversion_Test) {
ASSERT_TRUE(leb128::decode<uint64_t>(buffer, size) == 154452);
ASSERT_TRUE(size == 3);
- const char *p = buffer;
+ const char* p = buffer;
ASSERT_TRUE(leb128::decode<uint64_t>(p) == 154452);
ASSERT_TRUE(p == (buffer + 3));
}
diff --git a/unittests/LEB128Test.h b/unittests/LEB128Test.h
index f0a87e3..07febff 100644
--- a/unittests/LEB128Test.h
+++ b/unittests/LEB128Test.h
@@ -11,31 +11,28 @@
#include <gtest.h>
-namespace mcldtest
-{
+namespace mcldtest {
/** \class LEB128Test
* \brief
*
* \see LEB
*/
-class LEB128Test : public ::testing::Test
-{
-public:
- // Constructor can do set-up work for all test here.
- LEB128Test();
+class LEB128Test : public ::testing::Test {
+ public:
+ // Constructor can do set-up work for all test here.
+ LEB128Test();
- // Destructor can do clean-up work that doesn't throw exceptions here.
- virtual ~LEB128Test();
+ // Destructor can do clean-up work that doesn't throw exceptions here.
+ virtual ~LEB128Test();
- // SetUp() will be called immediately before each test.
- virtual void SetUp();
+ // SetUp() will be called immediately before each test.
+ virtual void SetUp();
- // TearDown() will be called immediately after each test.
- virtual void TearDown();
+ // TearDown() will be called immediately after each test.
+ virtual void TearDown();
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/LinearAllocatorTest.cpp b/unittests/LinearAllocatorTest.cpp
index d38684a..bc8092e 100644
--- a/unittests/LinearAllocatorTest.cpp
+++ b/unittests/LinearAllocatorTest.cpp
@@ -7,133 +7,127 @@
//
//===----------------------------------------------------------------------===//
#include "LinearAllocatorTest.h"
-#include <mcld/Support/Allocators.h>
+#include "mcld/Support/Allocators.h"
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-LinearAllocatorTest::LinearAllocatorTest()
-{
- // create testee. modify it if need
- m_pTestee = new LinearAllocator<Data, CHUNK_SIZE>();
+LinearAllocatorTest::LinearAllocatorTest() {
+ // create testee. modify it if need
+ m_pTestee = new LinearAllocator<Data, CHUNK_SIZE>();
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-LinearAllocatorTest::~LinearAllocatorTest()
-{
- delete m_pTestee;
+LinearAllocatorTest::~LinearAllocatorTest() {
+ delete m_pTestee;
}
// SetUp() will be called immediately before each test.
-void LinearAllocatorTest::SetUp()
-{
+void LinearAllocatorTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void LinearAllocatorTest::TearDown()
-{
+void LinearAllocatorTest::TearDown() {
}
//==========================================================================//
// Testcases
//
-TEST_F( LinearAllocatorTest, allocateN ) {
- Data* pointer = m_pTestee->allocate(10);
- ASSERT_FALSE(0 == pointer);
- ASSERT_EQ(CHUNK_SIZE, m_pTestee->max_size());
- ASSERT_FALSE(m_pTestee->empty());
+TEST_F(LinearAllocatorTest, allocateN) {
+ Data* pointer = m_pTestee->allocate(10);
+ ASSERT_FALSE(0 == pointer);
+ ASSERT_EQ(CHUNK_SIZE, m_pTestee->max_size());
+ ASSERT_FALSE(m_pTestee->empty());
}
-TEST_F( LinearAllocatorTest, allocate ) {
- Data* pointer = m_pTestee->allocate();
- ASSERT_FALSE(0 == pointer);
- ASSERT_EQ(CHUNK_SIZE, m_pTestee->max_size());
- ASSERT_FALSE(m_pTestee->empty());
+TEST_F(LinearAllocatorTest, allocate) {
+ Data* pointer = m_pTestee->allocate();
+ ASSERT_FALSE(0 == pointer);
+ ASSERT_EQ(CHUNK_SIZE, m_pTestee->max_size());
+ ASSERT_FALSE(m_pTestee->empty());
}
-TEST_F( LinearAllocatorTest, allocateOver ) {
- Data* pointer = m_pTestee->allocate(CHUNK_SIZE+1);
- ASSERT_TRUE(0 == pointer);
- ASSERT_TRUE(0 == m_pTestee->max_size());
- ASSERT_TRUE(m_pTestee->empty());
+TEST_F(LinearAllocatorTest, allocateOver) {
+ Data* pointer = m_pTestee->allocate(CHUNK_SIZE + 1);
+ ASSERT_TRUE(0 == pointer);
+ ASSERT_TRUE(0 == m_pTestee->max_size());
+ ASSERT_TRUE(m_pTestee->empty());
}
-TEST_F( LinearAllocatorTest, alloc_construct ) {
- Data* pointer = m_pTestee->allocate();
- m_pTestee->construct(pointer);
- ASSERT_TRUE(1 == pointer->one);
- ASSERT_TRUE(2 == pointer->two);
- ASSERT_TRUE(3 == pointer->three);
- ASSERT_TRUE(4 == pointer->four);
+TEST_F(LinearAllocatorTest, alloc_construct) {
+ Data* pointer = m_pTestee->allocate();
+ m_pTestee->construct(pointer);
+ ASSERT_TRUE(1 == pointer->one);
+ ASSERT_TRUE(2 == pointer->two);
+ ASSERT_TRUE(3 == pointer->three);
+ ASSERT_TRUE(4 == pointer->four);
}
-TEST_F( LinearAllocatorTest, alloc_constructCopy ) {
- Data* pointer = m_pTestee->allocate();
- Data data(7, 7, 7, 7);
- m_pTestee->construct(pointer, data);
-
- ASSERT_TRUE(7 == pointer->one);
- ASSERT_TRUE(7 == pointer->two);
- ASSERT_TRUE(7 == pointer->three);
- ASSERT_TRUE(7 == pointer->four);
-}
+TEST_F(LinearAllocatorTest, alloc_constructCopy) {
+ Data* pointer = m_pTestee->allocate();
+ Data data(7, 7, 7, 7);
+ m_pTestee->construct(pointer, data);
-TEST_F( LinearAllocatorTest, allocN_construct ) {
- Data* pointer = m_pTestee->allocate(10);
- m_pTestee->construct(pointer);
- ASSERT_TRUE(1 == pointer->one);
- ASSERT_TRUE(2 == pointer->two);
- ASSERT_TRUE(3 == pointer->three);
- ASSERT_TRUE(4 == pointer->four);
+ ASSERT_TRUE(7 == pointer->one);
+ ASSERT_TRUE(7 == pointer->two);
+ ASSERT_TRUE(7 == pointer->three);
+ ASSERT_TRUE(7 == pointer->four);
}
-TEST_F( LinearAllocatorTest, allocN_constructCopy ) {
- Data* pointer = m_pTestee->allocate(10);
- Data data(7, 7, 7, 7);
- m_pTestee->construct(pointer, data);
-
- ASSERT_TRUE(7 == pointer->one);
- ASSERT_TRUE(7 == pointer->two);
- ASSERT_TRUE(7 == pointer->three);
- ASSERT_TRUE(7 == pointer->four);
+TEST_F(LinearAllocatorTest, allocN_construct) {
+ Data* pointer = m_pTestee->allocate(10);
+ m_pTestee->construct(pointer);
+ ASSERT_TRUE(1 == pointer->one);
+ ASSERT_TRUE(2 == pointer->two);
+ ASSERT_TRUE(3 == pointer->three);
+ ASSERT_TRUE(4 == pointer->four);
}
-TEST_F( LinearAllocatorTest, multi_alloc_ctor_iterate ) {
- for (int i=0; i<101; ++i) {
- Data* pointer = m_pTestee->allocate();
- m_pTestee->construct(pointer);
- pointer->one = i;
- }
-/**
- Alloc::iterator data, dEnd = m_pTestee->end();
- int counter = 0;
- for (data=m_pTestee->begin(); data!=dEnd; ++data) {
- ASSERT_EQ(counter, (*data).one);
- ++counter;
- }
-**/
+TEST_F(LinearAllocatorTest, allocN_constructCopy) {
+ Data* pointer = m_pTestee->allocate(10);
+ Data data(7, 7, 7, 7);
+ m_pTestee->construct(pointer, data);
+
+ ASSERT_TRUE(7 == pointer->one);
+ ASSERT_TRUE(7 == pointer->two);
+ ASSERT_TRUE(7 == pointer->three);
+ ASSERT_TRUE(7 == pointer->four);
}
-TEST_F( LinearAllocatorTest, multi_allocN_ctor_iterate ) {
- int counter = 0;
- for (int i=0; i<10000; ++i) {
- Data* pointer = m_pTestee->allocate(10);
- for (int j=0; j<10; ++j) {
- m_pTestee->construct(pointer);
- pointer->one = counter;
- ++pointer;
- ++counter;
- }
- }
-/**
- Alloc::iterator data, dEnd = m_pTestee->end();
- counter = 0;
- for (data=m_pTestee->begin(); data!=dEnd; ++data) {
- ASSERT_EQ(counter, (*data).one);
- ++counter;
- }
-**/
+TEST_F(LinearAllocatorTest, multi_alloc_ctor_iterate) {
+ for (int i = 0; i < 101; ++i) {
+ Data* pointer = m_pTestee->allocate();
+ m_pTestee->construct(pointer);
+ pointer->one = i;
+ }
+ /**
+ Alloc::iterator data, dEnd = m_pTestee->end();
+ int counter = 0;
+ for (data=m_pTestee->begin(); data!=dEnd; ++data) {
+ ASSERT_EQ(counter, (*data).one);
+ ++counter;
+ }
+ **/
}
+TEST_F(LinearAllocatorTest, multi_allocN_ctor_iterate) {
+ int counter = 0;
+ for (int i = 0; i < 10000; ++i) {
+ Data* pointer = m_pTestee->allocate(10);
+ for (int j = 0; j < 10; ++j) {
+ m_pTestee->construct(pointer);
+ pointer->one = counter;
+ ++pointer;
+ ++counter;
+ }
+ }
+ /**
+ Alloc::iterator data, dEnd = m_pTestee->end();
+ counter = 0;
+ for (data=m_pTestee->begin(); data!=dEnd; ++data) {
+ ASSERT_EQ(counter, (*data).one);
+ ++counter;
+ }
+ **/
+}
diff --git a/unittests/LinearAllocatorTest.h b/unittests/LinearAllocatorTest.h
index 24b8715..fd9db10 100644
--- a/unittests/LinearAllocatorTest.h
+++ b/unittests/LinearAllocatorTest.h
@@ -12,64 +12,62 @@
#include <gtest.h>
#include "mcld/Support/Allocators.h"
-namespace mcldtest
-{
+namespace mcldtest {
/** \class LinearAllocatorTest
* \brief The testcase for LinearAllocator
*
* \see LinearAllocator
*/
-class LinearAllocatorTest : public ::testing::Test
-{
-public:
- struct Data {
- Data()
- : one(1), two(2), three(3), four(4)
- { }
+class LinearAllocatorTest : public ::testing::Test {
+ public:
+ struct Data {
+ Data() : one(1), two(2), three(3), four(4) {}
- Data( unsigned int pOne, unsigned int pTwo, unsigned char pThree, unsigned char pFour)
- {
- one = pOne;
- two = pTwo;
- three = pThree;
- four = pFour;
- }
+ Data(unsigned int pOne,
+ unsigned int pTwo,
+ unsigned char pThree,
+ unsigned char pFour) {
+ one = pOne;
+ two = pTwo;
+ three = pThree;
+ four = pFour;
+ }
- ~Data()
- {
- one = -1;
- two = -2;
- three = -3;
- four = -4;
- }
+ ~Data() {
+ one = -1;
+ two = -2;
+ three = -3;
+ four = -4;
+ }
- unsigned int one;
- unsigned int two;
- unsigned char three;
- unsigned char four;
- };
-public:
- // Constructor can do set-up work for all test here.
- LinearAllocatorTest();
+ unsigned int one;
+ unsigned int two;
+ unsigned char three;
+ unsigned char four;
+ };
- // Destructor can do clean-up work that doesn't throw exceptions here.
- virtual ~LinearAllocatorTest();
+ public:
+ // Constructor can do set-up work for all test here.
+ LinearAllocatorTest();
- // SetUp() will be called immediately before each test.
- virtual void SetUp();
+ // Destructor can do clean-up work that doesn't throw exceptions here.
+ virtual ~LinearAllocatorTest();
- // TearDown() will be called immediately after each test.
- virtual void TearDown();
+ // SetUp() will be called immediately before each test.
+ virtual void SetUp();
-protected:
- enum TemplateArgsType { CHUNK_SIZE = 32 };
- typedef mcld::LinearAllocator<Data, CHUNK_SIZE> Alloc;
-protected:
- Alloc* m_pTestee;
+ // TearDown() will be called immediately after each test.
+ virtual void TearDown();
+
+ protected:
+ enum TemplateArgsType { CHUNK_SIZE = 32 };
+ typedef mcld::LinearAllocator<Data, CHUNK_SIZE> Alloc;
+
+ protected:
+ Alloc* m_pTestee;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/LinkerTest.cpp b/unittests/LinkerTest.cpp
index f9d3224..2af4913 100644
--- a/unittests/LinkerTest.cpp
+++ b/unittests/LinkerTest.cpp
@@ -8,15 +8,15 @@
//===----------------------------------------------------------------------===//
#include "LinkerTest.h"
-#include <mcld/Environment.h>
-#include <mcld/Module.h>
-#include <mcld/InputTree.h>
-#include <mcld/IRBuilder.h>
-#include <mcld/Linker.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LinkerScript.h>
+#include "mcld/Environment.h"
+#include "mcld/Module.h"
+#include "mcld/InputTree.h"
+#include "mcld/IRBuilder.h"
+#include "mcld/Linker.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LinkerScript.h"
-#include <mcld/Support/Path.h>
+#include "mcld/Support/Path.h"
#include <llvm/Support/ELF.h>
@@ -24,32 +24,26 @@ using namespace mcld;
using namespace mcld::test;
using namespace mcld::sys::fs;
-
// Constructor can do set-up work for all test here.
-LinkerTest::LinkerTest()
-{
+LinkerTest::LinkerTest() {
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-LinkerTest::~LinkerTest()
-{
+LinkerTest::~LinkerTest() {
}
// SetUp() will be called immediately before each test.
-void LinkerTest::SetUp()
-{
+void LinkerTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void LinkerTest::TearDown()
-{
+void LinkerTest::TearDown() {
}
//===----------------------------------------------------------------------===//
// Testcases
//===----------------------------------------------------------------------===//
-TEST_F( LinkerTest, set_up_n_clean_up) {
-
+TEST_F(LinkerTest, set_up_n_clean_up) {
Initialize();
LinkerConfig config("arm-none-linux-gnueabi");
LinkerScript script;
@@ -77,8 +71,7 @@ TEST_F( LinkerTest, set_up_n_clean_up) {
// -lm -llog -ljnigraphics -lc
// %p/../../../libs/ARM/Android/android-14/crtend_so.o
// -o libplasma.so
-TEST_F( LinkerTest, plasma) {
-
+TEST_F(LinkerTest, plasma) {
Initialize();
Linker linker;
LinkerScript script;
@@ -124,7 +117,7 @@ TEST_F( LinkerTest, plasma) {
builder.ReadInput("crtend", crtend);
if (linker.link(module, builder)) {
- linker.emit(module, "libplasma.so"); ///< -o libplasma.so
+ linker.emit(module, "libplasma.so"); ///< -o libplasma.so
}
Finalize();
@@ -132,11 +125,11 @@ TEST_F( LinkerTest, plasma) {
// The outputs generated without -Bsymbolic usually have more relocation
// entries than the outputs generated with -Bsymbolic. This testcase generates
-// output with -Bsymbolic first, then generate the same output without -Bsymbolic.
+// output with -Bsymbolic first, then generate the same output without
+// -Bsymbolic.
// By this way, we can make sure symbols and relocations are cleaned between
// two linkings.
-TEST_F( LinkerTest, plasma_twice) {
-
+TEST_F(LinkerTest, plasma_twice) {
Initialize();
Linker linker;
@@ -154,8 +147,9 @@ TEST_F( LinkerTest, plasma_twice) {
linker.emulate(script1, config1);
config1.setCodeGenType(LinkerConfig::DynObj); ///< --shared
- config1.options().setSOName("libplasma.once.so"); ///< --soname=libplasma.twice.so
- config1.options().setBsymbolic(false); ///< -Bsymbolic
+ config1.options().setSOName(
+ "libplasma.once.so"); ///< --soname=libplasma.twice.so
+ config1.options().setBsymbolic(false); ///< -Bsymbolic
Module module1("libplasma.once.so", script1);
IRBuilder builder1(module1, config1);
@@ -182,7 +176,7 @@ TEST_F( LinkerTest, plasma_twice) {
builder1.ReadInput("crtend", crtend);
if (linker.link(module1, builder1)) {
- linker.emit(module1, "libplasma.once.so"); ///< -o libplasma.so
+ linker.emit(module1, "libplasma.once.so"); ///< -o libplasma.so
}
Finalize();
@@ -203,8 +197,9 @@ TEST_F( LinkerTest, plasma_twice) {
linker.emulate(script2, config2);
config2.setCodeGenType(LinkerConfig::DynObj); ///< --shared
- config2.options().setSOName("libplasma.twice.so"); ///< --soname=libplasma.twice.exe
- config2.options().setBsymbolic(); ///< -Bsymbolic
+ config2.options().setSOName(
+ "libplasma.twice.so"); ///< --soname=libplasma.twice.exe
+ config2.options().setBsymbolic(); ///< -Bsymbolic
Module module2("libplasma.so", script2);
IRBuilder builder2(module2, config2);
@@ -225,15 +220,14 @@ TEST_F( LinkerTest, plasma_twice) {
builder2.ReadInput("crtend", crtend);
if (linker.link(module2, builder2)) {
- linker.emit(module2, "libplasma.twice.so"); ///< -o libplasma.exe
+ linker.emit(module2, "libplasma.twice.so"); ///< -o libplasma.exe
}
Finalize();
}
// This testcase put IRBuilder in the heap
-TEST_F( LinkerTest, plasma_twice_irbuilder_heap) {
-
+TEST_F(LinkerTest, plasma_twice_irbuilder_heap) {
Initialize();
Linker linker;
@@ -251,11 +245,12 @@ TEST_F( LinkerTest, plasma_twice_irbuilder_heap) {
linker.emulate(script1, config1);
config1.setCodeGenType(LinkerConfig::DynObj); ///< --shared
- config1.options().setSOName("libplasma.once.so"); ///< --soname=libplasma.twice.so
- config1.options().setBsymbolic(false); ///< -Bsymbolic
+ config1.options().setSOName(
+ "libplasma.once.so"); ///< --soname=libplasma.twice.so
+ config1.options().setBsymbolic(false); ///< -Bsymbolic
Module module1("libplasma.once.so", script1);
- IRBuilder *builder1 = new IRBuilder(module1, config1);
+ IRBuilder* builder1 = new IRBuilder(module1, config1);
/// ${TOPDIR}/test/libs/ARM/Android/android-14/crtbegin_so.o
Path crtbegin(search_dir);
@@ -279,7 +274,7 @@ TEST_F( LinkerTest, plasma_twice_irbuilder_heap) {
builder1->ReadInput("crtend", crtend);
if (linker.link(module1, *builder1)) {
- linker.emit(module1, "libplasma.once.so"); ///< -o libplasma.so
+ linker.emit(module1, "libplasma.once.so"); ///< -o libplasma.so
}
// Can not delete builder until emit the output. Dynamic string table
@@ -305,8 +300,9 @@ TEST_F( LinkerTest, plasma_twice_irbuilder_heap) {
linker.emulate(script2, config2);
config2.setCodeGenType(LinkerConfig::DynObj); ///< --shared
- config2.options().setSOName("libplasma.twice.so"); ///< --soname=libplasma.twice.exe
- config2.options().setBsymbolic(); ///< -Bsymbolic
+ config2.options().setSOName(
+ "libplasma.twice.so"); ///< --soname=libplasma.twice.exe
+ config2.options().setBsymbolic(); ///< -Bsymbolic
Module module2("libplasma.so", script2);
IRBuilder* builder2 = new IRBuilder(module2, config2);
@@ -327,7 +323,7 @@ TEST_F( LinkerTest, plasma_twice_irbuilder_heap) {
builder2->ReadInput("crtend", crtend);
if (linker.link(module2, *builder2)) {
- linker.emit(module2, "libplasma.twice.so"); ///< -o libplasma.exe
+ linker.emit(module2, "libplasma.twice.so"); ///< -o libplasma.exe
}
delete builder2;
@@ -336,8 +332,7 @@ TEST_F( LinkerTest, plasma_twice_irbuilder_heap) {
// %MCLinker --shared -soname=libgotplt.so -mtriple arm-none-linux-gnueabi
// gotplt.o -o libgotplt.so
-TEST_F( LinkerTest, plasma_object) {
-
+TEST_F(LinkerTest, plasma_object) {
Initialize();
Linker linker;
@@ -360,96 +355,127 @@ TEST_F( LinkerTest, plasma_object) {
Input* input = builder.CreateInput("gotplt.o", gotplt_o, Input::Object);
/// Sections
- /// [ 0] NULL 00000000 000000 000000 00 0 0 0
- builder.CreateELFHeader(*input,
- "",
- LDFileFormat::Null,
- llvm::ELF::SHT_NULL,
- 0x0);
-
- /// [ 1] .text PROGBITS 00000000 000034 000010 00 AX 0 0 4
- LDSection* text = builder.CreateELFHeader(*input,
+ /// [ 0] NULL 00000000 000000 000000 00 0
+ /// 0 0
+ builder.CreateELFHeader(
+ *input, "", LDFileFormat::Null, llvm::ELF::SHT_NULL, 0x0);
+
+ /// [ 1] .text PROGBITS 00000000 000034 000010 00 AX 0
+ /// 0 4
+ LDSection* text =
+ builder.CreateELFHeader(*input,
".text",
llvm::ELF::SHT_PROGBITS,
llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
4);
SectionData* text_data = builder.CreateSectionData(*text);
- static uint8_t text_content[] = { 0x00, 0x48, 0x2d, 0xe9,
- 0xfe, 0xff, 0xff, 0xeb,
- 0x00, 0x48, 0xbd, 0xe8,
- 0x0e, 0xf0, 0xa0, 0xe1 };
+ static uint8_t text_content[] = {
+ 0x00, 0x48, 0x2d, 0xe9,
+ 0xfe, 0xff, 0xff, 0xeb,
+ 0x00, 0x48, 0xbd, 0xe8,
+ 0x0e, 0xf0, 0xa0, 0xe1
+ };
+
Fragment* text_frag = builder.CreateRegion(text_content, 0x10);
builder.AppendFragment(*text_frag, *text_data);
- /// [ 2] .rel.text REL 00000000 0002ac 000008 08 7 1 4
- LDSection* rel_text = builder.CreateELFHeader(*input,
- ".rel.text",
- llvm::ELF::SHT_REL,
- 0x0, 4);
+ /// [ 2] .rel.text REL 00000000 0002ac 000008 08 7
+ /// 1 4
+ LDSection* rel_text =
+ builder.CreateELFHeader(*input, ".rel.text", llvm::ELF::SHT_REL, 0x0, 4);
rel_text->setLink(text);
builder.CreateRelocData(*rel_text);
- /// [ 3] .data PROGBITS 00000000 000044 000000 00 WA 0 0 4
- LDSection* data = builder.CreateELFHeader(*input,
- ".data",
- llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 4);
-
- /// [ 4] .bss NOBITS 00000000 000044 000000 00 WA 0 0 4
- LDSection* bss = builder.CreateELFHeader(*input,
- ".bss",
- llvm::ELF::SHT_NOBITS,
- llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
- 4);
+ /// [ 3] .data PROGBITS 00000000 000044 000000 00 WA 0
+ /// 0 4
+ LDSection* data =
+ builder.CreateELFHeader(*input,
+ ".data",
+ llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 4);
+
+ /// [ 4] .bss NOBITS 00000000 000044 000000 00 WA 0
+ /// 0 4
+ LDSection* bss =
+ builder.CreateELFHeader(*input,
+ ".bss",
+ llvm::ELF::SHT_NOBITS,
+ llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
+ 4);
builder.CreateBSS(*bss);
- /// [ 5] .ARM.attributes ARM_ATTRIBUTES 00000000 000044 000020 00 0 0 1
- LDSection* attr = builder.CreateELFHeader(*input,
- ".ARM.attributes",
- llvm::ELF::SHT_ARM_ATTRIBUTES,
- 0x0,
- 1);
+ /// [ 5] .ARM.attributes ARM_ATTRIBUTES 00000000 000044 000020 00 0
+ /// 0 1
+ LDSection* attr = builder.CreateELFHeader(
+ *input, ".ARM.attributes", llvm::ELF::SHT_ARM_ATTRIBUTES, 0x0, 1);
SectionData* attr_data = builder.CreateSectionData(*attr);
static uint8_t attr_content[] = {
- 0x41, 0x1f, 0x00, 0x00,
- 0x00, 0x61, 0x65, 0x61,
- 0x62, 0x69, 0x00, 0x01,
- 0x15, 0x00, 0x00, 0x00,
- 0x06, 0x02, 0x08, 0x01,
- 0x09, 0x01, 0x14, 0x01,
- 0x15, 0x01, 0x17, 0x03,
- 0x18, 0x01, 0x19, 0x01 };
+ 0x41, 0x1f, 0x00, 0x00,
+ 0x00, 0x61, 0x65, 0x61,
+ 0x62, 0x69, 0x00, 0x01,
+ 0x15, 0x00, 0x00, 0x00,
+ 0x06, 0x02, 0x08, 0x01,
+ 0x09, 0x01, 0x14, 0x01,
+ 0x15, 0x01, 0x17, 0x03,
+ 0x18, 0x01, 0x19, 0x01
+ };
+
Fragment* attr_frag = builder.CreateRegion(attr_content, 0x20);
builder.AppendFragment(*attr_frag, *attr_data);
/// Symbols
/// 1: 00000000 0 FILE LOCAL DEFAULT ABS Output/gotplt.bc
builder.AddSymbol(*input,
- "Output/gotplt.bc", ResolveInfo::File,
- ResolveInfo::Define, ResolveInfo::Local, 0);
+ "Output/gotplt.bc",
+ ResolveInfo::File,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0);
/// 2: 00000000 0 SECTION LOCAL DEFAULT 1
builder.AddSymbol(*input,
- ".text", ResolveInfo::Section,
- ResolveInfo::Define, ResolveInfo::Local, 0, 0x0, text);
+ ".text",
+ ResolveInfo::Section,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0,
+ 0x0,
+ text);
/// 3: 00000000 0 SECTION LOCAL DEFAULT 3
builder.AddSymbol(*input,
- ".data", ResolveInfo::Section,
- ResolveInfo::Define, ResolveInfo::Local, 0, 0x0, data);
+ ".data",
+ ResolveInfo::Section,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0,
+ 0x0,
+ data);
/// 4: 00000000 0 SECTION LOCAL DEFAULT 4
builder.AddSymbol(*input,
- ".bss", ResolveInfo::Section,
- ResolveInfo::Define, ResolveInfo::Local, 0, 0x0, bss);
+ ".bss",
+ ResolveInfo::Section,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0,
+ 0x0,
+ bss);
/// 5: 00000000 0 SECTION LOCAL DEFAULT 5
builder.AddSymbol(*input,
- ".ARM.attributes", ResolveInfo::Section,
- ResolveInfo::Define, ResolveInfo::Local, 0, 0x0, attr);
+ ".ARM.attributes",
+ ResolveInfo::Section,
+ ResolveInfo::Define,
+ ResolveInfo::Local,
+ 0,
+ 0x0,
+ attr);
/// 6: 00000000 16 FUNC GLOBAL DEFAULT 1 _Z1fv
builder.AddSymbol(*input,
- "_Z1fv", ResolveInfo::Function,
- ResolveInfo::Define, ResolveInfo::Global,
+ "_Z1fv",
+ ResolveInfo::Function,
+ ResolveInfo::Define,
+ ResolveInfo::Global,
16,
0x0,
text);
@@ -462,13 +488,13 @@ TEST_F( LinkerTest, plasma_object) {
ResolveInfo::Global,
0);
- /// Relocations
- /// Offset Info Type Sym.Value Sym. Name
- /// 00000004 0000071b R_ARM_PLT32 00000000 _Z1gv
- builder.AddRelocation(*rel_text, llvm::ELF::R_ARM_PLT32, *z1gv, 0x4);
+ /// Relocations
+ /// Offset Info Type Sym.Value Sym. Name
+ /// 00000004 0000071b R_ARM_PLT32 00000000 _Z1gv
+ builder.AddRelocation(*rel_text, llvm::ELF::R_ARM_PLT32, *z1gv, 0x4);
if (linker.link(module, builder)) {
- linker.emit(module, "libgotplt.so"); ///< -o libgotplt.so
+ linker.emit(module, "libgotplt.so"); ///< -o libgotplt.so
}
Finalize();
diff --git a/unittests/LinkerTest.h b/unittests/LinkerTest.h
index cb60d40..f20fd62 100644
--- a/unittests/LinkerTest.h
+++ b/unittests/LinkerTest.h
@@ -17,9 +17,8 @@ class Linker;
namespace test {
-class LinkerTest : public ::testing::Test
-{
-public:
+class LinkerTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
LinkerTest();
@@ -33,8 +32,7 @@ public:
virtual void TearDown();
};
-} // namespace of test
-} // namespace for mcld
+} // namespace of test
+} // namespace for mcld
#endif
-
diff --git a/unittests/MCRegionFragmentTest.cpp b/unittests/MCRegionFragmentTest.cpp
index 7d6c3b9..0319845 100644
--- a/unittests/MCRegionFragmentTest.cpp
+++ b/unittests/MCRegionFragmentTest.cpp
@@ -9,47 +9,42 @@
#include "MCRegionFragmentTest.h"
-#include <mcld/MC/MCRegionFragment.h>
-#include <mcld/Support/MemoryAreaFactory.h>
-#include <mcld/Support/Path.h>
+#include "mcld/MC/MCRegionFragment.h"
+#include "mcld/Support/MemoryAreaFactory.h"
+#include "mcld/Support/Path.h"
using namespace mcld;
using namespace mcldtest;
using namespace mcld::sys::fs;
-
// Constructor can do set-up work for all test here.
-MCRegionFragmentTest::MCRegionFragmentTest()
-{
+MCRegionFragmentTest::MCRegionFragmentTest() {
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-MCRegionFragmentTest::~MCRegionFragmentTest()
-{
+MCRegionFragmentTest::~MCRegionFragmentTest() {
}
// SetUp() will be called immediately before each test.
-void MCRegionFragmentTest::SetUp()
-{
+void MCRegionFragmentTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void MCRegionFragmentTest::TearDown()
-{
+void MCRegionFragmentTest::TearDown() {
}
//==========================================================================//
// Testcases
//
-TEST_F( MCRegionFragmentTest, classof_explicit ) {
+TEST_F(MCRegionFragmentTest, classof_explicit) {
Path path(TOPDIR);
path.append("unittests/test3.txt");
MemoryAreaFactory* areaFactory = new MemoryAreaFactory(1);
MemoryArea* area = areaFactory->produce(path, MemoryArea::ReadWrite);
MemoryRegion* region = area->request(0, 4096);
- MCRegionFragment *frag = new MCRegionFragment(*region);
+ MCRegionFragment* frag = new MCRegionFragment(*region);
ASSERT_FALSE(llvm::MCDataFragment::classof(frag));
ASSERT_TRUE(MCRegionFragment::classof(frag));
@@ -57,18 +52,17 @@ TEST_F( MCRegionFragmentTest, classof_explicit ) {
delete areaFactory;
}
-TEST_F( MCRegionFragmentTest, classof_implicit ) {
+TEST_F(MCRegionFragmentTest, classof_implicit) {
Path path(TOPDIR);
path.append("unittests/test3.txt");
MemoryAreaFactory* areaFactory = new MemoryAreaFactory(1);
MemoryArea* area = areaFactory->produce(path, MemoryArea::ReadWrite);
MemoryRegion* region = area->request(0, 4096);
- llvm::MCFragment *frag = new MCRegionFragment(*region);
+ llvm::MCFragment* frag = new MCRegionFragment(*region);
ASSERT_FALSE(llvm::MCDataFragment::classof(frag));
ASSERT_TRUE(MCRegionFragment::classof(frag));
delete frag;
delete areaFactory;
}
-
diff --git a/unittests/MCRegionFragmentTest.h b/unittests/MCRegionFragmentTest.h
index 3d1dab8..5b9e00b 100644
--- a/unittests/MCRegionFragmentTest.h
+++ b/unittests/MCRegionFragmentTest.h
@@ -12,40 +12,36 @@
#include <gtest.h>
-namespace mcld
-{
+namespace mcld {
class MCRegionFragment;
-} // namespace for mcld
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
/** \class MCRegionFragmentTest
* \brief The testcase of MCRegionFragment.
*
* \see MCRegionFragment
*/
-class MCRegionFragmentTest : public ::testing::Test
-{
-public:
- // Constructor can do set-up work for all test here.
- MCRegionFragmentTest();
+class MCRegionFragmentTest : public ::testing::Test {
+ public:
+ // Constructor can do set-up work for all test here.
+ MCRegionFragmentTest();
- // Destructor can do clean-up work that doesn't throw exceptions here.
- virtual ~MCRegionFragmentTest();
+ // Destructor can do clean-up work that doesn't throw exceptions here.
+ virtual ~MCRegionFragmentTest();
- // SetUp() will be called immediately before each test.
- virtual void SetUp();
+ // SetUp() will be called immediately before each test.
+ virtual void SetUp();
- // TearDown() will be called immediately after each test.
- virtual void TearDown();
+ // TearDown() will be called immediately after each test.
+ virtual void TearDown();
-protected:
- mcld::MCRegionFragment* m_pTestee;
+ protected:
+ mcld::MCRegionFragment* m_pTestee;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/NamePoolTest.cpp b/unittests/NamePoolTest.cpp
index 614ee6a..57c78fe 100644
--- a/unittests/NamePoolTest.cpp
+++ b/unittests/NamePoolTest.cpp
@@ -7,11 +7,11 @@
//
//===----------------------------------------------------------------------===//
#include "NamePoolTest.h"
-#include <mcld/LD/NamePool.h>
-#include <mcld/LD/Resolver.h>
-#include <mcld/LD/StaticResolver.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
+#include "mcld/LD/NamePool.h"
+#include "mcld/LD/Resolver.h"
+#include "mcld/LD/StaticResolver.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/LDSymbol.h"
#include <llvm/ADT/StringRef.h>
#include <string>
#include <cstdio>
@@ -19,45 +19,39 @@
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-NamePoolTest::NamePoolTest()
-{
+NamePoolTest::NamePoolTest() {
// create testee. modify it if need
StaticResolver resolver;
m_pTestee = new NamePool(resolver, 10);
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-NamePoolTest::~NamePoolTest()
-{
+NamePoolTest::~NamePoolTest() {
delete m_pTestee;
}
// SetUp() will be called immediately before each test.
-void NamePoolTest::SetUp()
-{
+void NamePoolTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void NamePoolTest::TearDown()
-{
+void NamePoolTest::TearDown() {
}
//==========================================================================//
// Testcases
//
-
-TEST_F( NamePoolTest, insertString ) {
- const char *s1 = "Hello MCLinker";
+TEST_F(NamePoolTest, insertString) {
+ const char* s1 = "Hello MCLinker";
llvm::StringRef result1 = m_pTestee->insertString(s1);
EXPECT_NE(s1, result1.data());
EXPECT_STREQ(s1, result1.data());
}
-TEST_F( NamePoolTest, insertSameString ) {
- const char *s1 = "Hello MCLinker";
+TEST_F(NamePoolTest, insertSameString) {
+ const char* s1 = "Hello MCLinker";
std::string s2(s1);
llvm::StringRef result1 = m_pTestee->insertString(s1);
llvm::StringRef result2 = m_pTestee->insertString(s2.c_str());
@@ -66,8 +60,8 @@ TEST_F( NamePoolTest, insertSameString ) {
EXPECT_EQ(result1.data(), result2.data());
}
-TEST_F( NamePoolTest, insert_local_defined_Symbol ) {
- const char *name = "Hello MCLinker";
+TEST_F(NamePoolTest, insert_local_defined_Symbol) {
+ const char* name = "Hello MCLinker";
bool isDyn = false;
ResolveInfo::Type type = ResolveInfo::Function;
ResolveInfo::Desc desc = ResolveInfo::Define;
@@ -76,15 +70,8 @@ TEST_F( NamePoolTest, insert_local_defined_Symbol ) {
uint64_t size = 0;
ResolveInfo::Visibility other = ResolveInfo::Default;
Resolver::Result result1;
- m_pTestee->insertSymbol(name,
- isDyn,
- type,
- desc,
- binding,
- size,
- other,
- NULL,
- result1);
+ m_pTestee->insertSymbol(
+ name, isDyn, type, desc, binding, size, other, NULL, result1);
EXPECT_NE(name, result1.info->name());
EXPECT_STREQ(name, result1.info->name());
@@ -96,15 +83,8 @@ TEST_F( NamePoolTest, insert_local_defined_Symbol ) {
EXPECT_EQ(other, result1.info->visibility());
Resolver::Result result2;
- m_pTestee->insertSymbol(name,
- isDyn,
- type,
- desc,
- binding,
- size,
- other,
- NULL,
- result2);
+ m_pTestee->insertSymbol(
+ name, isDyn, type, desc, binding, size, other, NULL, result2);
EXPECT_NE(name, result1.info->name());
EXPECT_STREQ(name, result1.info->name());
@@ -118,8 +98,8 @@ TEST_F( NamePoolTest, insert_local_defined_Symbol ) {
EXPECT_NE(result1.existent, result2.existent);
}
-TEST_F( NamePoolTest, insert_global_reference_Symbol ) {
- const char *name = "Hello MCLinker";
+TEST_F(NamePoolTest, insert_global_reference_Symbol) {
+ const char* name = "Hello MCLinker";
bool isDyn = false;
ResolveInfo::Type type = ResolveInfo::NoType;
ResolveInfo::Desc desc = ResolveInfo::Undefined;
@@ -127,15 +107,8 @@ TEST_F( NamePoolTest, insert_global_reference_Symbol ) {
uint64_t size = 0;
ResolveInfo::Visibility other = ResolveInfo::Default;
Resolver::Result result1;
- m_pTestee->insertSymbol(name,
- isDyn,
- type,
- desc,
- binding,
- size,
- other,
- NULL,
- result1);
+ m_pTestee->insertSymbol(
+ name, isDyn, type, desc, binding, size, other, NULL, result1);
EXPECT_NE(name, result1.info->name());
EXPECT_STREQ(name, result1.info->name());
@@ -147,15 +120,8 @@ TEST_F( NamePoolTest, insert_global_reference_Symbol ) {
EXPECT_EQ(other, result1.info->visibility());
Resolver::Result result2;
- m_pTestee->insertSymbol(name,
- isDyn,
- type,
- desc,
- binding,
- size,
- other,
- NULL,
- result2);
+ m_pTestee->insertSymbol(
+ name, isDyn, type, desc, binding, size, other, NULL, result2);
EXPECT_EQ(result1.info, result2.info);
@@ -170,98 +136,71 @@ TEST_F( NamePoolTest, insert_global_reference_Symbol ) {
NULL,
result3);
-
EXPECT_NE(result1.info, result3.info);
}
-
-TEST_F( NamePoolTest, insertSymbol_after_insert_same_string ) {
- const char *name = "Hello MCLinker";
+TEST_F(NamePoolTest, insertSymbol_after_insert_same_string) {
+ const char* name = "Hello MCLinker";
bool isDyn = false;
LDSymbol::Type type = LDSymbol::Defined;
LDSymbol::Binding binding = LDSymbol::Global;
- const llvm::MCSectionData *section = 0;
+ const llvm::MCSectionData* section = 0;
uint64_t value = 0;
uint64_t size = 0;
uint8_t other = 0;
- const char *result1 = m_pTestee->insertString(name);
- LDSymbol *sym = m_pTestee->insertSymbol(name,
- isDyn,
- type,
- binding,
- section,
- value,
- size,
- other);
+ const char* result1 = m_pTestee->insertString(name);
+ LDSymbol* sym = m_pTestee->insertSymbol(
+ name, isDyn, type, binding, section, value, size, other);
EXPECT_STREQ(name, sym->name());
EXPECT_EQ(result1, sym->name());
char s[16];
strcpy(s, result1);
- const char *result2 = m_pTestee->insertString(result1);
- const char *result3 = m_pTestee->insertString(s);
+ const char* result2 = m_pTestee->insertString(result1);
+ const char* result3 = m_pTestee->insertString(s);
EXPECT_EQ(result1, result2);
EXPECT_EQ(result1, result3);
}
-
-TEST_F( NamePoolTest, insert_16384_weak_reference_symbols ) {
+TEST_F(NamePoolTest, insert_16384_weak_reference_symbols) {
char name[16];
bool isDyn = false;
LDSymbol::Type type = LDSymbol::Reference;
LDSymbol::Binding binding = LDSymbol::Weak;
- const llvm::MCSectionData *section = 0;
+ const llvm::MCSectionData* section = 0;
uint64_t value = 0;
uint64_t size = 0;
uint8_t other = 0;
strcpy(name, "Hello MCLinker");
- LDSymbol *syms[128][128];
- for(int i=0; i<128 ;++i) {
+ LDSymbol* syms[128][128];
+ for (int i = 0; i < 128; ++i) {
name[0] = i;
- for(int j=0; j<128 ;++j) {
+ for (int j = 0; j < 128; ++j) {
name[1] = j;
- syms[i][j] = m_pTestee->insertSymbol(name,
- isDyn,
- type,
- binding,
- section,
- value,
- size,
- other);
+ syms[i][j] = m_pTestee->insertSymbol(
+ name, isDyn, type, binding, section, value, size, other);
ASSERT_STREQ(name, syms[i][j]->name());
}
}
- for(int i=127; i>=0 ;--i) {
+ for (int i = 127; i >= 0; --i) {
name[0] = i;
- for(int j=0; j<128 ;++j) {
+ for (int j = 0; j < 128; ++j) {
name[1] = j;
- LDSymbol *sym = m_pTestee->insertSymbol(name,
- isDyn,
- type,
- binding,
- section,
- value,
- size,
- other);
+ LDSymbol* sym = m_pTestee->insertSymbol(
+ name, isDyn, type, binding, section, value, size, other);
ASSERT_EQ(sym, syms[i][j]);
}
}
- for(int i=0; i<128 ;++i) {
+ for (int i = 0; i < 128; ++i) {
name[0] = i;
- for(int j=0; j<128 ;++j) {
+ for (int j = 0; j < 128; ++j) {
name[1] = j;
- LDSymbol *sym = m_pTestee->insertSymbol(name,
- isDyn,
- type,
- binding,
- section,
- value,
- size,
- other);
+ LDSymbol* sym = m_pTestee->insertSymbol(
+ name, isDyn, type, binding, section, value, size, other);
ASSERT_EQ(sym, syms[i][j]);
}
}
diff --git a/unittests/NamePoolTest.h b/unittests/NamePoolTest.h
index 2e4a494..8c63dac 100644
--- a/unittests/NamePoolTest.h
+++ b/unittests/NamePoolTest.h
@@ -11,40 +11,36 @@
#include <gtest.h>
-namespace mcld
-{
+namespace mcld {
class NamePool;
-} // namespace for mcld
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
/** \class NamePoolTest
* \brief
*
* \see NamePool
*/
-class NamePoolTest : public ::testing::Test
-{
-public:
- // Constructor can do set-up work for all test here.
- NamePoolTest();
+class NamePoolTest : public ::testing::Test {
+ public:
+ // Constructor can do set-up work for all test here.
+ NamePoolTest();
- // Destructor can do clean-up work that doesn't throw exceptions here.
- virtual ~NamePoolTest();
+ // Destructor can do clean-up work that doesn't throw exceptions here.
+ virtual ~NamePoolTest();
- // SetUp() will be called immediately before each test.
- virtual void SetUp();
+ // SetUp() will be called immediately before each test.
+ virtual void SetUp();
- // TearDown() will be called immediately after each test.
- virtual void TearDown();
+ // TearDown() will be called immediately after each test.
+ virtual void TearDown();
-protected:
- mcld::NamePool* m_pTestee;
+ protected:
+ mcld::NamePool* m_pTestee;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/PathSetTest.cpp b/unittests/PathSetTest.cpp
index d735e9c..b5f7b21 100644
--- a/unittests/PathSetTest.cpp
+++ b/unittests/PathSetTest.cpp
@@ -12,34 +12,28 @@
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-PathSetTest::PathSetTest()
-{
- // create testee. modify it if need
- m_pTestee = new PathSet();
+PathSetTest::PathSetTest() {
+ // create testee. modify it if need
+ m_pTestee = new PathSet();
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-PathSetTest::~PathSetTest()
-{
- delete m_pTestee;
+PathSetTest::~PathSetTest() {
+ delete m_pTestee;
}
// SetUp() will be called immediately before each test.
-void PathSetTest::SetUp()
-{
+void PathSetTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void PathSetTest::TearDown()
-{
+void PathSetTest::TearDown() {
}
//==========================================================================//
// Testcases
//
-TEST_F( PathSetTest, ) {
+TEST_F(PathSetTest, ) {
}
-
diff --git a/unittests/PathSetTest.h b/unittests/PathSetTest.h
index 23a2dbf..aee9758 100644
--- a/unittests/PathSetTest.h
+++ b/unittests/PathSetTest.h
@@ -11,40 +11,36 @@
#include <gtest.h>
-namespace mcld
-{
+namespace mcld {
class PathSet;
-} // namespace for mcld
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
/** \class PathSetTest
* \brief The testcase of PathSet
*
* \see PathSet
*/
-class PathSetTest : public ::testing::Test
-{
-public:
- // Constructor can do set-up work for all test here.
- PathSetTest();
+class PathSetTest : public ::testing::Test {
+ public:
+ // Constructor can do set-up work for all test here.
+ PathSetTest();
- // Destructor can do clean-up work that doesn't throw exceptions here.
- virtual ~PathSetTest();
+ // Destructor can do clean-up work that doesn't throw exceptions here.
+ virtual ~PathSetTest();
- // SetUp() will be called immediately before each test.
- virtual void SetUp();
+ // SetUp() will be called immediately before each test.
+ virtual void SetUp();
- // TearDown() will be called immediately after each test.
- virtual void TearDown();
+ // TearDown() will be called immediately after each test.
+ virtual void TearDown();
-protected:
- mcld::PathSet* m_pTestee;
+ protected:
+ mcld::PathSet* m_pTestee;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/PathTest.cpp b/unittests/PathTest.cpp
index 73e62cc..b22788e 100644
--- a/unittests/PathTest.cpp
+++ b/unittests/PathTest.cpp
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
#include "PathTest.h"
-#include <mcld/Support/FileSystem.h>
+#include "mcld/Support/FileSystem.h"
#include <string>
//
@@ -15,34 +15,29 @@ using namespace mcld;
using namespace mcld::sys::fs;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-PathTest::PathTest()
-{
- // create testee. modify it if need
- m_pTestee = new Path();
+PathTest::PathTest() {
+ // create testee. modify it if need
+ m_pTestee = new Path();
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-PathTest::~PathTest()
-{
- delete m_pTestee;
+PathTest::~PathTest() {
+ delete m_pTestee;
}
// SetUp() will be called immediately before each test.
-void PathTest::SetUp()
-{
+void PathTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void PathTest::TearDown()
-{
+void PathTest::TearDown() {
}
//==========================================================================//
// Testcases
//
-TEST_F( PathTest, should_exist ) {
+TEST_F(PathTest, should_exist) {
std::string root(TOPDIR);
root += "/test/lit.cfg";
m_pTestee->assign(root);
@@ -53,7 +48,7 @@ TEST_F( PathTest, should_exist ) {
EXPECT_TRUE(exists(*m_pTestee));
}
-TEST_F( PathTest, should_not_exist ) {
+TEST_F(PathTest, should_not_exist) {
const std::string root = "/luck";
m_pTestee->assign(root);
EXPECT_FALSE(exists(*m_pTestee));
@@ -63,7 +58,7 @@ TEST_F( PathTest, should_not_exist ) {
EXPECT_FALSE(exists(*m_pTestee));
}
-TEST_F( PathTest, should_is_directory ) {
+TEST_F(PathTest, should_is_directory) {
const std::string root = "../././..";
m_pTestee->assign(root);
EXPECT_TRUE(exists(*m_pTestee));
@@ -74,7 +69,7 @@ TEST_F( PathTest, should_is_directory ) {
EXPECT_TRUE(is_directory(*m_pTestee));
}
-TEST_F( PathTest, should_not_is_directory ) {
+TEST_F(PathTest, should_not_is_directory) {
const std::string root = "/luck";
m_pTestee->assign(root);
EXPECT_FALSE(exists(*m_pTestee));
@@ -85,60 +80,59 @@ TEST_F( PathTest, should_not_is_directory ) {
EXPECT_FALSE(is_directory(*m_pTestee));
}
-TEST_F( PathTest, should_equal ) {
+TEST_F(PathTest, should_equal) {
const std::string root = "aaa/bbb/../../ccc/";
m_pTestee->assign(root);
Path* p2 = new Path("ccc///////");
- EXPECT_TRUE(*m_pTestee==*p2);
+ EXPECT_TRUE(*m_pTestee == *p2);
delete m_pTestee;
m_pTestee = new Path(root);
- EXPECT_TRUE(*m_pTestee==*m_pTestee);
+ EXPECT_TRUE(*m_pTestee == *m_pTestee);
delete p2;
}
-TEST_F( PathTest, should_not_equal ) {
+TEST_F(PathTest, should_not_equal) {
const std::string root = "aa/";
- Path* p2=new Path("aaa//");
-// p2->assign(root);
+ Path* p2 = new Path("aaa//");
+ // p2->assign(root);
m_pTestee->assign(root);
- EXPECT_TRUE(*m_pTestee!=*p2);
+ EXPECT_TRUE(*m_pTestee != *p2);
delete m_pTestee;
m_pTestee = new Path(root);
- EXPECT_TRUE(*m_pTestee!=*p2);
+ EXPECT_TRUE(*m_pTestee != *p2);
delete p2;
}
-TEST_F( PathTest, append_success ) {
-
+TEST_F(PathTest, append_success) {
const std::string root = "aa/";
m_pTestee->assign(root);
m_pTestee->append("aaa");
std::string a("aa/aaa");
- EXPECT_TRUE(m_pTestee->native()=="aa/aaa");
+ EXPECT_TRUE(m_pTestee->native() == "aa/aaa");
delete m_pTestee;
m_pTestee = new Path("aa/");
m_pTestee->append("/aaa");
- EXPECT_TRUE(m_pTestee->native()=="aa/aaa");
+ EXPECT_TRUE(m_pTestee->native() == "aa/aaa");
delete m_pTestee;
m_pTestee = new Path("aa");
m_pTestee->append("/aaa");
- EXPECT_TRUE(m_pTestee->native()=="aa/aaa");
+ EXPECT_TRUE(m_pTestee->native() == "aa/aaa");
delete m_pTestee;
m_pTestee = new Path("aa");
m_pTestee->append("aaa");
- EXPECT_TRUE(m_pTestee->native()=="aa/aaa");
+ EXPECT_TRUE(m_pTestee->native() == "aa/aaa");
}
-TEST_F( PathTest, should_become_generic_string ) {
+TEST_F(PathTest, should_become_generic_string) {
m_pTestee->assign("/etc/../dev/../usr//lib//");
EXPECT_STREQ("/usr/lib/", m_pTestee->generic_string().c_str());
}
-TEST_F( PathTest, parent_path ) {
+TEST_F(PathTest, parent_path) {
m_pTestee->assign("aa/bb/cc/dd");
EXPECT_STREQ("aa/bb/cc", m_pTestee->parent_path().c_str());
delete m_pTestee;
diff --git a/unittests/PathTest.h b/unittests/PathTest.h
index 417a07f..a31b16a 100644
--- a/unittests/PathTest.h
+++ b/unittests/PathTest.h
@@ -12,34 +12,31 @@
#include "mcld/Support/Path.h"
#include <gtest.h>
-namespace mcldtest
-{
+namespace mcldtest {
/** \class PathTest
* \brief a testcase for mcld::Path and its non-member funtions.
*
* \see Path
*/
-class PathTest : public ::testing::Test
-{
-public:
- // Constructor can do set-up work for all test here.
- PathTest();
+class PathTest : public ::testing::Test {
+ public:
+ // Constructor can do set-up work for all test here.
+ PathTest();
- // Destructor can do clean-up work that doesn't throw exceptions here.
- virtual ~PathTest();
+ // Destructor can do clean-up work that doesn't throw exceptions here.
+ virtual ~PathTest();
- // SetUp() will be called immediately before each test.
- virtual void SetUp();
+ // SetUp() will be called immediately before each test.
+ virtual void SetUp();
- // TearDown() will be called immediately after each test.
- virtual void TearDown();
+ // TearDown() will be called immediately after each test.
+ virtual void TearDown();
-protected:
- mcld::sys::fs::Path* m_pTestee;
+ protected:
+ mcld::sys::fs::Path* m_pTestee;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/RTLinearAllocatorTest.cpp b/unittests/RTLinearAllocatorTest.cpp
index 1e07f4a..1350c50 100644
--- a/unittests/RTLinearAllocatorTest.cpp
+++ b/unittests/RTLinearAllocatorTest.cpp
@@ -6,34 +6,29 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/Allocators.h>
+#include "mcld/Support/Allocators.h"
#include "RTLinearAllocatorTest.h"
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-RTLinearAllocatorTest::RTLinearAllocatorTest()
-{
- // create testee. modify it if need
- m_pTestee = new LinearAllocator<Data, 0>(CHUNK_SIZE);
+RTLinearAllocatorTest::RTLinearAllocatorTest() {
+ // create testee. modify it if need
+ m_pTestee = new LinearAllocator<Data, 0>(CHUNK_SIZE);
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-RTLinearAllocatorTest::~RTLinearAllocatorTest()
-{
- delete m_pTestee;
+RTLinearAllocatorTest::~RTLinearAllocatorTest() {
+ delete m_pTestee;
}
// SetUp() will be called immediately before each test.
-void RTLinearAllocatorTest::SetUp()
-{
+void RTLinearAllocatorTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void RTLinearAllocatorTest::TearDown()
-{
+void RTLinearAllocatorTest::TearDown() {
}
//==========================================================================//
@@ -41,100 +36,99 @@ void RTLinearAllocatorTest::TearDown()
//
TEST_F(RTLinearAllocatorTest, AllocateN) {
- Data* pointer = m_pTestee->allocate(10);
- ASSERT_FALSE(0 == pointer);
- ASSERT_TRUE(CHUNK_SIZE == m_pTestee->max_size());
- ASSERT_FALSE(m_pTestee->empty());
+ Data* pointer = m_pTestee->allocate(10);
+ ASSERT_FALSE(0 == pointer);
+ ASSERT_TRUE(CHUNK_SIZE == m_pTestee->max_size());
+ ASSERT_FALSE(m_pTestee->empty());
}
-TEST_F(RTLinearAllocatorTest, allocate ) {
- Data* pointer = m_pTestee->allocate();
- ASSERT_FALSE(0 == pointer);
- ASSERT_TRUE(CHUNK_SIZE == m_pTestee->max_size());
- ASSERT_FALSE(m_pTestee->empty());
+TEST_F(RTLinearAllocatorTest, allocate) {
+ Data* pointer = m_pTestee->allocate();
+ ASSERT_FALSE(0 == pointer);
+ ASSERT_TRUE(CHUNK_SIZE == m_pTestee->max_size());
+ ASSERT_FALSE(m_pTestee->empty());
}
-TEST_F(RTLinearAllocatorTest, allocateOver ) {
- Data* pointer = m_pTestee->allocate(CHUNK_SIZE+1);
- ASSERT_TRUE(0 == pointer);
- ASSERT_TRUE(0 == m_pTestee->max_size());
- ASSERT_TRUE(m_pTestee->empty());
+TEST_F(RTLinearAllocatorTest, allocateOver) {
+ Data* pointer = m_pTestee->allocate(CHUNK_SIZE + 1);
+ ASSERT_TRUE(0 == pointer);
+ ASSERT_TRUE(0 == m_pTestee->max_size());
+ ASSERT_TRUE(m_pTestee->empty());
}
-TEST_F(RTLinearAllocatorTest, alloc_construct ) {
- Data* pointer = m_pTestee->allocate();
- m_pTestee->construct(pointer);
- ASSERT_TRUE(1 == pointer->one);
- ASSERT_TRUE(2 == pointer->two);
- ASSERT_TRUE(3 == pointer->three);
- ASSERT_TRUE(4 == pointer->four);
+TEST_F(RTLinearAllocatorTest, alloc_construct) {
+ Data* pointer = m_pTestee->allocate();
+ m_pTestee->construct(pointer);
+ ASSERT_TRUE(1 == pointer->one);
+ ASSERT_TRUE(2 == pointer->two);
+ ASSERT_TRUE(3 == pointer->three);
+ ASSERT_TRUE(4 == pointer->four);
}
-TEST_F(RTLinearAllocatorTest, alloc_constructCopy ) {
- Data* pointer = m_pTestee->allocate();
- Data data(7, 7, 7, 7);
- m_pTestee->construct(pointer, data);
+TEST_F(RTLinearAllocatorTest, alloc_constructCopy) {
+ Data* pointer = m_pTestee->allocate();
+ Data data(7, 7, 7, 7);
+ m_pTestee->construct(pointer, data);
- ASSERT_TRUE(7 == pointer->one);
- ASSERT_TRUE(7 == pointer->two);
- ASSERT_TRUE(7 == pointer->three);
- ASSERT_TRUE(7 == pointer->four);
+ ASSERT_TRUE(7 == pointer->one);
+ ASSERT_TRUE(7 == pointer->two);
+ ASSERT_TRUE(7 == pointer->three);
+ ASSERT_TRUE(7 == pointer->four);
}
-TEST_F(RTLinearAllocatorTest, allocN_construct ) {
- Data* pointer = m_pTestee->allocate(10);
- m_pTestee->construct(pointer);
- ASSERT_TRUE(1 == pointer->one);
- ASSERT_TRUE(2 == pointer->two);
- ASSERT_TRUE(3 == pointer->three);
- ASSERT_TRUE(4 == pointer->four);
+TEST_F(RTLinearAllocatorTest, allocN_construct) {
+ Data* pointer = m_pTestee->allocate(10);
+ m_pTestee->construct(pointer);
+ ASSERT_TRUE(1 == pointer->one);
+ ASSERT_TRUE(2 == pointer->two);
+ ASSERT_TRUE(3 == pointer->three);
+ ASSERT_TRUE(4 == pointer->four);
}
-TEST_F(RTLinearAllocatorTest, allocN_constructCopy ) {
- Data* pointer = m_pTestee->allocate(10);
- Data data(7, 7, 7, 7);
- m_pTestee->construct(pointer, data);
-
- ASSERT_TRUE(7 == pointer->one);
- ASSERT_TRUE(7 == pointer->two);
- ASSERT_TRUE(7 == pointer->three);
- ASSERT_TRUE(7 == pointer->four);
-}
+TEST_F(RTLinearAllocatorTest, allocN_constructCopy) {
+ Data* pointer = m_pTestee->allocate(10);
+ Data data(7, 7, 7, 7);
+ m_pTestee->construct(pointer, data);
-TEST_F(RTLinearAllocatorTest, multi_alloc_ctor_iterate ) {
- for (int i=0; i<101; ++i) {
- Data* pointer = m_pTestee->allocate();
- m_pTestee->construct(pointer);
- pointer->one = i;
- }
-/**
- Alloc::iterator data, dEnd = m_pTestee->end();
- int counter = 0;
- for (data=m_pTestee->begin(); data!=dEnd; ++data) {
- ASSERT_EQ(counter, (*data).one);
- ++counter;
- }
-**/
+ ASSERT_TRUE(7 == pointer->one);
+ ASSERT_TRUE(7 == pointer->two);
+ ASSERT_TRUE(7 == pointer->three);
+ ASSERT_TRUE(7 == pointer->four);
}
-TEST_F(RTLinearAllocatorTest, multi_allocN_ctor_iterate ) {
- int counter = 0;
- for (int i=0; i<10000; ++i) {
- Data* pointer = m_pTestee->allocate(10);
- for (int j=0; j<10; ++j) {
- m_pTestee->construct(pointer);
- pointer->one = counter;
- ++pointer;
- ++counter;
- }
- }
-/**
- Alloc::iterator data, dEnd = m_pTestee->end();
- counter = 0;
- for (data=m_pTestee->begin(); data!=dEnd; ++data) {
- ASSERT_EQ(counter, (*data).one);
- ++counter;
- }
-**/
+TEST_F(RTLinearAllocatorTest, multi_alloc_ctor_iterate) {
+ for (int i = 0; i < 101; ++i) {
+ Data* pointer = m_pTestee->allocate();
+ m_pTestee->construct(pointer);
+ pointer->one = i;
+ }
+ /**
+ Alloc::iterator data, dEnd = m_pTestee->end();
+ int counter = 0;
+ for (data=m_pTestee->begin(); data!=dEnd; ++data) {
+ ASSERT_EQ(counter, (*data).one);
+ ++counter;
+ }
+ **/
}
+TEST_F(RTLinearAllocatorTest, multi_allocN_ctor_iterate) {
+ int counter = 0;
+ for (int i = 0; i < 10000; ++i) {
+ Data* pointer = m_pTestee->allocate(10);
+ for (int j = 0; j < 10; ++j) {
+ m_pTestee->construct(pointer);
+ pointer->one = counter;
+ ++pointer;
+ ++counter;
+ }
+ }
+ /**
+ Alloc::iterator data, dEnd = m_pTestee->end();
+ counter = 0;
+ for (data=m_pTestee->begin(); data!=dEnd; ++data) {
+ ASSERT_EQ(counter, (*data).one);
+ ++counter;
+ }
+ **/
+}
diff --git a/unittests/RTLinearAllocatorTest.h b/unittests/RTLinearAllocatorTest.h
index 3ba0cd9..2c4a732 100644
--- a/unittests/RTLinearAllocatorTest.h
+++ b/unittests/RTLinearAllocatorTest.h
@@ -12,63 +12,59 @@
#include <gtest.h>
#include "mcld/Support/Allocators.h"
-namespace mcldtest
-{
+namespace mcldtest {
/** \class RTLinearAllocatorTest
* \brief
*
* \see RTLinearAllocator
*/
-class RTLinearAllocatorTest : public ::testing::Test
-{
-public:
- // Constructor can do set-up work for all test here.
- RTLinearAllocatorTest();
+class RTLinearAllocatorTest : public ::testing::Test {
+ public:
+ // Constructor can do set-up work for all test here.
+ RTLinearAllocatorTest();
- // Destructor can do clean-up work that doesn't throw exceptions here.
- virtual ~RTLinearAllocatorTest();
+ // Destructor can do clean-up work that doesn't throw exceptions here.
+ virtual ~RTLinearAllocatorTest();
- // SetUp() will be called immediately before each test.
- virtual void SetUp();
+ // SetUp() will be called immediately before each test.
+ virtual void SetUp();
- // TearDown() will be called immediately after each test.
- virtual void TearDown();
+ // TearDown() will be called immediately after each test.
+ virtual void TearDown();
-public:
- struct Data {
- Data()
- : one(1), two(2), three(3), four(4)
- { }
+ public:
+ struct Data {
+ Data() : one(1), two(2), three(3), four(4) {}
- Data( unsigned int pOne, unsigned int pTwo, unsigned char pThree, unsigned char pFour)
- {
- one = pOne;
- two = pTwo;
- three = pThree;
- four = pFour;
- }
+ Data(unsigned int pOne,
+ unsigned int pTwo,
+ unsigned char pThree,
+ unsigned char pFour) {
+ one = pOne;
+ two = pTwo;
+ three = pThree;
+ four = pFour;
+ }
- ~Data()
- {
- one = -1;
- two = -2;
- three = -3;
- four = -4;
- }
+ ~Data() {
+ one = -1;
+ two = -2;
+ three = -3;
+ four = -4;
+ }
- unsigned int one;
- unsigned int two;
- unsigned char three;
- unsigned char four;
+ unsigned int one;
+ unsigned int two;
+ unsigned char three;
+ unsigned char four;
};
- enum { CHUNK_SIZE = 32 };
+ enum { CHUNK_SIZE = 32 };
-protected:
- mcld::LinearAllocator<Data,0>* m_pTestee;
+ protected:
+ mcld::LinearAllocator<Data, 0>* m_pTestee;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/SectionDataTest.cpp b/unittests/SectionDataTest.cpp
index 6a7e366..e9a9292 100644
--- a/unittests/SectionDataTest.cpp
+++ b/unittests/SectionDataTest.cpp
@@ -8,50 +8,44 @@
//===----------------------------------------------------------------------===//
#include "SectionDataTest.h"
-#include <mcld/LD/SectionData.h>
-#include <mcld/LD/LDFileFormat.h>
-#include <mcld/LD/LDSection.h>
+#include "mcld/LD/SectionData.h"
+#include "mcld/LD/LDFileFormat.h"
+#include "mcld/LD/LDSection.h"
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-SectionDataTest::SectionDataTest()
-{
+SectionDataTest::SectionDataTest() {
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-SectionDataTest::~SectionDataTest()
-{
+SectionDataTest::~SectionDataTest() {
}
// SetUp() will be called immediately before each test.
-void SectionDataTest::SetUp()
-{
+void SectionDataTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void SectionDataTest::TearDown()
-{
+void SectionDataTest::TearDown() {
}
//===----------------------------------------------------------------------===//
// Testcases
//===----------------------------------------------------------------------===//
-TEST_F( SectionDataTest, constructor_and_trivial_func ) {
+TEST_F(SectionDataTest, constructor_and_trivial_func) {
LDSection* test = LDSection::Create("test", LDFileFormat::Null, 0, 0);
SectionData* s = SectionData::Create(*test);
- EXPECT_TRUE(s->getSection().name() == "test" && \
+ EXPECT_TRUE(s->getSection().name() == "test" &&
s->getSection().kind() == LDFileFormat::Null);
-
LDSection::Destroy(test);
}
-TEST_F( SectionDataTest, Fragment_list_and_iterator ) {
+TEST_F(SectionDataTest, Fragment_list_and_iterator) {
LDSection* test = LDSection::Create("test", LDFileFormat::Null, 0, 0);
SectionData* s = SectionData::Create(*test);
EXPECT_TRUE(s->empty());
@@ -63,8 +57,8 @@ TEST_F( SectionDataTest, Fragment_list_and_iterator ) {
new Fragment(Fragment::Target, s);
EXPECT_TRUE(5 == s->size());
- //iterator
- llvm::iplist<Fragment>::iterator iter=s->begin();
+ // iterator
+ llvm::iplist<Fragment>::iterator iter = s->begin();
EXPECT_TRUE(Fragment::Alignment == iter->getKind());
++iter;
EXPECT_TRUE(Fragment::Alignment == iter->getKind());
diff --git a/unittests/SectionDataTest.h b/unittests/SectionDataTest.h
index bbc2736..6717f5e 100644
--- a/unittests/SectionDataTest.h
+++ b/unittests/SectionDataTest.h
@@ -13,14 +13,12 @@
namespace mcld {
class SectionData;
-} // namespace for mcld
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
-class SectionDataTest : public ::testing::Test
-{
-public:
+class SectionDataTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
SectionDataTest();
@@ -34,7 +32,6 @@ public:
virtual void TearDown();
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/StaticResolverTest.cpp b/unittests/StaticResolverTest.cpp
index a474cdd..75fb34c 100644
--- a/unittests/StaticResolverTest.cpp
+++ b/unittests/StaticResolverTest.cpp
@@ -7,12 +7,12 @@
//
//===----------------------------------------------------------------------===//
#include "StaticResolverTest.h"
-#include <mcld/Support/TargetSelect.h>
-#include <mcld/LD/StaticResolver.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LinkerConfig.h>
+#include "mcld/Support/TargetSelect.h"
+#include "mcld/LD/StaticResolver.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LinkerConfig.h"
-#include <mcld/Support/FileSystem.h>
+#include "mcld/Support/FileSystem.h"
using namespace mcld;
using namespace mcldtest;
@@ -21,8 +21,7 @@ using namespace mcldtest;
// StaticResolverTest
//===----------------------------------------------------------------------===//
// Constructor can do set-up work for all test here.
-StaticResolverTest::StaticResolverTest()
- : m_pResolver(NULL), m_pConfig(NULL) {
+StaticResolverTest::StaticResolverTest() : m_pResolver(NULL), m_pConfig(NULL) {
// create testee. modify it if need
m_pResolver = new StaticResolver();
@@ -30,41 +29,38 @@ StaticResolverTest::StaticResolverTest()
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-StaticResolverTest::~StaticResolverTest()
-{
+StaticResolverTest::~StaticResolverTest() {
delete m_pResolver;
delete m_pConfig;
}
// SetUp() will be called immediately before each test.
-void StaticResolverTest::SetUp()
-{
+void StaticResolverTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void StaticResolverTest::TearDown()
-{
+void StaticResolverTest::TearDown() {
}
//==========================================================================//
// Testcases
//
-TEST_F( StaticResolverTest, MDEF ) {
+TEST_F(StaticResolverTest, MDEF) {
ResolveInfo* old_sym = ResolveInfo::Create("abc");
ResolveInfo* new_sym = ResolveInfo::Create("abc");
new_sym->setDesc(ResolveInfo::Define);
old_sym->setDesc(ResolveInfo::Define);
- ASSERT_TRUE( mcld::ResolveInfo::Define == new_sym->desc());
- ASSERT_TRUE( mcld::ResolveInfo::Define == old_sym->desc());
- ASSERT_TRUE( mcld::ResolveInfo::define_flag == new_sym->info());
- ASSERT_TRUE( mcld::ResolveInfo::define_flag == old_sym->info());
+ ASSERT_TRUE(mcld::ResolveInfo::Define == new_sym->desc());
+ ASSERT_TRUE(mcld::ResolveInfo::Define == old_sym->desc());
+ ASSERT_TRUE(mcld::ResolveInfo::define_flag == new_sym->info());
+ ASSERT_TRUE(mcld::ResolveInfo::define_flag == old_sym->info());
bool override = true;
bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
ASSERT_TRUE(result);
- ASSERT_FALSE( override );
+ ASSERT_FALSE(override);
}
-TEST_F( StaticResolverTest, DynDefAfterDynUndef ) {
+TEST_F(StaticResolverTest, DynDefAfterDynUndef) {
ResolveInfo* old_sym = ResolveInfo::Create("abc");
ResolveInfo* new_sym = ResolveInfo::Create("abc");
@@ -79,19 +75,19 @@ TEST_F( StaticResolverTest, DynDefAfterDynUndef ) {
old_sym->setSize(1);
- ASSERT_TRUE( mcld::ResolveInfo::Global == new_sym->binding());
- ASSERT_TRUE( mcld::ResolveInfo::Global == old_sym->binding());
- ASSERT_TRUE( mcld::ResolveInfo::Undefined == new_sym->desc());
- ASSERT_TRUE( mcld::ResolveInfo::Define == old_sym->desc());
+ ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding());
+ ASSERT_TRUE(mcld::ResolveInfo::Global == old_sym->binding());
+ ASSERT_TRUE(mcld::ResolveInfo::Undefined == new_sym->desc());
+ ASSERT_TRUE(mcld::ResolveInfo::Define == old_sym->desc());
bool override = false;
bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
ASSERT_TRUE(result);
- ASSERT_FALSE( override );
+ ASSERT_FALSE(override);
ASSERT_TRUE(1 == old_sym->size());
}
-TEST_F( StaticResolverTest, DynDefAfterDynDef ) {
+TEST_F(StaticResolverTest, DynDefAfterDynDef) {
ResolveInfo* old_sym = ResolveInfo::Create("abc");
ResolveInfo* new_sym = ResolveInfo::Create("abc");
@@ -106,19 +102,19 @@ TEST_F( StaticResolverTest, DynDefAfterDynDef ) {
old_sym->setSize(1);
- ASSERT_TRUE( mcld::ResolveInfo::Global == new_sym->binding());
- ASSERT_TRUE( mcld::ResolveInfo::Global == old_sym->binding());
- ASSERT_TRUE( mcld::ResolveInfo::Define == new_sym->desc());
- ASSERT_TRUE( mcld::ResolveInfo::Define == old_sym->desc());
+ ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding());
+ ASSERT_TRUE(mcld::ResolveInfo::Global == old_sym->binding());
+ ASSERT_TRUE(mcld::ResolveInfo::Define == new_sym->desc());
+ ASSERT_TRUE(mcld::ResolveInfo::Define == old_sym->desc());
bool override = false;
bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
ASSERT_TRUE(result);
- ASSERT_FALSE( override );
+ ASSERT_FALSE(override);
ASSERT_TRUE(1 == old_sym->size());
}
-TEST_F( StaticResolverTest, DynUndefAfterDynUndef ) {
+TEST_F(StaticResolverTest, DynUndefAfterDynUndef) {
ResolveInfo* old_sym = ResolveInfo::Create("abc");
ResolveInfo* new_sym = ResolveInfo::Create("abc");
@@ -133,20 +129,19 @@ TEST_F( StaticResolverTest, DynUndefAfterDynUndef ) {
old_sym->setSize(1);
- ASSERT_TRUE( mcld::ResolveInfo::Global == new_sym->binding());
- ASSERT_TRUE( mcld::ResolveInfo::Global == old_sym->binding());
- ASSERT_TRUE( mcld::ResolveInfo::Undefined == new_sym->desc());
- ASSERT_TRUE( mcld::ResolveInfo::Undefined == old_sym->desc());
+ ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding());
+ ASSERT_TRUE(mcld::ResolveInfo::Global == old_sym->binding());
+ ASSERT_TRUE(mcld::ResolveInfo::Undefined == new_sym->desc());
+ ASSERT_TRUE(mcld::ResolveInfo::Undefined == old_sym->desc());
bool override = false;
bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
ASSERT_TRUE(result);
- ASSERT_FALSE( override );
+ ASSERT_FALSE(override);
ASSERT_TRUE(1 == old_sym->size());
}
-TEST_F( StaticResolverTest, OverrideWeakByGlobal )
-{
+TEST_F(StaticResolverTest, OverrideWeakByGlobal) {
ResolveInfo* old_sym = ResolveInfo::Create("abc");
ResolveInfo* new_sym = ResolveInfo::Create("abc");
@@ -155,19 +150,19 @@ TEST_F( StaticResolverTest, OverrideWeakByGlobal )
new_sym->setSize(0);
old_sym->setSize(1);
- ASSERT_TRUE( mcld::ResolveInfo::Global == new_sym->binding());
- ASSERT_TRUE( mcld::ResolveInfo::Weak == old_sym->binding());
+ ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding());
+ ASSERT_TRUE(mcld::ResolveInfo::Weak == old_sym->binding());
- ASSERT_TRUE( mcld::ResolveInfo::global_flag == new_sym->info());
- ASSERT_TRUE( mcld::ResolveInfo::weak_flag == old_sym->info());
+ ASSERT_TRUE(mcld::ResolveInfo::global_flag == new_sym->info());
+ ASSERT_TRUE(mcld::ResolveInfo::weak_flag == old_sym->info());
bool override = false;
bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
ASSERT_TRUE(result);
- ASSERT_TRUE( override );
+ ASSERT_TRUE(override);
ASSERT_TRUE(0 == old_sym->size());
}
-TEST_F( StaticResolverTest, DynWeakAfterDynDef ) {
+TEST_F(StaticResolverTest, DynWeakAfterDynDef) {
ResolveInfo* old_sym = ResolveInfo::Create("abc");
ResolveInfo* new_sym = ResolveInfo::Create("abc");
@@ -184,20 +179,19 @@ TEST_F( StaticResolverTest, DynWeakAfterDynDef ) {
old_sym->setSize(1);
- ASSERT_TRUE( mcld::ResolveInfo::Weak == old_sym->binding());
- ASSERT_TRUE( mcld::ResolveInfo::Global == new_sym->binding());
- ASSERT_TRUE( mcld::ResolveInfo::Define == old_sym->desc());
- ASSERT_TRUE( mcld::ResolveInfo::Define == new_sym->desc());
+ ASSERT_TRUE(mcld::ResolveInfo::Weak == old_sym->binding());
+ ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding());
+ ASSERT_TRUE(mcld::ResolveInfo::Define == old_sym->desc());
+ ASSERT_TRUE(mcld::ResolveInfo::Define == new_sym->desc());
bool override = false;
bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
ASSERT_TRUE(result);
- ASSERT_FALSE( override );
+ ASSERT_FALSE(override);
ASSERT_TRUE(1 == old_sym->size());
}
-TEST_F( StaticResolverTest, MarkByBiggerCommon )
-{
+TEST_F(StaticResolverTest, MarkByBiggerCommon) {
ResolveInfo* old_sym = ResolveInfo::Create("abc");
ResolveInfo* new_sym = ResolveInfo::Create("abc");
@@ -206,20 +200,19 @@ TEST_F( StaticResolverTest, MarkByBiggerCommon )
new_sym->setSize(999);
old_sym->setSize(0);
- ASSERT_TRUE( mcld::ResolveInfo::Common == new_sym->desc());
- ASSERT_TRUE( mcld::ResolveInfo::Common == old_sym->desc());
+ ASSERT_TRUE(mcld::ResolveInfo::Common == new_sym->desc());
+ ASSERT_TRUE(mcld::ResolveInfo::Common == old_sym->desc());
- ASSERT_TRUE( mcld::ResolveInfo::common_flag == new_sym->info());
- ASSERT_TRUE( mcld::ResolveInfo::common_flag == old_sym->info());
+ ASSERT_TRUE(mcld::ResolveInfo::common_flag == new_sym->info());
+ ASSERT_TRUE(mcld::ResolveInfo::common_flag == old_sym->info());
bool override = true;
bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
ASSERT_TRUE(result);
- ASSERT_FALSE( override );
+ ASSERT_FALSE(override);
ASSERT_TRUE(999 == old_sym->size());
}
-TEST_F( StaticResolverTest, OverrideByBiggerCommon )
-{
+TEST_F(StaticResolverTest, OverrideByBiggerCommon) {
ResolveInfo* old_sym = ResolveInfo::Create("abc");
ResolveInfo* new_sym = ResolveInfo::Create("abc");
@@ -229,22 +222,22 @@ TEST_F( StaticResolverTest, OverrideByBiggerCommon )
new_sym->setSize(999);
old_sym->setSize(0);
- ASSERT_TRUE( ResolveInfo::Common == new_sym->desc());
- ASSERT_TRUE( ResolveInfo::Common == old_sym->desc());
- ASSERT_TRUE( ResolveInfo::Weak == old_sym->binding());
+ ASSERT_TRUE(ResolveInfo::Common == new_sym->desc());
+ ASSERT_TRUE(ResolveInfo::Common == old_sym->desc());
+ ASSERT_TRUE(ResolveInfo::Weak == old_sym->binding());
- ASSERT_TRUE( ResolveInfo::common_flag == new_sym->info());
- ASSERT_TRUE( (ResolveInfo::weak_flag | ResolveInfo::common_flag) == old_sym->info());
+ ASSERT_TRUE(ResolveInfo::common_flag == new_sym->info());
+ ASSERT_TRUE((ResolveInfo::weak_flag | ResolveInfo::common_flag) ==
+ old_sym->info());
bool override = false;
bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
ASSERT_TRUE(result);
- ASSERT_TRUE( override );
+ ASSERT_TRUE(override);
ASSERT_TRUE(999 == old_sym->size());
}
-TEST_F( StaticResolverTest, OverrideCommonByDefine)
-{
+TEST_F(StaticResolverTest, OverrideCommonByDefine) {
ResolveInfo* old_sym = ResolveInfo::Create("abc");
ResolveInfo* new_sym = ResolveInfo::Create("abc");
@@ -254,183 +247,180 @@ TEST_F( StaticResolverTest, OverrideCommonByDefine)
new_sym->setDesc(ResolveInfo::Define);
new_sym->setSize(999);
- ASSERT_TRUE( ResolveInfo::Define == new_sym->desc());
- ASSERT_TRUE( ResolveInfo::Common == old_sym->desc());
+ ASSERT_TRUE(ResolveInfo::Define == new_sym->desc());
+ ASSERT_TRUE(ResolveInfo::Common == old_sym->desc());
- ASSERT_TRUE( ResolveInfo::define_flag == new_sym->info());
- ASSERT_TRUE( ResolveInfo::common_flag == old_sym->info());
+ ASSERT_TRUE(ResolveInfo::define_flag == new_sym->info());
+ ASSERT_TRUE(ResolveInfo::common_flag == old_sym->info());
bool override = false;
bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
ASSERT_TRUE(result);
- ASSERT_TRUE( override );
+ ASSERT_TRUE(override);
ASSERT_TRUE(999 == old_sym->size());
}
-TEST_F( StaticResolverTest, SetUpDesc)
-{
+TEST_F(StaticResolverTest, SetUpDesc) {
ResolveInfo* sym = ResolveInfo::Create("abc");
sym->setIsSymbol(true);
-// ASSERT_FALSE( sym->isSymbol() );
- ASSERT_TRUE( sym->isSymbol() );
- ASSERT_TRUE( sym->isGlobal() );
- ASSERT_FALSE( sym->isWeak() );
- ASSERT_FALSE( sym->isLocal() );
- ASSERT_FALSE( sym->isDefine() );
- ASSERT_TRUE( sym->isUndef() );
- ASSERT_FALSE( sym->isDyn() );
- ASSERT_FALSE( sym->isCommon() );
- ASSERT_FALSE( sym->isIndirect() );
- ASSERT_TRUE( ResolveInfo::NoType == sym->type());
- ASSERT_TRUE( 0 == sym->desc() );
- ASSERT_TRUE( 0 == sym->binding() );
- ASSERT_TRUE( 0 == sym->other() );
+ // ASSERT_FALSE( sym->isSymbol() );
+ ASSERT_TRUE(sym->isSymbol());
+ ASSERT_TRUE(sym->isGlobal());
+ ASSERT_FALSE(sym->isWeak());
+ ASSERT_FALSE(sym->isLocal());
+ ASSERT_FALSE(sym->isDefine());
+ ASSERT_TRUE(sym->isUndef());
+ ASSERT_FALSE(sym->isDyn());
+ ASSERT_FALSE(sym->isCommon());
+ ASSERT_FALSE(sym->isIndirect());
+ ASSERT_TRUE(ResolveInfo::NoType == sym->type());
+ ASSERT_TRUE(0 == sym->desc());
+ ASSERT_TRUE(0 == sym->binding());
+ ASSERT_TRUE(0 == sym->other());
sym->setIsSymbol(false);
- ASSERT_FALSE( sym->isSymbol() );
-// ASSERT_TRUE( sym->isSymbol() );
- ASSERT_TRUE( sym->isGlobal() );
- ASSERT_FALSE( sym->isWeak() );
- ASSERT_FALSE( sym->isLocal() );
- ASSERT_FALSE( sym->isDefine() );
- ASSERT_TRUE( sym->isUndef() );
- ASSERT_FALSE( sym->isDyn() );
- ASSERT_FALSE( sym->isCommon() );
- ASSERT_FALSE( sym->isIndirect() );
- ASSERT_TRUE( ResolveInfo::NoType == sym->type());
- ASSERT_TRUE( 0 == sym->desc() );
- ASSERT_TRUE( 0 == sym->binding() );
- ASSERT_TRUE( 0 == sym->other() );
+ ASSERT_FALSE(sym->isSymbol());
+ // ASSERT_TRUE( sym->isSymbol() );
+ ASSERT_TRUE(sym->isGlobal());
+ ASSERT_FALSE(sym->isWeak());
+ ASSERT_FALSE(sym->isLocal());
+ ASSERT_FALSE(sym->isDefine());
+ ASSERT_TRUE(sym->isUndef());
+ ASSERT_FALSE(sym->isDyn());
+ ASSERT_FALSE(sym->isCommon());
+ ASSERT_FALSE(sym->isIndirect());
+ ASSERT_TRUE(ResolveInfo::NoType == sym->type());
+ ASSERT_TRUE(0 == sym->desc());
+ ASSERT_TRUE(0 == sym->binding());
+ ASSERT_TRUE(0 == sym->other());
sym->setDesc(ResolveInfo::Define);
- ASSERT_FALSE( sym->isSymbol() );
-// ASSERT_TRUE( sym->isSymbol() );
- ASSERT_TRUE( sym->isGlobal() );
- ASSERT_FALSE( sym->isWeak() );
- ASSERT_FALSE( sym->isLocal() );
- ASSERT_TRUE( sym->isDefine() );
- ASSERT_FALSE( sym->isUndef() );
- ASSERT_FALSE( sym->isDyn() );
- ASSERT_FALSE( sym->isCommon() );
- ASSERT_FALSE( sym->isIndirect() );
- ASSERT_TRUE( ResolveInfo::NoType == sym->type());
- ASSERT_TRUE( ResolveInfo::Define == sym->desc() );
- ASSERT_TRUE( 0 == sym->binding() );
- ASSERT_TRUE( 0 == sym->other() );
+ ASSERT_FALSE(sym->isSymbol());
+ // ASSERT_TRUE( sym->isSymbol() );
+ ASSERT_TRUE(sym->isGlobal());
+ ASSERT_FALSE(sym->isWeak());
+ ASSERT_FALSE(sym->isLocal());
+ ASSERT_TRUE(sym->isDefine());
+ ASSERT_FALSE(sym->isUndef());
+ ASSERT_FALSE(sym->isDyn());
+ ASSERT_FALSE(sym->isCommon());
+ ASSERT_FALSE(sym->isIndirect());
+ ASSERT_TRUE(ResolveInfo::NoType == sym->type());
+ ASSERT_TRUE(ResolveInfo::Define == sym->desc());
+ ASSERT_TRUE(0 == sym->binding());
+ ASSERT_TRUE(0 == sym->other());
sym->setDesc(ResolveInfo::Common);
- ASSERT_FALSE( sym->isSymbol() );
-// ASSERT_TRUE( sym->isSymbol() );
- ASSERT_TRUE( sym->isGlobal() );
- ASSERT_FALSE( sym->isWeak() );
- ASSERT_FALSE( sym->isLocal() );
- ASSERT_FALSE( sym->isDyn() );
- ASSERT_FALSE( sym->isDefine() );
- ASSERT_FALSE( sym->isUndef() );
- ASSERT_TRUE( sym->isCommon() );
- ASSERT_FALSE( sym->isIndirect() );
- ASSERT_TRUE( ResolveInfo::NoType == sym->type());
- ASSERT_TRUE( ResolveInfo::Common == sym->desc() );
- ASSERT_TRUE( 0 == sym->binding() );
- ASSERT_TRUE( 0 == sym->other() );
+ ASSERT_FALSE(sym->isSymbol());
+ // ASSERT_TRUE( sym->isSymbol() );
+ ASSERT_TRUE(sym->isGlobal());
+ ASSERT_FALSE(sym->isWeak());
+ ASSERT_FALSE(sym->isLocal());
+ ASSERT_FALSE(sym->isDyn());
+ ASSERT_FALSE(sym->isDefine());
+ ASSERT_FALSE(sym->isUndef());
+ ASSERT_TRUE(sym->isCommon());
+ ASSERT_FALSE(sym->isIndirect());
+ ASSERT_TRUE(ResolveInfo::NoType == sym->type());
+ ASSERT_TRUE(ResolveInfo::Common == sym->desc());
+ ASSERT_TRUE(0 == sym->binding());
+ ASSERT_TRUE(0 == sym->other());
sym->setDesc(ResolveInfo::Indirect);
- ASSERT_FALSE( sym->isSymbol() );
- ASSERT_TRUE( sym->isGlobal() );
- ASSERT_FALSE( sym->isWeak() );
- ASSERT_FALSE( sym->isLocal() );
- ASSERT_FALSE( sym->isDyn() );
- ASSERT_FALSE( sym->isDefine() );
- ASSERT_FALSE( sym->isUndef() );
- ASSERT_FALSE( sym->isCommon() );
- ASSERT_TRUE( sym->isIndirect() );
- ASSERT_TRUE( ResolveInfo::NoType == sym->type());
- ASSERT_TRUE( ResolveInfo::Indirect == sym->desc() );
- ASSERT_TRUE( 0 == sym->binding() );
- ASSERT_TRUE( 0 == sym->other() );
+ ASSERT_FALSE(sym->isSymbol());
+ ASSERT_TRUE(sym->isGlobal());
+ ASSERT_FALSE(sym->isWeak());
+ ASSERT_FALSE(sym->isLocal());
+ ASSERT_FALSE(sym->isDyn());
+ ASSERT_FALSE(sym->isDefine());
+ ASSERT_FALSE(sym->isUndef());
+ ASSERT_FALSE(sym->isCommon());
+ ASSERT_TRUE(sym->isIndirect());
+ ASSERT_TRUE(ResolveInfo::NoType == sym->type());
+ ASSERT_TRUE(ResolveInfo::Indirect == sym->desc());
+ ASSERT_TRUE(0 == sym->binding());
+ ASSERT_TRUE(0 == sym->other());
sym->setDesc(ResolveInfo::Undefined);
- ASSERT_FALSE( sym->isSymbol() );
- ASSERT_TRUE( sym->isGlobal() );
- ASSERT_FALSE( sym->isWeak() );
- ASSERT_FALSE( sym->isLocal() );
- ASSERT_FALSE( sym->isDyn() );
- ASSERT_TRUE( sym->isUndef() );
- ASSERT_FALSE( sym->isDefine() );
- ASSERT_FALSE( sym->isCommon() );
- ASSERT_FALSE( sym->isIndirect() );
- ASSERT_TRUE( ResolveInfo::NoType == sym->type());
- ASSERT_TRUE( 0 == sym->desc() );
- ASSERT_TRUE( 0 == sym->binding() );
- ASSERT_TRUE( 0 == sym->other() );
+ ASSERT_FALSE(sym->isSymbol());
+ ASSERT_TRUE(sym->isGlobal());
+ ASSERT_FALSE(sym->isWeak());
+ ASSERT_FALSE(sym->isLocal());
+ ASSERT_FALSE(sym->isDyn());
+ ASSERT_TRUE(sym->isUndef());
+ ASSERT_FALSE(sym->isDefine());
+ ASSERT_FALSE(sym->isCommon());
+ ASSERT_FALSE(sym->isIndirect());
+ ASSERT_TRUE(ResolveInfo::NoType == sym->type());
+ ASSERT_TRUE(0 == sym->desc());
+ ASSERT_TRUE(0 == sym->binding());
+ ASSERT_TRUE(0 == sym->other());
}
-TEST_F( StaticResolverTest, SetUpBinding)
-{
+TEST_F(StaticResolverTest, SetUpBinding) {
ResolveInfo* sym = ResolveInfo::Create("abc");
sym->setIsSymbol(true);
-// ASSERT_FALSE( sym->isSymbol() );
- ASSERT_TRUE( sym->isSymbol() );
- ASSERT_TRUE( sym->isGlobal() );
- ASSERT_FALSE( sym->isWeak() );
- ASSERT_FALSE( sym->isLocal() );
- ASSERT_FALSE( sym->isDefine() );
- ASSERT_TRUE( sym->isUndef() );
- ASSERT_FALSE( sym->isDyn() );
- ASSERT_FALSE( sym->isCommon() );
- ASSERT_FALSE( sym->isIndirect() );
- ASSERT_TRUE( ResolveInfo::NoType == sym->type());
- ASSERT_TRUE( 0 == sym->desc() );
- ASSERT_TRUE( 0 == sym->binding() );
- ASSERT_TRUE( 0 == sym->other() );
+ // ASSERT_FALSE( sym->isSymbol() );
+ ASSERT_TRUE(sym->isSymbol());
+ ASSERT_TRUE(sym->isGlobal());
+ ASSERT_FALSE(sym->isWeak());
+ ASSERT_FALSE(sym->isLocal());
+ ASSERT_FALSE(sym->isDefine());
+ ASSERT_TRUE(sym->isUndef());
+ ASSERT_FALSE(sym->isDyn());
+ ASSERT_FALSE(sym->isCommon());
+ ASSERT_FALSE(sym->isIndirect());
+ ASSERT_TRUE(ResolveInfo::NoType == sym->type());
+ ASSERT_TRUE(0 == sym->desc());
+ ASSERT_TRUE(0 == sym->binding());
+ ASSERT_TRUE(0 == sym->other());
sym->setBinding(ResolveInfo::Global);
- ASSERT_TRUE( sym->isSymbol() );
- ASSERT_TRUE( sym->isGlobal() );
- ASSERT_FALSE( sym->isWeak() );
- ASSERT_FALSE( sym->isLocal() );
- ASSERT_FALSE( sym->isDefine() );
- ASSERT_TRUE( sym->isUndef() );
- ASSERT_FALSE( sym->isDyn() );
- ASSERT_FALSE( sym->isCommon() );
- ASSERT_FALSE( sym->isIndirect() );
- ASSERT_TRUE( ResolveInfo::NoType == sym->type());
- ASSERT_TRUE( 0 == sym->desc() );
- ASSERT_TRUE( ResolveInfo::Global == sym->binding() );
- ASSERT_TRUE( 0 == sym->other() );
+ ASSERT_TRUE(sym->isSymbol());
+ ASSERT_TRUE(sym->isGlobal());
+ ASSERT_FALSE(sym->isWeak());
+ ASSERT_FALSE(sym->isLocal());
+ ASSERT_FALSE(sym->isDefine());
+ ASSERT_TRUE(sym->isUndef());
+ ASSERT_FALSE(sym->isDyn());
+ ASSERT_FALSE(sym->isCommon());
+ ASSERT_FALSE(sym->isIndirect());
+ ASSERT_TRUE(ResolveInfo::NoType == sym->type());
+ ASSERT_TRUE(0 == sym->desc());
+ ASSERT_TRUE(ResolveInfo::Global == sym->binding());
+ ASSERT_TRUE(0 == sym->other());
sym->setBinding(ResolveInfo::Weak);
- ASSERT_TRUE( sym->isSymbol() );
- ASSERT_FALSE( sym->isGlobal() );
- ASSERT_TRUE( sym->isWeak() );
- ASSERT_FALSE( sym->isLocal() );
- ASSERT_FALSE( sym->isDyn() );
- ASSERT_FALSE( sym->isDefine() );
- ASSERT_TRUE( sym->isUndef() );
- ASSERT_FALSE( sym->isCommon() );
- ASSERT_FALSE( sym->isIndirect() );
- ASSERT_TRUE( ResolveInfo::NoType == sym->type());
- ASSERT_TRUE( 0 == sym->desc() );
- ASSERT_TRUE( ResolveInfo::Weak == sym->binding() );
- ASSERT_TRUE( 0 == sym->other() );
+ ASSERT_TRUE(sym->isSymbol());
+ ASSERT_FALSE(sym->isGlobal());
+ ASSERT_TRUE(sym->isWeak());
+ ASSERT_FALSE(sym->isLocal());
+ ASSERT_FALSE(sym->isDyn());
+ ASSERT_FALSE(sym->isDefine());
+ ASSERT_TRUE(sym->isUndef());
+ ASSERT_FALSE(sym->isCommon());
+ ASSERT_FALSE(sym->isIndirect());
+ ASSERT_TRUE(ResolveInfo::NoType == sym->type());
+ ASSERT_TRUE(0 == sym->desc());
+ ASSERT_TRUE(ResolveInfo::Weak == sym->binding());
+ ASSERT_TRUE(0 == sym->other());
sym->setBinding(ResolveInfo::Local);
- ASSERT_TRUE( sym->isSymbol() );
- ASSERT_FALSE( sym->isGlobal() );
- ASSERT_FALSE( sym->isWeak() );
- ASSERT_TRUE( sym->isLocal() );
- ASSERT_FALSE( sym->isDyn() );
- ASSERT_FALSE( sym->isDefine() );
- ASSERT_TRUE( sym->isUndef() );
- ASSERT_FALSE( sym->isCommon() );
- ASSERT_FALSE( sym->isIndirect() );
- ASSERT_TRUE( ResolveInfo::NoType == sym->type());
- ASSERT_TRUE( 0 == sym->desc() );
- ASSERT_TRUE( ResolveInfo::Local == sym->binding() );
- ASSERT_TRUE( 0 == sym->other() );
+ ASSERT_TRUE(sym->isSymbol());
+ ASSERT_FALSE(sym->isGlobal());
+ ASSERT_FALSE(sym->isWeak());
+ ASSERT_TRUE(sym->isLocal());
+ ASSERT_FALSE(sym->isDyn());
+ ASSERT_FALSE(sym->isDefine());
+ ASSERT_TRUE(sym->isUndef());
+ ASSERT_FALSE(sym->isCommon());
+ ASSERT_FALSE(sym->isIndirect());
+ ASSERT_TRUE(ResolveInfo::NoType == sym->type());
+ ASSERT_TRUE(0 == sym->desc());
+ ASSERT_TRUE(ResolveInfo::Local == sym->binding());
+ ASSERT_TRUE(0 == sym->other());
}
-
diff --git a/unittests/StaticResolverTest.h b/unittests/StaticResolverTest.h
index c6f0699..06f5052 100644
--- a/unittests/StaticResolverTest.h
+++ b/unittests/StaticResolverTest.h
@@ -10,7 +10,7 @@
#define STATICRESOLVER_TEST_H
#include <gtest.h>
-#include <mcld/LinkerConfig.h>
+#include "mcld/LinkerConfig.h"
namespace mcld {
@@ -18,19 +18,17 @@ class StaticResolver;
class ResolveInfoFactory;
class DiagnosticPrinter;
-} // namespace for mcld
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
/** \class StaticResolverTest
* \brief The testcases for static resolver
*
* \see StaticResolver
*/
-class StaticResolverTest : public ::testing::Test
-{
-public:
+class StaticResolverTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
StaticResolverTest();
@@ -43,13 +41,12 @@ public:
// TearDown() will be called immediately after each test.
virtual void TearDown();
-protected:
+ protected:
mcld::StaticResolver* m_pResolver;
mcld::LinkerConfig* m_pConfig;
mcld::DiagnosticPrinter* m_pPrinter;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/StringTableTest.cpp b/unittests/StringTableTest.cpp
index 59a8e7b..061068a 100644
--- a/unittests/StringTableTest.cpp
+++ b/unittests/StringTableTest.cpp
@@ -13,10 +13,8 @@
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-StringTableTest::StringTableTest()
-{
+StringTableTest::StringTableTest() {
// create testee. modify it if need
Resolver* R = new Resolver();
StrSymPool* Pool = new StrSymPool(1, 1, *R);
@@ -24,26 +22,23 @@ StringTableTest::StringTableTest()
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-StringTableTest::~StringTableTest()
-{
+StringTableTest::~StringTableTest() {
delete m_pTestee;
}
// SetUp() will be called immediately before each test.
-void StringTableTest::SetUp()
-{
+void StringTableTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void StringTableTest::TearDown()
-{
+void StringTableTest::TearDown() {
}
//==========================================================================//
// Testcases
//
TEST_F(StringTableTest, different_string_size) {
- int size = 127-32;
+ int size = 127 - 32;
for (int i = 32; i < 127; ++i) {
char c[2];
c[0] = i;
diff --git a/unittests/StringTableTest.h b/unittests/StringTableTest.h
index 60d7f00..8c2ae03 100644
--- a/unittests/StringTableTest.h
+++ b/unittests/StringTableTest.h
@@ -11,23 +11,20 @@
#include <gtest.h>
-namespace mcld
-{
+namespace mcld {
class StringTable;
-} // namespace for mcld
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
/** \class StringTableTest
* \brief
*
* \see StringTable
*/
-class StringTableTest : public ::testing::Test
-{
-public:
+class StringTableTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
StringTableTest();
@@ -40,11 +37,10 @@ public:
// TearDown() will be called immediately after each test.
virtual void TearDown();
-protected:
+ protected:
mcld::StringTable* m_pTestee;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/SymbolCategoryTest.cpp b/unittests/SymbolCategoryTest.cpp
index f1de1d7..7eb1988 100644
--- a/unittests/SymbolCategoryTest.cpp
+++ b/unittests/SymbolCategoryTest.cpp
@@ -6,9 +6,9 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/SymbolCategory.h>
-#include <mcld/LD/ResolveInfo.h>
-#include <mcld/LD/LDSymbol.h>
+#include "mcld/MC/SymbolCategory.h"
+#include "mcld/LD/ResolveInfo.h"
+#include "mcld/LD/LDSymbol.h"
#include <iostream>
#include "SymbolCategoryTest.h"
@@ -16,28 +16,23 @@ using namespace std;
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-SymbolCategoryTest::SymbolCategoryTest()
-{
+SymbolCategoryTest::SymbolCategoryTest() {
// create testee. modify it if need
m_pTestee = new SymbolCategory();
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-SymbolCategoryTest::~SymbolCategoryTest()
-{
+SymbolCategoryTest::~SymbolCategoryTest() {
delete m_pTestee;
}
// SetUp() will be called immediately before each test.
-void SymbolCategoryTest::SetUp()
-{
+void SymbolCategoryTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void SymbolCategoryTest::TearDown()
-{
+void SymbolCategoryTest::TearDown() {
}
//==========================================================================//
diff --git a/unittests/SymbolCategoryTest.h b/unittests/SymbolCategoryTest.h
index a7109ed..39dabd7 100644
--- a/unittests/SymbolCategoryTest.h
+++ b/unittests/SymbolCategoryTest.h
@@ -11,23 +11,20 @@
#include <gtest.h>
-namespace mcld
-{
+namespace mcld {
class SymbolCategory;
-} // namespace for mcld
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
/** \class SymbolCategoryTest
* \brief The testcases of symbol category.
*
* \see SymbolCategory
*/
-class SymbolCategoryTest : public ::testing::Test
-{
-public:
+class SymbolCategoryTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
SymbolCategoryTest();
@@ -40,11 +37,10 @@ public:
// TearDown() will be called immediately after each test.
virtual void TearDown();
-protected:
+ protected:
mcld::SymbolCategory* m_pTestee;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-
diff --git a/unittests/SymbolTableTest.cpp b/unittests/SymbolTableTest.cpp
index 2dc5143..a601d07 100644
--- a/unittests/SymbolTableTest.cpp
+++ b/unittests/SymbolTableTest.cpp
@@ -6,34 +6,29 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/LD/SymbolTable.h>
+#include "mcld/LD/SymbolTable.h"
#include "SymbolTableTest.h"
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-SymbolTableTest::SymbolTableTest()
-{
+SymbolTableTest::SymbolTableTest() {
// create testee. modify it if need
m_pTestee = new SymbolTable<>(m_StrTable);
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-SymbolTableTest::~SymbolTableTest()
-{
+SymbolTableTest::~SymbolTableTest() {
delete m_pTestee;
}
// SetUp() will be called immediately before each test.
-void SymbolTableTest::SetUp()
-{
+void SymbolTableTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void SymbolTableTest::TearDown()
-{
+void SymbolTableTest::TearDown() {
}
//==========================================================================//
diff --git a/unittests/SymbolTableTest.h b/unittests/SymbolTableTest.h
index 39e8751..4a4ce70 100644
--- a/unittests/SymbolTableTest.h
+++ b/unittests/SymbolTableTest.h
@@ -11,23 +11,20 @@
#include "mcld/LD/StringTable.h"
#include <gtest.h>
-namespace mcld
-{
- template <template <class> class, class>
- class SymbolTable;
-} // namespace for mcld
+namespace mcld {
+template <template <class> class, class>
+class SymbolTable;
+} // namespace for mcld
-namespace mcldtest
-{
+namespace mcldtest {
/** \class SymbolTableTest
* \brief
*
* \see SymbolTable
*/
-class SymbolTableTest : public ::testing::Test
-{
-public:
+class SymbolTableTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
SymbolTableTest();
@@ -40,11 +37,11 @@ public:
// TearDown() will be called immediately after each test.
virtual void TearDown();
-protected:
+ protected:
mcld::SymbolTable<>* m_pTestee;
mcld::StringTable m_StrTable;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
diff --git a/unittests/SystemUtilsTest.cpp b/unittests/SystemUtilsTest.cpp
index 1222794..3923aee 100644
--- a/unittests/SystemUtilsTest.cpp
+++ b/unittests/SystemUtilsTest.cpp
@@ -6,37 +6,31 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/Support/SystemUtils.h>
+#include "mcld/Support/SystemUtils.h"
#include "SystemUtilsTest.h"
using namespace mcld;
using namespace mcld::test;
-
// Constructor can do set-up work for all test here.
-SystemUtilsTest::SystemUtilsTest()
-{
+SystemUtilsTest::SystemUtilsTest() {
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-SystemUtilsTest::~SystemUtilsTest()
-{
+SystemUtilsTest::~SystemUtilsTest() {
}
// SetUp() will be called immediately before each test.
-void SystemUtilsTest::SetUp()
-{
+void SystemUtilsTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void SystemUtilsTest::TearDown()
-{
+void SystemUtilsTest::TearDown() {
}
//===----------------------------------------------------------------------===//
// Testcases
//===----------------------------------------------------------------------===//
-TEST_F( SystemUtilsTest, test_strerror) {
+TEST_F(SystemUtilsTest, test_strerror) {
ASSERT_TRUE(NULL != mcld::sys::strerror(0));
}
-
diff --git a/unittests/SystemUtilsTest.h b/unittests/SystemUtilsTest.h
index 660d7bb..ce0d204 100644
--- a/unittests/SystemUtilsTest.h
+++ b/unittests/SystemUtilsTest.h
@@ -14,9 +14,8 @@
namespace mcld {
namespace test {
-class SystemUtilsTest : public ::testing::Test
-{
-public:
+class SystemUtilsTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
SystemUtilsTest();
@@ -30,8 +29,7 @@ public:
virtual void TearDown();
};
-} // namespace of test
-} // namespace of mcld
+} // namespace of test
+} // namespace of mcld
#endif
-
diff --git a/unittests/TargetMachineTest.cpp b/unittests/TargetMachineTest.cpp
index 85950a9..8501d84 100644
--- a/unittests/TargetMachineTest.cpp
+++ b/unittests/TargetMachineTest.cpp
@@ -11,32 +11,26 @@
using namespace mcld;
using namespace mcldTEST;
-
// Constructor can do set-up work for all test here.
-TargetMachineTest::TargetMachineTest()
-{
+TargetMachineTest::TargetMachineTest() {
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-TargetMachineTest::~TargetMachineTest()
-{
+TargetMachineTest::~TargetMachineTest() {
}
// SetUp() will be called immediately before each test.
-void TargetMachineTest::SetUp()
-{
+void TargetMachineTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void TargetMachineTest::TearDown()
-{
+void TargetMachineTest::TearDown() {
}
//==========================================================================//
// Testcases
//
-TEST_F( TargetMachineTest, addPassesToEmitFile ) {
- mcld::addPassesToEmitFile();
+TEST_F(TargetMachineTest, addPassesToEmitFile) {
+ mcld::addPassesToEmitFile();
}
-
diff --git a/unittests/TargetMachineTest.h b/unittests/TargetMachineTest.h
index 88a44dc..3d19e68 100644
--- a/unittests/TargetMachineTest.h
+++ b/unittests/TargetMachineTest.h
@@ -11,31 +11,28 @@
#include "mcld/Target/TargetMachine.h"
#include <gtest.h>
-namespace mcldTEST
-{
+namespace mcldTEST {
/** \class TargetMachineTest
* \brief
*
* \see TargetMachine
*/
-class TargetMachineTest : public ::testing::Test
-{
-public:
- // Constructor can do set-up work for all test here.
- TargetMachineTest();
+class TargetMachineTest : public ::testing::Test {
+ public:
+ // Constructor can do set-up work for all test here.
+ TargetMachineTest();
- // Destructor can do clean-up work that doesn't throw exceptions here.
- virtual ~TargetMachineTest();
+ // Destructor can do clean-up work that doesn't throw exceptions here.
+ virtual ~TargetMachineTest();
- // SetUp() will be called immediately before each test.
- virtual void SetUp();
+ // SetUp() will be called immediately before each test.
+ virtual void SetUp();
- // TearDown() will be called immediately after each test.
- virtual void TearDown();
+ // TearDown() will be called immediately after each test.
+ virtual void TearDown();
};
-} // namespace of BOLDTEST
+} // namespace of BOLDTEST
#endif
-
diff --git a/unittests/UniqueGCFactoryBaseTest.cpp b/unittests/UniqueGCFactoryBaseTest.cpp
index a6f7289..5480eab 100644
--- a/unittests/UniqueGCFactoryBaseTest.cpp
+++ b/unittests/UniqueGCFactoryBaseTest.cpp
@@ -6,92 +6,91 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <mcld/MC/ContextFactory.h>
-#include <mcld/Support/MemoryAreaFactory.h>
-#include <mcld/Support/TargetSelect.h>
-#include <mcld/Support/Path.h>
+#include "mcld/MC/ContextFactory.h"
+#include "mcld/Support/MemoryAreaFactory.h"
+#include "mcld/Support/TargetSelect.h"
+#include "mcld/Support/Path.h"
#include "UniqueGCFactoryBaseTest.h"
using namespace mcld;
using namespace mcldtest;
-
// Constructor can do set-up work for all test here.
-UniqueGCFactoryBaseTest::UniqueGCFactoryBaseTest()
-{
+UniqueGCFactoryBaseTest::UniqueGCFactoryBaseTest() {
m_pConfig = new LinkerConfig("arm-none-linux-gnueabi");
}
// Destructor can do clean-up work that doesn't throw exceptions here.
-UniqueGCFactoryBaseTest::~UniqueGCFactoryBaseTest()
-{
+UniqueGCFactoryBaseTest::~UniqueGCFactoryBaseTest() {
delete m_pConfig;
}
// SetUp() will be called immediately before each test.
-void UniqueGCFactoryBaseTest::SetUp()
-{
+void UniqueGCFactoryBaseTest::SetUp() {
}
// TearDown() will be called immediately after each test.
-void UniqueGCFactoryBaseTest::TearDown()
-{
+void UniqueGCFactoryBaseTest::TearDown() {
}
//==========================================================================//
// Testcases
//
-TEST_F( UniqueGCFactoryBaseTest, number_constructor ) {
- ContextFactory *contextFactory = new ContextFactory(10);
- contextFactory->produce("/");
- contextFactory->produce("ab/c");
- ASSERT_TRUE( 2 == contextFactory->size());
- delete contextFactory;
+TEST_F(UniqueGCFactoryBaseTest, number_constructor) {
+ ContextFactory* contextFactory = new ContextFactory(10);
+ contextFactory->produce("/");
+ contextFactory->produce("ab/c");
+ ASSERT_TRUE(2 == contextFactory->size());
+ delete contextFactory;
}
-TEST_F( UniqueGCFactoryBaseTest, unique_produce ) {
- ContextFactory *contextFactory = new ContextFactory(10);
- LDContext* context1 = contextFactory->produce("/");
- contextFactory->produce("ab/c");
- ASSERT_TRUE( 2 == contextFactory->size());
- LDContext* context2 = contextFactory->produce("/");
- ASSERT_EQ( context1, context2 );
- delete contextFactory;
+TEST_F(UniqueGCFactoryBaseTest, unique_produce) {
+ ContextFactory* contextFactory = new ContextFactory(10);
+ LDContext* context1 = contextFactory->produce("/");
+ contextFactory->produce("ab/c");
+ ASSERT_TRUE(2 == contextFactory->size());
+ LDContext* context2 = contextFactory->produce("/");
+ ASSERT_EQ(context1, context2);
+ delete contextFactory;
}
-TEST_F( UniqueGCFactoryBaseTest, unique_produce2 ) {
- ContextFactory *contextFactory = new ContextFactory(10);
- LDContext* context1 = contextFactory->produce("abc/def");
- contextFactory->produce("ab/c");
- ASSERT_TRUE( 2 == contextFactory->size());
- LDContext* context2 = contextFactory->produce("ttt/../abc/def");
- ASSERT_EQ( context1, context2 );
- delete contextFactory;
+TEST_F(UniqueGCFactoryBaseTest, unique_produce2) {
+ ContextFactory* contextFactory = new ContextFactory(10);
+ LDContext* context1 = contextFactory->produce("abc/def");
+ contextFactory->produce("ab/c");
+ ASSERT_TRUE(2 == contextFactory->size());
+ LDContext* context2 = contextFactory->produce("ttt/../abc/def");
+ ASSERT_EQ(context1, context2);
+ delete contextFactory;
}
-TEST_F( UniqueGCFactoryBaseTest, iterator )
-{
- sys::fs::Path path1(TOPDIR), path2(TOPDIR);
- path1.append("unittests/test.txt");
- path2.append("unittests/test2.txt");
+TEST_F(UniqueGCFactoryBaseTest, iterator) {
+ sys::fs::Path path1(TOPDIR), path2(TOPDIR);
+ path1.append("unittests/test.txt");
+ path2.append("unittests/test2.txt");
- MemoryAreaFactory* memFactory = new MemoryAreaFactory(10);
- MemoryArea* area1 = memFactory->produce(path1, FileHandle::ReadOnly);
- MemoryArea* area2 = memFactory->produce(path2, FileHandle::ReadOnly);
- ASSERT_NE( area1, area2);
+ MemoryAreaFactory* memFactory = new MemoryAreaFactory(10);
+ MemoryArea* area1 =
+ memFactory->produce(path1, FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System));
+ MemoryArea* area2 =
+ memFactory->produce(path2, FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System));
+ ASSERT_NE(area1, area2);
- MemoryArea* area3 = memFactory->produce(path1, FileHandle::ReadOnly);
+ MemoryArea* area3 =
+ memFactory->produce(path1, FileHandle::OpenMode(FileHandle::ReadOnly),
+ FileHandle::Permission(FileHandle::System));
- ASSERT_EQ(area1, area3);
- ASSERT_FALSE( memFactory->empty());
- ASSERT_TRUE( 2 == memFactory->size());
- MemoryAreaFactory::iterator aIter = memFactory->begin();
- ASSERT_EQ( area1, &(*aIter));
- ++aIter;
- ASSERT_EQ( area2, &(*aIter));
- ++aIter;
- MemoryAreaFactory::iterator aEnd = memFactory->end();
- ASSERT_TRUE( aEnd == aIter);
- delete memFactory;
+ ASSERT_EQ(area1, area3);
+ ASSERT_FALSE(memFactory->empty());
+ ASSERT_TRUE(2 == memFactory->size());
+ MemoryAreaFactory::iterator aIter = memFactory->begin();
+ ASSERT_EQ(area1, &(*aIter));
+ ++aIter;
+ ASSERT_EQ(area2, &(*aIter));
+ ++aIter;
+ MemoryAreaFactory::iterator aEnd = memFactory->end();
+ ASSERT_TRUE(aEnd == aIter);
+ delete memFactory;
}
-
diff --git a/unittests/UniqueGCFactoryBaseTest.h b/unittests/UniqueGCFactoryBaseTest.h
index c2f1c1b..14ba2e0 100644
--- a/unittests/UniqueGCFactoryBaseTest.h
+++ b/unittests/UniqueGCFactoryBaseTest.h
@@ -9,22 +9,20 @@
#ifndef UNIQUE_GCFACTORYBASE_TEST_H
#define UNIQUE_GCFACTORYBASE_TEST_H
-#include <mcld/Support/UniqueGCFactory.h>
-#include <mcld/LinkerConfig.h>
-#include <mcld/LD/DiagnosticPrinter.h>
+#include "mcld/Support/UniqueGCFactory.h"
+#include "mcld/LinkerConfig.h"
+#include "mcld/LD/DiagnosticPrinter.h"
#include <gtest.h>
-namespace mcldtest
-{
+namespace mcldtest {
/** \class UniqueGCFactoryBaseTest
* - check the unique of key.
* - make sure the key associates with the same storage of value.
* - check if all functions in the GCFactoryBase are available.
*/
-class UniqueGCFactoryBaseTest : public ::testing::Test
-{
-public:
+class UniqueGCFactoryBaseTest : public ::testing::Test {
+ public:
// Constructor can do set-up work for all test here.
UniqueGCFactoryBaseTest();
@@ -37,11 +35,10 @@ public:
// TearDown() will be called immediately after each test.
virtual void TearDown();
-private:
+ private:
mcld::LinkerConfig* m_pConfig;
};
-} // namespace of mcldtest
+} // namespace of mcldtest
#endif
-