@@ -2051,32 +2051,31 @@ PartialSection *Writer::findPartialSection(StringRef name, uint32_t outChars) {
2051
2051
}
2052
2052
2053
2053
void Writer::fixTlsAlignment () {
2054
- if (Symbol *sym = symtab->findUnderscore (" _tls_used" )) {
2055
- if (Defined *b = dyn_cast<Defined>(sym)) {
2056
- OutputSection *sec = b->getChunk ()->getOutputSection ();
2057
- assert (sec && b->getRVA () >= sec->getRVA () &&
2058
- " no output section for _tls_used" );
2059
-
2060
- uint8_t *secBuf = buffer->getBufferStart () + sec->getFileOff ();
2061
- uint64_t tlsOffset = b->getRVA () - sec->getRVA ();
2062
- uint64_t directorySize = config->is64 ()
2063
- ? sizeof (object::coff_tls_directory64)
2064
- : sizeof (object::coff_tls_directory32);
2065
-
2066
- if (tlsOffset + directorySize > sec->getRawSize ())
2067
- fatal (" _tls_used is malformed" );
2068
-
2069
- if (config->is64 ()) {
2070
- object::coff_tls_directory64 *tlsDir =
2071
- reinterpret_cast <object::coff_tls_directory64 *>(
2072
- &secBuf[tlsOffset]);
2073
- tlsDir->setAlignment (tlsAlignment);
2074
- } else {
2075
- object::coff_tls_directory32 *tlsDir =
2076
- reinterpret_cast <object::coff_tls_directory32 *>(
2077
- &secBuf[tlsOffset]);
2078
- tlsDir->setAlignment (tlsAlignment);
2079
- }
2080
- }
2054
+ Defined *tlsSym =
2055
+ dyn_cast_or_null<Defined>(symtab->findUnderscore (" _tls_used" ));
2056
+ if (!tlsSym)
2057
+ return ;
2058
+
2059
+ OutputSection *sec = tlsSym->getChunk ()->getOutputSection ();
2060
+ assert (sec && tlsSym->getRVA () >= sec->getRVA () &&
2061
+ " no output section for _tls_used" );
2062
+
2063
+ uint8_t *secBuf = buffer->getBufferStart () + sec->getFileOff ();
2064
+ uint64_t tlsOffset = tlsSym->getRVA () - sec->getRVA ();
2065
+ uint64_t directorySize = config->is64 ()
2066
+ ? sizeof (object::coff_tls_directory64)
2067
+ : sizeof (object::coff_tls_directory32);
2068
+
2069
+ if (tlsOffset + directorySize > sec->getRawSize ())
2070
+ fatal (" _tls_used is malformed" );
2071
+
2072
+ if (config->is64 ()) {
2073
+ object::coff_tls_directory64 *tlsDir =
2074
+ reinterpret_cast <object::coff_tls_directory64 *>(&secBuf[tlsOffset]);
2075
+ tlsDir->setAlignment (tlsAlignment);
2076
+ } else {
2077
+ object::coff_tls_directory32 *tlsDir =
2078
+ reinterpret_cast <object::coff_tls_directory32 *>(&secBuf[tlsOffset]);
2079
+ tlsDir->setAlignment (tlsAlignment);
2081
2080
}
2082
- }
2081
+ }
0 commit comments