Skip to content

Always emit column field of .loc directive#7

Merged
mshinwell merged 2 commits intooxcaml:4.11from
gretay-js:emit_loc_with_column
Mar 22, 2021
Merged

Always emit column field of .loc directive#7
mshinwell merged 2 commits intooxcaml:4.11from
gretay-js:emit_loc_with_column

Conversation

@gretay-js
Copy link
Contributor

When source location's column is not available from debug info (e.g., for a dummy location), we should emit the default value 0 for it, not leave it out. If the optional column field of .loc is not emitted, debug_line program keeps column value of a previous .loc directive that explicitly set the column field (even for an unrelated file and line).

Manually tested on small examples. Column value can be seen with llvm-symbolizer (addr2line does not show them).

@gretay-js gretay-js force-pushed the emit_loc_with_column branch from 06eb628 to dd4b6ed Compare March 22, 2021 16:34
@mshinwell mshinwell merged commit 3e08610 into oxcaml:4.11 Mar 22, 2021
mshinwell referenced this pull request in mshinwell/oxcaml May 17, 2021
poechsel pushed a commit to poechsel/flambda-backend that referenced this pull request May 26, 2021
poechsel pushed a commit that referenced this pull request Jun 28, 2021
poechsel pushed a commit that referenced this pull request Jun 29, 2021
stedolan added a commit to stedolan/flambda-backend that referenced this pull request Mar 7, 2022
da6ff04 Accept [@ocaml.local] without -extension, and move autogenerated attrs to [@extension.local] (oxcaml#9)
30ce67d Improve inclusion error messages for [@local_opt] (oxcaml#10)
f925a62 Remove some uneeded mode variables (oxcaml#8)
dec721c Local solver speedups (oxcaml#7)
e9afc49 Fix check_all_arches build
0b9b32a Fix i386 build
a515093 Merge flambda-backend changes

git-subtree-dir: ocaml
git-subtree-split: da6ff04
stedolan added a commit that referenced this pull request Mar 7, 2022
da6ff04 Accept [@ocaml.local] without -extension, and move autogenerated attrs to [@extension.local] (#9)
30ce67d Improve inclusion error messages for [@local_opt] (#10)
f925a62 Remove some uneeded mode variables (#8)
dec721c Local solver speedups (#7)
e9afc49 Fix check_all_arches build
0b9b32a Fix i386 build
a515093 Merge flambda-backend changes

git-subtree-dir: ocaml
git-subtree-split: da6ff04
NickBarnes pushed a commit to NickBarnes/oxcaml that referenced this pull request Feb 3, 2025
The toplevel printer detects cycles by keeping a hashtable of values
that it has already traversed.

However, some OCaml runtime types (at least bigarrays) may be
partially uninitialized, and hashing them at arbitrary program points
may read uninitialized memory. In particular, the OCaml testsuite
fails when running with a memory-sanitizer enabled, as bigarray
printing results in reads to uninitialized memory:

```
==133712==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x4e6d11 in caml_ba_hash /var/home/edwin/git/ocaml/runtime/bigarray.c:486:45
    oxcaml#1 0x52474a in caml_hash /var/home/edwin/git/ocaml/runtime/hash.c:251:35
    oxcaml#2 0x599ebf in caml_interprete /var/home/edwin/git/ocaml/runtime/interp.c:1065:14
    oxcaml#3 0x5a909a in caml_main /var/home/edwin/git/ocaml/runtime/startup_byt.c:575:9
    oxcaml#4 0x540ccb in main /var/home/edwin/git/ocaml/runtime/main.c:37:3
    oxcaml#5 0x7f0910abb087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: 8f53abaad945a669f2bdcd25f471d80e077568ef)
    oxcaml#6 0x7f0910abb14a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a14a) (BuildId: 8f53abaad945a669f2bdcd25f471d80e077568ef)
    oxcaml#7 0x441804 in _start (/var/home/edwin/git/ocaml/runtime/ocamlrun+0x441804) (BuildId: 7a60eef57e1c2baf770bc38d10d6c227e60ead37)

  Uninitialized value was created by a heap allocation
    #0 0x47d306 in malloc (/var/home/edwin/git/ocaml/runtime/ocamlrun+0x47d306) (BuildId: 7a60eef57e1c2baf770bc38d10d6c227e60ead37)
    oxcaml#1 0x4e7960 in caml_ba_alloc /var/home/edwin/git/ocaml/runtime/bigarray.c:246:12
    oxcaml#2 0x4e801f in caml_ba_create /var/home/edwin/git/ocaml/runtime/bigarray.c:673:10
    oxcaml#3 0x59b8fc in caml_interprete /var/home/edwin/git/ocaml/runtime/interp.c:1058:14
    oxcaml#4 0x5a909a in caml_main /var/home/edwin/git/ocaml/runtime/startup_byt.c:575:9
    oxcaml#5 0x540ccb in main /var/home/edwin/git/ocaml/runtime/main.c:37:3
    oxcaml#6 0x7f0910abb087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: 8f53abaad945a669f2bdcd25f471d80e077568ef)
    oxcaml#7 0x7f0910abb14a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a14a) (BuildId: 8f53abaad945a669f2bdcd25f471d80e077568ef)
    oxcaml#8 0x441804 in _start (/var/home/edwin/git/ocaml/runtime/ocamlrun+0x441804) (BuildId: 7a60eef57e1c2baf770bc38d10d6c227e60ead37)

SUMMARY: MemorySanitizer: use-of-uninitialized-value /var/home/edwin/git/ocaml/runtime/bigarray.c:486:45 in caml_ba_hash
```

The only use of hashing in genprintval is to avoid cycles, that is, it
is only useful for OCaml values that contain other OCaml values
(including possibly themselves). Bigarrays cannot introduce cycles,
and they are always printed as "<abstr>" anyway.

The present commit proposes to be more conservative in which values
are hashed by the cycle detector to avoid this issue: we skip hashing
any value with tag above No_scan_tag -- which may not contain any
OCaml values.

Suggested-by: Gabriel Scherer <[email protected]>

Signed-off-by: Edwin Török <[email protected]>
Co-authored-by: Edwin Török <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants