2017-10-11 06:33:29 +08:00
|
|
|
//===- llvm/CodeGen/MachineModuleInfoImpls.cpp ----------------------------===//
|
2009-09-16 14:03:48 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-09-16 14:03:48 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements object-file format specific implementations of
|
|
|
|
// MachineModuleInfoImpl.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
2017-10-11 06:33:29 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2009-09-16 14:03:48 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2017-10-11 06:33:29 +08:00
|
|
|
|
2009-09-16 14:03:48 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MachineModuleInfoMachO
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Out of line virtual method.
|
2012-09-26 14:36:36 +08:00
|
|
|
void MachineModuleInfoMachO::anchor() {}
|
|
|
|
void MachineModuleInfoELF::anchor() {}
|
[MinGW] [X86] Add stubs for references to data variables that might end up imported from a dll
Variables declared with the dllimport attribute are accessed via a
stub variable named __imp_<var>. In MinGW configurations, variables that
aren't declared with a dllimport attribute might still end up imported
from another DLL with runtime pseudo relocs.
For x86_64, this avoids the risk that the target is out of range
for a 32 bit PC relative reference, in case the target DLL is loaded
further than 4 GB from the reference. It also avoids having to make the
text section writable at runtime when doing the runtime fixups, which
makes it worthwhile to do for i386 as well.
Add stub variables for all dso local data references where a definition
of the variable isn't visible within the module, since the DLL data
autoimporting might make them imported even though they are marked as
dso local within LLVM.
Don't do this for variables that actually are defined within the same
module, since we then know for sure that it actually is dso local.
Don't do this for references to functions, since there's no need for
runtime pseudo relocations for autoimporting them; if a function from
a different DLL is called without the appropriate dllimport attribute,
the call just gets routed via a thunk instead.
GCC does something similar since 4.9 (when compiling with -mcmodel=medium
or large; from that version, medium is the default code model for x86_64
mingw), but only for x86_64.
Differential Revision: https://reviews.llvm.org/D51288
llvm-svn: 340942
2018-08-30 01:28:34 +08:00
|
|
|
void MachineModuleInfoCOFF::anchor() {}
|
[WebAssembly] Added initial type checker to MC Assembler
This to protect against non-sensical instruction sequences being assembled,
which would either cause asserts/crashes further down, or a Wasm module being output that doesn't validate.
Unlike a validator, this type checker is able to give type-errors as part of the parsing process, which makes the assembler much friendlier to be used by humans writing manual input.
Because the MC system is single pass (instructions aren't even stored in MC format, they are directly output) the type checker has to be single pass as well, which means that from now on .globaltype and .functype decls must come before their use. An extra pass is added to Codegen to collect information for this purpose, since AsmPrinter is normally single pass / streaming as well, and would otherwise generate this information on the fly.
A `-no-type-check` flag was added to llvm-mc (and any other tools that take asm input) that surpresses type errors, as a quick escape hatch for tests that were not intended to be type correct.
This is a first version of the type checker that ignores control flow, i.e. it checks that types are correct along the linear path, but not the branch path. This will still catch most errors. Branch checking could be added in the future.
Differential Revision: https://reviews.llvm.org/D104945
2021-06-08 03:10:47 +08:00
|
|
|
void MachineModuleInfoWasm::anchor() {}
|
2009-09-16 14:03:48 +08:00
|
|
|
|
2017-10-27 00:07:20 +08:00
|
|
|
using PairTy = std::pair<MCSymbol *, MachineModuleInfoImpl::StubValueTy>;
|
|
|
|
static int SortSymbolPair(const PairTy *LHS, const PairTy *RHS) {
|
|
|
|
return LHS->first->getName().compare(RHS->first->getName());
|
2009-09-16 14:03:48 +08:00
|
|
|
}
|
|
|
|
|
2015-04-07 20:59:28 +08:00
|
|
|
MachineModuleInfoImpl::SymbolListTy MachineModuleInfoImpl::getSortedStubs(
|
|
|
|
DenseMap<MCSymbol *, MachineModuleInfoImpl::StubValueTy> &Map) {
|
2010-02-16 06:35:59 +08:00
|
|
|
MachineModuleInfoImpl::SymbolListTy List(Map.begin(), Map.end());
|
|
|
|
|
2017-10-27 00:07:20 +08:00
|
|
|
array_pod_sort(List.begin(), List.end(), SortSymbolPair);
|
2015-04-07 20:59:28 +08:00
|
|
|
|
|
|
|
Map.clear();
|
2009-09-16 14:03:48 +08:00
|
|
|
return List;
|
|
|
|
}
|