bebbo / binutils-gdb

Unofficial mirror of sourceware binutils-gdb repository. Updated daily.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git
GNU General Public License v2.0
3 stars 3 forks source link

-gc crashes ld (Segmentation fault) #24

Closed githubaf closed 2 years ago

githubaf commented 2 years ago

I tried your last changes for garbage collection with WCS now, but the linker crashes.

m68k-amigaos-gcc  -o "WCS"  ./vgl/boards.o ./vgl/clib.o ./vgl/color.o ./vgl/defpal.o ./vgl/dumb.o ./vgl/dumbbitblt.o ./vgl/dumbpoly.o ./vgl/dumbtext.o ./vgl/fontsmall.o ./vgl/pixmap.o ./vgl/wuline.o  ./esp/.metadata/.plugins/org.eclipse.cdt.make.core/specs.o  ./AGUI.o ./BitMaps.o ./Cloud.o ./CloudGUI.o ./ColorBlends.o ./Commands.o ./DEM.o ./DEMGUI.o ./DEMObject.o ./DLG.o ./DataBase.o ./DataOps.o ./DataOpsGUI.o ./DefaultParams.o ./DiagnosticGUI.o ./DispatchGUI.o ./EdDBaseGUI.o ./EdEcoGUI.o ./EdMoGUI.o ./EdPar.o ./EdSetExtrasGUI.o ./EdSetGUI.o ./EditGui.o ./EvenMoreGUI.o ./Foliage.o ./FoliageGUI.o ./Fractal.o ./GenericParams.o ./GenericTLGUI.o ./GlobeMap.o ./GlobeMapSupport.o ./GrammarTable.o ./HelpGUI.o ./HyperKhorner4M-1_gcc.o ./Images.o ./InteractiveDraw.o ./InteractiveUtils.o ./InteractiveView.o ./LWSupport.o ./LineSupport.o ./MUIFloatInt.o ./MakeFaces.o ./Map.o ./MapExtra.o ./MapGUI.o ./MapLineObject.o ./MapSupport.o ./MapTopo.o ./MapTopoObject.o ./MapUtil.o ./Memory.o ./Menu.o ./MoreGUI.o ./Params.o ./ParamsGUI.o ./PlotGUI.o ./RequesterGUI.o ./RexxSupport.o ./ScratchPad.o ./ScreenModeGUI.o ./Support.o ./TLSupportGUI.o ./TimeLinesGUI.o ./Tree.o ./Version.o ./VocabTable.o ./WCS.o ./Wave.o ./WaveGUI.o ./nncrunch.o ./nngridr.o ./sasc_functions.o   -lmui -lm -noixemul -Wl,-Map=wcs.map,--trace,--gc-sections,--print-gc-sections
collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
compilation terminated.

The Eclipse-project is on https://github.com/githubaf/3DNature Build confuguartion -> set Active -> gc-sections Build project

A quick gdb call shows

warning: core file may not match specified executable file.
[New LWP 1761235]
Core was generated by `/home/developer/opt/m68k-amigaos_15May22/lib/gcc/m68k-amigaos/6.5.0b/../../../.'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000561b7eafd837 in amiga_gc_sections ()
(gdb) 
bebbo commented 2 years ago

make: *** No targets specified and no makefile found. Stop.

githubaf commented 2 years ago

Do you use eclipse? It seems to create the makefiles when doing "Build project" I can of course add them all to git if you like.

bebbo commented 2 years ago

fixed that one - the resulting file is very small /shrug guess you have to add some symbols via -u _function to get these picked up.

bebbo commented 2 years ago

ok, better now. please test once live

githubaf commented 2 years ago

There is no ld crash any longer. But the executable file just crashes here. I will look if other options such as -ffast-math -mregparm have an influence.

-> -ffast-math -mregparm are not guilty.

githubaf commented 2 years ago

For a test I compiled all sources without "-ffunction-sections -fdata-secetions" but linked with --gc-sections,--print-gc-sections. The executable still wouldn't start.

/home/developer/opt/m68k-amigaos_16May22/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: removing unused section '.data' in file './vgl/boards.o'
/home/developer/opt/m68k-amigaos_16May22/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: removing unused section '.data' in file './vgl/clib.o'
/home/developer/opt/m68k-amigaos_16May22/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: removing unused section '.data' in file './vgl/defpal.o'
/home/developer/opt/m68k-amigaos_16May22/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: removing unused section '.data' in file './vgl/dumbbitblt.o'
/home/developer/opt/m68k-amigaos_16May22/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: removing unused section '.bss' in file './vgl/dumbpoly.o'
/home/developer/opt/m68k-amigaos_16May22/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: removing unused section '.data' in file './vgl/dumbtext.o'
/home/developer/opt/m68k-amigaos_16May22/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: removing unused section '.data' in file './vgl/fontsmall.o'
./HyperKhorner4M-1_gcc.o
./Images.o
./InteractiveDraw.o
./InteractiveUtils.o
./InteractiveView.o
/home/developer/opt/m68k-amigaos_16May22/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: removing unused section '.text' in file './MUIFloatInt.o'
/home/developer/opt/m68k-amigaos_16May22/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: removing unused section '.data' in file './MUIFloatInt.o'
/home/developer/opt/m68k-amigaos_16May22/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: removing unused section '.data' in file './MapExtra.o'
/home/developer/opt/m68k-amigaos_16May22/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: removing unused section '.text' in file '/home/developer/opt/m68k-amigaos_16May22/m68k-amigaos/libnix/lib/libnix.a(atol.o)'

Is the empty section removing unused section '.text' in file './MUIFloatInt.o' correct? There are used functions...

As a nice part: when building WCS with -ffunction-sections -fdata-secetions and linking with --gc-sections,--print-gc-sections it really founds several unused functions that I had overseen before. So undefining them and compiling without garbage collection resulted in a smaller working executable.

bebbo commented 2 years ago

if the program does not run, then there is a bug, something is not evaluated to determine what should be picked up...

... but:

Is the empty section removing unused section '.text' in file './MUIFloatInt.o' correct? There are used functions...

really? which one? All seems either static, excluded via #ifdef or not used...

githubaf commented 2 years ago

If I compile with -ffunctions-sections and -fdata-sections and link with -gc, the linker says

m68k-amigaos/bin/ld: removing unused section '.text.mSync' in file './MUIFloatInt.o'
m68k-amigaos/bin/ld: removing unused section '.text.mNew' in file './MUIFloatInt.o'
m68k-amigaos/bin/ld: removing unused section '.text.mDispose' in file './MUIFloatInt.o'
m68k-amigaos/bin/ld: removing unused section '.text.mInc' in file './MUIFloatInt.o'
m68k-amigaos/bin/ld: removing unused section '.text.mDec' in file './MUIFloatInt.o'
m68k-amigaos/bin/ld: removing unused section '.text.mStr' in file './MUIFloatInt.o'
m68k-amigaos/bin/ld: removing unused section '.text.mSet' in file './MUIFloatInt.o'
m68k-amigaos/bin/ld: removing unused section '.text.mGet' in file './MUIFloatInt.o'
m68k-amigaos/bin/ld: removing unused section '.text.mChangeFocus' in file './MUIFloatInt.o'
m68k-amigaos/bin/ld: removing unused section '.text.mLoseFocus' in file './MUIFloatInt.o'
m68k-amigaos/bin/ld: removing unused section '.text.Dispatcher' in file './MUIFloatInt.o'
m68k-amigaos/bin/ld: removing unused section '.text.DoIncDec' in file './MUIFloatInt.o'
m68k-amigaos/bin/ld: removing unused section '.text.CalcIncDec' in file './MUIFloatInt.o'

That made me wonder. They are used, aren't they? (Maybe that is correct but looks strange?)

bebbo commented 2 years ago

Dispatcher isn't use elsewhere - thus the static functions aren't used either.

githubaf commented 2 years ago

You are right, sorry for confusion. Nice gcc found that. Makes the executable another 4.5kBytes smaller. (But the problem with the -gc linked executable is still there)

updated github

bebbo commented 2 years ago

you have to figure out what's left out but should be there...

githubaf commented 2 years ago

If I compare the output of m68k-amigaos-nm or the linker-mapfile, for instance _cpucheck _CreateExtIO DoMethod getMathIeeeDoubBasBase ___getUtilityBase

are missing in the bad executable.

But I find the static functions and variables in the bad file.

githubaf commented 2 years ago

The program starts and works (but not entirely correct) when compiled/linked without -fbaserel. I will test more.

bebbo commented 2 years ago

The program starts and works (but not entirely correct) when compiled/linked without -fbaserel. I will test more.

uh - ah - baserel: guess then all .data and .bss must be kept

githubaf commented 2 years ago

Status: I am currently trying to find more indicative. The program seems to do nothing when started, no GUI, just nothing. I am adding KPrintF to find where the program hangs.

KPrintF shows that main is called several times!??? It looks like a loop where after a fixed sequence of lines main() is called again.

githubaf commented 2 years ago
../WCS.c main() is called.
   ../WCS.c main() calls ../AGUI.c WCS_App_New()
      ../AGUI.c WCS_App_New() calls ../RexxSupport.c Rexx_New()
         ../RexxSupport.c Rexx_New() calls CreatePort(), that does not return!!!
---> ../WCS.c main() is called again at the very beginning!

I am not sure about the map-file. Is CreatePort() included or removed from the executable?

wcs.zip

bebbo commented 2 years ago

hm, that SAS/C output is not that helpful... but:

Discarded input sections
...
 .text          0x0000000000000000       0xbc /opt/amiga/m68k-amigaos/lib/libamiga.a(CreatePort.o)
...
bebbo commented 2 years ago

it is referenced from RexxSupport.o

SYMBOL TABLE:
...
00000000         *UND*      0001 81 _CreatePort

Disassembly of section .text.Rexx_New:
00000000 00000000 _Rexx_New:
...
 13e:   4eb9 0000 0000  jsr 0 0 _CreatePort

but some stuff from RexxSupport.o is also dropped and that's the default .text section.

What if these undefined symbols are all attached to the default .text section? => none of these gets picked up...

bebbo commented 2 years ago

GAH!

The library libamiga.a is in the old a.out format -> can't work!

bebbo commented 2 years ago

Now it gets picked up

 .text          0x0000000000015980       0xbc /opt/amiga/m68k-amigaos/lib/libamiga.a(CreatePort.o)
                0x0000000000015980                CreatePort
                0x00000000000159fa                DeletePort
githubaf commented 2 years ago

Super! We are comming closer. WCS with garbage collection can now start again without hanging or repeating main(). Image calculation does not crash.

~~The calculated picture has distorted rocks, however (when compiled with garbage collection). Seems like a surface is missing? Water looks good and so do sky, sun and clouds.~~ I will investigate more. Update: All is fine now. I compiled with -m68040 but mistakenly linked without -m68040. I wonder why this had so little impact?

Thank you very much for your permanent improvements!