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

In <caml/major_gc.h> declare some variables 'extern' #1770

Merged
merged 2 commits into from
May 16, 2018

Conversation

xavierleroy
Copy link
Contributor

The variables in question are caml_major_ring, caml_major_ring_index, and caml_major_work_credit.

It is correct C code to declare those variables in the .h without a storage class, in which case they are treated as "common" variables by the linker.

However, this causes problems with Clang's address sanitizer: it increases the size of the common variable when it is used, but leaves it unchanged when it is not. As a consequence, the linker sees several occurrences of a "common" variable with different sizes. The linker does the right thing and takes the "max" of the sizes, but not without printing an annoying warning, which is then reported as suspicious behavior by ocamltest.

This commit puts "extern" storage class on the incriminated variables in <caml/major_gc.h>, consistently with the other GC variables.

The variables in question are caml_major_ring, caml_major_ring_index, and caml_major_work_credit.

It is correct C code to declare those variables in the .h without a storage class, in which case they are treated as "common" variables by the linker.

However, this causes problems with Clang's address sanitizer: it increases the size of the common variable when it is used, but leaves it unchanged when it is not.  As a consequence, the linker sees several occurrences of a "common" variable with different sizes.  The linker does the right thing and takes the "max" of the sizes, but not without printing an annoying warning, which is then reported as suspicious behavior by ocamltest.

This commit puts "extern" storage class on the incriminated variables in <caml/major_gc.h>, consistently with the other GC variables.
@xavierleroy
Copy link
Contributor Author

xavierleroy commented May 8, 2018

@damiendoligez please review ASAP, this is your code, and I'd like the fix to go in 4.07.

And add proper declaration in byterun/fix_code.c and asmrun/startup.c
(the places where this table is initialized).

As explained in commit 74ce561, it is preferable to declare variables
"extern" in .h files and have them declared non-extern only once, in a
.c file.
@xavierleroy
Copy link
Contributor Author

For completeness I used clang's warnings to find other variables that should be extern in .h files but are not. I found one in <caml/intext.h>. The second commit fixes this.

@xavierleroy
Copy link
Contributor Author

Reviewers are hard to find and code is obviously correct, so I take responsibility for merging.

@xavierleroy xavierleroy merged commit 675e98a into ocaml:trunk May 16, 2018
xavierleroy added a commit that referenced this pull request May 16, 2018
GPR #1770.

* In <caml/major_gc.h> declare some variables 'extern'

The variables in question are caml_major_ring, caml_major_ring_index, and caml_major_work_credit.

It is correct C code to declare those variables in the .h without a storage class, in which case they are treated as "common" variables by the linker.

However, this causes problems with Clang's address sanitizer: it increases the size of the common variable when it is used, but leaves it unchanged when it is not.  As a consequence, the linker sees several occurrences of a "common" variable with different sizes.  The linker does the right thing and takes the "max" of the sizes, but not without printing an annoying warning, which is then reported as suspicious behavior by ocamltest.

This commit puts "extern" storage class on the incriminated variables in <caml/major_gc.h>, consistently with the other GC variables.

* In <caml/intext.h> declare `caml_code_fragments_table` as extern

And add proper declaration in byterun/fix_code.c and asmrun/startup.c
(the places where this table is initialized).

Same reasons as above.
@xavierleroy
Copy link
Contributor Author

Cherry-pciked in 4.07, 1161b77

@damiendoligez
Copy link
Member

Note that COMMON data is a source of other problems anyway (https://caml.inria.fr/mantis/view.php?id=5693).

@xavierleroy xavierleroy deleted the missing-extern-decl branch June 8, 2018 07:41
gasche pushed a commit that referenced this pull request Sep 26, 2021
GPR #1770.

* In <caml/major_gc.h> declare some variables 'extern'

The variables in question are caml_major_ring, caml_major_ring_index, and caml_major_work_credit.

It is correct C code to declare those variables in the .h without a storage class, in which case they are treated as "common" variables by the linker.

However, this causes problems with Clang's address sanitizer: it increases the size of the common variable when it is used, but leaves it unchanged when it is not.  As a consequence, the linker sees several occurrences of a "common" variable with different sizes.  The linker does the right thing and takes the "max" of the sizes, but not without printing an annoying warning, which is then reported as suspicious behavior by ocamltest.

This commit puts "extern" storage class on the incriminated variables in <caml/major_gc.h>, consistently with the other GC variables.

* In <caml/intext.h> declare `caml_code_fragments_table` as extern

And add proper declaration in byterun/fix_code.c and asmrun/startup.c
(the places where this table is initialized).

Same reasons as above.

(cherry picked from commit 1161b77)
OlivierNicole pushed a commit to OlivierNicole/ocaml that referenced this pull request Sep 30, 2022
GPR ocaml#1770.

* In <caml/major_gc.h> declare some variables 'extern'

The variables in question are caml_major_ring, caml_major_ring_index, and caml_major_work_credit.

It is correct C code to declare those variables in the .h without a storage class, in which case they are treated as "common" variables by the linker.

However, this causes problems with Clang's address sanitizer: it increases the size of the common variable when it is used, but leaves it unchanged when it is not.  As a consequence, the linker sees several occurrences of a "common" variable with different sizes.  The linker does the right thing and takes the "max" of the sizes, but not without printing an annoying warning, which is then reported as suspicious behavior by ocamltest.

This commit puts "extern" storage class on the incriminated variables in <caml/major_gc.h>, consistently with the other GC variables.

* In <caml/intext.h> declare `caml_code_fragments_table` as extern

And add proper declaration in byterun/fix_code.c and asmrun/startup.c
(the places where this table is initialized).

Same reasons as above.
dra27 pushed a commit to dra27/ocaml that referenced this pull request Dec 12, 2022
GPR ocaml#1770.

* In <caml/major_gc.h> declare some variables 'extern'

The variables in question are caml_major_ring, caml_major_ring_index, and caml_major_work_credit.

It is correct C code to declare those variables in the .h without a storage class, in which case they are treated as "common" variables by the linker.

However, this causes problems with Clang's address sanitizer: it increases the size of the common variable when it is used, but leaves it unchanged when it is not.  As a consequence, the linker sees several occurrences of a "common" variable with different sizes.  The linker does the right thing and takes the "max" of the sizes, but not without printing an annoying warning, which is then reported as suspicious behavior by ocamltest.

This commit puts "extern" storage class on the incriminated variables in <caml/major_gc.h>, consistently with the other GC variables.

* In <caml/intext.h> declare `caml_code_fragments_table` as extern

And add proper declaration in byterun/fix_code.c and asmrun/startup.c
(the places where this table is initialized).

Same reasons as above.

(cherry picked from commit 1161b77)
dra27 pushed a commit to dra27/ocaml that referenced this pull request Dec 12, 2022
GPR ocaml#1770.

* In <caml/major_gc.h> declare some variables 'extern'

The variables in question are caml_major_ring, caml_major_ring_index, and caml_major_work_credit.

It is correct C code to declare those variables in the .h without a storage class, in which case they are treated as "common" variables by the linker.

However, this causes problems with Clang's address sanitizer: it increases the size of the common variable when it is used, but leaves it unchanged when it is not.  As a consequence, the linker sees several occurrences of a "common" variable with different sizes.  The linker does the right thing and takes the "max" of the sizes, but not without printing an annoying warning, which is then reported as suspicious behavior by ocamltest.

This commit puts "extern" storage class on the incriminated variables in <caml/major_gc.h>, consistently with the other GC variables.

* In <caml/intext.h> declare `caml_code_fragments_table` as extern

And add proper declaration in byterun/fix_code.c and asmrun/startup.c
(the places where this table is initialized).

Same reasons as above.

(cherry picked from commit 1161b77)
dra27 pushed a commit to dra27/ocaml that referenced this pull request Dec 12, 2022
GPR ocaml#1770.

* In <caml/intext.h> declare `caml_code_fragments_table` as extern

And add proper declaration in byterun/fix_code.c and asmrun/startup.c
(the places where this table is initialized).

Same reasons as above.

(cherry picked from commit 1161b77)
dra27 pushed a commit to dra27/ocaml that referenced this pull request Dec 12, 2022
GPR ocaml#1770.

* In <caml/major_gc.h> declare some variables 'extern'

The variables in question are caml_major_ring, caml_major_ring_index, and caml_major_work_credit.

It is correct C code to declare those variables in the .h without a storage class, in which case they are treated as "common" variables by the linker.

However, this causes problems with Clang's address sanitizer: it increases the size of the common variable when it is used, but leaves it unchanged when it is not.  As a consequence, the linker sees several occurrences of a "common" variable with different sizes.  The linker does the right thing and takes the "max" of the sizes, but not without printing an annoying warning, which is then reported as suspicious behavior by ocamltest.

This commit puts "extern" storage class on the incriminated variables in <caml/major_gc.h>, consistently with the other GC variables.

* In <caml/intext.h> declare `caml_code_fragments_table` as extern

And add proper declaration in byterun/fix_code.c and asmrun/startup.c
(the places where this table is initialized).

Same reasons as above.

(cherry picked from commit 1161b77)
dra27 pushed a commit to dra27/ocaml that referenced this pull request Dec 12, 2022
GPR ocaml#1770.

* In <caml/intext.h> declare `caml_code_fragments_table` as extern

And add proper declaration in byterun/fix_code.c and asmrun/startup.c
(the places where this table is initialized).

Same reasons as above.

(cherry picked from commit 1161b77)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants