# gcc segmentation fault



## Suzie Q (Nov 21, 2022)

Hi I recently installed FreeBSD , when I compile with gcc my programs that used to work under Linux now not anymore it gives me segmentation fault tips ?


----------



## SirDice (Nov 21, 2022)

It would probably help if you showed some of the code and the information from the segfault.


----------



## Suzie Q (Nov 21, 2022)

SirDice said:


> It would probably help if you showed some of the code and the information from the segfault.


But if you compile with clang and ok , with gcc no it gives me segmentation fault
Every program I've written from Linux to FreeBSD does this


----------



## SirDice (Nov 21, 2022)

Show us an example please. We can't see what's on your screen and we cannot see what you're doing.


----------



## Suzie Q (Nov 21, 2022)

SirDice said:


> Show us an example please. We can't see what's on your screen and we cannot see what you're doing.


Tonight I'll send some screenshots now I'm not at the pc


----------



## Alain De Vos (Nov 21, 2022)

Post a short program which demonstrates the problem.


----------



## SirDice (Nov 21, 2022)

Suzie Q said:


> Tonight I'll send some screenshots


Please don't send _pictures_ of text, just copy/paste the information.


----------



## Paul Floyd (Nov 21, 2022)

Do you have experience using a debugger (lldb or gdb)? The first thing that I would do is to make a debug build, check if you can still reproduce the problem then either examine a core file or run your app under lldb or gdb.

After that, try using either Valgrind or Address Sanitizer.


----------



## ralphbsz (Nov 21, 2022)

Underlying question: Why are you trying to use GCC? On FreeBSD, Clang and LLVM are the standard (default) compiler, and they work fine. Instead of trying to debug your GCC installation, it might be easier to just "when in Rome, do like the Romans".

If you have a strong reason to use GCC, it would be interesting to hear about it.


----------



## Alain De Vos (Nov 21, 2022)

Seg faults are mostly caused by pointers that are −

Used to being properly initialized.
Used after the memory they point to has been reallocated or freed.
Used in an indexed array where the index is outside of the array bounds.


----------



## Suzie Q (Nov 22, 2022)

This Error in gdb 

```
Program received signal SIGSEGV, Segmentation fault.

Invalid permissions for mapped object.

Oxooooo0080099fd48 in vtable for t.so.1

cxxabiv1: : si_class_type_info () from /lib/Libcoxr
```


----------



## Suzie Q (Nov 22, 2022)

ralphbsz said:


> Underlying question: Why are you trying to use GCC? On FreeBSD, Clang and LLVM are the standard (default) compiler, and they work fine. Instead of trying to debug your GCC installation, it might be easier to just "when in Rome, do like the Romans".
> 
> If you have a strong reason to use GCC, it would be interesting to hear about it.


Im live in rome


----------



## Alain De Vos (Nov 22, 2022)

which freebsd package has "Libcoxr" ?


----------



## covacat (Nov 22, 2022)

one known problem is if you have lc++ (clang) and lstdc++ (gcc) pulled in by  main and/or other shared objects will bomb


----------



## _martin (Nov 22, 2022)

ralphbsz said:


> "when in Rome, do like the Romans".





Suzie Q said:


> Im live in rome


X_X I don't know if this was intentional but I love this double pun here.

If you are not mixing code and or compilers the other reason could be that optimization could have revealed a bug in your code that is not triggered by the other compiler. 
Btw. did you actually manually hide the faulty address by placing "o" chars in Oxooooo0080099fd48 ?

More information is needed to help you. The best way would be to show us either
a) how did you compile the code
b) are you able to narrow down the code to a shareable demo?
c) run it through debugger and show us more information about the crash
d) if you are not familiar with debugger at least run `truss <your program>` and show as the trace

It's hard to judge from very little you showed us. Error occured in vtable so object was attempting to call some method id t.so but that's not enough to say anything. Especially if you say that code works under gcc (and you are not hitting issue covacat mentioned)


----------



## Paul Floyd (Nov 23, 2022)

Run ldd on your exe and post the output here. If you see both libc++ and libstdc++ then indeed you have a problem.


----------

