Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2007-05

x86_64 linking issue (2.1.4)

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alan Krause

I posted a similar email to the fpc-pascal mailing list, but I am guessing that since the issue is somewhat complex, someone on this list might have a better understanding of what the underlying issue might be.

I have successfully ported a Delphi DLL to a compiled shared library under 32-bit linux using free pascal, and it works wonderfully. Yesterday, I decided to try and port it over to the x86_64 architecture on linux.

For the most part, everything went smoothly - there was a small issue which I resolved using PtrInt instead of integer, and all units now compile.

The problem arises when the linker attempts to put all the pieces together into one .so :

/usr/bin/ld: uCUNASP_CLCalc.o: relocation R_X86_64_32S against `U_UCUNASP_CLCALC_CUNASPCLSET' can not be used when making a shared object; recompile with -fPIC
uCUNASP_CLCalc.o: could not read symbols: Bad value

I have successfully created a shared library, so it is not an -fPIC issue (I think, and am compiling with the -Cg flag as well).

The CUNASPCLSET refers to a public unit-wide variable (a custom record type). If I redeclare the record type as an object and dynamically create the variable in the unit's initialization section (and free it up on finalization), then the error disappears, and a similar issue pops up with another record type in a different unit - I have also seen a similar error appear with a unit level array [0..10] of double.

Again - the code works fine on 32-bit linux, but not for x86_64. Does anyone have any ideas?

Thanks much,
Alan Krause

Reply by email

Jonas Maebe
to Alan Krause
Alan Krause wrote 21 lines
The problem arises when the linker attempts to put all the pieces together into one .so : /usr/bin/ld: uCUNASP_CLCalc.o: relocation R_X86_64_32S against `U_UCUNASP_CLCALC_CUNASPCLSET' can not be used when making a shared object; recompile with -fPIC uCUNASP_CLCalc.o: could not read symbols: Bad value I have successfully created a shared library, so it is not an -fPIC issue (I think, and am compiling with the -Cg flag as well). The CUNASPCLSET refers to a public unit-wide variable (a custom record type). If I redeclare the record type as an object and dynamically create the variable in the unit's initialization section (and free it up on finalization), then the error disappears, and a similar issue pops up with another record type in a different unit - I have also seen a similar error appear with a unit level array [0..10] of double. Again - the code works fine on 32-bit linux, but not for x86_64. Does anyone have any ideas?

It's a bug in the compiler. Please submit a bug report with a compilable sample that demonstrates the problem.

Jonas

Reply by email

Alan Krause
to Jonas Maebe
Jonas Maebe wrote
It's a bug in the compiler. Please submit a bug report with a compilable sample that demonstrates the problem.

Jonas,

Thanks much for the reply. I will submit a bug report ASAP. I spent most of the morning trying to simplify the error case, and came up with the following:

---

library project1;
uses
Classes;
function dRound(iDec: integer; dRate: double): double;
const
   TenToPower: Array[0..9] of integer = (1, 10, 100, 1000, 10000, 100000,
                                         1000000, 10000000, 100000000,
1000000000);
var
   dInc : double;
begin
   if iDec > 0 then begin
      dInc := 0.5000001;
      result := trunc (dRate * (TenToPower [iDec]) + dInc) /
         TenToPower [iDec];
   end else begin
      result := dRate;
   end ;
end;
function one : double; cdecl;
begin
   Result := dRound( 2, 0.529 ) ;
end;

---

Trying to compile this under fpc 2.1.4 on x86_64 via "fpc -Sd proj.pas" gives me the following results:

Compiling proj.pas
Linking libproj.so
/usr/bin/ld: proj.o: relocation R_X86_64_32S against `TC_P$PROJECT1_DROUND$LONGINT$TROUNDTYPE$DOUBLE$$DOUBLE_TENTOPOWER' can not be used when making a shared object; recompile with -fPIC proj.o: could not read symbols: Bad value

I'll sign up for an account and post the ticket now.

Thanks much,
Alan

Reply by email