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

Strange MemorySanitizer warnings on E2K #457

Open
ivmai opened this issue Jul 7, 2022 · 5 comments
Open

Strange MemorySanitizer warnings on E2K #457

ivmai opened this issue Jul 7, 2022 · 5 comments

Comments

@ivmai
Copy link
Owner

ivmai commented Jul 7, 2022

Source: master (2afde24)
Host: Linux/E2K
Compiler: lcc:1.26.12:Jun--5-2022:e2k-v4-linux; gcc (GCC) 9.3.0 compatible
How to reproduce (1): ./autogen.sh && ./configure && make -j check CFLAGS_EXTRA="-fsanitize=memory" && cat gctest.log

==20773==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x4585e20e9ad8 in GC_expand_hp_inner /export/home/ivmai/bdwgc/extra/../alloc.c:336
    #1 0x4585e2171e10 in GC_init /export/home/ivmai/bdwgc/extra/../misc.c:1313
    #2 0x4585e21c3a50 in GC_pthread_create /export/home/ivmai/bdwgc/extra/../pthread_support.c:2195
    #3 0x23e518 in main /export/home/ivmai/bdwgc/tests/gctest.c:2435

How to reproduce (2): ./autogen.sh && ./configure && make -j check CFLAGS_EXTRA="-fsanitize=memory -O0" && cat gctest.log

==22711==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x4579401d4a00 in GC_exclude_static_roots_inner /export/home/ivmai/bdwgc/extra/../mark_rts.c:580
    #1 0x4579402031a0 in GC_init /export/home/ivmai/bdwgc/extra/../misc.c:1210
    #2 0x457940207038 in GC_enable_incremental /export/home/ivmai/bdwgc/extra/../misc.c:1404
    #3 0x252ff0 in enable_incremental_mode /export/home/ivmai/bdwgc/tests/gctest.c:1958
    #4 0x254c08 in main /export/home/ivmai/bdwgc/tests/gctest.c:2419

Related issue #411

@ivmai
Copy link
Owner Author

ivmai commented Jul 8, 2022

GC_expand_hp_inner /export/home/ivmai/bdwgc/extra/../alloc.c:336 :

static size_t min_bytes_allocd_minimum = 1;
...
static word min_bytes_allocd(void)
{
 ...
    result = scan_size / GC_free_space_divisor;
    if (GC_incremental) {
      result /= 2;
    }
    return result > min_bytes_allocd_minimum // <-- line 336
            ? result : min_bytes_allocd_minimum;
}

@ivmai
Copy link
Owner Author

ivmai commented Jul 29, 2022

GC_exclude_static_roots_inner /export/home/ivmai/bdwgc/extra/../mark_rts.c:580 :

    struct exclusion * next;
    ...
    if (0 == GC_excl_table_entries) {
        next = 0;
    } else {
        next = GC_next_exclusion((ptr_t)start);
    }
    if (0 != next) { // <-- line 580

@ivmai
Copy link
Owner Author

ivmai commented Jul 29, 2022

gcc -I include -O0 -fsanitize=memory tests/gctest.c extra/gc.c && ./a.out

==12626==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x2f9bc8 in GC_exclude_static_roots_inner /export/home/ivmai/bdwgc/extra/../mark_rts.c:600

@ivmai
Copy link
Owner Author

ivmai commented Jul 29, 2022

I've created a small reproducible testcase.c:

#include <stddef.h>

typedef char * ptr_t;

struct exclusion {
    ptr_t e_start;
    ptr_t e_end;
};

struct _GC_arrays {
# define GC_excl_table_entries GC_arrays._excl_table_entries
  size_t _excl_table_entries;
# define GC_excl_table GC_arrays._excl_table
  struct exclusion _excl_table[512];
};

struct _GC_arrays GC_arrays = { 0 };

struct exclusion * next = 0;

void GC_exclude_static_roots_inner(void *start)
{
    size_t next_index;
    if (0 != next) {
      size_t i;
      next_index = 0;
      for (i = GC_excl_table_entries; i > next_index; --i) {
        GC_excl_table[i] = GC_excl_table[i-1];
      }
    } else {
      next_index = GC_excl_table_entries;
    }
    GC_excl_table[next_index].e_start = (ptr_t)start;
}

int main(void) {
  GC_exclude_static_roots_inner(0);
  return 0;
}

gcc -O0 -g -fsanitize=memory testcase.c && ./a.out
Output:

==16175==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x213790 in GC_exclude_static_roots_inner /export/home/ivmai/bdwgc/t.c:33
    #1 0x2138e0 in main /export/home/ivmai/bdwgc/t.c:37
    #2 0x4650607bf0d0 in __libc_start_main (/lib64/libc.so.6+0x220d0)
    #3 0x2fec8 in _start (/export/home/ivmai/bdwgc/a.out+0x2fec8)
    #4 0x46505ffd4298 in _start

@ivmai
Copy link
Owner Author

ivmai commented Aug 2, 2022

As said by lcc folks, MSan is not yet supported properly by lcc (unlike ASan).
I will close this issue after fixing it in lcc.

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

1 participant