Last active
May 6, 2020 04:14
-
-
Save wataash/0a55bdaedf723b8145f8f3478d6d3f0f to your computer and use it in GitHub Desktop.
wsl glibc-2.31のワークアラウンド https://qiita.com/mmns/items/eaf42dd3345a2285ff9e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MIT License | |
# | |
# Copyright (c) 2020 Wataru Ashihara | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
# https://qiita.com/mmns/items/eaf42dd3345a2285ff9e | |
# https://twitter.com/wata_ash/status/1255130650723487746 | |
# 筆者はWindowsを持っていなくてUbuntuでしか試していない。 | |
# 高確率で環境破壊するので自己責任でお願いします。 | |
# ------------------------------------------------------------------------------ | |
# 環境の確認 | |
cat /etc/lsb-release # DISTRIB_DESCRIPTION="Ubuntu 20.04" | |
# md5sum が異なったら終了して下さい。(そしてできれば教えて下さい) | |
md5sum /usr/lib/x86_64-linux-gnu/libc-2.31.so # 10fdeb77eea525914332769e9cd912ae | |
# ------------------------------------------------------------------------------ | |
# バグの確認 | |
echo > a.c ' | |
#include <errno.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
int main(int argc, char *argv[]) { | |
const struct timespec ts = {.tv_sec = 1}; | |
printf("sleep 1\n"); | |
if (nanosleep(&ts, NULL) == -1) { | |
perror("nanosleep"); | |
exit(EXIT_FAILURE); | |
} | |
printf("done\n"); | |
}' | |
cc a.c | |
./a.out | |
# 通常のUbuntuなら1秒スリープするが、 | |
# WSLだと nanosleep: Invalid argument と出力してすぐ終了すると思われる | |
# ------------------------------------------------------------------------------ | |
# HACK | |
cp -v /usr/lib/x86_64-linux-gnu/libc-2.31.so ./libc-2.31.so.work.0.realtime.orig | |
cp -v /usr/lib/x86_64-linux-gnu/libc-2.31.so ./libc-2.31.so.work.1.monotonic | |
cp -v /usr/lib/x86_64-linux-gnu/libc-2.31.so ./libc-2.31.so.work.7.boottime | |
echo -en '\xbf\x01\x00\x00\x00' | dd seek=918244 bs=1 count=5 of=./libc-2.31.so.work.1.monotonic | |
dd skip=918249 seek=918249 bs=1 if=./libc-2.31.so.work.0.realtime.orig of=./libc-2.31.so.work.1.monotonic | |
echo -en '\xbf\x07\x00\x00\x00' | dd seek=918244 bs=1 count=5 of=./libc-2.31.so.work.7.boottime | |
dd skip=918249 seek=918249 bs=1 if=./libc-2.31.so.work.0.realtime.orig of=./libc-2.31.so.work.7.boottime | |
# ------------------------------------------------------------------------------ | |
# 確認 | |
ls -l ./libc* # 全て 2029224 バイト | |
md5sum ./libc-2.31.so.work.0.realtime.orig # 10fdeb77eea525914332769e9cd912ae | |
md5sum ./libc-2.31.so.work.1.monotonic # a3de8ddf981b31db75c2e14fb9a330c8 | |
md5sum ./libc-2.31.so.work.7.boottime # cc62215f49f8f229f8294c005ef5ec51 | |
# objdump --disassemble=clock_nanosleep ./libc-2.31.so.work.0.original | |
# objdump --disassemble=clock_nanosleep ./libc-2.31.so.work.1.monotonic | |
# objdump --disassemble=clock_nanosleep ./libc-2.31.so.work.7.boottime | |
# ------------------------------------------------------------------------------ | |
# Install・ためす (キケン) | |
# 直接cpしないこと!!死にます(コメント参照) | |
cp -v ./libc-2.31.so.work.1.monotonic tmp && sudo mv -v tmp /usr/lib/x86_64-linux-gnu/libc-2.31.so | |
./a.out # 1秒sleepすればOK | |
cp -v ./libc-2.31.so.work.7.boottime tmp && sudo mv -v tmp /usr/lib/x86_64-linux-gnu/libc-2.31.so | |
./a.out # 1秒sleepすればOK | |
# ------------------------------------------------------------------------------ | |
# もどす場合 | |
cp -v ./libc-2.31.so.work.0.orig tmp && sudo mv -v tmp /usr/lib/x86_64-linux-gnu/libc-2.31.so | |
./a.out # EINVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
memo