Skip to content

Commit

Permalink
get rid of weak symbols and hack with dynamic linkage
Browse files Browse the repository at this point in the history
  • Loading branch information
mkornaukhov03 committed Oct 31, 2024
1 parent 077c234 commit 92f40a7
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 49 deletions.
2 changes: 1 addition & 1 deletion compiler/data/class-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ std::vector<ClassPtr> ClassData::get_all_ancestors() const {
}

bool ClassData::is_builtin() const {
return is_ffi_cdata() || (file_id && file_id->is_builtin() && !internal_interface);
return is_ffi_cdata() || (file_id && file_id->is_builtin());
}

bool ClassData::is_polymorphic_or_has_polymorphic_member() const {
Expand Down
4 changes: 0 additions & 4 deletions compiler/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,10 +1723,6 @@ VertexPtr GenTree::get_class(const PhpDocComment *phpdoc, ClassType class_type)
cur_class->is_immutable = phpdoc && phpdoc->has_tag(PhpDocType::kphp_immutable_class);
cur_class->need_generated_stub = phpdoc && phpdoc->has_tag(PhpDocType::kphp_generated_stub_class);
cur_class->internal_interface = phpdoc && phpdoc->has_tag(PhpDocType::kphp_internal_interface);
if (cur_class->internal_interface && full_class_name == "ArrayAccess") {
// TODO get rid of it later
cur_class->may_be_mixed = true;
}
cur_class->location_line_num = line_num;

bool registered = G->register_class(cur_class);
Expand Down
10 changes: 4 additions & 6 deletions compiler/make/make.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class MakeSetup {
return create_target(new H2PchTarget(), to_targets(header_h), pch);
}

Target *create_objs2obj_target(std::vector<File *> objs, File *obj, bool force_obj = false) {
return create_target(new Objs2ObjTarget(force_obj), to_targets(std::move(objs)), obj);
Target *create_objs2obj_target(std::vector<File *> objs, File *obj) {
return create_target(new Objs2ObjTarget(), to_targets(std::move(objs)), obj);
}

Target *create_objs2bin_target(std::vector<File *> objs, File *bin) {
Expand Down Expand Up @@ -395,15 +395,13 @@ static std::vector<File *> create_obj_files(MakeSetup *make, Index &obj_dir, con
vk::hash_combine(hash, vk::std_hash(f->name));
}

bool force_obj = name_and_files.first == "internal_interfaces";

auto intermediate_file_name = fmt_format("{}_{:x}.{}", name_and_files.first, hash,
G->settings().dynamic_incremental_linkage.get() && (!force_obj) ? "so" : "o");
G->settings().dynamic_incremental_linkage.get() ? "so" : "o");
File *obj_file = obj_dir.insert_file(std::move(intermediate_file_name));



make->create_objs2obj_target(std::move(deps), obj_file, force_obj);
make->create_objs2obj_target(std::move(deps), obj_file);
objs.push_back(obj_file);
}
fmt_fprintf(stderr, "objs cnt = {}\n", objs.size());
Expand Down
8 changes: 1 addition & 7 deletions compiler/make/objs-to-obj-target.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@
#include "compiler/make/target.h"

class Objs2ObjTarget : public Target {
bool force_obj;

public:
explicit Objs2ObjTarget(bool force_obj_) : force_obj(force_obj_) {}

std::string get_cmd() final {
std::stringstream ss;
ss << settings->cxx.get() <<
" " << settings->cxx_toolchain_option.get() <<
" " <<
// settings->incremental_linker_flags.get() <<
(force_obj ? "-r -nostdlib" : settings->incremental_linker_flags.get())
<<
settings->incremental_linker_flags.get() <<
" -o " << target() <<
" " << dep_list();
return ss.str();
Expand Down
4 changes: 0 additions & 4 deletions compiler/pipes/code-gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ std::string CodeGenF::calc_subdir_for_function(FunctionPtr func) {
return "o_l";
}

if (func->name.find("ArrayAccess") != std::string::npos) {
return "internal_interfaces";
}

int bucket = vk::std_hash(func->file_id->short_file_name) % 100;
return "o_" + std::to_string(bucket);
}
Expand Down
21 changes: 21 additions & 0 deletions runtime-common/core/array_access.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Compiler for PHP (aka KPHP)
// Copyright (c) 2024 LLC «V Kontakte»
// Distributed under the GPL v3 License, see LICENSE.notice.txt

#pragma once
#include "runtime-common/core/class-instance/refcountable-php-classes.h"

// TODO may be add guard to force include only from runtime-core.h?

struct C$ArrayAccess : public may_be_mixed_base {
virtual int get_hash() const noexcept = 0;

C$ArrayAccess() __attribute__((always_inline)) = default;
~C$ArrayAccess() override __attribute__((always_inline)) = default;
};


bool f$ArrayAccess$$offsetExists(class_instance<C$ArrayAccess> const & /*v$this*/, mixed const & /*v$offset*/) noexcept;
mixed f$ArrayAccess$$offsetGet(class_instance<C$ArrayAccess> const & /*v$this*/, mixed const & /*v$offset*/) noexcept;
void f$ArrayAccess$$offsetSet(class_instance<C$ArrayAccess> const & /*v$this*/, mixed const & /*v$offset*/, mixed const & /*v$value*/) noexcept;
void f$ArrayAccess$$offsetUnset(class_instance<C$ArrayAccess> const & /*v$this*/, mixed const & /*v$offset*/) noexcept;
27 changes: 0 additions & 27 deletions runtime-common/core/core-types/definition/mixed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,6 @@
#include "runtime-common/core/runtime-core.h"
#include <cassert>

// TODO must check that in runtime nothing will get wrong or store it some runtime header file
struct C$ArrayAccess : public may_be_mixed_base {
virtual int get_hash() const noexcept = 0;

C$ArrayAccess() __attribute__((always_inline)) = default;
~C$ArrayAccess() __attribute__((always_inline)) = default;
};

__attribute__((weak)) bool f$ArrayAccess$$offsetExists(class_instance<C$ArrayAccess> const & /*v$this*/, mixed const & /*v$offset*/) noexcept {
assert(0 && "using stub of offsetExists");
return {};
}

__attribute__((weak)) mixed f$ArrayAccess$$offsetGet(class_instance<C$ArrayAccess> const & /*v$this*/, mixed const & /*v$offset*/) noexcept {
assert(0 && "using stub of offsetGet");
return {};
}

__attribute__((weak)) void f$ArrayAccess$$offsetSet(class_instance<C$ArrayAccess> const & /*v$this*/, mixed const & /*v$offset*/,
mixed const & /*v$value*/) noexcept {
assert(0 && "using stub of offsetSet");
}

__attribute__((weak)) void f$ArrayAccess$$offsetUnset(class_instance<C$ArrayAccess> const & /*v$this*/, mixed const & /*v$offset*/) noexcept {
assert(0 && "using stub of offsetUnset");
}

void mixed::copy_from(const mixed &other) {
switch (other.get_type()) {
case type::STRING:
Expand Down
1 change: 1 addition & 0 deletions runtime-common/core/runtime-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#define INCLUDED_FROM_KPHP_CORE

#include "runtime-common/core/array_access.h"
#include "runtime-common/core/core-types/decl/string_decl.inl"
#include "runtime-common/core/core-types/decl/array_decl.inl"
#include "runtime-common/core/class-instance/class-instance-decl.inl"
Expand Down
20 changes: 20 additions & 0 deletions tests/cpp/runtime/_runtime-tests-env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "runtime/pdo/pdo_statement.h"
#include "runtime/php_assert.h"
#include "runtime/tl/rpc_response.h"
#include "runtime-common/core/array_access.h"
#include "server/php-engine-vars.h"
#include "server/workers-control.h"

Expand Down Expand Up @@ -82,3 +83,22 @@ char **get_runtime_options(int *) noexcept {
assert(0 && "this code shouldn't be executed and only for linkage test");
return nullptr;
}


bool f$ArrayAccess$$offsetExists(class_instance<C$ArrayAccess> const & /*v$this*/, mixed const & /*v$offset*/) noexcept {
assert(0 && "this code shouldn't be executed and only for linkage test");
return {};
}

mixed f$ArrayAccess$$offsetGet(class_instance<C$ArrayAccess> const & /*v$this*/, mixed const & /*v$offset*/) noexcept {
assert(0 && "this code shouldn't be executed and only for linkage test");
return {};
}

void f$ArrayAccess$$offsetSet(class_instance<C$ArrayAccess> const & /*v$this*/, mixed const & /*v$offset*/, mixed const & /*v$value*/) noexcept {
assert(0 && "this code shouldn't be executed and only for linkage test");
}

void f$ArrayAccess$$offsetUnset(class_instance<C$ArrayAccess> const & /*v$this*/, mixed const & /*v$offset*/) noexcept {
assert(0 && "this code shouldn't be executed and only for linkage test");
}

0 comments on commit 92f40a7

Please sign in to comment.