Open8

FreeBSD ports の `lang/mosh` のfailureが来た

okuokuokuoku

ケースを減らしたい

エラー箇所を見るに ucs4string のクラス宣言で問題があったと思うんだけど、これでエラーが発生する組合せが手元にない。これはFreeBSD 15-CURRENTをインストールして試すしかないかな。。

#include <stdint.h>

typedef int32_t ucs4char;

#include <string>
#include <vector>
 
typedef std::basic_string< ucs4char, std::char_traits<ucs4char>, std::allocator<ucs4char> > ucs4string_base;

class ucs4string : public ucs4string_base
{
public:
    ucs4string() = default;
    explicit ucs4string(size_t n, ucs4char c = ' ') : ucs4string_base(n, c) {}
    explicit ucs4string(const ucs4char* s) : ucs4string_base(s) {}
    ucs4string(const ucs4char* s, size_t n) : ucs4string_base(s, n) {}
    ucs4string(ucs4string::const_iterator a, ucs4string::const_iterator b) : ucs4string_base(a, b) {}
    char* ascii_c_str() const;
    ucs4string substr(size_t x, size_t size) const;
    void split(ucs4char ch, std::vector<ucs4string>& v) const;
    ucs4char* strdup();
    bool is_ascii() const;
    static ucs4string from_c_str(const char* s, size_t size);
    static ucs4string from_c_str(const char* s);
    // see R6RS 11.11 Characters
    static bool isValidScalar(int ch)
    {
        return (0 <= ch && ch <= 0xD7FF) || (0xE000 <= ch && ch <= 0x10FFFF);
    }
};
okuokuokuoku

クラスの定義だけでダメだった

これで再現する。

#include <stdint.h>

typedef int32_t ucs4char;

#include <string>
#include <vector>
 
typedef std::basic_string< ucs4char, std::char_traits<ucs4char>, std::allocator<ucs4char> > ucs4string_base;

class ucs4string : public ucs4string_base { };

https://github.com/llvm/llvm-project/pull/72694 の影響だな。つまり、 std::char_traits<ucs4char> (に、相当するtrait)が今まではC++ヘッダ側に定義されていたが、それが消えたのでコンパイルが通らなくなった。

char32_t を持つシステムでは ucs4char はそれにするのが正しいので、そういう方向で一旦パッチする。これはWindows向けに既に実装している:

https://github.com/higepon/mosh/commit/d0d52485b319d957589655e36931ee5d3c7d0b74

okuokuokuoku

これも直さないとな。。

In file included from src/VM-Profiler.cpp:38:
src/Object-inl.h:268:61: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
  268 |     return isTextualOutputPort() || isBinaryOutputPort() || isTextualInputOutputPort() | isBinaryInputOutputPort();
      |                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                        ||
okuokuokuoku

0.2.9 はどうか?

depbase=`echo src/OSCompatSocket.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`; c++ -DHAVE_CONFIG_H -I. -I./src -I ./extlibs/gc-cvs/include -I ./extlibs/gc-cvs/include/gc -I ./extlibs/gc-cvs/libatomic_ops/src -I./src    -I/usr/local/include -I/usr/local/include -g -Wall -I src -I  /usr/local/include -D MONA_SCHEME -D USE_BOEHM_GC -D  MOSH_LIB_PATH="\"/usr/local/share/mosh-0.2.9-rc1\""  -D_FILE_OFFSET_BITS=64 -Wall -pipe  -DGC_THREADS  -DLARGE_CONFIG=1  -DTHREAD_LOCAL_ALLOC=1  -DHAS_X86_THREAD_STATE64___RAX=1  -DATOMIC_UNCOLLECTABLE=1  -DGC_BUILTIN_ATOMIC=1  -DNO_EXECUTE_PERMISSION=1  -DALL_INTERIOR_POINTERS=1  -DJAVA_FINALIZATION=1  -DGC_GCJ_SUPPORT=1  -DUSE_I686_PREFETCH  -DDONT_ADD_BYTE_AT_END  -DHANDLE_FORK  -DGC_NOT_DLL  -O3 -momit-leaf-frame-pointer -fomit-frame-pointer -D  GIT_COMMIT_REVISION="\"""3925196""\"" -D  GIT_COMMIT_DATE="\"""Mon, 28 Nov 2022 11:00:02 +0000""\"" -Wno-deprecated -std=c++11  -MT src/OSCompatSocket.o -MD -MP -MF $depbase.Tpo -c -o src/OSCompatSocket.o src/OSCompatSocket.cpp && mv -f $depbase.Tpo $depbase.Po
In file included from src/OSCompatSocket.cpp:42:
In file included from src/scheme.h:89:
In file included from /usr/include/c++/v1/map:2175:
In file included from /usr/include/c++/v1/functional:581:
In file included from /usr/include/c++/v1/vector:325:
In file included from /usr/include/c++/v1/__format/formatter_bool.h:19:
In file included from /usr/include/c++/v1/__format/formatter_integral.h:35:
/usr/include/c++/v1/__locale:530:12: error: use of undeclared identifier 'isascii'
  530 |     return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) != 0 : false;
      |            ^
/usr/include/c++/v1/__locale:535:16: error: use of undeclared identifier 'isascii'
  535 |       *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
      |                ^
/usr/include/c++/v1/__locale:541:11: error: use of undeclared identifier 'isascii'
  541 |       if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
      |           ^
/usr/include/c++/v1/__locale:548:12: error: use of undeclared identifier 'isascii'
  548 |       if (!isascii(*__low) || !(__tab_[static_cast<int>(*__low)] & __m))
      |            ^
In file included from src/OSCompatSocket.cpp:44:
src/Object-inl.h:268:61: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
  268 |     return isTextualOutputPort() || isBinaryOutputPort() || isTextualInputOutputPort() | isBinaryInputOutputPort();
      |                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                        ||

自分のコミットで __FreeBSD__ 足し忘れてる。。

https://github.com/higepon/mosh/commit/d867cf6cd0522a959feb65c611cd879939fbcf0d

okuokuokuoku

ビルドは通ったけど起動すらしない

そもそもFreeBSD + AMD64では正常に動作しない傾向にある。これはそろそろ真面目にデバッグしないとダメかな。。

https://github.com/higepon/mosh/issues/129

当時は GC_DONT_GC で起動していたようだが、手元ではこれでも起動しなくなる(どちらもUnknown instruction)。

#5  0x00000000003b86d8 in scheme::callAssertionViolationAfter (theVM=0x60bd80, who=..., message=..., irritants=...) at src/ErrorProcedures.cpp:332
#6  0x00000000003b93c7 in scheme::callAssertionViolationAfter (theVM=0x60bd80, who=0x20c5cc U"VM", message=0x20af5c U"unknown instruction, bug of VM", irritants=...) at src/ErrorProcedures.cpp:314
#7  0x0000000000351e89 in scheme::VM::runLoop (this=0x60bd80, code=0x630000, returnPoint=0x0, returnTable=false) at src/VM-Run.cpp:1425
#8  0x000000000033dd57 in scheme::VM::evaluateUnsafe (this=0x60bd80, code=0x630000, codeSize=74048, isCompiler=true) at src/VM.cpp:401
#9  0x000000000033d5ad in scheme::VM::evaluateUnsafe (this=0x60bd80, code=0x627690, isCompiler=true) at src/VM.cpp:406
#10 0x000000000033d45a in scheme::VM::loadCompiler (this=0x60bd80) at src/VM.cpp:311
#11 0x000000000040252e in scheme::VMFactory::create (this=0x7fffffffe983, initialStackSize=10000, isProfilerOn=false) at src/VMFactory.cpp:82
#12 0x00000000004260d0 in main (argc=1, argv=0x7fffffffea78) at src/main.cpp:316

そもそもloadCompilerが終わっていない。FASLデコーダが正常にヒープイメージを作れていない説。。?

とりあえずUBSanもASanもヒットしないことは確認した。

okuokuokuoku

gccにしてみる

FreeBSDのシステムコンパイラは既にclangなので、 pkg install gcc でインストールできる。

Message from gcc13-13.3.0:

--
To ensure binaries built with this toolchain find appropriate versions
of the necessary run-time libraries, you may want to link using

  -Wl,-rpath=/usr/local/lib/gcc13

For ports leveraging USE_GCC, USES=compiler, or USES=fortran this happens
transparently.

微妙に挙動が違う。

#6  0x000000000045ca0b in scheme::EqHashTable::ref (this=0x7e9e60, key=..., defaultVal=...) at src/EqHashTable.cpp:74
#7  0x00000000004189cb in scheme::VM::getGlobalValueOrFalse (this=0x7f0d80, id=...) at src/VM.cpp:859
#8  0x0000000000484d0b in scheme::callAssertionViolationAfter (theVM=0x7f0d80, who=..., message=..., irritants=...) at src/ErrorProcedures.cpp:332
#9  0x0000000000484c18 in scheme::callAssertionViolationAfter (theVM=0x7f0d80, who=0x55225c U"apply", message=0x552360 U"invalid application", irritants=...) at src/ErrorProcedures.cpp:314
#10 0x000000000041dea7 in scheme::VM::runLoop (this=0x7f0d80, code=0x817000, returnPoint=0x0, returnTable=false) at src/call.inc.cpp:220
#11 0x0000000000416f2d in scheme::VM::evaluateUnsafe (this=0x7f0d80, code=0x817000, codeSize=74048, isCompiler=true) at src/VM.cpp:401
#12 0x0000000000416f7b in scheme::VM::evaluateUnsafe (this=0x7f0d80, code=0x80d6a0, isCompiler=true) at src/VM.cpp:406
#13 0x00000000004167b1 in scheme::VM::loadCompiler (this=0x7f0d80) at src/VM.cpp:311
#14 0x00000000004c1564 in scheme::VMFactory::create (this=0x7fffffffe93b, initialStackSize=10000, isProfilerOn=false) at src/VMFactory.cpp:82
#15 0x00000000004df710 in main (argc=1, argv=0x7fffffffea50) at src/main.cpp:316

ucs4charint に戻したら正常に起動した。なのでこれによって差分が出ているところが怪しい。