gcc dcraw.c: bad reloc address; Undefined Host to Network byte order conversions

Only 5 minutes to edit comments. 🙁

The post below is a thorough description of a blocking problem and documents the exact steps to solve it. It was posted to help the next person who runs into this or a similar problem; to give something back to the community.

From http://stackoverflow.com/tour, the big idea is to “to build a library of detailed answers to every question about programming”.

What could motivate one to DownVote such a contribution? I wish the Poobahs here would fix the scoring to A) identify the Denigrators and B) charge them points. Such Surliness constitutes Anti-Information and should be neither free nor anonymous nor encouraged!

========= Back to The Answers!!! =======================================

Great New Development!

Compiling for this exact machine architecture and throwing any compatibility out the window, the speed of converting a D800Extreme NEF to a TIFF has increased by over 3x vs the “current”, v9.26, “64 bit” binary on
dcraw-9.26-ms-64-bit.exe
http://www.centrostudiprogressofotografico.it/en/dcraw/ md5=ffe54327e66b6b509f86d92eb23ab93a

Over 6 runs of: dcraw*.exe -v -o 0 -q 3 -6 -w -T sx-2015.0319-245469.nef

Exe dcraw.exe:    SD=0.37124, Ave=13.531, Tot=81.186, Qty=6
Exe dcraw.g6.exe: SD=0.01149, Ave=04.439, Tot=26.634, Qty=6

81.186 / 26.634 = 3.048 ! Over 3x faster and 32 times more consistent!

The GCC incantation used is:

e:/strawberry.perl/c/bin/gcc.exe -v -o dcraw.g6.exe -O4 -ffast-math -m64 -Ofast -mtune=corei7-avx -march=corei7-avx  -Be:/strawberry.perl/c c:/bin/dcraw/dcraw.c -Le:strawberry.perlcx86_64-w64-mingw32lib -lws2_32  -lm -DNODEPS > c:/bin/dcraw/gcc.log 2>&1

Raw photo decoder "dcraw" v9.26
-rwxrwxrwx   1 user     group      378880 Jun  7 12:16 c:/bin/bat/dcraw.exe
dumpbin /headers $exe | grep machine
14C machine (x86)    <<  Does NOT look like 64 bit, 86 Bits. Wow! <:)
ffe54327e66b6b509f86d92eb23ab93a *c:binbatdcraw.exe
ffe54327e66b6b509f86d92eb23ab93a *dcraw-9.26-ms-64-bit.exe

Raw photo decoder "dcraw" v9.26
-rwxrwxrwx   1 user     group      425672 Jun  7 19:41 c:/bin/bat/dcraw.g6.exe
dumpbin /headers $exe | grep machine
8664 machine (x64)  Only 64 bits
3b5a9d3d372c3daae00ffd80444e48 *c:binbatdcraw.g6.exe

Run Times:

dcraw.exe    time=13.375 sec
dcraw.g6.exe time=4.450 sec
dcraw.g6.exe time=4.449 sec
dcraw.exe    time=13.423 sec
dcraw.g6.exe time=4.481 sec
dcraw.exe    time=13.383 sec
dcraw.exe    time=14.444 sec
dcraw.g6.exe time=4.468 sec
dcraw.g6.exe time=4.452 sec
dcraw.exe    time=13.383 sec
dcraw.g6.exe time=4.454 sec
dcraw.exe    time=13.371 sec
dcraw.exe    time=13.386 sec
dcraw.g6.exe time=4.461 sec
dcraw.g6.exe time=4.434 sec
dcraw.exe    time=13.374 sec
dcraw.g6.exe time=4.442 sec
dcraw.exe    time=13.353 sec
dcraw.exe    time=14.361 sec
dcraw.g6.exe time=4.424 sec
dcraw.g6.exe time=4.440 sec
dcraw.exe    time=13.360 sec
dcraw.g6.exe time=4.432 sec
dcraw.exe    time=13.354 sec

=============== END of UPDATE =========================================

I am trying to compile DCRaw.c on win7/64 with the Mingw GCC which comes built into Strawberry Perl (4.8.3). The build command is about as simple as can be and I recall having built it not long ago, but with earlier versions of both GCC and dcraw.c.

      gcc -o dcraw -O4 dcraw.c -lm -DNODEPS   <<< FUBAR

After a good deal of research & experimentation and excessive execration, here is an incantation which produces an executable:

e:/strawberry.perl/c/bin/gcc.exe -v -o dcraw.g6.exe -O4 -Be:/strawberry.perl/c c:/bin/dcraw/dcraw.c -Le:strawberry.perlcx86_64-w64-mingw32lib -lws2_32  -lm -DNODEPS > c:/bin/dcraw/gcc.log 2>&1

E:strawberry.perlc> dcraw.g6.exe | grep dcraw
Raw photo decoder "dcraw" v9.26
Usage:  dcraw.g6.exe [OPTION]... [FILE]...

======== GORY DETAILS ========================================================

All of the host to network byte order functions are improperly decorated/mangled:
undefined reference to `__imp_ntohs’
The function declarations are located in winsock2.h which has a #include. I found documentation online that they might also reside in inet.h (which is a dummy file) or in which does not exist on my system.

The –prefix= the compiler was configured with is wrong (“/mingw64” <- DNE!) so I used an explicit -B option but it made no difference.
And there is also a linker error:
ld.exe: XXXX.o: bad reloc address 0x0 in section `.pdata’

A person on this forum seems to have fixed a similar problem by reversing the module compilation order, but I only have 1 C module:
@vitalyster Changing the order of files seems to have worked. hjpotter92 Dec 16 ’14 at 6:40

Another similar thread suggested linking to a library. How is it possible that Dave Coffin gets away with only lib MATH??

I found one of the undefined symbols:

E:strawberry.perlc>nm .x86_64-w64-mingw32liblibws2_32.a | grep  ntohs
0000000000000000 I __imp_ntohs
0000000000000000 T ntohs
                 U __imp_ntohs

Here is the entire FAILING Verbose build output from the latest code and exact gcc command line on https://www.cybercom.net/~dcoffin/dcraw:

  dcraw.c: In function 'read_shorts':
dcraw.c:366:5: warning: passing argument 1 of 'swab' from incompatible pointer type [enabled by default]
     swab (pixel, pixel, count*2);
     ^
In file included from dcraw.c:40:0:
e:/strawberry.perl/c/x86_64-w64-mingw32/include/stdlib.h:616:16: note: expected 'char *' but argument is of type 'short unsigned int *'
   void __cdecl swab(char *_Buf1,char *_Buf2,int _SizeInBytes) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
                ^
dcraw.c:366:5: warning: passing argument 2 of 'swab' from incompatible pointer type [enabled by default]
     swab (pixel, pixel, count*2);
     ^
In file included from dcraw.c:40:0:
e:/strawberry.perl/c/x86_64-w64-mingw32/include/stdlib.h:616:16: note: expected 'char *' but argument is of type 'short unsigned int *'
   void __cdecl swab(char *_Buf1,char *_Buf2,int _SizeInBytes) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
                ^
dcraw.c: In function 'minolta_z2':
dcraw.c:1334:3: warning: overflow in implicit constant conversion [-Woverflow]
   fseek (ifp, -sizeof tail, SEEK_END);
   ^
dcraw.c: In function 'write_ppm_tiff':
dcraw.c:9717:7: warning: passing argument 1 of 'swab' from incompatible pointer type [enabled by default]
       swab (ppm2, ppm2, width*colors*2);
       ^
In file included from dcraw.c:40:0:
e:/strawberry.perl/c/x86_64-w64-mingw32/include/stdlib.h:616:16: note: expected 'char *' but argument is of type 'short unsigned int *'
   void __cdecl swab(char *_Buf1,char *_Buf2,int _SizeInBytes) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
                ^
dcraw.c:9717:7: warning: passing argument 2 of 'swab' from incompatible pointer type [enabled by default]
       swab (ppm2, ppm2, width*colors*2);
       ^
In file included from dcraw.c:40:0:
e:/strawberry.perl/c/x86_64-w64-mingw32/include/stdlib.h:616:16: note: expected 'char *' but argument is of type 'short unsigned int *'
   void __cdecl swab(char *_Buf1,char *_Buf2,int _SizeInBytes) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
                ^
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0xdc0): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0xfd2): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x14c9): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x2082): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x24e5): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x274b): undefined reference to `__imp_htons'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x2787): undefined reference to `__imp_htonl'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x74a1): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x990a): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x9f0c): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0xa38a): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x14e78): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x15b47): undefined reference to `__imp_htonl'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x15d28): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x1f874): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x1f8cb): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x2e2fe): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x31f18): undefined reference to `__imp_ntohs'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x412a9): undefined reference to `__imp_htonl'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x42109): undefined reference to `__imp_htonl'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x42438): undefined reference to `__imp_ntohl'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x435ac): undefined reference to `__imp_htons'
P:tmpwin_tempcctkYQ0z.o:dcraw.c:(.text+0x43783): undefined reference to `__imp_ntohl'
e:/strawberry.perl/c/bin/../lib/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: P:tmpwin_tempcctkYQ0z.o: bad reloc address 0x0 in section `.pdata'
collect2.exe: error: ld returned 1 exit status


Source: gcc

Leave a Reply