Skip to content

Commit

Permalink
Move build to Ubuntu 14.04 and GCC 7.2.
Browse files Browse the repository at this point in the history
To be able to run on the same distributions as before we need to have
the same GLIBC version dependency as in Ubuntu 12.04, which is 2.15.

For that we need to remove all usages of GLIBC features from 2.16 and above.
Currently there are three methods used, so they're wrapped in a separate
static library, linux_glibc_wraps.

It is a separate library because it must be compiled without '-flto' flag,
otherwise the inline __asm__ is not working and we get unresolved symbols.
  • Loading branch information
john-preston committed Nov 16, 2017
1 parent 1cd126d commit 21b1ba1
Show file tree
Hide file tree
Showing 16 changed files with 464 additions and 198 deletions.
150 changes: 149 additions & 1 deletion Telegram/Patches/breakpad.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/src/build/common.gypi b/src/build/common.gypi
index b9466a3..9fb31aa 100644
index 29990c6..53e99d4 100644
--- a/src/build/common.gypi
+++ b/src/build/common.gypi
@@ -330,6 +330,7 @@
Expand Down Expand Up @@ -479,3 +479,151 @@ index 1d2e519..943310f 100644
return true;
}

diff --git a/src/common/language.cc b/src/common/language.cc
index 978fb85..a95ae5f 100644
--- a/src/common/language.cc
+++ b/src/common/language.cc
@@ -46,8 +46,27 @@

#include <limits>

+#include <cstdio>
+#include <iostream>
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <array>
+
namespace {

+std::string exec(std::string cmd) {
+ std::array<char, 128> buffer;
+ std::string result;
+ std::shared_ptr<FILE> pipe(popen(cmd.c_str(), "r"), pclose);
+ if (!pipe) throw std::runtime_error("popen() failed!");
+ while (!feof(pipe.get())) {
+ if (fgets(buffer.data(), 128, pipe.get()) != nullptr)
+ result += buffer.data();
+ }
+ return result;
+}
+
string MakeQualifiedNameWithSeparator(const string& parent_name,
const char* separator,
const string& name) {
@@ -79,11 +98,29 @@ class CPPLanguage: public Language {
demangled->clear();
return kDontDemangle;
#else
+ DemangleResult result;
+ if (mangled.find("type_erased_handlers") != std::string::npos
+ && mangled.find("vtable_once_impl") != std::string::npos) {
+
+ auto demangled_str = exec("c++filt " + mangled);
+ if (!demangled_str.empty() && demangled_str.back() == '\n') {
+ demangled_str.pop_back();
+ }
+ if (demangled_str != mangled) {
+ result = kDemangleSuccess;
+ demangled->assign(demangled_str.c_str());
+ } else {
+ result = kDemangleFailure;
+ demangled->clear();
+ }
+
+ } else {
+
int status;
char* demangled_c =
abi::__cxa_demangle(mangled.c_str(), NULL, NULL, &status);

- DemangleResult result;
+// DemangleResult result;
if (status == 0) {
result = kDemangleSuccess;
demangled->assign(demangled_c);
@@ -96,6 +133,8 @@ class CPPLanguage: public Language {
free(reinterpret_cast<void*>(demangled_c));
}

+ }
+
return result;
#endif
}
diff --git a/src/common/linux/elf_symbols_to_module.cc b/src/common/linux/elf_symbols_to_module.cc
index 562875e..4367851 100644
--- a/src/common/linux/elf_symbols_to_module.cc
+++ b/src/common/linux/elf_symbols_to_module.cc
@@ -39,6 +39,29 @@
#include "common/byte_cursor.h"
#include "common/module.h"

+#include <cstdio>
+#include <iostream>
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <array>
+
+namespace {
+
+std::string exec(std::string cmd) {
+ std::array<char, 128> buffer;
+ std::string result;
+ std::shared_ptr<FILE> pipe(popen(cmd.c_str(), "r"), pclose);
+ if (!pipe) throw std::runtime_error("popen() failed!");
+ while (!feof(pipe.get())) {
+ if (fgets(buffer.data(), 128, pipe.get()) != nullptr)
+ result += buffer.data();
+ }
+ return result;
+}
+
+}
+
namespace google_breakpad {

class ELFSymbolIterator {
@@ -159,6 +182,19 @@ bool ELFSymbolsToModule(const uint8_t *symtab_section,
Module::Extern *ext = new Module::Extern(iterator->value);
ext->name = SymbolString(iterator->name_offset, strings);
#if !defined(__ANDROID__) // Android NDK doesn't provide abi::__cxa_demangle.
+ if (ext->name.find("type_erased_handlers") != std::string::npos
+ && ext->name.find("vtable_once_impl") != std::string::npos) {
+
+ auto demangled_str = exec("c++filt " + ext->name);
+ if (!demangled_str.empty() && demangled_str.back() == '\n') {
+ demangled_str.pop_back();
+ }
+ if (demangled_str != ext->name) {
+ ext->name = demangled_str;
+ }
+
+ } else {
+
int status = 0;
char* demangled =
abi::__cxa_demangle(ext->name.c_str(), NULL, NULL, &status);
@@ -167,6 +203,8 @@ bool ELFSymbolsToModule(const uint8_t *symtab_section,
ext->name = demangled;
free(demangled);
}
+
+ }
#endif
module->AddExtern(ext);
}
diff --git a/src/tools/linux/tools_linux.gypi b/src/tools/linux/tools_linux.gypi
index 1c15992..020e4c1 100644
--- a/src/tools/linux/tools_linux.gypi
+++ b/src/tools/linux/tools_linux.gypi
@@ -58,7 +58,7 @@
'target_name': 'minidump_upload',
'type': 'executable',
'sources': [
- 'symupload/minidump_upload.m',
+ 'symupload/minidump_upload.cc',
],
'dependencies': [
'../common/common.gyp:common',
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/calls/calls_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ void Call::setState(State state) {
break;
case State::Ended:
_delegate->playSound(Delegate::Sound::Ended);
// [[fallthrough]]
[[fallthrough]];
case State::EndedByOtherDevice:
_delegate->callFinished(this);
break;
Expand Down
17 changes: 1 addition & 16 deletions Telegram/SourceFiles/core/basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,10 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include <ctime>

#include "base/build_config.h"
#include "base/ordered_set.h"

using gsl::not_null;

#if defined COMPILER_GCC
namespace std {

template <typename T>
constexpr std::add_const_t<T>& as_const(T& t) noexcept {
return t;
}

template <typename T>
void as_const(const T&&) = delete;

} // namespace std
#endif // COMPILER_GCC

#include "base/ordered_set.h"

//using uchar = unsigned char; // Qt has uchar
using int16 = qint16;
using uint16 = quint16;
Expand Down
43 changes: 43 additions & 0 deletions Telegram/SourceFiles/platform/linux/linux_glibc_wraps.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
This file is part of Telegram Desktop,
the official desktop version of Telegram messaging app, see https://telegram.org
Telegram Desktop is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
It is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

void *__wrap_aligned_alloc(size_t alignment, size_t size) {
void *result = NULL;
return (posix_memalign(&result, alignment, size) == 0)
? result
: NULL;
}

int enable_secure_inited = 0;
int enable_secure = 1;

char *__wrap_secure_getenv(const char *name) {
if (enable_secure_inited == 0) {
enable_secure_inited = 1;
enable_secure = (geteuid() != getuid())
|| (getegid() != getgid());
}
return enable_secure ? NULL : getenv(name);
}

55 changes: 55 additions & 0 deletions Telegram/SourceFiles/platform/linux/linux_glibc_wraps_32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
This file is part of Telegram Desktop,
the official desktop version of Telegram messaging app, see https://telegram.org
Telegram Desktop is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
It is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#include <time.h>
#include <stdint.h>

int __clock_gettime_glibc_old(clockid_t clk_id, struct timespec *tp);
__asm__(".symver __clock_gettime_glibc_old,clock_gettime@GLIBC_2.2");

int __wrap_clock_gettime(clockid_t clk_id, struct timespec *tp) {
return __clock_gettime_glibc_old(clk_id, tp);
}

uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem_p);

int64_t __wrap___divmoddi4(int64_t num, int64_t den, int64_t *rem_p) {
int minus = 0;
int64_t v;

if (num < 0) {
num = -num;
minus = 1;
}
if (den < 0) {
den = -den;
minus ^= 1;
}

v = __udivmoddi4(num, den, (uint64_t *)rem_p);
if (minus) {
v = -v;
if (rem_p)
*rem_p = -(*rem_p);
}

return v;
}

29 changes: 29 additions & 0 deletions Telegram/SourceFiles/platform/linux/linux_glibc_wraps_64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
This file is part of Telegram Desktop,
the official desktop version of Telegram messaging app, see https://telegram.org
Telegram Desktop is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
It is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#include <time.h>

int __clock_gettime_glibc_old(clockid_t clk_id, struct timespec *tp);
__asm__(".symver __clock_gettime_glibc_old,clock_gettime@GLIBC_2.2.5");

int __wrap_clock_gettime(clockid_t clk_id, struct timespec *tp) {
return __clock_gettime_glibc_old(clk_id, tp);
}

41 changes: 0 additions & 41 deletions Telegram/SourceFiles/rpl/details/callable.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "base/build_config.h"
#include <tuple>

#ifdef COMPILER_GCC
namespace std {

template <bool Value>
using bool_constant = integral_constant<bool, Value>;

template <typename ...Args>
constexpr auto tuple_size_v = std::tuple_size<Args...>::value;

template <typename ...Args>
constexpr auto is_rvalue_reference_v = is_rvalue_reference<Args...>::value;

template <typename ...Args>
constexpr auto is_base_of_v = is_base_of<Args...>::value;

template <typename ...Args>
constexpr auto is_same_v = is_same<Args...>::value;

namespace detail {

template <typename Method, typename Tuple, size_t... I>
constexpr decltype(auto) apply_impl(
Method &&method,
Tuple &&tuple,
index_sequence<I...>) {
return forward<Method>(method)(get<I>(forward<Tuple>(tuple))...);
}

} // namespace detail

template <class Method, class Tuple>
constexpr decltype(auto) apply(Method &&method, Tuple&& tuple) {
return detail::apply_impl(
forward<Method>(method),
forward<Tuple>(tuple),
make_index_sequence<tuple_size_v<decay_t<Tuple>>>{});
}

} // namespace std
#endif // COMPILER_GCC

namespace rpl {
namespace details {

Expand Down
Loading

0 comments on commit 21b1ba1

Please sign in to comment.