Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glibc: inconsistency detected by ld.so #128

Open
ghost opened this issue Mar 18, 2018 · 2 comments
Open

glibc: inconsistency detected by ld.so #128

ghost opened this issue Mar 18, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Mar 18, 2018

I get this strange error:

Inconsistency detected by ld.so: dl-fini.c: 87: _dl_fini: Assertion `ns != LM_ID_BASE || i == nloaded' failed!

The code used to work before until I rearranged it but I got segmentation fault when calling libc fgets twice or more until this recent error about assertion failed.

Here is the code causing the error:

get_inf :: fn(arg: *u8) -> []string {
    _rcp_file : rawptr = fopen(arg, "r".raw)

    if !_rcp_file {
        printf("error: could not open file: '%s'\n".raw, arg)
        exit(1)
    }

    INF_PKG, INF_VER, INF_REL: string
    rcp_buff_pkg, rcp_buff_ver, rcp_buff_rel: *u8
    rcp_line_pkg : i32 = 100
    //rcp_line_ver : i32 = 50
    //rcp_line_rel : i32 = 10

    INF_PKG.raw = fgets(rcp_buff_pkg, rcp_line_pkg, _rcp_file)
    //INF_VER.raw = fgets(rcp_buff_ver, rcp_line_ver, _rcp_file)
    //INF_REL.raw = fgets(rcp_buff_rel, rcp_line_rel, _rcp_file)

    //INF_PKG_CUT := strstr(INF_PKG.raw, ":".raw)
    //INF_VER_CUT := strstr(INF_VER.raw, ":".raw)
    //INF_REL_CUT := strstr(INF_REL.raw, ":".raw)

    //INF_PKG_TRIM := trimstr(INF_PKG_CUT)
    //INF_VER_TRIM := trimstr(INF_VER_CUT)
    //INF_REL_TRIM := trimstr(INF_REL_CUT)

    fclose(_rcp_file)
    return []string { "hello", "world", "!" }
    //return []string {INF_PKG_TRIM, INF_VER_TRIM, INF_REL_TRIM}
}
@ghost
Copy link
Author

ghost commented Mar 18, 2018

In the main function, calling fopen(argv[1]) directly causes segfault. It works if I define like this:

rcp_file: string
rcp_file.raw = argv[1]
_rcp_file := fopen(rcp_file.raw, "r".raw)

@ghost ghost closed this as completed Mar 18, 2018
@ghost ghost reopened this Mar 19, 2018
@ghost
Copy link
Author

ghost commented Mar 19, 2018

When compiling two almost identical codes, this one works:

#import "lib/apkg.kai" _
#import kai("posix") _
#import kai("arrays") _

printf_red :: fn() -> void {
    //printf("\033[1;31m.raw");
    printf("\x1b[1;31m".raw);

}

printf_grn :: fn() -> void {
    //printf("\033[1;32m".raw);
    printf("\x1b[1;32m".raw);
}

printf_rst :: fn() -> void {
    //printf("\033[0m".raw);
    printf("\x1b[0m".raw);
}

rcp_inf :: fn(_rcp: rawptr, _fbf: *u8, _chr: i32) -> string {
    _inf: string
    _inf.raw = fgets(_fbf, _chr, _rcp)
    return _inf
}

trimstr :: fn(str: *u8) -> string {
    _str := []u8{}
    _len := strlen(str)

    for i := 0; i < _len; i += 1 {
        if str[i] == 0x20 {
            continue
        } else if str[i] == 0x0a {
            continue
        } else if str[i] == ":" {
            continue
        } else {
            _str = Append(_str, str[i])
        }
    }
    return _str
}

main :: fn(argc: i32, argv: **u8) -> void {
    if argc < 2 {
        printf("usage: %s <recipe>\n".raw, argv[0])
        exit(1)
    }

    if argv[1] {
        rcp_file: string
        rcp_file.raw = argv[1]
        read_rcp := fopen(rcp_file.raw, "r".raw)

        if !read_rcp {
            printf("error: could not open file: '%s'\n".raw, rcp_file.raw)
            exit(1)
        }

        _meta:= []string{}
        line_num: i32 = 1
        rcp_buff: *u8

        for true {
            if line_num == 4 {
                break
            }
            _line := rcp_inf(read_rcp, rcp_buff, 150)
            split := strstr(_line.raw, ":".raw)
            value := trimstr(split)
            _meta = Append(_meta, value)
 
           line_num = line_num + 1

        }

        meta := Metadata {_meta[0], _meta[1], _meta[2]}

        fclose(read_rcp)

        TAR_OPT := "/bin/tar -C /home/ahc/DestDIR --keep-directory-symlink --no-overwrite-dir -Ipixz -xpf /pkg/arc/apkg-0.14.0-1-x86_64.apkg"

        if access("/pkg/arc/apkg-0.14.0-1-x86_64.apkg".raw, F_OK) == 0 {
            printf_grn()
            printf("  installing".raw)
            printf_rst()
            printf("  %s-%s-%s\n".raw, meta.PKG.raw, meta.VER.raw, meta.REL.raw)
            system(TAR_OPT.raw)
        }
    }
}

While this code gives me segfault:

#import "lib/apkg.kai" _
#import kai("posix") _
#import kai("arrays") _

printf_red :: fn() -> void {
    //printf("\033[1;31m.raw");
    printf("\x1b[1;31m".raw);

}

printf_grn :: fn() -> void {
    //printf("\033[1;32m".raw);
    printf("\x1b[1;32m".raw);
}

printf_rst :: fn() -> void {
    //printf("\033[0m".raw);
    printf("\x1b[0m".raw);
}

rcp_inf :: fn(_rcp: rawptr, _fbf: *u8, _chr: i32) -> string {
    _inf: string
    _inf.raw = fgets(_fbf, _chr, _rcp)
    return _inf
}

get_inf :: fn(arg: *u8) -> []string {
        rcp_file: string
        rcp_file.raw = arg
        read_rcp := fopen(rcp_file.raw, "r".raw)

        if !read_rcp {
            printf("error: could not open file: '%s'\n".raw, rcp_file.raw)
            exit(1)
        }

        _meta:= []string{}
        line_num: i32 = 1
        rcp_buff: *u8

        for true {
            if line_num == 4 {
                break
            }
            _line := rcp_inf(read_rcp, rcp_buff, 150)
            split := strstr(_line.raw, ":".raw)
            value := trimstr(split)
            _meta = Append(_meta, value)
 
           line_num = line_num + 1

        }
        fclose(read_rcp)
        return []string {_meta[0], _meta[1], _meta[2]}
}

trimstr :: fn(str: *u8) -> string {
    _str := []u8{}
    _len := strlen(str)

    for i := 0; i < _len; i += 1 {
        if str[i] == 0x20 {
            continue
        } else if str[i] == 0x0a {
            continue
        } else if str[i] == ":" {
            continue
        } else {
            _str = Append(_str, str[i])
        }
    }
    return _str
}

main :: fn(argc: i32, argv: **u8) -> void {
    if argc < 2 {
        printf("usage: %s <recipe>\n".raw, argv[0])
        exit(1)
    }

    if argv[1] {
        _meta_ : []string = get_inf(argv[1])
        meta := Metadata {_meta_[0], _meta_[1], _meta_[2]}

        TAR_OPT := "/bin/tar -C /home/ahc/DestDIR --keep-directory-symlink --no-overwrite-dir -Ipixz -xpf /pkg/arc/apkg-0.14.0-1-x86_64.apkg"

        if access("/pkg/arc/apkg-0.14.0-1-x86_64.apkg".raw, F_OK) == 0 {
            printf_grn()
            printf("  installing".raw)
            printf_rst()
            printf("  %s-%s-%s\n".raw, meta.PKG.raw, meta.VER.raw, meta.REL.raw)
            system(TAR_OPT.raw)
        }
    }
}

Am I doing something wrong here? Both versions are opening a text file containing:

PKG:: apkg
VER:: 0.14.0
REL:: 1

lib/apkg.kai :

Metadata :: struct {
    PKG: string
    VER: string
    REL: string
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants