Skip to content

Commit

Permalink
Merged master:1108f5c737d into amd-gfx:532c99a8595
Browse files Browse the repository at this point in the history
Local branch amd-gfx 532c99a Merged master:60dff35fd43 into amd-gfx:90f8570b7b5
Remote branch master 1108f5c Revert "[Analyzer][WebKit] RefCntblBaseVirtualDtorChecker"
  • Loading branch information
Sw authored and Sw committed May 21, 2020
2 parents 532c99a + 1108f5c commit f8d60b6
Show file tree
Hide file tree
Showing 31 changed files with 2,133 additions and 83 deletions.
32 changes: 6 additions & 26 deletions libcxx/utils/ci/macos-backdeployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,22 @@ set -ue

function usage() {
cat <<EOM
$(basename ${0}) [-h|--help] --monorepo-root <MONOREPO-ROOT> --std <STD> --deployment-target <TARGET> --sdk-version <SDK-VERSION> [--libcxx-roots <DIR>] [--lit-args <ARGS...>] [--no-cleanup]
$(basename ${0}) [-h|--help] --monorepo-root <MONOREPO-ROOT> --std <STD> --deployment-target <TARGET> [--libcxx-roots <DIR>] [--lit-args <ARGS...>] [--no-cleanup]
This script is used to continually test the back-deployment use case of libc++ and libc++abi on MacOS.
Specifically, this script runs the libc++ test suite against the just-built headers and linking against the just-built dylib, but it runs the tests against the dylibs for the given deployment target.
--monorepo-root Full path to the root of the LLVM monorepo. Both libc++ and libc++abi headers from the monorepo are used.
--std Version of the C++ Standard to run the tests under (c++03, c++11, etc..).
--deployment-target The deployment target to run the tests for. This should be a version number of MacOS (e.g. 10.12). All MacOS versions until and including 10.9 are supported.
--sdk-version The version of the SDK to test with. This should be a version number of MacOS (e.g. 10.12). We'll link against the libc++ dylib in that SDK, but we'll run against the one on the given deployment target. The SDK version must be no older than the deployment target.
[--libcxx-roots] The path to previous libc++/libc++abi dylibs to use for back-deployment testing. Those are normally downloaded automatically, but if specified, this option will override the directory used. The directory should have the same layout as the roots downloaded automatically.
[--lit-args] Additional arguments to pass to lit (optional). If there are multiple arguments, quote them to pass them as a single argument to this script.
[--no-cleanup] Do not cleanup the temporary directory that was used for testing at the end. This can be useful to debug failures. Make sure to clean up manually after.
[-h, --help] Print this help.
EOM
}

function version-less-equal() {
[ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]
}

function version-less() {
[ "$1" = "$2" ] && return 1 || version-less-equal $1 $2
}

while [[ $# -gt 0 ]]; do
case "$1" in
--monorepo-root)
Expand All @@ -46,10 +39,6 @@ while [[ $# -gt 0 ]]; do
DEPLOYMENT_TARGET="${2}"
shift; shift
;;
--sdk-version)
MACOS_SDK_VERSION="${2}"
shift; shift
;;
--lit-args)
ADDITIONAL_LIT_ARGS="${2}"
shift; shift
Expand Down Expand Up @@ -77,16 +66,9 @@ done
if [[ -z ${MONOREPO_ROOT+x} ]]; then echo "--monorepo-root is a required parameter"; usage; exit 1; fi
if [[ -z ${STD+x} ]]; then echo "--std is a required parameter"; usage; exit 1; fi
if [[ -z ${DEPLOYMENT_TARGET+x} ]]; then echo "--deployment-target is a required parameter"; usage; exit 1; fi
if [[ -z ${MACOS_SDK_VERSION+x} ]]; then echo "--sdk-version is a required parameter"; usage; exit 1; fi
if [[ -z ${ADDITIONAL_LIT_ARGS+x} ]]; then ADDITIONAL_LIT_ARGS=""; fi
if [[ -z ${PREVIOUS_DYLIBS_DIR+x} ]]; then PREVIOUS_DYLIBS_DIR=""; fi

if version-less "${MACOS_SDK_VERSION}" "${DEPLOYMENT_TARGET}"; then
echo "SDK version ${MACOS_SDK_VERSION} shouldn't be older than the deployment target (${DEPLOYMENT_TARGET})"
usage
exit 1
fi

TEMP_DIR="$(mktemp -d)"
echo "Created temporary directory ${TEMP_DIR}"
function cleanup {
Expand Down Expand Up @@ -121,12 +103,11 @@ mkdir -p "${LLVM_BUILD_DIR}"
echo "@@@@@@"


echo "@@@ Installing the latest libc++ headers @@@"
ninja -C "${LLVM_BUILD_DIR}" install-cxx-headers
echo "@@@ Building and installing libc++ and libc++abi @@@"
ninja -C "${LLVM_BUILD_DIR}" install-cxx install-cxxabi
echo "@@@@@@"


# TODO: We should also link against the libc++abi.dylib that was shipped in the SDK
if [[ ${PREVIOUS_DYLIBS_DIR} == "" ]]; then
echo "@@@ Downloading dylibs for older deployment targets @@@"
PREVIOUS_DYLIBS_DIR="${TEMP_DIR}/libcxx-dylibs"
Expand All @@ -137,7 +118,6 @@ fi

LIBCXX_ROOT_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/libc++/${DEPLOYMENT_TARGET}"
LIBCXXABI_ROOT_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/libc++abi/${DEPLOYMENT_TARGET}"
LIBCXX_ROOT_IN_SDK="${PREVIOUS_DYLIBS_DIR}/macOS/libc++/${MACOS_SDK_VERSION}"

# TODO: We need to also run the tests for libc++abi.
echo "@@@ Running tests for libc++ @@@"
Expand All @@ -146,7 +126,7 @@ echo "@@@ Running tests for libc++ @@@"
--param=cxx_headers="${LLVM_INSTALL_DIR}/include/c++/v1" \
--param=std="${STD}" \
--param=platform="macosx${DEPLOYMENT_TARGET}" \
--param=cxx_library_root="${LIBCXX_ROOT_IN_SDK}" \
--param=cxx_library_root="${LLVM_INSTALL_DIR}/lib" \
--param=cxx_runtime_root="${LIBCXX_ROOT_ON_DEPLOYMENT_TARGET}" \
--param=abi_library_path="${LIBCXXABI_ROOT_ON_DEPLOYMENT_TARGET}" \
--param=use_system_cxx_lib="True" \
Expand Down
5 changes: 4 additions & 1 deletion lld/test/wasm/data-segments.ll
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ target triple = "wasm32-unknown-unknown"

; PASSIVE-LABEL: - Type: START
; PASSIVE-NEXT: StartFunction: 1
; PASSIVE-LABEL: - Type: DATACOUNT
; PASSIVE-NEXT: Count: 2
; PASSIVE-LABEL: - Type: CODE
; PASSIVE-NEXT: Functions:
; PASSIVE-NEXT: - Index: 0
; PASSIVE-NEXT: Locals: []
; PASSIVE-NEXT: Body: 0B
; PASSIVE-NEXT: - Index: 1
; PASSIVE-NEXT: Locals: []
; PASSIVE-NEXT: Body: 41B4D60041004101FE480200044041B4D6004101427FFE0102001A054180084100410DFC08000041900841004114FC08010041A40841004190CE00FC08020041B4D6004102FE17020041B4D600417FFE0002001A0BFC0900FC0901FC09020B
; PASSIVE-NEXT: Body: 41B4D60041004101FE480200044041B4D6004101427FFE0102001A054180084100410DFC08000041900841004114FC08010041B4D6004102FE17020041B4D600417FFE0002001A0BFC0900FC09010B

; PASSIVE-NEXT: - Index: 2
; PASSIVE-NEXT: Locals: []
; PASSIVE-NEXT: Body: 0B
Expand Down
2 changes: 1 addition & 1 deletion lld/wasm/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ void ExportSection::writeBody() {
}

bool StartSection::isNeeded() const {
return !config->relocatable && numSegments && config->sharedMemory;
return !config->relocatable && hasInitializedSegments && config->sharedMemory;
}

void StartSection::writeBody() {
Expand Down
8 changes: 4 additions & 4 deletions lld/wasm/SyntheticSections.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,14 @@ class ExportSection : public SyntheticSection {

class StartSection : public SyntheticSection {
public:
StartSection(uint32_t numSegments)
: SyntheticSection(llvm::wasm::WASM_SEC_START), numSegments(numSegments) {
}
StartSection(bool hasInitializedSegments)
: SyntheticSection(llvm::wasm::WASM_SEC_START),
hasInitializedSegments(hasInitializedSegments) {}
bool isNeeded() const override;
void writeBody() override;

protected:
uint32_t numSegments;
bool hasInitializedSegments;
};

class ElemSection : public SyntheticSection {
Expand Down
23 changes: 19 additions & 4 deletions lld/wasm/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Writer {
private:
void openFile();

bool needsPassiveInitialization(const OutputSegment *segment);
bool hasPassiveInitializedSegments();

void createInitMemoryFunction();
void createApplyRelocationsFunction();
void createCallCtorsFunction();
Expand Down Expand Up @@ -729,6 +732,18 @@ static void createFunction(DefinedFunction *func, StringRef bodyContent) {
cast<SyntheticFunction>(func->function)->setBody(body);
}

bool Writer::needsPassiveInitialization(const OutputSegment *segment) {
return segment->initFlags & WASM_SEGMENT_IS_PASSIVE &&
segment->name != ".tdata" && !segment->isBss;
}

bool Writer::hasPassiveInitializedSegments() {
return std::find_if(segments.begin(), segments.end(),
[this](const OutputSegment *s) {
return this->needsPassiveInitialization(s);
}) != segments.end();
}

void Writer::createInitMemoryFunction() {
LLVM_DEBUG(dbgs() << "createInitMemoryFunction\n");
assert(WasmSym::initMemoryFlag);
Expand All @@ -738,7 +753,7 @@ void Writer::createInitMemoryFunction() {
raw_string_ostream os(bodyContent);
writeUleb128(os, 0, "num locals");

if (segments.size()) {
if (hasPassiveInitializedSegments()) {
// Initialize memory in a thread-safe manner. The thread that successfully
// increments the flag from 0 to 1 is is responsible for performing the
// memory initialization. Other threads go sleep on the flag until the
Expand Down Expand Up @@ -804,7 +819,7 @@ void Writer::createInitMemoryFunction() {

// Did increment 0, so conditionally initialize passive data segments
for (const OutputSegment *s : segments) {
if (s->initFlags & WASM_SEGMENT_IS_PASSIVE && s->name != ".tdata") {
if (needsPassiveInitialization(s)) {
// destination address
writeI32Const(os, s->startVA, "destination address");
// source segment offset
Expand Down Expand Up @@ -838,7 +853,7 @@ void Writer::createInitMemoryFunction() {

// Unconditionally drop passive data segments
for (const OutputSegment *s : segments) {
if (s->initFlags & WASM_SEGMENT_IS_PASSIVE && s->name != ".tdata") {
if (needsPassiveInitialization(s)) {
// data.drop instruction
writeU8(os, WASM_OPCODE_MISC_PREFIX, "bulk-memory prefix");
writeUleb128(os, WASM_OPCODE_DATA_DROP, "data.drop");
Expand Down Expand Up @@ -983,7 +998,7 @@ void Writer::createSyntheticSections() {
out.eventSec = make<EventSection>();
out.globalSec = make<GlobalSection>();
out.exportSec = make<ExportSection>();
out.startSec = make<StartSection>(segments.size());
out.startSec = make<StartSection>(hasPassiveInitializedSegments());
out.elemSec = make<ElemSection>();
out.dataCountSec = make<DataCountSection>(segments);
out.linkingSec = make<LinkingSection>(initFunctions, segments);
Expand Down
8 changes: 8 additions & 0 deletions llvm/docs/CommandGuide/dsymutil.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ OPTIONS
Produce a flat dSYM file. A ``.dwarf`` extension will be appended to the
executable name unless the output file is specified using the ``-o`` option.

.. option:: --gen-reproducer

Generate a reproducer consisting of the input object files.

.. option:: --help, -h

Print this help output.
Expand Down Expand Up @@ -131,6 +135,10 @@ OPTIONS
other DWARF optimizations. This option will rebuild the '.apple_names' and
'.apple_types' hashed accelerator tables.

.. option:: --use-reproducer <path>

Use the object files from the given reproducer path.

.. option:: --verbose

Display verbose information when linking.
Expand Down
13 changes: 10 additions & 3 deletions llvm/include/llvm/IR/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ class Module {
/// converted result in MFB.
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB);

/// Check if the given module flag metadata represents a valid module flag,
/// and store the flag behavior, the key string and the value metadata.
static bool isValidModuleFlag(const MDNode &ModFlag, ModFlagBehavior &MFB,
MDString *&Key, Metadata *&Val);

struct ModuleFlagEntry {
ModFlagBehavior Behavior;
MDString *Key;
Expand Down Expand Up @@ -493,10 +498,12 @@ class Module {
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Constant *Val);
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);
void addModuleFlag(MDNode *Node);
/// Like addModuleFlag but replaces the old module flag if it already exists.
void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val);

/// @}
/// @name Materialization
/// @{
/// @}
/// @name Materialization
/// @{

/// Sets the GVMaterializer to GVM. This module must not yet have a
/// Materializer. To reset the materializer for a module that already has one,
Expand Down
43 changes: 36 additions & 7 deletions llvm/lib/IR/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,20 @@ bool Module::isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB) {
return false;
}

bool Module::isValidModuleFlag(const MDNode &ModFlag, ModFlagBehavior &MFB,
MDString *&Key, Metadata *&Val) {
if (ModFlag.getNumOperands() < 3)
return false;
if (!isValidModFlagBehavior(ModFlag.getOperand(0), MFB))
return false;
MDString *K = dyn_cast_or_null<MDString>(ModFlag.getOperand(1));
if (!K)
return false;
Key = K;
Val = ModFlag.getOperand(2);
return true;
}

/// getModuleFlagsMetadata - Returns the module flags in the provided vector.
void Module::
getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const {
Expand All @@ -291,13 +305,11 @@ getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const {

for (const MDNode *Flag : ModFlags->operands()) {
ModFlagBehavior MFB;
if (Flag->getNumOperands() >= 3 &&
isValidModFlagBehavior(Flag->getOperand(0), MFB) &&
dyn_cast_or_null<MDString>(Flag->getOperand(1))) {
MDString *Key = nullptr;
Metadata *Val = nullptr;
if (isValidModuleFlag(*Flag, MFB, Key, Val)) {
// Check the operands of the MDNode before accessing the operands.
// The verifier will actually catch these failures.
MDString *Key = cast<MDString>(Flag->getOperand(1));
Metadata *Val = Flag->getOperand(2);
Flags.push_back(ModuleFlagEntry(MFB, Key, Val));
}
}
Expand Down Expand Up @@ -358,6 +370,23 @@ void Module::addModuleFlag(MDNode *Node) {
getOrInsertModuleFlagsMetadata()->addOperand(Node);
}

void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
Metadata *Val) {
NamedMDNode *ModFlags = getOrInsertModuleFlagsMetadata();
// Replace the flag if it already exists.
for (unsigned I = 0, E = ModFlags->getNumOperands(); I != E; ++I) {
MDNode *Flag = ModFlags->getOperand(I);
ModFlagBehavior MFB;
MDString *K = nullptr;
Metadata *V = nullptr;
if (isValidModuleFlag(*Flag, MFB, K, V) && K->getString() == Key) {
Flag->replaceOperandWith(2, Val);
return;
}
}
addModuleFlag(Behavior, Key, Val);
}

void Module::setDataLayout(StringRef Desc) {
DL.reset(Desc);
}
Expand Down Expand Up @@ -547,9 +576,9 @@ void Module::setCodeModel(CodeModel::Model CL) {

void Module::setProfileSummary(Metadata *M, ProfileSummary::Kind Kind) {
if (Kind == ProfileSummary::PSK_CSInstr)
addModuleFlag(ModFlagBehavior::Error, "CSProfileSummary", M);
setModuleFlag(ModFlagBehavior::Error, "CSProfileSummary", M);
else
addModuleFlag(ModFlagBehavior::Error, "ProfileSummary", M);
setModuleFlag(ModFlagBehavior::Error, "ProfileSummary", M);
}

Metadata *Module::getProfileSummary(bool IsCS) {
Expand Down
Loading

0 comments on commit f8d60b6

Please sign in to comment.