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

Mark OPENSSL_armcap_P .hidden in arm asm #22181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

dg0yt
Copy link
Contributor

@dg0yt dg0yt commented Sep 23, 2023

Fixes #21583 (comment):

ld: error: relocation R_ARM_REL32 cannot be used against symbol 'OPENSSL_armcap_P'; recompile with -fPIC

when linking a static build of openssl to a shared library for 32 bit arm on Android,
since #21583.

This source change has one observable change in readelf output (e.g. for crypto/sha/libcrypto-lib-sha512-armv4.o):

 Symbol table '.symtab' contains 12 entries:
    Num:    Value  Size Type    Bind   Vis      Ndx Name
      0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
      1: 00000000     0 SECTION LOCAL  DEFAULT    2 
      2: 00000000   640 OBJECT  LOCAL  DEFAULT    2 K512
      3: 00000000     0 NOTYPE  LOCAL  DEFAULT    2 $d.0
      4: 000002a0     0 NOTYPE  LOCAL  DEFAULT    2 $t.1
      5: 0000183a     0 NOTYPE  LOCAL  DEFAULT    2 $d.2
      6: 00000000     0 SECTION LOCAL  DEFAULT    6 
      7: 00000000     0 SECTION LOCAL  DEFAULT    8 
      8: 00000000     0 SECTION LOCAL  DEFAULT   11 
-     9: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND OPENSSL_armcap_P
+     9: 00000000     0 NOTYPE  GLOBAL HIDDEN   UND OPENSSL_armcap_P
     10: 000002a1  1134 FUNC    GLOBAL DEFAULT    2 sha512_block_data_order
     11: 00000711  4394 FUNC    GLOBAL DEFAULT    2 sha512_block_data_order_n
 

This change was automated using

sed -e '/[.]hidden.*OPENSSL_armcap_P/d; /[.]extern.*OPENSSL_armcap_P/ {p; s/extern/hidden/ }' -i -- crypto/*arm*pl crypto/*/asm/*arm*pl

with the filepath patterns derived from #21583.

@dg0yt
Copy link
Contributor Author

dg0yt commented Sep 23, 2023

More reading:
Commit message in google/boringssl@16e38b2.
android/ndk#191.

@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Sep 23, 2023
@@ -293,6 +293,7 @@
#endif

.extern OPENSSL_armcap_P
.hidden OPENSSL_armcap_P
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than making an identical change in every Perl-asm file, and then requiring this same pairing in every new Perl-asm that gets added in the future, wouldn't it be better to have arm-xlate.pl apply this directly? (At least, that's the way I've been looking at fixing this)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say much about openssl's perl asm stuff.
First, it should be validated that .hidden is the right thing here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this isn't what BoringSSL has anyway - they still have .comm rather than .extern. One of our recent-ish changes made that here, but I am now revisiting whether that was the best thing to do, as arm-xlate.pl actually removes the .extern altogether, but .comm keeps it in

@kroeckx
Copy link
Member

kroeckx commented Sep 25, 2023 via email

@talregev
Copy link

talregev commented Oct 3, 2023

@t8m
Any news?

@tom-cosgrove-arm
Copy link
Contributor

I am looking at this (slowly, sorry)

@t8m t8m added branch: master Merge to master branch approval: review pending This pull request needs review by a committer approval: otc review pending This pull request needs review by an OTC member triaged: bug The issue/pr is/fixes a bug branch: 3.0 Merge to openssl-3.0 branch branch: 3.1 Merge to openssl-3.1 tests: exempted The PR is exempt from requirements for testing labels Oct 9, 2023
@BillyONeal
Copy link

@tom-cosgrove-arm @t8m Given those tags just added does that mean this solution is acceptable to the OpenSSL maintainers? (I'm trying to confirm that it's safe to merge @dg0yt 's patch of this in vcpkg)

@tom-cosgrove-arm
Copy link
Contributor

tom-cosgrove-arm commented Oct 10, 2023

@BillyONeal I don't think the final fix will look like this, but not sure exactly what it should be at the moment. This is now top of my OpenSSL list, though

(The reason I don't think the final fix will look like this is at a minimum the duplication, and I think the fix will need something in arm-xlate.pl too)

@t8m t8m removed approval: review pending This pull request needs review by a committer approval: otc review pending This pull request needs review by an OTC member labels Oct 10, 2023
@BillyONeal
Copy link

@tom-cosgrove-arm OK, thanks, I'll drop this from daily checks. Please poke me when this is fixed if you remember :)

@kroeckx
Copy link
Member

kroeckx commented Oct 11, 2023 via email

@BillyONeal
Copy link

I see no problem with the patch as is

As in, it passes for the platforms vcpkg ships to but there are others that openssl cares about perl scripts or something like that, so I should merge @dg0yt's PR?

@tom-cosgrove-arm
Copy link
Contributor

As it stands, this patch would require us to add .hidden every time we add a new assembler file - specifically, to remember to do that. That's not good for maintainability - it will just cause this issue to recur every now and them. Moreover, I don't understand why this patch works - declaring the variable .extern should be sufficient. However, the xlate script removes .extern for unknown reasons, and that doesn't seem right either. Hence: doing more investigations to understand the root cause, rather than adding a workaround

@talregev
Copy link

@tom-cosgrove-arm We just want to know if the current change is safe to merge in vcpkg side. meaning everytime that someone will use vcpkg openssl with this patch it will work correctly and it will be safe to use.
When you find long term solution and it will be in different PR or / and it will be on the next version, when vcpkg will update the openssl next version it will take the long term solution with the new version / new commit.

Thank you for your time.

@dg0yt
Copy link
Contributor Author

dg0yt commented Oct 13, 2023

However, the xlate script removes .extern for unknown reasons, and that doesn't seem right either.

Can you verify this? I don't see in the script, and I don't see the effect in the build dir. E.g.:

buildtrees/openssl/arm-neon-android-dbg/crypto/sha/sha512-armv4.S:.extern       OPENSSL_armcap_P
buildtrees/openssl/arm-neon-android-dbg/crypto/sha/sha512-armv4.S:.hidden       OPENSSL_armcap_P

And IIUC, OPENSSL_armcap_P would be undeclared without .extern.

@kroeckx
Copy link
Member

kroeckx commented Oct 13, 2023

As the linker complains, the code is not position independent code (PIC). With a symbol that's exported, the dynamic linker needs to be able to support replacing the symbol by one from an other library (or executable). To be able to do that, the code needs to be PIC, and you'll get a different relocation type. So there are a few solutions:

  • Don't export the symbol. This can be done by marking it hidden. The linker will then know no other library can replace it, and it doesn't need to be PIC.
  • Rewrite the code to be PIC.
  • Tell the linker it doesn't need to support replacing the symbol, by building the shared library using -Bsymbolic.

@kroeckx
Copy link
Member

kroeckx commented Oct 17, 2023 via email

@t8m
Copy link
Member

t8m commented Oct 18, 2023

The problem is now independently reported in #22414

@Eimji
Copy link

Eimji commented Oct 26, 2023

Hello

I tried the fix here, it works, I can compile openssl for my Android application.

Thanks.

@t8m t8m added branch: 3.2 Merge to openssl-3.2 branch: 3.0 Merge to openssl-3.0 branch and removed branch: 3.0 Merge to openssl-3.0 branch labels Oct 26, 2023
@dg0yt
Copy link
Contributor Author

dg0yt commented Oct 26, 2023

Is the fix to a present problem still blocked by concerns about files which might be added in the future?
Isn't it possible to verify whether "the xlate script removes .extern"?

@dg0yt
Copy link
Contributor Author

dg0yt commented Nov 21, 2023

Still waiting.

@dg0yt
Copy link
Contributor Author

dg0yt commented Dec 6, 2023

I am looking at this (slowly, sorry)

Any progress?

@talregev
Copy link

talregev commented Dec 6, 2023

@t8m Are you going to respond on this issue?
Not solving this issue is also a respond.

@dg0yt
Copy link
Contributor Author

dg0yt commented Dec 6, 2023

@talregev Please don't put oil on the fire.

@tom-cosgrove-arm
Copy link
Contributor

Yes, still looking at it. The issue recently fixed by #22880 meant that some of the changes we made to the handling of OPENSSL_armcap_P could be rolled back, so I am looking at doing that as an option

@t8m t8m linked an issue Dec 6, 2023 that may be closed by this pull request
Fsu0413 added a commit to Fsu0413/openssl-externalCMake that referenced this pull request Dec 11, 2023
see openssl/openssl#22181 (comment)

We only apply it to arm32 since it causes unwanted effects

Signed-off-by: Fs <Fsu0413@vip.qq.com>
Fsu0413 added a commit to Fsu0413/openssl-externalCMake that referenced this pull request Dec 11, 2023
see openssl/openssl#22181 (comment)

We only apply it to arm32 since it causes unwanted effects

Signed-off-by: Fs <Fsu0413@vip.qq.com>
@dg0yt
Copy link
Contributor Author

dg0yt commented Jan 24, 2024

Another six weeks. Why contribute at all.

@t8m
Copy link
Member

t8m commented Jan 24, 2024

@tom-cosgrove-arm any progress on this?

@ospfranco
Copy link

ospfranco commented Jan 24, 2024

Facing this issue. Seems there is no possible workaround at the moment. Is there anything that can be done to merge this faster? Is sponsoring possible?

I've also created an issue on the NDK repo in hopes of finding a workaround.

At least in my use case, openSSL is being compiled as a subdependency from Rust, so I cannot apply this changes directly I believe.

@dg0yt
Copy link
Contributor Author

dg0yt commented Mar 10, 2024

Spring 2024.

@t8m
Copy link
Member

t8m commented Mar 12, 2024

@tom-cosgrove-arm ping?

@tom-cosgrove-arm
Copy link
Contributor

Yes, sorry, won't be this week, but still on my radar

@dg0yt
Copy link
Contributor Author

dg0yt commented May 5, 2024

May 2024.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch: master Merge to master branch branch: 3.0 Merge to openssl-3.0 branch branch: 3.1 Merge to openssl-3.1 branch: 3.2 Merge to openssl-3.2 severity: fips change The pull request changes FIPS provider sources tests: exempted The PR is exempt from requirements for testing triaged: bug The issue/pr is/fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trying to cross compile 3.1.3 against Python
8 participants